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