Mercurial > hg > early-roguelike
comparison urogue/getplay.c @ 256:c495a4f288c6
Import UltraRogue from the Roguelike Restoration Project (r1490)
| author | John "Elwin" Edwards |
|---|---|
| date | Tue, 31 Jan 2017 19:56:04 -0500 |
| parents | |
| children | 778938a5c21d |
comparison
equal
deleted
inserted
replaced
| 253:d9badb9c0179 | 256:c495a4f288c6 |
|---|---|
| 1 /* | |
| 2 getplay.c - Procedures for saving and retrieving a characters starting | |
| 3 attributes, armour, and weapon. | |
| 4 | |
| 5 UltraRogue: The Ultimate Adventure in the Dungeons of Doom | |
| 6 Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong | |
| 7 All rights reserved. | |
| 8 | |
| 9 See the file LICENSE.TXT for full copyright and licensing information. | |
| 10 */ | |
| 11 | |
| 12 /* 11/08/83 ???, S.A. Hester */ | |
| 13 | |
| 14 #include <stdlib.h> | |
| 15 #include <ctype.h> | |
| 16 #include <string.h> | |
| 17 #include "rogue.h" | |
| 18 | |
| 19 #define I_STR 0 | |
| 20 #define I_INTEL 1 | |
| 21 #define I_WISDOM 2 | |
| 22 #define I_DEXT 3 | |
| 23 #define I_CONST 4 | |
| 24 #define I_CHARISMA 5 | |
| 25 #define I_HPT 6 | |
| 26 #define I_POWER 7 | |
| 27 #define I_CTYPE 8 | |
| 28 #define MAXPATT 9 /* Total Number of above defines. */ | |
| 29 #define MAXPDEF 10 /* Maximum number of pre-defined chars */ | |
| 30 | |
| 31 static int def_array[MAXPDEF][MAXPATT]; /* Pre-def'd chars */ | |
| 32 | |
| 33 static void get_chr_filename(char *filename, int size) | |
| 34 { | |
| 35 const char *home; | |
| 36 | |
| 37 home = getenv("HOME"); | |
| 38 | |
| 39 if (home) { | |
| 40 if ((int)strlen(home) < (size - 12) ) | |
| 41 { | |
| 42 strcpy(filename, home); | |
| 43 strcat(filename,"/urogue.chr"); | |
| 44 } | |
| 45 else | |
| 46 strncpy(filename,"urogue.chr",size); | |
| 47 } | |
| 48 else | |
| 49 strcpy(filename, "urogue.chr"); | |
| 50 } | |
| 51 | |
| 52 int | |
| 53 geta_player(void) | |
| 54 { | |
| 55 int i; | |
| 56 FILE *fd; | |
| 57 char pbuf[2 * LINELEN]; | |
| 58 char filename[200]; | |
| 59 | |
| 60 get_chr_filename(filename, sizeof(filename)); | |
| 61 | |
| 62 if ((fd = fopen(filename, "r")) == NULL) | |
| 63 return(FALSE); | |
| 64 | |
| 65 fread(def_array, sizeof(def_array), 1, fd); | |
| 66 fclose(fd); | |
| 67 | |
| 68 wclear(hw); | |
| 69 touchwin(hw); | |
| 70 | |
| 71 print_stored(); | |
| 72 mvwaddstr(hw, 0, 0, "Do you wish to select a character? "); | |
| 73 wrefresh(hw); | |
| 74 | |
| 75 if (readcharw(hw) != 'y') | |
| 76 return FALSE; | |
| 77 | |
| 78 do | |
| 79 { | |
| 80 wmove(hw, LINES - 1, 0); | |
| 81 wclrtoeol(hw); | |
| 82 mvwaddstr(hw, 0, 0, "Enter the number of a pre-defined character: "); | |
| 83 wclrtoeol(hw); | |
| 84 wrefresh(hw); | |
| 85 get_string(pbuf, hw); | |
| 86 i = atoi(pbuf) - 1; | |
| 87 | |
| 88 if (i < 0 || i > MAXPDEF - 1) | |
| 89 { | |
| 90 wstandout(hw); | |
| 91 mvwaddstr(hw, 1, 0, "Please use the range 1 to"); | |
| 92 wprintw(hw, " %d.", MAXPDEF); | |
| 93 wstandend(hw); | |
| 94 wclrtoeol(hw); | |
| 95 wrefresh(hw); | |
| 96 } | |
| 97 else if (def_array[i][I_STR] == 0) | |
| 98 { | |
| 99 wstandout(hw); | |
| 100 mvwaddstr(hw,1,0,"Please enter the number of a known character: "); | |
| 101 wstandend(hw); | |
| 102 wclrtoeol(hw); | |
| 103 } | |
| 104 else | |
| 105 { | |
| 106 mvwaddstr(hw, 1, 0, ""); | |
| 107 wclrtoeol(hw); | |
| 108 } | |
| 109 | |
| 110 } | |
| 111 while (i < 0 || i > MAXPDEF - 1 || (def_array[i][I_STR] == 0)); | |
| 112 | |
| 113 pstats.s_str = def_array[i][I_STR]; | |
| 114 pstats.s_intel = def_array[i][I_INTEL]; | |
| 115 pstats.s_wisdom = def_array[i][I_WISDOM]; | |
| 116 pstats.s_dext = def_array[i][I_DEXT]; | |
| 117 pstats.s_const = def_array[i][I_CONST]; | |
| 118 pstats.s_charisma = def_array[i][I_CHARISMA]; | |
| 119 pstats.s_hpt = def_array[i][I_HPT]; | |
| 120 pstats.s_power = def_array[i][I_POWER]; | |
| 121 player.t_ctype = char_type = def_array[i][I_CTYPE]; | |
| 122 max_stats = pstats; | |
| 123 | |
| 124 return(TRUE); | |
| 125 } | |
| 126 | |
| 127 void | |
| 128 puta_player(void) | |
| 129 { | |
| 130 FILE *fd; | |
| 131 char pbuf[2 * LINELEN]; | |
| 132 char filename[200]; | |
| 133 int i; | |
| 134 char *class = which_class(player.t_ctype); | |
| 135 | |
| 136 sprintf(pbuf, "You have a %s with the following attributes:", class); | |
| 137 mvwaddstr(hw, 2, 0, pbuf); | |
| 138 wclrtoeol(hw); | |
| 139 | |
| 140 sprintf(pbuf, | |
| 141 "Int: %d Str: %d Wis: %d Dex: %d Con: %d Cha: %d Pow: %d Hpt: %d", | |
| 142 pstats.s_intel, | |
| 143 pstats.s_str, | |
| 144 pstats.s_wisdom, | |
| 145 pstats.s_dext, | |
| 146 pstats.s_const, | |
| 147 pstats.s_charisma, | |
| 148 pstats.s_power, | |
| 149 pstats.s_hpt ); | |
| 150 | |
| 151 mvwaddstr(hw, 3, 0, ""); | |
| 152 wclrtoeol(hw); | |
| 153 mvwaddstr(hw, 4, 0, pbuf); | |
| 154 wclrtoeol(hw); | |
| 155 mvwaddstr(hw, 5, 0, ""); | |
| 156 wclrtoeol(hw); | |
| 157 mvwaddstr(hw, 0, 0, "Would you like to save this character?"); | |
| 158 wclrtoeol(hw); | |
| 159 | |
| 160 | |
| 161 wrefresh(hw); | |
| 162 | |
| 163 if ((readcharw(hw) & 0177) != 'y') | |
| 164 return; | |
| 165 | |
| 166 do | |
| 167 { | |
| 168 mvwaddstr(hw, 0, 0, "Overwrite which number? "); | |
| 169 wclrtoeol(hw); | |
| 170 wrefresh(hw); | |
| 171 get_string(pbuf, hw); | |
| 172 i = atoi(pbuf) - 1; | |
| 173 | |
| 174 if (i < 0 || i > MAXPDEF - 1) | |
| 175 { | |
| 176 wstandout(hw); | |
| 177 mvwaddstr(hw, 1, 0, "Use the range 1 to"); | |
| 178 wprintw(hw, " %d!", MAXPDEF); | |
| 179 wstandend(hw); | |
| 180 wclrtoeol(hw); | |
| 181 wrefresh(hw); | |
| 182 } | |
| 183 } | |
| 184 while (i < 0 || i > MAXPDEF - 1); | |
| 185 | |
| 186 /* Set some global stuff */ | |
| 187 | |
| 188 def_array[i][I_STR] = pstats.s_str; | |
| 189 def_array[i][I_INTEL] = pstats.s_intel; | |
| 190 def_array[i][I_WISDOM] = pstats.s_wisdom; | |
| 191 def_array[i][I_DEXT] = pstats.s_dext; | |
| 192 def_array[i][I_CONST] = pstats.s_const; | |
| 193 def_array[i][I_CHARISMA] = pstats.s_charisma; | |
| 194 def_array[i][I_HPT] = pstats.s_hpt; | |
| 195 def_array[i][I_POWER] = pstats.s_power; | |
| 196 def_array[i][I_CTYPE] = player.t_ctype; | |
| 197 | |
| 198 /* OK. Now let's write this stuff out! */ | |
| 199 | |
| 200 get_chr_filename(filename, sizeof(filename)); | |
| 201 | |
| 202 | |
| 203 if ((fd = fopen(filename, "w")) == NULL) | |
| 204 { | |
| 205 sprintf(pbuf, "I can't seem to open/create urogue.chr."); | |
| 206 mvwaddstr(hw, 5, 5, pbuf); | |
| 207 mvwaddstr(hw, 6, 5, "However I'll let you play it anyway!"); | |
| 208 mvwaddstr(hw, LINES - 1, 0, spacemsg); | |
| 209 wrefresh(hw); | |
| 210 wait_for(' '); | |
| 211 | |
| 212 return; | |
| 213 } | |
| 214 | |
| 215 fwrite(def_array, sizeof(def_array), 1, fd); | |
| 216 fclose(fd); | |
| 217 return; | |
| 218 } | |
| 219 | |
| 220 void | |
| 221 do_getplayer(void) | |
| 222 { | |
| 223 print_stored(); | |
| 224 | |
| 225 if (char_type == C_NOTSET) | |
| 226 do | |
| 227 { | |
| 228 /* See what type character will be */ | |
| 229 | |
| 230 mvwaddstr(hw, 3, 0, "[a] Fighter\t" | |
| 231 "[b] Paladin\t" | |
| 232 "[c] Ranger\n" | |
| 233 "[d] Cleric\t" | |
| 234 "[e] Druid\t" | |
| 235 "[f] Magician\n" | |
| 236 "[g] Illusionist\t" | |
| 237 "[h] Thief\t" | |
| 238 "[i] Assasin\t" | |
| 239 "[j] Ninja"); | |
| 240 | |
| 241 mvwaddstr(hw, 0, 0, "What character class do you desire? "); | |
| 242 wrefresh(hw); | |
| 243 char_type = readcharw(hw) - 'a'; | |
| 244 | |
| 245 if (char_type < C_FIGHTER || char_type >= C_MONSTER) | |
| 246 { | |
| 247 wstandout(hw); | |
| 248 mvwaddstr(hw, 1, 0, "Please enter a letter from a - j"); | |
| 249 wstandend(hw); | |
| 250 wclrtoeol(hw); | |
| 251 wrefresh(hw); | |
| 252 } | |
| 253 else | |
| 254 { | |
| 255 mvwaddstr(hw, 1, 0, ""); | |
| 256 wclrtoeol(hw); | |
| 257 } | |
| 258 } | |
| 259 while (char_type < C_FIGHTER || char_type >= C_MONSTER); | |
| 260 | |
| 261 player.t_ctype = char_type; | |
| 262 } | |
| 263 | |
| 264 void | |
| 265 print_stored(void) | |
| 266 { | |
| 267 int i; | |
| 268 char *class; | |
| 269 char pbuf[2 * LINELEN]; | |
| 270 | |
| 271 wstandout(hw); | |
| 272 mvwaddstr(hw, 9, 0, "YOUR CURRENT CHARACTERS:"); | |
| 273 wstandend(hw); | |
| 274 wclrtoeol(hw); | |
| 275 | |
| 276 for (i = 0; i < MAXPDEF; i++) | |
| 277 { | |
| 278 if (def_array[i][I_STR]) | |
| 279 { | |
| 280 class = which_class(def_array[i][I_CTYPE]); | |
| 281 | |
| 282 sprintf(pbuf, | |
| 283 "%2d. (%s): Int: %d Str: %d Wis: %d Dex: %d Con: %d Cha: %d" | |
| 284 " Pow: %d Hpt: %d", | |
| 285 i + 1, | |
| 286 class, | |
| 287 def_array[i][I_INTEL], | |
| 288 def_array[i][I_STR], | |
| 289 def_array[i][I_WISDOM], | |
| 290 def_array[i][I_DEXT], | |
| 291 def_array[i][I_CONST], | |
| 292 def_array[i][I_CHARISMA], | |
| 293 def_array[i][I_POWER], | |
| 294 def_array[i][I_HPT]); | |
| 295 | |
| 296 mvwaddstr(hw, 11 + i, 0, pbuf); | |
| 297 | |
| 298 } | |
| 299 else | |
| 300 { | |
| 301 sprintf(pbuf, "%2d. ### NONE ###", i + 1); | |
| 302 mvwaddstr(hw, 11 + i, 0, pbuf); | |
| 303 } | |
| 304 } | |
| 305 } | |
| 306 | |
| 307 char * | |
| 308 which_class(int c_class) | |
| 309 { | |
| 310 char *class; | |
| 311 | |
| 312 switch (c_class) | |
| 313 { | |
| 314 case C_FIGHTER: | |
| 315 class = "Fighter"; | |
| 316 break; | |
| 317 case C_MAGICIAN: | |
| 318 class = "Magician"; | |
| 319 break; | |
| 320 case C_CLERIC: | |
| 321 class = "Cleric"; | |
| 322 break; | |
| 323 case C_THIEF: | |
| 324 class = "Thief"; | |
| 325 break; | |
| 326 case C_PALADIN: | |
| 327 class = "Paladin"; | |
| 328 break; | |
| 329 case C_RANGER: | |
| 330 class = "Ranger"; | |
| 331 break; | |
| 332 case C_DRUID: | |
| 333 class = "Druid"; | |
| 334 break; | |
| 335 case C_ILLUSION: | |
| 336 class = "Illusionist"; | |
| 337 break; | |
| 338 case C_ASSASIN: | |
| 339 class = "Assasin"; | |
| 340 break; | |
| 341 case C_NINJA: | |
| 342 class = "Ninja"; | |
| 343 break; | |
| 344 default: | |
| 345 class = "Monster"; | |
| 346 break; | |
| 347 } | |
| 348 | |
| 349 return (class); | |
| 350 } |
