[BACK]Return to getplay.c CVS log [TXT][DIR] Up to [contributed] / early-roguelike / urogue

Annotation of early-roguelike/urogue/getplay.c, Revision 1.1

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

CVSweb