Annotation of early-roguelike/srogue/encumb.c, Revision 1.1.1.1
1.1 rubenllo 1: /*
2: * Stuff to do with encumberence
3: *
4: * @(#)encumb.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 <string.h>
14: #include "rogue.h"
15: #include "rogue.ext"
16:
17: int packweight(void);
18: int pack_vol(void);
19:
20: /*
21: * updpack:
22: * Update his pack weight and adjust fooduse accordingly
23: */
24: void
25: updpack(void)
26: {
27: reg int topcarry, curcarry;
28:
29: him->s_carry = totalenc(); /* get total encumb */
30: curcarry = packweight(); /* get pack weight */
31: topcarry = him->s_carry / 5; /* 20% of total carry */
32: if (curcarry > 4 * topcarry) {
33: if (rnd(100) < 80)
34: foodlev = 3; /* > 80% of pack */
35: }
36: else if (curcarry > 3 * topcarry) {
37: if (rnd(100) < 60)
38: foodlev = 2; /* > 60% of pack */
39: }
40: else
41: foodlev = 1; /* <= 60% of pack */
42: him->s_pack = curcarry; /* update pack weight */
43: packvol = pack_vol(); /* update pack volume */
44: nochange = FALSE; /* also change display */
45: }
46:
47:
48: /*
49: * packweight:
50: * Get the total weight of the hero's pack
51: */
52: int
53: packweight(void)
54: {
55: reg struct object *obj;
56: reg struct linked_list *pc;
57: reg int weight, i;
58:
59: weight = 0;
60: for (pc = pack ; pc != NULL ; pc = next(pc)) {
61: obj = OBJPTR(pc);
62: weight += itemweight(obj) * obj->o_count;
63: }
64: if (weight < 0) /* in case of amulet */
65: weight = 0;
66: for (i = LEFT; i <= RIGHT; i += 1) {
67: obj = cur_ring[i];
68: if (obj != NULL) {
69: if (obj->o_type == R_HEAVY && o_off(obj, ISBLESS))
70: weight += weight / 4;
71: }
72: }
73: return weight;
74: }
75:
76:
77: /*
78: * itemweight:
79: * Get the weight of an object
80: */
81: int
82: itemweight(struct object *wh)
83: {
84: reg int weight;
85:
86: weight = wh->o_weight; /* get base weight */
87: switch (wh->o_type) {
88: case ARMOR:
89: if ((armors[wh->o_which].a_class - wh->o_ac) > 0)
90: weight /= 2;
91: when WEAPON:
92: if ((wh->o_hplus + wh->o_dplus) > 0)
93: weight /= 2;
94: }
95: if (o_on(wh,ISCURSED))
96: weight += weight / 5; /* 20% more for cursed */
97: if (o_on(wh, ISBLESS))
98: weight -= weight / 5; /* 20% less for blessed */
99: return weight;
100: }
101:
102: /*
103: * pack_vol:
104: * Get the total volume of the hero's pack
105: */
106: int
107: pack_vol(void)
108: {
109: reg struct object *obj;
110: reg struct linked_list *pc;
111: reg int volume;
112:
113: volume = 0;
114: for (pc = pack ; pc != NULL ; pc = next(pc)) {
115: obj = OBJPTR(pc);
116: volume += itemvol(obj);
117: }
118: return volume;
119: }
120:
121: /*
122: * itemvol:
123: * Get the volume of an object
124: */
125: int
126: itemvol(struct object *wh)
127: {
128: reg int volume, what, extra;
129:
130: extra = 0;
131: what = getindex(wh->o_type);
132: switch (wh->o_type) {
133: case ARMOR: extra = armors[wh->o_which].a_vol;
134: when WEAPON: extra = weaps[wh->o_which].w_vol;
135: when STICK: if (strcmp(ws_stuff[wh->o_which].ws_type,"staff") == 0)
136: extra = V_WS_STAFF;
137: else
138: extra = V_WS_WAND;
139: }
140: volume = thnginfo[what].mf_vol + extra;
141: volume *= wh->o_count;
142: return volume;
143: }
144:
145: /*
146: * playenc:
147: * Get hero's carrying ability above norm
148: */
149: int
150: playenc(void)
151: {
152: reg int estr = him->s_ef.a_str;
153: if (estr >= 24)
154: return 3000;
155: switch(him->s_ef.a_str) {
156: case 23: return 2000;
157: case 22: return 1500;
158: case 21: return 1250;
159: case 20: return 1100;
160: case 19: return 1000;
161: case 18: return 700;
162: case 17: return 500;
163: case 16: return 350;
164: case 15:
165: case 14: return 200;
166: case 13:
167: case 12: return 100;
168: case 11:
169: case 10:
170: case 9:
171: case 8: return 0;
172: case 7:
173: case 6: return -150;
174: case 5:
175: case 4: return -250;
176: }
177: return -350;
178: }
179:
180:
181: /*
182: * totalenc:
183: * Get total weight that the hero can carry
184: */
185: int
186: totalenc(void)
187: {
188: reg int wtotal;
189:
190: wtotal = NORMENCB + playenc();
191: switch(hungry_state) {
192: case F_OKAY:
193: case F_HUNGRY: ; /* no change */
194: when F_WEAK: wtotal -= wtotal / 10; /* 10% off weak */
195: when F_FAINT: wtotal /= 2; /* 50% off faint */
196: }
197: return wtotal;
198: }
199:
200: /*
201: * whgtchk:
202: * See if the hero can carry his pack
203: */
204: void
205: wghtchk(int fromfuse)
206: {
207: reg int dropchk, err = TRUE;
208: reg char ch;
209:
210: inwhgt = TRUE;
211: if (him->s_pack > him->s_carry) {
212: ch = player.t_oldch;
213: extinguish(wghtchk);
214: if ((ch != FLOOR && ch != PASSAGE) || isfight) {
215: fuse(wghtchk, TRUE, 1);
216: inwhgt = FALSE;
217: return;
218: }
219: msg("Your pack is too heavy for you.");
220: do {
221: dropchk = drop(NULL);
222: if (dropchk == SOMTHERE)
223: err = FALSE;
224: else if (dropchk == FALSE) {
225: mpos = 0;
226: msg("You must drop something");
227: }
228: if (dropchk == TRUE)
229: err = FALSE;
230: } while(err);
231: }
232: inwhgt = FALSE;
233: }
234:
235:
236: /*
237: * hitweight:
238: * Gets the fighting ability according to current weight
239: * This returns a +1 hit for light pack weight
240: * 0 hit for medium pack weight
241: * -1 hit for heavy pack weight
242: */
243: int
244: hitweight(void)
245: {
246: return(2 - foodlev);
247: }
CVSweb