Mercurial > hg > early-roguelike
comparison srogue/pstats.c @ 36:2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author | elwin |
---|---|
date | Thu, 25 Nov 2010 12:21:41 +0000 |
parents | |
children | 94a0d9dd5ce1 |
comparison
equal
deleted
inserted
replaced
35:05018c63a721 | 36:2128c7dc8a40 |
---|---|
1 /* | |
2 * Players status routines | |
3 * | |
4 * @(#)pstats.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 "rogue.h" | |
14 #include "rogue.ext" | |
15 | |
16 | |
17 /* | |
18 * chg_hpt: | |
19 * Changes players hit points | |
20 */ | |
21 chg_hpt(howmany, alsomax, what) | |
22 int howmany; | |
23 bool alsomax; | |
24 char what; | |
25 { | |
26 nochange = FALSE; | |
27 if(alsomax) | |
28 him->s_maxhp += howmany; | |
29 him->s_hpt += howmany; | |
30 if (him->s_hpt < 1) { | |
31 msg(" "); | |
32 death(what); | |
33 } | |
34 } | |
35 | |
36 | |
37 /* | |
38 * rchg_str: | |
39 * Update the players real strength | |
40 */ | |
41 rchg_str(amt) | |
42 int amt; | |
43 { | |
44 chg_abil(STR,amt,TRUE); | |
45 } | |
46 | |
47 /* | |
48 * chg_abil: | |
49 * Used to modify the hero's abilities | |
50 */ | |
51 chg_abil(what,amt,how) | |
52 int amt, what, how; | |
53 { | |
54 if (amt == 0) | |
55 return; | |
56 if (how == TRUE) { /* real (must be 1st) */ | |
57 updabil(what,amt,&pstats.s_re,TRUE); | |
58 how = FALSE; | |
59 } | |
60 updabil(what,amt,&pstats.s_ef,how); /* effective */ | |
61 updpack(); | |
62 wghtchk(FALSE); | |
63 } | |
64 | |
65 /* | |
66 * updabil: | |
67 * Do the actual abilities updating | |
68 */ | |
69 updabil(what, amt, pst, how) | |
70 struct real *pst; | |
71 int what, amt, how; | |
72 { | |
73 register int *wh, *mx, *mr; | |
74 struct real *mst, *msr; | |
75 bool is_str = FALSE; | |
76 int rtype; | |
77 | |
78 msr = &him->s_re; | |
79 if (how == TRUE) /* max real abilities */ | |
80 mst = &max_stats.s_re; | |
81 else /* max effective abil */ | |
82 mst = &max_stats.s_ef; | |
83 switch (what) { | |
84 case STR: | |
85 is_str = TRUE; | |
86 wh = &pst->a_str; | |
87 mx = &mst->a_str; | |
88 mr = &msr->a_str; | |
89 rtype = R_ADDSTR; | |
90 when DEX: | |
91 wh = &pst->a_dex; | |
92 mx = &mst->a_dex; | |
93 mr = &msr->a_dex; | |
94 rtype = R_DEX; | |
95 when CON: | |
96 wh = &pst->a_con; | |
97 mx = &mst->a_con; | |
98 mr = &msr->a_con; | |
99 rtype = R_CONST; | |
100 when WIS: | |
101 wh = &pst->a_wis; | |
102 mx = &mst->a_wis; | |
103 mr = &msr->a_wis; | |
104 rtype = R_KNOW; | |
105 otherwise: | |
106 return; | |
107 } | |
108 *wh += amt; /* update by amt */ | |
109 if (amt < 0) { /* if decrement */ | |
110 if (*wh < MINABIL) /* minimum = 3 */ | |
111 *wh = MINABIL; | |
112 if (how == FALSE) { | |
113 if (*wh < *mr) /* if less than real abil */ | |
114 *wh = *mr; /* make equal to real */ | |
115 } | |
116 } | |
117 else { /* increment */ | |
118 int themax; | |
119 | |
120 themax = MAXOTHER; /* default maximum */ | |
121 if (is_str) | |
122 themax = MAXSTR; /* strength maximum */ | |
123 if (how != TRUE) | |
124 themax += ringex(rtype); /* get ring extra */ | |
125 if (*wh > themax) { /* see if > max (if real) */ | |
126 *wh = themax; /* max = 18 (24 if str) */ | |
127 } | |
128 /* | |
129 * Check for updating the max player stats. | |
130 */ | |
131 if (*wh > *mx) | |
132 *mx = *wh; | |
133 } | |
134 } | |
135 | |
136 | |
137 /* | |
138 * add_haste: | |
139 * add a haste to the player | |
140 */ | |
141 add_haste(potion) | |
142 bool potion; | |
143 { | |
144 if (pl_on(ISHASTE)) { | |
145 msg("You faint from exhaustion."); | |
146 player.t_nocmd += rnd(8); | |
147 player.t_flags &= ~ISHASTE; | |
148 extinguish(nohaste); | |
149 } | |
150 else { | |
151 player.t_flags |= ISHASTE; | |
152 if (potion) | |
153 fuse(nohaste, TRUE, roll(10,10)); | |
154 else | |
155 fuse(nohaste, TRUE, roll(40,20)); | |
156 } | |
157 } | |
158 | |
159 /* | |
160 * getpdex: | |
161 * Gets players added dexterity for fighting | |
162 */ | |
163 getpdex(who, heave) | |
164 struct stats *who; | |
165 bool heave; | |
166 { | |
167 reg int edex; | |
168 | |
169 edex = who->s_ef.a_dex; | |
170 if (heave) { /* an object was thrown here */ | |
171 if (edex > 18) | |
172 return (edex - 15); | |
173 switch(edex) { | |
174 case 18: return 3; | |
175 case 17: return 2; | |
176 case 16: return 1; | |
177 case 15: | |
178 case 14: | |
179 case 13: | |
180 case 12: | |
181 case 11: | |
182 case 10: | |
183 case 9: | |
184 case 8: | |
185 case 7: | |
186 case 6: return 0; | |
187 case 5: return -1; | |
188 case 4: return -2; | |
189 default: return -3; | |
190 } | |
191 } | |
192 else { /* object NOT thrown here (affects armor class) */ | |
193 if (edex > 18) | |
194 return (14 - edex); | |
195 switch(edex) { | |
196 case 18: return -4; | |
197 case 17: return -3; | |
198 case 16: return -2; | |
199 case 15: return -1; | |
200 case 14: | |
201 case 13: | |
202 case 12: | |
203 case 11: | |
204 case 10: | |
205 case 9: | |
206 case 8: | |
207 case 7: return 0; | |
208 case 6: return 1; | |
209 case 5: return 2; | |
210 case 4: return 3; | |
211 default: return 4; | |
212 } | |
213 } | |
214 } | |
215 | |
216 /* | |
217 * getpwis: | |
218 * Get a players wisdom for fighting | |
219 */ | |
220 getpwis(who) | |
221 struct stats *who; | |
222 { | |
223 reg int ewis; | |
224 | |
225 ewis = who->s_ef.a_wis; | |
226 if (ewis > 18) | |
227 return (ewis - 14); | |
228 switch(ewis) { | |
229 case 18: return 4; | |
230 case 17: return 3; | |
231 case 16: return 2; | |
232 case 15: return 1; | |
233 case 14: | |
234 case 13: | |
235 case 12: | |
236 case 11: | |
237 case 10: | |
238 case 9: | |
239 case 8: return 0; | |
240 case 7: | |
241 case 6: return -1; | |
242 case 5: | |
243 case 4: return -2; | |
244 default: return -3; | |
245 } | |
246 } | |
247 | |
248 /* | |
249 * getpcon: | |
250 * Get added hit points from players constitution | |
251 */ | |
252 getpcon(who) | |
253 struct stats *who; | |
254 { | |
255 reg int econ; | |
256 | |
257 econ = who->s_ef.a_con; | |
258 if (econ > 18) | |
259 return (econ - 14); | |
260 switch(econ) { | |
261 case 18: return 4; | |
262 case 17: return 3; | |
263 case 16: return 2; | |
264 case 15: return 1; | |
265 case 14: | |
266 case 13: | |
267 case 12: | |
268 case 11: | |
269 case 10: | |
270 case 9: | |
271 case 8: | |
272 case 7: return 0; | |
273 case 6: | |
274 case 5: | |
275 case 4: return -1; | |
276 default: return -2; | |
277 } | |
278 } | |
279 | |
280 | |
281 /* | |
282 * str_plus: | |
283 * compute bonus/penalties for strength on the "to hit" roll | |
284 */ | |
285 str_plus(who) | |
286 struct stats *who; | |
287 { | |
288 reg int hitplus, str; | |
289 | |
290 hitplus = 0; | |
291 str = who->s_ef.a_str; | |
292 if (str > 24) /* > 24 */ | |
293 hitplus = str - 21; | |
294 else if (str == 24) /* 24 */ | |
295 hitplus = 3; | |
296 else if (str > 20) /* 21 to 23 */ | |
297 hitplus = 2; | |
298 else if(str >= 17) /* 17 to 20 */ | |
299 hitplus = 1; | |
300 else if(str > 7) /* 8 to 16 */ | |
301 hitplus = 0; | |
302 else if(str > 5) /* 6 to 7 */ | |
303 hitplus = -1; | |
304 else if(str > 3) /* 4 to 5 */ | |
305 hitplus = -2; | |
306 else | |
307 hitplus = -3; /* < 4 */ | |
308 if (who == him) /* add pack weight if hero */ | |
309 hitplus += hitweight(); | |
310 return hitplus; | |
311 } | |
312 | |
313 | |
314 /* | |
315 * add_dam: | |
316 * Compute additional damage done depending on strength | |
317 */ | |
318 add_dam(who) | |
319 struct stats *who; | |
320 { | |
321 reg int exdam, str; | |
322 | |
323 exdam = 0; | |
324 str = who->s_ef.a_str; | |
325 if (str > 24) /* > 24 */ | |
326 exdam = str - 18; | |
327 else if (str == 24) /* 24 */ | |
328 exdam = 6; | |
329 else if (str == 23) /* 23 */ | |
330 exdam = 5; | |
331 else if (str > 20) /* 21 to 22 */ | |
332 exdam = 4; | |
333 else if (str > 18) /* 19 to 20 */ | |
334 exdam = 3; | |
335 else if (str == 18) /* 18 */ | |
336 exdam = 2; | |
337 else if (str > 15) /* 16 to 17 */ | |
338 exdam = 1; | |
339 else if (str > 6) /* 7 to 14 */ | |
340 exdam = 0; | |
341 else | |
342 exdam = -1; /* 3 to 6 */ | |
343 if (who == him) | |
344 exdam += hungdam(); /* add hungry state if hero */ | |
345 return exdam; | |
346 } | |
347 | |
348 | |
349 /* | |
350 * hungdam: | |
351 * Calculate damage depending on players hungry state | |
352 */ | |
353 hungdam() | |
354 { | |
355 switch (hungry_state) { | |
356 case F_OKAY: | |
357 case F_HUNGRY: return 0; | |
358 when F_WEAK: return -1; | |
359 when F_FAINT: return -2; | |
360 } | |
361 } | |
362 | |
363 /* | |
364 * heal_self: | |
365 * Heal the hero. | |
366 */ | |
367 heal_self(factor, updmaxhp) | |
368 int factor; | |
369 bool updmaxhp; | |
370 { | |
371 him->s_hpt += roll(him->s_lvl + getpcon(him), factor); | |
372 if (updmaxhp) | |
373 him->s_maxhp += 1; | |
374 if (him->s_hpt > him->s_maxhp) | |
375 him->s_hpt = him->s_maxhp; | |
376 nochange = FALSE; | |
377 } |