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