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

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

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

CVSweb