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

Annotation of early-roguelike/srogue/pstats.c, Revision 1.1.1.1

1.1       rubenllo    1: /*
                      2:  * Players status routines
                      3:  *
                      4:  * @(#)pstats.c        9.0     (rdk)    7/17/84
                      5:  *
                      6:  * Super-Rogue
                      7:  * Copyright (C) 1984 Robert D. Kindelberger
                      8:  * All rights reserved.
                      9:  *
                     10:  * See the file LICENSE.TXT for full copyright and licensing information.
                     11:  */
                     12:
                     13: #include "rogue.h"
                     14: #include "rogue.ext"
                     15:
                     16: void updabil(int what, int amt, struct real *pst, int how);
                     17: int hungdam(void);
                     18:
                     19: /*
                     20:  * chg_hpt:
                     21:  *     Changes players hit points
                     22:  */
                     23: void
                     24: chg_hpt(int howmany, bool alsomax, char what)
                     25: {
                     26:        nochange = FALSE;
                     27:        if(alsomax)
                     28:                him->s_maxhp += howmany;
                     29:        him->s_hpt += howmany;
                     30:        if (him->s_hpt < 1) {
                     31:                msg(" ");
                     32:                death(what);
                     33:        }
                     34: }
                     35:
                     36:
                     37: /*
                     38:  * rchg_str:
                     39:  *     Update the players real strength
                     40:  */
                     41: void
                     42: rchg_str(int amt)
                     43: {
                     44:        chg_abil(STR,amt,TRUE);
                     45: }
                     46:
                     47: /*
                     48:  * chg_abil:
                     49:  *     Used to modify the hero's abilities
                     50:  */
                     51: void
                     52: chg_abil(int what, int amt, int how)
                     53: {
                     54:        if (amt == 0)
                     55:                return;
                     56:        if (how == TRUE) {                      /* real (must be 1st) */
                     57:                updabil(what,amt,&pstats.s_re,TRUE);
                     58:                how = FALSE;
                     59:        }
                     60:        updabil(what,amt,&pstats.s_ef,how);     /* effective */
                     61:        updpack();
                     62:        wghtchk(FALSE);
                     63: }
                     64:
                     65: /*
                     66:  * updabil:
                     67:  *     Do the actual abilities updating
                     68:  */
                     69: void
                     70: updabil(int what, int amt, struct real *pst, int how)
                     71: {
                     72:        register int *wh, *mx, *mr;
                     73:        struct real *mst, *msr;
                     74:        bool is_str = FALSE;
                     75:        int rtype;
                     76:
                     77:        msr = &him->s_re;
                     78:        if (how == TRUE)                                /* max real abilities */
                     79:                mst = &max_stats.s_re;
                     80:        else                                                    /* max effective abil */
                     81:                mst = &max_stats.s_ef;
                     82:        switch (what) {
                     83:                case STR:
                     84:                        is_str = TRUE;
                     85:                        wh = &pst->a_str;
                     86:                        mx = &mst->a_str;
                     87:                        mr = &msr->a_str;
                     88:                        rtype = R_ADDSTR;
                     89:                when DEX:
                     90:                        wh = &pst->a_dex;
                     91:                        mx = &mst->a_dex;
                     92:                        mr = &msr->a_dex;
                     93:                        rtype = R_DEX;
                     94:                when CON:
                     95:                        wh = &pst->a_con;
                     96:                        mx = &mst->a_con;
                     97:                        mr = &msr->a_con;
                     98:                        rtype = R_CONST;
                     99:                when WIS:
                    100:                        wh = &pst->a_wis;
                    101:                        mx = &mst->a_wis;
                    102:                        mr = &msr->a_wis;
                    103:                        rtype = R_KNOW;
                    104:                otherwise:
                    105:                        return;
                    106:        }
                    107:        *wh += amt;                                             /* update by amt */
                    108:        if (amt < 0) {                                  /* if decrement */
                    109:                if (*wh < MINABIL)                      /* minimum = 3 */
                    110:                        *wh = MINABIL;
                    111:                if (how == FALSE) {
                    112:                        if (*wh < *mr)                  /* if less than real abil */
                    113:                                *wh = *mr;                      /* make equal to real */
                    114:                }
                    115:        }
                    116:        else {                                                  /* increment */
                    117:                int themax;
                    118:
                    119:                themax = MAXOTHER;                              /* default maximum */
                    120:                if (is_str)
                    121:                        themax = MAXSTR;                        /* strength maximum */
                    122:                if (how != TRUE)
                    123:                        themax += ringex(rtype);        /* get ring extra */
                    124:                if (*wh > themax) {                             /* see if > max (if real) */
                    125:                        *wh = themax;                           /* max = 18  (24 if str) */
                    126:                }
                    127:                /*
                    128:                 * Check for updating the max player stats.
                    129:                 */
                    130:                if (*wh > *mx)
                    131:                        *mx = *wh;
                    132:        }
                    133: }
                    134:
                    135:
                    136: /*
                    137:  * add_haste:
                    138:  *     add a haste to the player
                    139:  */
                    140: void
                    141: add_haste(bool potion)
                    142: {
                    143:        if (pl_on(ISHASTE)) {
                    144:                msg("You faint from exhaustion.");
                    145:                player.t_nocmd += rnd(8);
                    146:                player.t_flags &= ~ISHASTE;
                    147:                extinguish(nohaste);
                    148:        }
                    149:        else {
                    150:                player.t_flags |= ISHASTE;
                    151:                if (potion) {
                    152:                        fuse(nohaste, TRUE, roll(10,10));
                    153:                        msg("You feel yourself moving much faster.");
                    154:                }
                    155:                else {
                    156:                        fuse(nohaste, TRUE, roll(40,20));
                    157:                        msg("You find yourself moving much faster.");
                    158:                }
                    159:        }
                    160: }
                    161:
                    162: /*
                    163:  * getpdex:
                    164:  *     Gets players added dexterity for fighting
                    165:  */
                    166: int
                    167: getpdex(struct stats *who, bool heave)
                    168: {
                    169:        reg int edex;
                    170:
                    171:        edex = who->s_ef.a_dex;
                    172:        if (heave) {                            /* an object was thrown here */
                    173:                if (edex > 18)
                    174:                        return (edex - 15);
                    175:                switch(edex) {
                    176:                        case 18: return 3;
                    177:                        case 17: return 2;
                    178:                        case 16: return 1;
                    179:                        case 15:
                    180:                        case 14:
                    181:                        case 13:
                    182:                        case 12:
                    183:                        case 11:
                    184:                        case 10:
                    185:                        case 9:
                    186:                        case 8:
                    187:                        case 7:
                    188:                        case 6: return 0;
                    189:                        case 5: return -1;
                    190:                        case 4: return -2;
                    191:                        default: return -3;
                    192:                }
                    193:        }
                    194:        else {          /* object NOT thrown here (affects armor class) */
                    195:                if (edex > 18)
                    196:                        return (14 - edex);
                    197:                switch(edex) {
                    198:                        case 18: return -4;
                    199:                        case 17: return -3;
                    200:                        case 16: return -2;
                    201:                        case 15: return -1;
                    202:                        case 14:
                    203:                        case 13:
                    204:                        case 12:
                    205:                        case 11:
                    206:                        case 10:
                    207:                        case 9:
                    208:                        case 8:
                    209:                        case 7: return 0;
                    210:                        case 6: return 1;
                    211:                        case 5: return 2;
                    212:                        case 4: return 3;
                    213:                        default: return 4;
                    214:                }
                    215:        }
                    216: }
                    217:
                    218: /*
                    219:  * getpwis:
                    220:  *     Get a players wisdom for fighting
                    221:  */
                    222: int
                    223: getpwis(struct stats *who)
                    224: {
                    225:        reg int ewis;
                    226:
                    227:        ewis = who->s_ef.a_wis;
                    228:        if (ewis > 18)
                    229:                return (ewis - 14);
                    230:        switch(ewis) {
                    231:                case 18: return 4;
                    232:                case 17: return 3;
                    233:                case 16: return 2;
                    234:                case 15: return 1;
                    235:                case 14:
                    236:                case 13:
                    237:                case 12:
                    238:                case 11:
                    239:                case 10:
                    240:                case 9:
                    241:                case 8: return 0;
                    242:                case 7:
                    243:                case 6: return -1;
                    244:                case 5:
                    245:                case 4: return -2;
                    246:                default: return -3;
                    247:        }
                    248: }
                    249:
                    250: /*
                    251:  * getpcon:
                    252:  *     Get added hit points from players constitution
                    253:  */
                    254: int
                    255: getpcon(struct stats *who)
                    256: {
                    257:        reg int econ;
                    258:
                    259:        econ = who->s_ef.a_con;
                    260:        if (econ > 18)
                    261:                return (econ - 14);
                    262:        switch(econ) {
                    263:                case 18: return 4;
                    264:                case 17: return 3;
                    265:                case 16: return 2;
                    266:                case 15: return 1;
                    267:                case 14:
                    268:                case 13:
                    269:                case 12:
                    270:                case 11:
                    271:                case 10:
                    272:                case 9:
                    273:                case 8:
                    274:                case 7: return 0;
                    275:                case 6:
                    276:                case 5:
                    277:                case 4: return -1;
                    278:                default: return -2;
                    279:        }
                    280: }
                    281:
                    282:
                    283: /*
                    284:  * str_plus:
                    285:  *     compute bonus/penalties for strength on the "to hit" roll
                    286:  */
                    287: int
                    288: str_plus(struct stats *who)
                    289: {
                    290:        reg int hitplus, str;
                    291:
                    292:        hitplus = 0;
                    293:        str = who->s_ef.a_str;
                    294:        if (str > 24)                   /* > 24 */
                    295:                hitplus = str - 21;
                    296:        else if (str == 24)             /* 24 */
                    297:                hitplus = 3;
                    298:        else if (str > 20)              /* 21 to 23 */
                    299:                hitplus = 2;
                    300:        else if(str >= 17)              /* 17 to 20 */
                    301:                hitplus = 1;
                    302:        else if(str > 7)                /* 8 to 16 */
                    303:                hitplus = 0;
                    304:        else if(str > 5)                /* 6 to 7 */
                    305:                hitplus = -1;
                    306:        else if(str > 3)                /* 4 to 5 */
                    307:                hitplus = -2;
                    308:        else
                    309:                hitplus = -3;           /* < 4 */
                    310:        if (who == him)                 /* add pack weight if hero */
                    311:                hitplus += hitweight();
                    312:        return hitplus;
                    313: }
                    314:
                    315:
                    316: /*
                    317:  * add_dam:
                    318:  *     Compute additional damage done depending on strength
                    319:  */
                    320: int
                    321: add_dam(struct stats *who)
                    322: {
                    323:        reg int exdam, str;
                    324:
                    325:        exdam = 0;
                    326:        str = who->s_ef.a_str;
                    327:        if (str > 24)                   /* > 24 */
                    328:                exdam = str - 18;
                    329:        else if (str == 24)             /* 24 */
                    330:                exdam = 6;
                    331:        else if (str == 23)             /* 23 */
                    332:                exdam = 5;
                    333:        else if (str > 20)              /* 21 to 22 */
                    334:                exdam = 4;
                    335:        else if (str > 18)              /* 19 to 20 */
                    336:                exdam = 3;
                    337:        else if (str == 18)             /* 18 */
                    338:                exdam = 2;
                    339:        else if (str > 15)              /* 16 to 17 */
                    340:                exdam = 1;
                    341:        else if (str > 6)               /* 7 to 14 */
                    342:                exdam = 0;
                    343:        else
                    344:                exdam = -1;                     /* 3 to 6 */
                    345:        if (who == him)
                    346:                exdam += hungdam();             /* add hungry state if hero */
                    347:        return exdam;
                    348: }
                    349:
                    350:
                    351: /*
                    352:  * hungdam:
                    353:  *     Calculate damage depending on players hungry state
                    354:  */
                    355: int
                    356: hungdam(void)
                    357: {
                    358:        switch (hungry_state) {
                    359:                case F_OKAY:
                    360:                case F_HUNGRY:  return 0;
                    361:                when F_WEAK:    return -1;
                    362:                when F_FAINT:   return -2;
                    363:        }
                    364:        return 0;
                    365: }
                    366:
                    367: /*
                    368:  * heal_self:
                    369:  *     Heal the hero.
                    370:  */
                    371: void
                    372: heal_self(int factor, bool updmaxhp)
                    373: {
                    374:        him->s_hpt += roll(him->s_lvl + getpcon(him), factor);
                    375:        if (updmaxhp)
                    376:                him->s_maxhp += 1;
                    377:        if (him->s_hpt > him->s_maxhp)
                    378:                him->s_hpt = him->s_maxhp;
                    379:        nochange = FALSE;
                    380: }

CVSweb