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

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

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

CVSweb