OSDN Git Service

update year to 2019
[jnethack/source.git] / src / attrib.c
1 /* NetHack 3.6  attrib.c        $NHDT-Date: 1494034337 2017/05/06 01:32:17 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.62 $ */
2 /*      Copyright 1988, 1989, 1990, 1992, M. Stephenson           */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019            */
8 /* JNetHack may be freely redistributed.  See license for details. */
9
10
11 /*  attribute modification routines. */
12
13 #include "hack.h"
14 #include <ctype.h>
15
16 /* part of the output on gain or loss of attribute */
17 static const char
18 #if 0 /*JP*/
19     *const plusattr[] = { "strong", "smart", "wise",
20                           "agile",  "tough", "charismatic" },
21 #else
22     *const plusattr[] = { "\8b­\82¢", "\8c«\96¾\82¾", "\8c«\82¢",
23                           "\8b@\95q\82¾", "\8aæ\8fä\82¾", "\96£\97Í\93I\82¾" },
24 #endif
25 #if 0 /*JP*/
26     *const minusattr[] = { "weak",    "stupid",
27                            "foolish", "clumsy",
28                            "fragile", "repulsive" };
29 #else
30     *const minusattr[] = { "\8eã\82¢", "\8bð\82©\82¾",
31                            "\8aÔ\94²\82¯\82¾", "\95s\8aí\97p\82¾",
32                            "\82Ð\8eã\82¾","\8fX\82¢" };
33 #endif
34 /* also used by enlightenment for non-abbreviated status info */
35 const char
36 #if 0 /*JP*/
37     *const attrname[] = { "strength", "intelligence", "wisdom",
38                           "dexterity", "constitution", "charisma" };
39 #else
40     *const attrname[] = { "\8b­\82³", "\92m\97Í", "\8c«\82³",
41                           "\91f\91\81\82³", "\91Ï\8bv\97Í", "\96£\97Í" };
42 #endif
43
44 static const struct innate {
45     schar ulevel;
46     long *ability;
47     const char *gainstr, *losestr;
48 } arc_abil[] = { { 1, &(HStealth), "", "" },
49                  { 1, &(HFast), "", "" },
50 /*JP
51                  { 10, &(HSearching), "perceptive", "" },
52 */
53                  { 10, &(HSearching), "\92m\8ao\97Í\82ð\93¾\82½", "\92m\8ao\97Í\82ð\8e¸\82Á\82½" },
54                  { 0, 0, 0, 0 } },
55
56   bar_abil[] = { { 1, &(HPoison_resistance), "", "" },
57 /*JP
58                  { 7, &(HFast), "quick", "slow" },
59 */
60                  { 7, &(HFast), "\91f\91\81\82³\82ð\93¾\82½", "\92x\82­\82È\82Á\82½" },
61 /*JP
62                  { 15, &(HStealth), "stealthy", "" },
63 */
64                  { 15, &(HStealth), "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\93¾\82½", "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\8e¸\82Á\82½" },
65                  { 0, 0, 0, 0 } },
66
67 /*JP
68   cav_abil[] = { { 7, &(HFast), "quick", "slow" },
69 */
70   cav_abil[] = { { 7, &(HFast), "\91f\91\81\82³\82ð\93¾\82½", "\92x\82­\82È\82Á\82½" },
71 /*JP
72                  { 15, &(HWarning), "sensitive", "" },
73 */
74                  { 15, &(HWarning), "\95q\8a´\82É\82È\82Á\82½", "\93Ý\8a´\82É\82È\82Á\82½" },
75                  { 0, 0, 0, 0 } },
76
77   hea_abil[] = { { 1, &(HPoison_resistance), "", "" },
78 /*JP
79                  { 15, &(HWarning), "sensitive", "" },
80 */
81                  { 15, &(HWarning), "\95q\8a´\82É\82È\82Á\82½", "\93Ý\8a´\82É\82È\82Á\82½" },
82                  { 0, 0, 0, 0 } },
83
84 /*JP
85   kni_abil[] = { { 7, &(HFast), "quick", "slow" }, { 0, 0, 0, 0 } },
86 */
87   kni_abil[] = { { 7, &(HFast), "\91f\91\81\82³\82ð\93¾\82½", "\92x\82­\82È\82Á\82½" }, { 0, 0, 0, 0 } },
88
89   mon_abil[] = { { 1, &(HFast), "", "" },
90                  { 1, &(HSleep_resistance), "", "" },
91                  { 1, &(HSee_invisible), "", "" },
92 /*JP
93                  { 3, &(HPoison_resistance), "healthy", "" },
94 */
95                  { 3, &(HPoison_resistance), "\8c\92\8dN\82É\82È\82Á\82½", "\95s\8c\92\8dN\82É\82È\82Á\82½" },
96 /*JP
97                  { 5, &(HStealth), "stealthy", "" },
98 */
99                  { 5, &(HStealth), "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\93¾\82½", "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\8e¸\82Á\82½" },
100 /*JP
101                  { 7, &(HWarning), "sensitive", "" },
102 */
103                  { 7, &(HWarning), "\95q\8a´\82É\82È\82Á\82½", "\93Ý\8a´\82É\82È\82Á\82½" },
104 /*JP
105                  { 9, &(HSearching), "perceptive", "unaware" },
106 */
107                  { 9, &(HSearching), "\92m\8ao\97Í\82ð\93¾\82½", "\92m\8ao\97Í\82ð\8e¸\82Á\82½" },
108 /*JP
109                  { 11, &(HFire_resistance), "cool", "warmer" },
110 */
111                  { 11, &(HFire_resistance), "\97â\82½\82­\82È\82Á\82½", "\92g\82©\82­\82È\82Á\82½" },
112 /*JP
113                  { 13, &(HCold_resistance), "warm", "cooler" },
114 */
115                  { 13, &(HCold_resistance), "\92g\82©\82­\82È\82Á\82½", "\97â\82½\82­\82È\82Á\82½"},
116 /*JP
117                  { 15, &(HShock_resistance), "insulated", "conductive" },
118 */
119                  { 15, &(HShock_resistance), "\90â\89\8f\82³\82ê\82½", "\93±\93d\82³\82ê\82½" },
120 /*JP
121                  { 17, &(HTeleport_control), "controlled", "uncontrolled" },
122 */
123                  { 17, &(HTeleport_control), "\90§\8cä\97Í\82ð\93¾\82½","\90§\8cä\97Í\82ð\8e¸\82Á\82½" },
124                  { 0, 0, 0, 0 } },
125
126 /*JP
127   pri_abil[] = { { 15, &(HWarning), "sensitive", "" },
128 */
129   pri_abil[] = { { 15, &(HWarning), "\95q\8a´\82É\82È\82Á\82½", "\93Ý\8a´\82É\82È\82Á\82½" },
130 /*JP
131                  { 20, &(HFire_resistance), "cool", "warmer" },
132 */
133                  { 20, &(HFire_resistance), "\97â\82½\82­\82È\82Á\82½", "\92g\82©\82­\82È\82Á\82½" },
134                  { 0, 0, 0, 0 } },
135
136   ran_abil[] = { { 1, &(HSearching), "", "" },
137 /*JP
138                  { 7, &(HStealth), "stealthy", "" },
139 */
140                  { 7, &(HStealth), "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\93¾\82½", "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\8e¸\82Á\82½" },
141                  { 15, &(HSee_invisible), "", "" },
142                  { 0, 0, 0, 0 } },
143
144   rog_abil[] = { { 1, &(HStealth), "", "" },
145 /*JP
146                  { 10, &(HSearching), "perceptive", "" },
147 */
148                  { 10, &(HSearching), "\92m\8ao\97Í\82ð\93¾\82½", "\92m\8ao\97Í\82ð\8e¸\82Á\82½" },
149                  { 0, 0, 0, 0 } },
150
151   sam_abil[] = { { 1, &(HFast), "", "" },
152 /*JP
153                  { 15, &(HStealth), "stealthy", "" },
154 */
155                  { 15, &(HStealth), "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\93¾\82½", "\90l\96Ú\82ð\93\90\82Þ\97Í\82ð\8e¸\82Á\82½" },
156                  { 0, 0, 0, 0 } },
157
158 /*JP
159   tou_abil[] = { { 10, &(HSearching), "perceptive", "" },
160 */
161   tou_abil[] = { { 10, &(HSearching), "\92m\8ao\97Í\82ð\93¾\82½", "\92m\8ao\97Í\82ð\8e¸\82Á\82½" },
162 /*JP
163                  { 20, &(HPoison_resistance), "hardy", "" },
164 */
165                  { 20, &(HPoison_resistance), "\96Æ\89u\97Í\82ð\93¾\82½", "\96Æ\89u\97Í\82ð\8e¸\82Á\82½" },
166                  { 0, 0, 0, 0 } },
167
168   val_abil[] = { { 1, &(HCold_resistance), "", "" },
169                  { 1, &(HStealth), "", "" },
170 /*JP
171                  { 7, &(HFast), "quick", "slow" },
172 */
173                  { 7, &(HFast), "\91f\91\81\82³\82ð\93¾\82½", "\92x\82­\82È\82Á\82½" },
174                  { 0, 0, 0, 0 } },
175
176 /*JP
177   wiz_abil[] = { { 15, &(HWarning), "sensitive", "" },
178 */
179   wiz_abil[] = { { 15, &(HWarning), "\95q\8a´\82É\82È\82Á\82½", "\93Ý\8a´\82É\82È\82Á\82½" },
180 /*JP
181                  { 17, &(HTeleport_control), "controlled", "uncontrolled" },
182 */
183                  { 17, &(HTeleport_control), "\90§\8cä\97Í\82ð\93¾\82½","\90§\8cä\97Í\82ð\8e¸\82Á\82½" },
184                  { 0, 0, 0, 0 } },
185
186   /* Intrinsics conferred by race */
187   dwa_abil[] = { { 1, &HInfravision, "", "" },
188                  { 0, 0, 0, 0 } },
189
190   elf_abil[] = { { 1, &HInfravision, "", "" },
191 /*JP
192                  { 4, &HSleep_resistance, "awake", "tired" },
193 */
194                  { 4, &(HSleep_resistance), "\96Ú\82ª\8ao\82ß\82½", "\96°\82­\82È\82Á\82½" },
195                  { 0, 0, 0, 0 } },
196
197   gno_abil[] = { { 1, &HInfravision, "", "" },
198                  { 0, 0, 0, 0 } },
199
200   orc_abil[] = { { 1, &HInfravision, "", "" },
201                  { 1, &HPoison_resistance, "", "" },
202                  { 0, 0, 0, 0 } },
203
204   hum_abil[] = { { 0, 0, 0, 0 } };
205
206 STATIC_DCL void NDECL(exerper);
207 STATIC_DCL void FDECL(postadjabil, (long *));
208 STATIC_DCL const struct innate *FDECL(role_abil, (int));
209 STATIC_DCL const struct innate *FDECL(check_innate_abil, (long *, long));
210 STATIC_DCL int FDECL(innately, (long *));
211
212 /* adjust an attribute; return TRUE if change is made, FALSE otherwise */
213 boolean
214 adjattrib(ndx, incr, msgflg)
215 int ndx, incr;
216 int msgflg; /* positive => no message, zero => message, and */
217 {           /* negative => conditional (msg if change made) */
218     int old_acurr, old_abase;
219     boolean abonflg;
220     const char *attrstr;
221
222     if (Fixed_abil || !incr)
223         return FALSE;
224
225     if ((ndx == A_INT || ndx == A_WIS) && uarmh && uarmh->otyp == DUNCE_CAP) {
226         if (msgflg == 0)
227 /*JP
228             Your("cap constricts briefly, then relaxes again.");
229 */
230             Your("\96X\8eq\82ª\82µ\82Î\82ç\82­\82Ì\8aÔ\83L\83\85\82Á\82Æ\92÷\82ß\82Â\82¯\81C\82»\82µ\82Ä\82ä\82é\82ñ\82¾\81D");
231         return FALSE;
232     }
233
234     old_acurr = ACURR(ndx);
235     old_abase = ABASE(ndx);
236     if (incr > 0) {
237         ABASE(ndx) += incr;
238         if (ABASE(ndx) > AMAX(ndx)) {
239             incr = ABASE(ndx) - AMAX(ndx);
240             AMAX(ndx) += incr;
241             if (AMAX(ndx) > ATTRMAX(ndx))
242                 AMAX(ndx) = ATTRMAX(ndx);
243             ABASE(ndx) = AMAX(ndx);
244         }
245         attrstr = plusattr[ndx];
246         abonflg = (ABON(ndx) < 0);
247     } else {
248         ABASE(ndx) += incr;
249         if (ABASE(ndx) < ATTRMIN(ndx)) {
250             incr = ABASE(ndx) - ATTRMIN(ndx);
251             ABASE(ndx) = ATTRMIN(ndx);
252             AMAX(ndx) += incr;
253             if (AMAX(ndx) < ATTRMIN(ndx))
254                 AMAX(ndx) = ATTRMIN(ndx);
255         }
256         attrstr = minusattr[ndx];
257         abonflg = (ABON(ndx) > 0);
258     }
259     if (ACURR(ndx) == old_acurr) {
260         if (msgflg == 0 && flags.verbose) {
261             if (ABASE(ndx) == old_abase)
262 #if 0 /*JP*/
263                 pline("You're %s as %s as you can get.",
264                       abonflg ? "currently" : "already", attrstr);
265 #else
266                 You("%s\8f\\95ª\82É%s\81D",
267                       abonflg ? "\8d¡\82Ì\82Æ\82±\82ë" : "\8aù\82É", attrstr);
268 #endif
269             else /* current stayed the same but base value changed */
270 #if 0 /*JP*/
271                 Your("innate %s has %s.", attrname[ndx],
272                      (incr > 0) ? "improved" : "declined");
273 #else
274                 Your("\96{\8e¿\93I\82È%s\82ª%s\82µ\82½\81D", attrname[ndx],
275                      (incr > 0) ? "\8cü\8fã" : "\92á\89º");
276 #endif
277         }
278         return FALSE;
279     }
280
281     if (msgflg <= 0)
282 /*JP
283         You_feel("%s%s!", (incr > 1 || incr < -1) ? "very " : "", attrstr);
284 */
285         You("%s%s\82È\82Á\82½\82æ\82¤\82È\8bC\82ª\82µ\82½\81I", (incr > 1 || incr < -1) ? "\82Æ\82Ä\82à" : "", jconj_adj(attrstr));
286     context.botl = 1;
287     if (moves > 1 && (ndx == A_STR || ndx == A_CON))
288         (void) encumber_msg();
289     return TRUE;
290 }
291
292 void
293 gainstr(otmp, incr, givemsg)
294 struct obj *otmp;
295 int incr;
296 boolean givemsg;
297 {
298     int num = incr;
299
300     if (!num) {
301         if (ABASE(A_STR) < 18)
302             num = (rn2(4) ? 1 : rnd(6));
303         else if (ABASE(A_STR) < STR18(85))
304             num = rnd(10);
305         else
306             num = 1;
307     }
308     (void) adjattrib(A_STR, (otmp && otmp->cursed) ? -num : num,
309                      givemsg ? -1 : 1);
310 }
311
312 /* may kill you; cause may be poison or monster like 'a' */
313 void
314 losestr(num)
315 register int num;
316 {
317     int ustr = ABASE(A_STR) - num;
318
319     while (ustr < 3) {
320         ++ustr;
321         --num;
322         if (Upolyd) {
323             u.mh -= 6;
324             u.mhmax -= 6;
325         } else {
326             u.uhp -= 6;
327             u.uhpmax -= 6;
328         }
329     }
330     (void) adjattrib(A_STR, -num, 1);
331 }
332
333 static const struct poison_effect_message {
334     void VDECL((*delivery_func), (const char *, ...));
335     const char *effect_msg;
336 } poiseff[] = {
337 #if 0 /*JP*/
338     { You_feel, "weaker" },             /* A_STR */
339 #else
340     { You_feel, "\8eã\82­\82È\82Á\82½" },         /* A_STR */
341 #endif
342 #if 0 /*JP*/
343     { Your, "brain is on fire" },       /* A_INT */
344 #else
345     { You, "\93ª\82É\8c\8c\82ª\82Ì\82Ú\82Á\82½" },        /* A_INT */
346 #endif
347 #if 0 /*JP*/
348     { Your, "judgement is impaired" },  /* A_WIS */
349 #else
350     { You, "\94»\92f\97Í\82ð\8e¸\82Á\82½" },          /* A_WIS */
351 #endif
352 #if 0 /*JP*/
353     { Your, "muscles won't obey you" }, /* A_DEX */
354 #else
355     { You, "\8ev\82¤\82æ\82¤\82É\93®\82¯\82È\82¢" },      /* A_DEX */
356 #endif
357 #if 0 /*JP*/
358     { You_feel, "very sick" },          /* A_CON */
359 #else
360     { You_feel, "\82Æ\82Ä\82à\8bC\95ª\82ª\88«\82­\82È\82Á\82½" }, /* A_CON */
361 #endif
362 #if 0 /*JP*/
363     { You, "break out in hives" }       /* A_CHA */
364 #else
365     { You, "\82\82ñ\82Ü\82µ\82ñ\82ª\82 \82ç\82í\82ê\82½" }   /* A_CHA */
366 #endif
367 };
368
369 /* feedback for attribute loss due to poisoning */
370 void
371 poisontell(typ, exclaim)
372 int typ;         /* which attribute */
373 boolean exclaim; /* emphasis */
374 {
375     void VDECL((*func), (const char *, ...)) = poiseff[typ].delivery_func;
376     const char *msg_txt = poiseff[typ].effect_msg;
377
378     /*
379      * "You feel weaker" or "you feel very sick" aren't appropriate when
380      * wearing or wielding something (gauntlets of power, Ogresmasher)
381      * which forces the attribute to maintain its maximum value.
382      * Phrasing for other attributes which might have fixed values
383      * (dunce cap) is such that we don't need message fixups for them.
384      */
385     if (typ == A_STR && ACURR(A_STR) == STR19(25))
386 /*JP
387         msg_txt = "innately weaker";
388 */
389         msg_txt = "\96{\8e¿\93I\82É\8eã\82­\82È\82Á\82½";
390     else if (typ == A_CON && ACURR(A_CON) == 25)
391 /*JP
392         msg_txt = "sick inside";
393 */
394         msg_txt = "\93à\95\94\82É\95a\82ð\82©\82©\82¦\82½";
395
396 /*JP
397     (*func)("%s%c", msg_txt, exclaim ? '!' : '.');
398 */
399     (*func)("%s%s", msg_txt, exclaim ? "\81I" : "\81D");
400 }
401
402 /* called when an attack or trap has poisoned hero (used to be in mon.c) */
403 void
404 poisoned(reason, typ, pkiller, fatal, thrown_weapon)
405 const char *reason,    /* controls what messages we display */
406            *pkiller;   /* for score+log file if fatal */
407 int typ, fatal;        /* if fatal is 0, limit damage to adjattrib */
408 boolean thrown_weapon; /* thrown weapons are less deadly */
409 {
410     int i, loss, kprefix = KILLED_BY_AN;
411
412     /* inform player about being poisoned unless that's already been done;
413        "blast" has given a "blast of poison gas" message; "poison arrow",
414        "poison dart", etc have implicitly given poison messages too... */
415 #if 0 /*JP*/
416     if (strcmp(reason, "blast") && !strstri(reason, "poison")) {
417 #else
418     if (strcmp(reason, "\95\97") && strcmp(reason, "\91§") && !strstri(reason, "\93Å")) {
419 #endif
420 #if 0 /*JP*/
421         boolean plural = (reason[strlen(reason) - 1] == 's') ? 1 : 0;
422 #endif
423
424         /* avoid "The" Orcus's sting was poisoned... */
425 #if 0 /*JP*/
426         pline("%s%s %s poisoned!",
427               isupper((uchar) *reason) ? "" : "The ", reason,
428               plural ? "were" : "was");
429 #else
430         pline("%s\82Í\93Å\82É\82¨\82©\82³\82ê\82Ä\82¢\82é\81I", reason);
431 #endif
432     }
433     if (Poison_resistance) {
434 #if 0 /*JP*/
435         if (!strcmp(reason, "blast"))
436 #else
437         if (!strcmp(reason, "\95\97") || !strcmp(reason, "\91§"))
438 #endif
439             shieldeff(u.ux, u.uy);
440 /*JP
441         pline_The("poison doesn't seem to affect you.");
442 */
443         pline("\93Å\82Í\8cø\82©\82È\82©\82Á\82½\82æ\82¤\82¾\81D");
444         return;
445     }
446
447 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\95s\97v*/
448     /* suppress killer prefix if it already has one */
449     i = name_to_mon(pkiller);
450     if (i >= LOW_PM && (mons[i].geno & G_UNIQ)) {
451         kprefix = KILLED_BY;
452         if (!type_is_pname(&mons[i]))
453             pkiller = the(pkiller);
454     } else if (!strncmpi(pkiller, "the ", 4) || !strncmpi(pkiller, "an ", 3)
455                || !strncmpi(pkiller, "a ", 2)) {
456         /*[ does this need a plural check too? ]*/
457         kprefix = KILLED_BY;
458     }
459 #endif
460
461     i = !fatal ? 1 : rn2(fatal + (thrown_weapon ? 20 : 0));
462     if (i == 0 && typ != A_CHA) {
463         /* instant kill */
464         u.uhp = -1;
465         context.botl = TRUE;
466 /*JP
467         pline_The("poison was deadly...");
468 */
469         pline("\93Å\82Í\92v\8e\80\97Ê\82¾\82Á\82½\81D\81D\81D");
470     } else if (i > 5) {
471         /* HP damage; more likely--but less severe--with missiles */
472         loss = thrown_weapon ? rnd(6) : rn1(10, 6);
473         losehp(loss, pkiller, kprefix); /* poison damage */
474     } else {
475         /* attribute loss; if typ is A_STR, reduction in current and
476            maximum HP will occur once strength has dropped down to 3 */
477         loss = (thrown_weapon || !fatal) ? 1 : d(2, 2); /* was rn1(3,3) */
478         /* check that a stat change was made */
479         if (adjattrib(typ, -loss, 1))
480             poisontell(typ, TRUE);
481     }
482
483     if (u.uhp < 1) {
484         killer.format = kprefix;
485         Strcpy(killer.name, pkiller);
486 #if 0 /*JP*/
487         /* "Poisoned by a poisoned ___" is redundant */
488         done(strstri(pkiller, "poison") ? DIED : POISONING);
489 #else /*JP:\93ú\96{\8cê\82Å\82Í\8bæ\95Ê\82µ\82Ä\82¢\82È\82¢*/
490         done(POISONING);
491 #endif
492     }
493     (void) encumber_msg();
494 }
495
496 void
497 change_luck(n)
498 register schar n;
499 {
500     u.uluck += n;
501     if (u.uluck < 0 && u.uluck < LUCKMIN)
502         u.uluck = LUCKMIN;
503     if (u.uluck > 0 && u.uluck > LUCKMAX)
504         u.uluck = LUCKMAX;
505 }
506
507 int
508 stone_luck(parameter)
509 boolean parameter; /* So I can't think up of a good name.  So sue me. --KAA */
510 {
511     register struct obj *otmp;
512     register long bonchance = 0;
513
514     for (otmp = invent; otmp; otmp = otmp->nobj)
515         if (confers_luck(otmp)) {
516             if (otmp->cursed)
517                 bonchance -= otmp->quan;
518             else if (otmp->blessed)
519                 bonchance += otmp->quan;
520             else if (parameter)
521                 bonchance += otmp->quan;
522         }
523
524     return sgn((int) bonchance);
525 }
526
527 /* there has just been an inventory change affecting a luck-granting item */
528 void
529 set_moreluck()
530 {
531     int luckbon = stone_luck(TRUE);
532
533     if (!luckbon && !carrying(LUCKSTONE))
534         u.moreluck = 0;
535     else if (luckbon >= 0)
536         u.moreluck = LUCKADD;
537     else
538         u.moreluck = -LUCKADD;
539 }
540
541 void
542 restore_attrib()
543 {
544     int i, equilibrium;;
545
546     /*
547      * Note:  this gets called on every turn but ATIME() is never set
548      * to non-zero anywhere, and ATEMP() is only used for strength loss
549      * from hunger, so it doesn't actually do anything.
550      */
551
552     for (i = 0; i < A_MAX; i++) { /* all temporary losses/gains */
553         equilibrium = (i == A_STR && u.uhs >= WEAK) ? -1 : 0;
554         if (ATEMP(i) != equilibrium && ATIME(i) != 0) {
555             if (!(--(ATIME(i)))) { /* countdown for change */
556                 ATEMP(i) += (ATEMP(i) > 0) ? -1 : 1;
557                 context.botl = 1;
558                 if (ATEMP(i)) /* reset timer */
559                     ATIME(i) = 100 / ACURR(A_CON);
560             }
561         }
562     }
563     if (context.botl)
564         (void) encumber_msg();
565 }
566
567 #define AVAL 50 /* tune value for exercise gains */
568
569 void
570 exercise(i, inc_or_dec)
571 int i;
572 boolean inc_or_dec;
573 {
574     debugpline0("Exercise:");
575     if (i == A_INT || i == A_CHA)
576         return; /* can't exercise these */
577
578     /* no physical exercise while polymorphed; the body's temporary */
579     if (Upolyd && i != A_WIS)
580         return;
581
582     if (abs(AEXE(i)) < AVAL) {
583         /*
584          *      Law of diminishing returns (Part I):
585          *
586          *      Gain is harder at higher attribute values.
587          *      79% at "3" --> 0% at "18"
588          *      Loss is even at all levels (50%).
589          *
590          *      Note: *YES* ACURR is the right one to use.
591          */
592         AEXE(i) += (inc_or_dec) ? (rn2(19) > ACURR(i)) : -rn2(2);
593         debugpline3("%s, %s AEXE = %d",
594                     (i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" : (i == A_DEX)
595                                                                       ? "Dex"
596                                                                       : "Con",
597                     (inc_or_dec) ? "inc" : "dec", AEXE(i));
598     }
599     if (moves > 0 && (i == A_STR || i == A_CON))
600         (void) encumber_msg();
601 }
602
603 STATIC_OVL void
604 exerper()
605 {
606     if (!(moves % 10)) {
607         /* Hunger Checks */
608
609         int hs = (u.uhunger > 1000) ? SATIATED : (u.uhunger > 150)
610                                                      ? NOT_HUNGRY
611                                                      : (u.uhunger > 50)
612                                                            ? HUNGRY
613                                                            : (u.uhunger > 0)
614                                                                  ? WEAK
615                                                                  : FAINTING;
616
617         debugpline0("exerper: Hunger checks");
618         switch (hs) {
619         case SATIATED:
620             exercise(A_DEX, FALSE);
621             if (Role_if(PM_MONK))
622                 exercise(A_WIS, FALSE);
623             break;
624         case NOT_HUNGRY:
625             exercise(A_CON, TRUE);
626             break;
627         case WEAK:
628             exercise(A_STR, FALSE);
629             if (Role_if(PM_MONK)) /* fasting */
630                 exercise(A_WIS, TRUE);
631             break;
632         case FAINTING:
633         case FAINTED:
634             exercise(A_CON, FALSE);
635             break;
636         }
637
638         /* Encumbrance Checks */
639         debugpline0("exerper: Encumber checks");
640         switch (near_capacity()) {
641         case MOD_ENCUMBER:
642             exercise(A_STR, TRUE);
643             break;
644         case HVY_ENCUMBER:
645             exercise(A_STR, TRUE);
646             exercise(A_DEX, FALSE);
647             break;
648         case EXT_ENCUMBER:
649             exercise(A_DEX, FALSE);
650             exercise(A_CON, FALSE);
651             break;
652         }
653     }
654
655     /* status checks */
656     if (!(moves % 5)) {
657         debugpline0("exerper: Status checks");
658         if ((HClairvoyant & (INTRINSIC | TIMEOUT)) && !BClairvoyant)
659             exercise(A_WIS, TRUE);
660         if (HRegeneration)
661             exercise(A_STR, TRUE);
662
663         if (Sick || Vomiting)
664             exercise(A_CON, FALSE);
665         if (Confusion || Hallucination)
666             exercise(A_WIS, FALSE);
667         if ((Wounded_legs && !u.usteed) || Fumbling || HStun)
668             exercise(A_DEX, FALSE);
669     }
670 }
671
672 /* exercise/abuse text (must be in attribute order, not botl order);
673    phrased as "You must have been [][0]." or "You haven't been [][1]." */
674 static NEARDATA const char *const exertext[A_MAX][2] = {
675 #if 0 /*JP*/
676     { "exercising diligently", "exercising properly" },           /* Str */
677     { 0, 0 },                                                     /* Int */
678     { "very observant", "paying attention" },                     /* Wis */
679     { "working on your reflexes", "working on reflexes lately" }, /* Dex */
680     { "leading a healthy life-style", "watching your health" },   /* Con */
681     { 0, 0 },                                                     /* Cha */
682 #else
683     { "\94O\93ü\82è\82É\89^\93®\82µ\82Ä\82¢\82½", "\93K\90Ø\82É\89^\93®\82µ\82Ä\82¢\82È\82©\82Á\82½" },       /* Str */
684     { 0, 0 },                                                     /* Int */
685     { "\90T\8fd\82É\8ds\93®\82µ\82Ä\82¢\82½", "\92\8d\88Ó\95s\91«\82¾\82Á\82½" },                   /* Wis */
686     { "\94½\8eË\90_\8co\82ð\8eg\82Á\82Ä\82¢\82½", "\8dÅ\8bß\94½\8eË\90_\8co\82ð\8eg\82Á\82Ä\82¢\82È\82©\82Á\82½" }, /* Dex */
687     { "\8c\92\8dN\93I\82È\90\8a\88\82ð\82µ\82Ä\82¢\82½", "\8c\92\8dN\8aÇ\97\9d\82ð\91Ó\82Á\82Ä\82¢\82½" },         /* Con */
688     { 0, 0 },                                                     /* Cha */
689 #endif
690 };
691
692 void
693 exerchk()
694 {
695     int i, ax, mod_val, lolim, hilim;
696
697     /*  Check out the periodic accumulations */
698     exerper();
699
700     if (moves >= context.next_attrib_check) {
701         debugpline1("exerchk: ready to test. multi = %d.", multi);
702     }
703     /*  Are we ready for a test? */
704     if (moves >= context.next_attrib_check && !multi) {
705         debugpline0("exerchk: testing.");
706         /*
707          *      Law of diminishing returns (Part II):
708          *
709          *      The effects of "exercise" and "abuse" wear
710          *      off over time.  Even if you *don't* get an
711          *      increase/decrease, you lose some of the
712          *      accumulated effects.
713          */
714         for (i = 0; i < A_MAX; ++i) {
715             ax = AEXE(i);
716             /* nothing to do here if no exercise or abuse has occurred
717                (Int and Cha always fall into this category) */
718             if (!ax)
719                 continue; /* ok to skip nextattrib */
720
721             mod_val = sgn(ax); /* +1 or -1; used below */
722             /* no further effect for exercise if at max or abuse if at min;
723                can't exceed 18 via exercise even if actual max is higher */
724             lolim = ATTRMIN(i); /* usually 3; might be higher */
725             hilim = ATTRMAX(i); /* usually 18; maybe lower or higher */
726             if (hilim > 18)
727                 hilim = 18;
728             if ((ax < 0) ? (ABASE(i) <= lolim) : (ABASE(i) >= hilim))
729                 goto nextattrib;
730             /* can't exercise non-Wisdom while polymorphed; previous
731                exercise/abuse gradually wears off without impact then */
732             if (Upolyd && i != A_WIS)
733                 goto nextattrib;
734
735             debugpline2("exerchk: testing %s (%d).",
736                         (i == A_STR)
737                             ? "Str"
738                             : (i == A_INT)
739                                   ? "Int?"
740                                   : (i == A_WIS)
741                                         ? "Wis"
742                                         : (i == A_DEX)
743                                               ? "Dex"
744                                               : (i == A_CON)
745                                                     ? "Con"
746                                                     : (i == A_CHA)
747                                                           ? "Cha?"
748                                                           : "???",
749                         ax);
750             /*
751              *  Law of diminishing returns (Part III):
752              *
753              *  You don't *always* gain by exercising.
754              *  [MRS 92/10/28 - Treat Wisdom specially for balance.]
755              */
756             if (rn2(AVAL) > ((i != A_WIS) ? (abs(ax) * 2 / 3) : abs(ax)))
757                 goto nextattrib;
758
759             debugpline1("exerchk: changing %d.", i);
760             if (adjattrib(i, mod_val, -1)) {
761                 debugpline1("exerchk: changed %d.", i);
762                 /* if you actually changed an attrib - zero accumulation */
763                 AEXE(i) = ax = 0;
764                 /* then print an explanation */
765 #if 0 /*JP*/
766                 You("%s %s.",
767                     (mod_val > 0) ? "must have been" : "haven't been",
768                     exertext[i][(mod_val > 0) ? 0 : 1]);
769 #else
770                 You("%s\82É\88á\82¢\82È\82¢\81D",
771                     exertext[i][(mod_val > 0) ? 0 : 1]);
772 #endif
773             }
774         nextattrib:
775             /* this used to be ``AEXE(i) /= 2'' but that would produce
776                platform-dependent rounding/truncation for negative vals */
777             AEXE(i) = (abs(ax) / 2) * mod_val;
778         }
779         context.next_attrib_check += rn1(200, 800);
780         debugpline1("exerchk: next check at %ld.", context.next_attrib_check);
781     }
782 }
783
784 void
785 init_attr(np)
786 register int np;
787 {
788     register int i, x, tryct;
789
790     for (i = 0; i < A_MAX; i++) {
791         ABASE(i) = AMAX(i) = urole.attrbase[i];
792         ATEMP(i) = ATIME(i) = 0;
793         np -= urole.attrbase[i];
794     }
795
796     tryct = 0;
797     while (np > 0 && tryct < 100) {
798         x = rn2(100);
799         for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++)
800             ;
801         if (i >= A_MAX)
802             continue; /* impossible */
803
804         if (ABASE(i) >= ATTRMAX(i)) {
805             tryct++;
806             continue;
807         }
808         tryct = 0;
809         ABASE(i)++;
810         AMAX(i)++;
811         np--;
812     }
813
814     tryct = 0;
815     while (np < 0 && tryct < 100) { /* for redistribution */
816
817         x = rn2(100);
818         for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++)
819             ;
820         if (i >= A_MAX)
821             continue; /* impossible */
822
823         if (ABASE(i) <= ATTRMIN(i)) {
824             tryct++;
825             continue;
826         }
827         tryct = 0;
828         ABASE(i)--;
829         AMAX(i)--;
830         np++;
831     }
832 }
833
834 void
835 redist_attr()
836 {
837     register int i, tmp;
838
839     for (i = 0; i < A_MAX; i++) {
840         if (i == A_INT || i == A_WIS)
841             continue;
842         /* Polymorphing doesn't change your mind */
843         tmp = AMAX(i);
844         AMAX(i) += (rn2(5) - 2);
845         if (AMAX(i) > ATTRMAX(i))
846             AMAX(i) = ATTRMAX(i);
847         if (AMAX(i) < ATTRMIN(i))
848             AMAX(i) = ATTRMIN(i);
849         ABASE(i) = ABASE(i) * AMAX(i) / tmp;
850         /* ABASE(i) > ATTRMAX(i) is impossible */
851         if (ABASE(i) < ATTRMIN(i))
852             ABASE(i) = ATTRMIN(i);
853     }
854     (void) encumber_msg();
855 }
856
857 STATIC_OVL
858 void
859 postadjabil(ability)
860 long *ability;
861 {
862     if (!ability)
863         return;
864     if (ability == &(HWarning) || ability == &(HSee_invisible))
865         see_monsters();
866 }
867
868 STATIC_OVL const struct innate *
869 role_abil(r)
870 int r;
871 {
872     const struct {
873         short role;
874         const struct innate *abil;
875     } roleabils[] = {
876         { PM_ARCHEOLOGIST, arc_abil },
877         { PM_BARBARIAN, bar_abil },
878         { PM_CAVEMAN, cav_abil },
879         { PM_HEALER, hea_abil },
880         { PM_KNIGHT, kni_abil },
881         { PM_MONK, mon_abil },
882         { PM_PRIEST, pri_abil },
883         { PM_RANGER, ran_abil },
884         { PM_ROGUE, rog_abil },
885         { PM_SAMURAI, sam_abil },
886         { PM_TOURIST, tou_abil },
887         { PM_VALKYRIE, val_abil },
888         { PM_WIZARD, wiz_abil },
889         { 0, 0 }
890     };
891     int i;
892
893     for (i = 0; roleabils[i].abil && roleabils[i].role != r; i++)
894         continue;
895     return roleabils[i].abil;
896 }
897
898 STATIC_OVL const struct innate *
899 check_innate_abil(ability, frommask)
900 long *ability;
901 long frommask;
902 {
903     const struct innate *abil = 0;
904
905     if (frommask == FROMEXPER)
906         abil = role_abil(Role_switch);
907     else if (frommask == FROMRACE)
908         switch (Race_switch) {
909         case PM_DWARF:
910             abil = dwa_abil;
911             break;
912         case PM_ELF:
913             abil = elf_abil;
914             break;
915         case PM_GNOME:
916             abil = gno_abil;
917             break;
918         case PM_ORC:
919             abil = orc_abil;
920             break;
921         case PM_HUMAN:
922             abil = hum_abil;
923             break;
924         default:
925             break;
926         }
927
928     while (abil && abil->ability) {
929         if ((abil->ability == ability) && (u.ulevel >= abil->ulevel))
930             return abil;
931         abil++;
932     }
933     return (struct innate *) 0;
934 }
935
936 /* reasons for innate ability */
937 #define FROM_NONE 0
938 #define FROM_ROLE 1 /* from experience at level 1 */
939 #define FROM_RACE 2
940 #define FROM_INTR 3 /* intrinsically (eating some corpse or prayer reward) */
941 #define FROM_EXP  4 /* from experience for some level > 1 */
942 #define FROM_FORM 5
943 #define FROM_LYCN 6
944
945 /* check whether particular ability has been obtained via innate attribute */
946 STATIC_OVL int
947 innately(ability)
948 long *ability;
949 {
950     const struct innate *iptr;
951
952     if ((iptr = check_innate_abil(ability, FROMEXPER)) != 0)
953         return (iptr->ulevel == 1) ? FROM_ROLE : FROM_EXP;
954     if ((iptr = check_innate_abil(ability, FROMRACE)) != 0)
955         return FROM_RACE;
956     if ((*ability & FROMOUTSIDE) != 0L)
957         return FROM_INTR;
958     if ((*ability & FROMFORM) != 0L)
959         return FROM_FORM;
960     return FROM_NONE;
961 }
962
963 int
964 is_innate(propidx)
965 int propidx;
966 {
967     int innateness;
968
969     /* innately() would report FROM_FORM for this; caller wants specificity */
970     if (propidx == DRAIN_RES && u.ulycn >= LOW_PM)
971         return FROM_LYCN;
972     if (propidx == FAST && Very_fast)
973         return FROM_NONE; /* can't become very fast innately */
974     if ((innateness = innately(&u.uprops[propidx].intrinsic)) != FROM_NONE)
975         return innateness;
976     if (propidx == JUMPING && Role_if(PM_KNIGHT)
977         /* knight has intrinsic jumping, but extrinsic is more versatile so
978            ignore innateness if equipment is going to claim responsibility */
979         && !u.uprops[propidx].extrinsic)
980         return FROM_ROLE;
981     if (propidx == BLINDED && !haseyes(youmonst.data))
982         return FROM_FORM;
983     return FROM_NONE;
984 }
985
986 char *
987 from_what(propidx)
988 int propidx; /* special cases can have negative values */
989 {
990     static char buf[BUFSZ];
991
992     buf[0] = '\0';
993     /*
994      * Restrict the source of the attributes just to debug mode for now
995      */
996 /*JP:\81u\82 \82È\82½\82Í\82 \82È\82½\82Ì\81c\82É\82æ\82Á\82Ä\81v\82Æ\82È\82é\82Æ\95s\8e©\91R\82È\82Ì\82Åsimpleonames()\82ð\8eg\82¤*/
997 /*JP: \96{\97\88\82Íminimal_xname()\82ð\8eg\82¤\82×\82«\82¾\82ªstatic\82È\82Ì\82Å\91ã\97p*/
998     if (wizard) {
999 /*JP
1000         static NEARDATA const char because_of[] = " because of %s";
1001 */
1002         static NEARDATA const char because_of[] = "%s\82É\82æ\82Á\82Ä";
1003
1004         if (propidx >= 0) {
1005 #if 0 /*JP*/
1006             char *p;
1007 #endif
1008             struct obj *obj = (struct obj *) 0;
1009             int innateness = is_innate(propidx);
1010
1011             /*
1012              * Properties can be obtained from multiple sources and we
1013              * try to pick the most significant one.  Classification
1014              * priority is not set in stone; current precedence is:
1015              * "from the start" (from role or race at level 1),
1016              * "from outside" (eating corpse, divine reward, blessed potion),
1017              * "from experience" (from role or race at level 2+),
1018              * "from current form" (while polymorphed),
1019              * "from timed effect" (potion or spell),
1020              * "from worn/wielded equipment" (Firebrand, elven boots, &c),
1021              * "from carried equipment" (mainly quest artifacts).
1022              * There are exceptions.  Versatile jumping from spell or boots
1023              * takes priority over knight's innate but limited jumping.
1024              */
1025             if (propidx == BLINDED && u.uroleplay.blind)
1026 /*JP
1027                 Sprintf(buf, " from birth");
1028 */
1029                 Sprintf(buf, "\90\82Ü\82ê\82Ä\82©\82ç\82¸\82Á\82Æ");
1030             else if (innateness == FROM_ROLE || innateness == FROM_RACE)
1031 /*JP
1032                 Strcpy(buf, " innately");
1033 */
1034                 Strcpy(buf, "\90\82Ü\82ê\82È\82ª\82ç\82É");
1035             else if (innateness == FROM_INTR) /* [].intrinsic & FROMOUTSIDE */
1036 /*JP
1037                 Strcpy(buf, " intrinsically");
1038 */
1039                 Strcpy(buf, "\96{\8e¿\93I\82É");
1040             else if (innateness == FROM_EXP)
1041 /*JP
1042                 Strcpy(buf, " because of your experience");
1043 */
1044                 Strcpy(buf, "\8co\8c±\82É\82æ\82Á\82Ä");
1045             else if (innateness == FROM_LYCN)
1046 /*JP
1047                 Strcpy(buf, " due to your lycanthropy");
1048 */
1049                 Strcpy(buf, "\8fb\89»\95a\82É\82æ\82Á\82Ä");
1050             else if (innateness == FROM_FORM)
1051 /*JP
1052                 Strcpy(buf, " from current creature form");
1053 */
1054                 Strcpy(buf, "\8c»\8dÝ\82Ì\8ep\82É\82æ\82Á\82Ä");
1055             else if (propidx == FAST && Very_fast)
1056 #if 0 /*JP*/
1057                 Sprintf(buf, because_of,
1058                         ((HFast & TIMEOUT) != 0L) ? "a potion or spell"
1059                           : ((EFast & W_ARMF) != 0L && uarmf->dknown
1060                              && objects[uarmf->otyp].oc_name_known)
1061                               ? ysimple_name(uarmf) /* speed boots */
1062                                 : EFast ? "worn equipment"
1063                                   : something);
1064 #else
1065                 Sprintf(buf, because_of,
1066                         ((HFast & TIMEOUT) != 0L) ? "\96ò\82â\8eô\95¶"
1067                           : ((EFast & W_ARMF) != 0L && uarmf->dknown
1068                              && objects[uarmf->otyp].oc_name_known)
1069                               ? ysimple_name(uarmf) /* speed boots */
1070                                 : EFast ? "\91\95\94õ"
1071                                   : something);
1072 #endif
1073             else if (wizard
1074                      && (obj = what_gives(&u.uprops[propidx].extrinsic)) != 0)
1075                 Sprintf(buf, because_of, obj->oartifact
1076                                              ? bare_artifactname(obj)
1077 /*JP
1078                                              : ysimple_name(obj));
1079 */
1080                                              : simpleonames(obj));
1081             else if (propidx == BLINDED && Blindfolded_only)
1082 /*JP
1083                 Sprintf(buf, because_of, ysimple_name(ublindf));
1084 */
1085                 Sprintf(buf, because_of, simpleonames(ublindf));
1086
1087 #if 0 /*JP*//*\95s\97v*/
1088             /* remove some verbosity and/or redundancy */
1089             if ((p = strstri(buf, " pair of ")) != 0)
1090                 copynchars(p + 1, p + 9, BUFSZ); /* overlapping buffers ok */
1091             else if (propidx == STRANGLED
1092                      && (p = strstri(buf, " of strangulation")) != 0)
1093                 *p = '\0';
1094 #endif
1095
1096         } else { /* negative property index */
1097             /* if more blocking capabilities get implemented we'll need to
1098                replace this with what_blocks() comparable to what_gives() */
1099             switch (-propidx) {
1100             case BLINDED:
1101                 if (ublindf
1102                     && ublindf->oartifact == ART_EYES_OF_THE_OVERWORLD)
1103                     Sprintf(buf, because_of, bare_artifactname(ublindf));
1104                 break;
1105             case INVIS:
1106                 if (u.uprops[INVIS].blocked & W_ARMC)
1107 #if 0 /*JP*/
1108                     Sprintf(buf, because_of,
1109                             ysimple_name(uarmc)); /* mummy wrapping */
1110 #else
1111                     Sprintf(buf, because_of,
1112                             simpleonames(uarmc)); /* mummy wrapping */
1113 #endif
1114                 break;
1115             case CLAIRVOYANT:
1116                 if (wizard && (u.uprops[CLAIRVOYANT].blocked & W_ARMH))
1117 #if 0 /*JP*/
1118                     Sprintf(buf, because_of,
1119                             ysimple_name(uarmh)); /* cornuthaum */
1120 #else
1121                     Sprintf(buf, because_of,
1122                             simpleonames(uarmh)); /* cornuthaum */
1123 #endif
1124                 break;
1125             }
1126         }
1127
1128     } /*wizard*/
1129     return buf;
1130 }
1131
1132 void
1133 adjabil(oldlevel, newlevel)
1134 int oldlevel, newlevel;
1135 {
1136     register const struct innate *abil, *rabil;
1137     long prevabil, mask = FROMEXPER;
1138
1139     abil = role_abil(Role_switch);
1140
1141     switch (Race_switch) {
1142     case PM_ELF:
1143         rabil = elf_abil;
1144         break;
1145     case PM_ORC:
1146         rabil = orc_abil;
1147         break;
1148     case PM_HUMAN:
1149     case PM_DWARF:
1150     case PM_GNOME:
1151     default:
1152         rabil = 0;
1153         break;
1154     }
1155
1156     while (abil || rabil) {
1157         /* Have we finished with the intrinsics list? */
1158         if (!abil || !abil->ability) {
1159             /* Try the race intrinsics */
1160             if (!rabil || !rabil->ability)
1161                 break;
1162             abil = rabil;
1163             rabil = 0;
1164             mask = FROMRACE;
1165         }
1166         prevabil = *(abil->ability);
1167         if (oldlevel < abil->ulevel && newlevel >= abil->ulevel) {
1168             /* Abilities gained at level 1 can never be lost
1169              * via level loss, only via means that remove _any_
1170              * sort of ability.  A "gain" of such an ability from
1171              * an outside source is devoid of meaning, so we set
1172              * FROMOUTSIDE to avoid such gains.
1173              */
1174             if (abil->ulevel == 1)
1175                 *(abil->ability) |= (mask | FROMOUTSIDE);
1176             else
1177                 *(abil->ability) |= mask;
1178             if (!(*(abil->ability) & INTRINSIC & ~mask)) {
1179                 if (*(abil->gainstr))
1180 /*JP
1181                     You_feel("%s!", abil->gainstr);
1182 */
1183                     You("%s\82æ\82¤\82È\8bC\82ª\82µ\82½\81I", abil->gainstr);
1184             }
1185         } else if (oldlevel >= abil->ulevel && newlevel < abil->ulevel) {
1186             *(abil->ability) &= ~mask;
1187             if (!(*(abil->ability) & INTRINSIC)) {
1188                 if (*(abil->losestr))
1189 /*JP
1190                     You_feel("%s!", abil->losestr);
1191 */
1192                     You("%s\82æ\82¤\82È\8bC\82ª\82µ\82½\81I", abil->losestr);
1193 /*JP:\82±\82Ì\8fð\8c\8f\82Í\96\9e\82³\82È\82¢\82Í\82¸\81D*/
1194                 else if (*(abil->gainstr))
1195                     You_feel("less %s!", abil->gainstr);
1196             }
1197         }
1198         if (prevabil != *(abil->ability)) /* it changed */
1199             postadjabil(abil->ability);
1200         abil++;
1201     }
1202
1203     if (oldlevel > 0) {
1204         if (newlevel > oldlevel)
1205             add_weapon_skill(newlevel - oldlevel);
1206         else
1207             lose_weapon_skill(oldlevel - newlevel);
1208     }
1209 }
1210
1211 int
1212 newhp()
1213 {
1214     int hp, conplus;
1215
1216     if (u.ulevel == 0) {
1217         /* Initialize hit points */
1218         hp = urole.hpadv.infix + urace.hpadv.infix;
1219         if (urole.hpadv.inrnd > 0)
1220             hp += rnd(urole.hpadv.inrnd);
1221         if (urace.hpadv.inrnd > 0)
1222             hp += rnd(urace.hpadv.inrnd);
1223         if (moves <= 1L) { /* initial hero; skip for polyself to new man */
1224             /* Initialize alignment stuff */
1225             u.ualign.type = aligns[flags.initalign].value;
1226             u.ualign.record = urole.initrecord;
1227         }
1228         /* no Con adjustment for initial hit points */
1229     } else {
1230         if (u.ulevel < urole.xlev) {
1231             hp = urole.hpadv.lofix + urace.hpadv.lofix;
1232             if (urole.hpadv.lornd > 0)
1233                 hp += rnd(urole.hpadv.lornd);
1234             if (urace.hpadv.lornd > 0)
1235                 hp += rnd(urace.hpadv.lornd);
1236         } else {
1237             hp = urole.hpadv.hifix + urace.hpadv.hifix;
1238             if (urole.hpadv.hirnd > 0)
1239                 hp += rnd(urole.hpadv.hirnd);
1240             if (urace.hpadv.hirnd > 0)
1241                 hp += rnd(urace.hpadv.hirnd);
1242         }
1243         if (ACURR(A_CON) <= 3)
1244             conplus = -2;
1245         else if (ACURR(A_CON) <= 6)
1246             conplus = -1;
1247         else if (ACURR(A_CON) <= 14)
1248             conplus = 0;
1249         else if (ACURR(A_CON) <= 16)
1250             conplus = 1;
1251         else if (ACURR(A_CON) == 17)
1252             conplus = 2;
1253         else if (ACURR(A_CON) == 18)
1254             conplus = 3;
1255         else
1256             conplus = 4;
1257         hp += conplus;
1258     }
1259     if (hp <= 0)
1260         hp = 1;
1261     if (u.ulevel < MAXULEV)
1262         u.uhpinc[u.ulevel] = (xchar) hp;
1263     return hp;
1264 }
1265
1266 schar
1267 acurr(x)
1268 int x;
1269 {
1270     register int tmp = (u.abon.a[x] + u.atemp.a[x] + u.acurr.a[x]);
1271
1272     if (x == A_STR) {
1273         if (tmp >= 125 || (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER))
1274             return (schar) 125;
1275         else
1276 #ifdef WIN32_BUG
1277             return (x = ((tmp <= 3) ? 3 : tmp));
1278 #else
1279             return (schar) ((tmp <= 3) ? 3 : tmp);
1280 #endif
1281     } else if (x == A_CHA) {
1282         if (tmp < 18
1283             && (youmonst.data->mlet == S_NYMPH || u.umonnum == PM_SUCCUBUS
1284                 || u.umonnum == PM_INCUBUS))
1285             return (schar) 18;
1286     } else if (x == A_CON) {
1287         if (uwep && uwep->oartifact == ART_OGRESMASHER)
1288             return (schar) 25;
1289     } else if (x == A_INT || x == A_WIS) {
1290         /* yes, this may raise int/wis if player is sufficiently
1291          * stupid.  there are lower levels of cognition than "dunce".
1292          */
1293         if (uarmh && uarmh->otyp == DUNCE_CAP)
1294             return (schar) 6;
1295     }
1296 #ifdef WIN32_BUG
1297     return (x = ((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp));
1298 #else
1299     return (schar) ((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp);
1300 #endif
1301 }
1302
1303 /* condense clumsy ACURR(A_STR) value into value that fits into game formulas
1304  */
1305 schar
1306 acurrstr()
1307 {
1308     register int str = ACURR(A_STR);
1309
1310     if (str <= 18)
1311         return (schar) str;
1312     if (str <= 121)
1313         return (schar) (19 + str / 50); /* map to 19..21 */
1314     else
1315         return (schar) (min(str, 125) - 100); /* 22..25 */
1316 }
1317
1318 /* when wearing (or taking off) an unID'd item, this routine is used
1319    to distinguish between observable +0 result and no-visible-effect
1320    due to an attribute not being able to exceed maximum or minimum */
1321 boolean
1322 extremeattr(attrindx) /* does attrindx's value match its max or min? */
1323 int attrindx;
1324 {
1325     /* Fixed_abil and racial MINATTR/MAXATTR aren't relevant here */
1326     int lolimit = 3, hilimit = 25, curval = ACURR(attrindx);
1327
1328     /* upper limit for Str is 25 but its value is encoded differently */
1329     if (attrindx == A_STR) {
1330         hilimit = STR19(25); /* 125 */
1331         /* lower limit for Str can also be 25 */
1332         if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER)
1333             lolimit = hilimit;
1334     } else if (attrindx == A_CON) {
1335         if (uwep && uwep->oartifact == ART_OGRESMASHER)
1336             lolimit = hilimit;
1337     }
1338     /* this exception is hypothetical; the only other worn item affecting
1339        Int or Wis is another helmet so can't be in use at the same time */
1340     if (attrindx == A_INT || attrindx == A_WIS) {
1341         if (uarmh && uarmh->otyp == DUNCE_CAP)
1342             hilimit = lolimit = 6;
1343     }
1344
1345     /* are we currently at either limit? */
1346     return (curval == lolimit || curval == hilimit) ? TRUE : FALSE;
1347 }
1348
1349 /* avoid possible problems with alignment overflow, and provide a centralized
1350    location for any future alignment limits */
1351 void
1352 adjalign(n)
1353 int n;
1354 {
1355     int newalign = u.ualign.record + n;
1356
1357     if (n < 0) {
1358         if (newalign < u.ualign.record)
1359             u.ualign.record = newalign;
1360     } else if (newalign > u.ualign.record) {
1361         u.ualign.record = newalign;
1362         if (u.ualign.record > ALIGNLIM)
1363             u.ualign.record = ALIGNLIM;
1364     }
1365 }
1366
1367 /* change hero's alignment type, possibly losing use of artifacts */
1368 void
1369 uchangealign(newalign, reason)
1370 int newalign;
1371 int reason; /* 0==conversion, 1==helm-of-OA on, 2==helm-of-OA off */
1372 {
1373     aligntyp oldalign = u.ualign.type;
1374
1375     u.ublessed = 0;   /* lose divine protection */
1376     context.botl = 1; /* status line needs updating */
1377     if (reason == 0) {
1378         /* conversion via altar */
1379         u.ualignbase[A_CURRENT] = (aligntyp) newalign;
1380         /* worn helm of opposite alignment might block change */
1381         if (!uarmh || uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT)
1382             u.ualign.type = u.ualignbase[A_CURRENT];
1383 #if 0 /*JP*/
1384         You("have a %ssense of a new direction.",
1385             (u.ualign.type != oldalign) ? "sudden " : "");
1386 #else
1387         You("%s\95Ê\82Ì\95û\8cü\90«\82É\82ß\82´\82ß\82½\81D",
1388             (u.ualign.type != oldalign) ? "\93Ë\91R" : "");
1389 #endif
1390     } else {
1391         /* putting on or taking off a helm of opposite alignment */
1392         u.ualign.type = (aligntyp) newalign;
1393         if (reason == 1)
1394 /*JP
1395             Your("mind oscillates %s.", Hallucination ? "wildly" : "briefly");
1396 */
1397             You("%s\90Q\95Ô\82Á\82½\81D", Hallucination ? "\8dr\82Á\82Û\82­" : "\82 \82Á\82³\82è\82Æ");
1398         else if (reason == 2)
1399 #if 0 /*JP*/
1400             Your("mind is %s.", Hallucination
1401                                     ? "much of a muchness"
1402                                     : "back in sync with your body");
1403 #else
1404             Your("\90S\82Í%s\81D", Hallucination
1405                                     ? "\8e\97\82½\82è\8añ\82Á\82½\82è\82É\82È\82Á\82½"
1406                                     : "\8dÄ\82Ñ\91Ì\82Æ\88ê\92v\82·\82é\82æ\82¤\82É\82È\82Á\82½");
1407 #endif
1408     }
1409
1410     if (u.ualign.type != oldalign) {
1411         u.ualign.record = 0; /* slate is wiped clean */
1412         retouch_equipment(0);
1413     }
1414 }
1415
1416 /*attrib.c*/