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

Annotation of early-roguelike/arogue5/encumb.c, Revision 1.1.1.1

1.1       rubenllo    1: /*
                      2:  * Stuff to do with encumberence
                      3:  *
                      4:  * Advanced Rogue
                      5:  * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
                      6:  * All rights reserved.
                      7:  *
                      8:  * Based on "Super-Rogue"
                      9:  * Copyright (C) 1984 Robert D. Kindelberger
                     10:  * All rights reserved.
                     11:  *
                     12:  * See the file LICENSE.TXT for full copyright and licensing information.
                     13:  */
                     14:
                     15: #include "curses.h"
                     16: #include "rogue.h"
                     17:
                     18: int packweight(void);
                     19:
                     20: /*
                     21:  * updpack:
                     22:  *     Update his pack weight and adjust fooduse accordingly
                     23:  */
                     24: void
                     25: updpack(bool getmax)
                     26: {
                     27:
                     28:        reg int topcarry, curcarry;
                     29:
                     30:        if (getmax)
                     31:            pstats.s_carry = totalenc();        /* get total encumb */
                     32:        curcarry = packweight();                /* get pack weight */
                     33:        topcarry = pstats.s_carry / 5;          /* 20% of total carry */
                     34:        if(curcarry > 4 * topcarry) {
                     35:            if(rnd(100) < 80)
                     36:                foodlev = 3;                    /* > 80% of pack */
                     37:        } else if(curcarry > 3 * topcarry) {
                     38:            if(rnd(100) < 60)
                     39:                foodlev = 2;                    /* > 60% of pack */
                     40:        } else
                     41:            foodlev = 1;                        /* <= 60% of pack */
                     42:        pstats.s_pack = curcarry;               /* update pack weight */
                     43: }
                     44:
                     45:
                     46: /*
                     47:  * packweight:
                     48:  *     Get the total weight of the hero's pack
                     49:  */
                     50: int
                     51: packweight(void)
                     52: {
                     53:        reg struct object *obj;
                     54:        reg struct linked_list *pc;
                     55:        reg int weight;
                     56:
                     57:        weight = 0;
                     58:        for(pc = pack ; pc != NULL ; pc = next(pc)) {
                     59:            obj = OBJPTR(pc);
                     60:            weight += itemweight(obj);
                     61:        }
                     62:        if(weight < 0)          /* in case of amulet */
                     63:             weight = 0;
                     64:        if(ISWEARING(R_HEAVY))
                     65:            weight += weight / 4;
                     66:        return(weight);
                     67: }
                     68:
                     69:
                     70: /*
                     71:  * itemweight:
                     72:  *     Get the weight of an object
                     73:  */
                     74: int
                     75: itemweight(struct object *wh)
                     76: {
                     77:        reg int weight;
                     78:        reg int ac;
                     79:
                     80:        weight = wh->o_weight;          /* get base weight */
                     81:        switch(wh->o_type) {
                     82:            case ARMOR:
                     83:                /*
                     84:                 * subtract 10% for each enchantment
                     85:                 * this will add weight for negative items
                     86:                 */
                     87:                ac = armors[wh->o_which].a_class - wh->o_ac;
                     88:                weight = ((weight*10) - (weight*ac)) / 10;
                     89:                if (weight < 0) weight = 0;
                     90:            when WEAPON:
                     91:                if ((wh->o_hplus + wh->o_dplus) > 0)
                     92:                        weight /= 2;
                     93:        }
                     94:        if(wh->o_flags & ISCURSED)
                     95:                weight += weight / 5;   /* 20% more for cursed */
                     96:         weight *= wh->o_count;
                     97:        return(weight);
                     98: }
                     99:
                    100:
                    101: /*
                    102:  * playenc:
                    103:  *     Get hero's carrying ability above norm
                    104:  */
                    105: int
                    106: playenc(void)
                    107: {
                    108:        return ((str_compute()-8)*50);
                    109: }
                    110:
                    111:
                    112: /*
                    113:  * totalenc:
                    114:  *     Get total weight that the hero can carry
                    115:  */
                    116: int
                    117: totalenc(void)
                    118: {
                    119:        reg int wtotal;
                    120:
                    121:        wtotal = NORMENCB + playenc();
                    122:        switch(hungry_state) {
                    123:                case F_OKAY:
                    124:                case F_HUNGRY:  ;                       /* no change */
                    125:                when F_WEAK:    wtotal -= wtotal / 10;  /* 10% off weak */
                    126:                when F_FAINT:   wtotal /= 2;            /* 50% off faint */
                    127:        }
                    128:        return(wtotal);
                    129: }
                    130:
                    131:
                    132:
                    133: /*
                    134:  * whgtchk:
                    135:  *     See if the hero can carry his pack
                    136:  */
                    137:
                    138: void
                    139: wghtchk(void)
                    140: {
                    141:        reg int dropchk, err = TRUE;
                    142:        reg char ch;
                    143:
                    144:        inwhgt = TRUE;
                    145:        if (pstats.s_pack > pstats.s_carry) {
                    146:            ch = CCHAR( mvwinch(stdscr, hero.y, hero.x) );
                    147:            if((ch != FLOOR && ch != PASSAGE)) {
                    148:                extinguish(wghtchk);
                    149:                fuse(wghtchk,NULL,1,AFTER);
                    150:                inwhgt = FALSE;
                    151:                return;
                    152:            }
                    153:            extinguish(wghtchk);
                    154:            msg("Your pack is too heavy for you");
                    155:            do {
                    156:                dropchk = drop(NULL);
                    157:                if(dropchk == FALSE) {
                    158:                    mpos = 0;
                    159:                    msg("You must drop something");
                    160:                }
                    161:                if(dropchk == TRUE)
                    162:                    err = FALSE;
                    163:            } while(err);
                    164:        }
                    165:        inwhgt = FALSE;
                    166: }
                    167:
                    168:
                    169: /*
                    170:  * hitweight:
                    171:  *     Gets the fighting ability according to current weight
                    172:  *     This returns a  +1 hit for light pack weight
                    173:  *                      0 hit for medium pack weight
                    174:  *                     -1 hit for heavy pack weight
                    175:  */
                    176:
                    177: int
                    178: hitweight(void)
                    179: {
                    180:        return(2 - foodlev);
                    181: }

CVSweb