1 /* NetHack 3.6 attrib.c $NHDT-Date: 1449269911 2015/12/04 22:58:31 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.51 $ */
2 /* Copyright 1988, 1989, 1990, 1992, M. Stephenson */
3 /* NetHack may be freely redistributed. See license for details. */
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016 */
8 /* JNetHack may be freely redistributed. See license for details. */
11 /* attribute modification routines. */
16 /* part of the output on gain or loss of attribute */
19 *const plusattr[] = { "strong", "smart", "wise",
20 "agile", "tough", "charismatic" },
22 *const plusattr[] = { "
\8b
\82¢", "
\8c«
\96¾
\82¾", "
\8c«
\82¢",
23 "
\8b@
\95q
\82¾", "
\8aæ
\8fä
\82¾", "
\96£
\97Í
\93I
\82¾" },
26 *const minusattr[] = { "weak", "stupid",
28 "fragile", "repulsive" };
30 *const minusattr[] = { "
\8eã
\82¢", "
\8bð
\82©
\82¾",
31 "
\8aÔ
\94²
\82¯
\82¾", "
\95s
\8aí
\97p
\82¾",
32 "
\82Ð
\8eã
\82¾","
\8fX
\82¢" };
35 static const struct innate {
38 const char *gainstr, *losestr;
39 } arc_abil[] = { { 1, &(HStealth), "", "" },
40 { 1, &(HFast), "", "" },
42 { 10, &(HSearching), "perceptive", "" },
44 { 10, &(HSearching), "
\92m
\8ao
\97Í
\82ð
\93¾
\82½", "
\92m
\8ao
\97Í
\82ð
\8e¸
\82Á
\82½" },
47 bar_abil[] = { { 1, &(HPoison_resistance), "", "" },
49 { 7, &(HFast), "quick", "slow" },
51 { 7, &(HFast), "
\91f
\91\81\82³
\82ð
\93¾
\82½", "
\92x
\82
\82È
\82Á
\82½" },
53 { 15, &(HStealth), "stealthy", "" },
55 { 15, &(HStealth), "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\93¾
\82½", "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\8e¸
\82Á
\82½" },
59 cav_abil[] = { { 7, &(HFast), "quick", "slow" },
61 cav_abil[] = { { 7, &(HFast), "
\91f
\91\81\82³
\82ð
\93¾
\82½", "
\92x
\82
\82È
\82Á
\82½" },
63 { 15, &(HWarning), "sensitive", "" },
65 { 15, &(HWarning), "
\95q
\8a´
\82É
\82È
\82Á
\82½", "
\93Ý
\8a´
\82É
\82È
\82Á
\82½" },
68 hea_abil[] = { { 1, &(HPoison_resistance), "", "" },
70 { 15, &(HWarning), "sensitive", "" },
72 { 15, &(HWarning), "
\95q
\8a´
\82É
\82È
\82Á
\82½", "
\93Ý
\8a´
\82É
\82È
\82Á
\82½" },
76 kni_abil[] = { { 7, &(HFast), "quick", "slow" }, { 0, 0, 0, 0 } },
78 kni_abil[] = { { 7, &(HFast), "
\91f
\91\81\82³
\82ð
\93¾
\82½", "
\92x
\82
\82È
\82Á
\82½" }, { 0, 0, 0, 0 } },
80 mon_abil[] = { { 1, &(HFast), "", "" },
81 { 1, &(HSleep_resistance), "", "" },
82 { 1, &(HSee_invisible), "", "" },
84 { 3, &(HPoison_resistance), "healthy", "" },
86 { 3, &(HPoison_resistance), "
\8c\92\8dN
\82É
\82È
\82Á
\82½", "
\95s
\8c\92\8dN
\82É
\82È
\82Á
\82½" },
88 { 5, &(HStealth), "stealthy", "" },
90 { 5, &(HStealth), "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\93¾
\82½", "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\8e¸
\82Á
\82½" },
92 { 7, &(HWarning), "sensitive", "" },
94 { 7, &(HWarning), "
\95q
\8a´
\82É
\82È
\82Á
\82½", "
\93Ý
\8a´
\82É
\82È
\82Á
\82½" },
96 { 9, &(HSearching), "perceptive", "unaware" },
98 { 9, &(HSearching), "
\92m
\8ao
\97Í
\82ð
\93¾
\82½", "
\92m
\8ao
\97Í
\82ð
\8e¸
\82Á
\82½" },
100 { 11, &(HFire_resistance), "cool", "warmer" },
102 { 11, &(HFire_resistance), "
\97â
\82½
\82
\82È
\82Á
\82½", "
\92g
\82©
\82
\82È
\82Á
\82½" },
104 { 13, &(HCold_resistance), "warm", "cooler" },
106 { 13, &(HCold_resistance), "
\92g
\82©
\82
\82È
\82Á
\82½", "
\97â
\82½
\82
\82È
\82Á
\82½"},
108 { 15, &(HShock_resistance), "insulated", "conductive" },
110 { 15, &(HShock_resistance), "
\90â
\89\8f\82³
\82ê
\82½", "
\93±
\93d
\82³
\82ê
\82½" },
112 { 17, &(HTeleport_control), "controlled", "uncontrolled" },
114 { 17, &(HTeleport_control), "
\90§
\8cä
\97Í
\82ð
\93¾
\82½","
\90§
\8cä
\97Í
\82ð
\8e¸
\82Á
\82½" },
118 pri_abil[] = { { 15, &(HWarning), "sensitive", "" },
120 pri_abil[] = { { 15, &(HWarning), "
\95q
\8a´
\82É
\82È
\82Á
\82½", "
\93Ý
\8a´
\82É
\82È
\82Á
\82½" },
122 { 20, &(HFire_resistance), "cool", "warmer" },
124 { 20, &(HFire_resistance), "
\97â
\82½
\82
\82È
\82Á
\82½", "
\92g
\82©
\82
\82È
\82Á
\82½" },
127 ran_abil[] = { { 1, &(HSearching), "", "" },
129 { 7, &(HStealth), "stealthy", "" },
131 { 7, &(HStealth), "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\93¾
\82½", "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\8e¸
\82Á
\82½" },
132 { 15, &(HSee_invisible), "", "" },
135 rog_abil[] = { { 1, &(HStealth), "", "" },
137 { 10, &(HSearching), "perceptive", "" },
139 { 10, &(HSearching), "
\92m
\8ao
\97Í
\82ð
\93¾
\82½", "
\92m
\8ao
\97Í
\82ð
\8e¸
\82Á
\82½" },
142 sam_abil[] = { { 1, &(HFast), "", "" },
144 { 15, &(HStealth), "stealthy", "" },
146 { 15, &(HStealth), "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\93¾
\82½", "
\90l
\96Ú
\82ð
\93\90\82Þ
\97Í
\82ð
\8e¸
\82Á
\82½" },
150 tou_abil[] = { { 10, &(HSearching), "perceptive", "" },
152 tou_abil[] = { { 10, &(HSearching), "
\92m
\8ao
\97Í
\82ð
\93¾
\82½", "
\92m
\8ao
\97Í
\82ð
\8e¸
\82Á
\82½" },
154 { 20, &(HPoison_resistance), "hardy", "" },
156 { 20, &(HPoison_resistance), "
\96Æ
\89u
\97Í
\82ð
\93¾
\82½", "
\96Æ
\89u
\97Í
\82ð
\8e¸
\82Á
\82½" },
159 val_abil[] = { { 1, &(HCold_resistance), "", "" },
160 { 1, &(HStealth), "", "" },
162 { 7, &(HFast), "quick", "slow" },
164 { 7, &(HFast), "
\91f
\91\81\82³
\82ð
\93¾
\82½", "
\92x
\82
\82È
\82Á
\82½" },
168 wiz_abil[] = { { 15, &(HWarning), "sensitive", "" },
170 wiz_abil[] = { { 15, &(HWarning), "
\95q
\8a´
\82É
\82È
\82Á
\82½", "
\93Ý
\8a´
\82É
\82È
\82Á
\82½" },
172 { 17, &(HTeleport_control), "controlled", "uncontrolled" },
174 { 17, &(HTeleport_control), "
\90§
\8cä
\97Í
\82ð
\93¾
\82½","
\90§
\8cä
\97Í
\82ð
\8e¸
\82Á
\82½" },
177 /* Intrinsics conferred by race */
179 elf_abil[] = { { 4, &(HSleep_resistance), "awake", "tired" },
181 elf_abil[] = { { 4, &(HSleep_resistance), "
\96Ú
\82ª
\8ao
\82ß
\82½", "
\96°
\82
\82È
\82Á
\82½" },
184 orc_abil[] = { { 1, &(HPoison_resistance), "", "" }, { 0, 0, 0, 0 } };
186 STATIC_DCL void NDECL(exerper);
187 STATIC_DCL void FDECL(postadjabil, (long *));
188 STATIC_DCL const struct innate *FDECL(check_innate_abil, (long *, long));
189 STATIC_DCL int FDECL(innately, (long *));
191 /* adjust an attribute; return TRUE if change is made, FALSE otherwise */
193 adjattrib(ndx, incr, msgflg)
195 int msgflg; /* positive => no message, zero => message, and */
196 { /* negative => conditional (msg if change made) */
201 if (Fixed_abil || !incr)
204 if ((ndx == A_INT || ndx == A_WIS) && uarmh && uarmh->otyp == DUNCE_CAP) {
207 Your("cap constricts briefly, then relaxes again.");
209 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");
213 old_acurr = ACURR(ndx);
216 if (ABASE(ndx) > AMAX(ndx)) {
217 incr = ABASE(ndx) - AMAX(ndx);
219 if (AMAX(ndx) > ATTRMAX(ndx))
220 AMAX(ndx) = ATTRMAX(ndx);
221 ABASE(ndx) = AMAX(ndx);
223 attrstr = plusattr[ndx];
224 abonflg = (ABON(ndx) < 0);
227 if (ABASE(ndx) < ATTRMIN(ndx)) {
228 incr = ABASE(ndx) - ATTRMIN(ndx);
229 ABASE(ndx) = ATTRMIN(ndx);
231 if (AMAX(ndx) < ATTRMIN(ndx))
232 AMAX(ndx) = ATTRMIN(ndx);
234 attrstr = minusattr[ndx];
235 abonflg = (ABON(ndx) > 0);
237 if (ACURR(ndx) == old_acurr) {
238 if (msgflg == 0 && flags.verbose)
240 pline("You're %s as %s as you can get.",
241 abonflg ? "currently" : "already", attrstr);
243 You("%s
\8f\
\95ª
\82É%s
\81D",
244 abonflg ? "
\8d¡
\82Ì
\82Æ
\82±
\82ë" : "
\8aù
\82É", attrstr);
251 You_feel("%s%s!", (incr > 1 || incr < -1) ? "very " : "", attrstr);
253 You("%s%s
\82È
\82Á
\82½
\82æ
\82¤
\82È
\8bC
\82ª
\82µ
\82½
\81I", (incr > 1 || incr < -1) ? "
\82Æ
\82Ä
\82à" : "", jconj_adj(attrstr));
255 if (moves > 1 && (ndx == A_STR || ndx == A_CON))
256 (void) encumber_msg();
261 gainstr(otmp, incr, givemsg)
269 if (ABASE(A_STR) < 18)
270 num = (rn2(4) ? 1 : rnd(6));
271 else if (ABASE(A_STR) < STR18(85))
276 (void) adjattrib(A_STR, (otmp && otmp->cursed) ? -num : num,
280 /* may kill you; cause may be poison or monster like 'a' */
285 int ustr = ABASE(A_STR) - num;
298 (void) adjattrib(A_STR, -num, 1);
301 static const struct poison_effect_message {
302 void VDECL((*delivery_func), (const char *, ...));
303 const char *effect_msg;
305 { You_feel, "weaker" }, /* A_STR */
306 { Your, "brain is on fire" }, /* A_INT */
307 { Your, "judgement is impaired" }, /* A_WIS */
308 { Your, "muscles won't obey you" }, /* A_DEX */
309 { You_feel, "very sick" }, /* A_CON */
310 { You, "break out in hives" } /* A_CHA */
313 /* feedback for attribute loss due to poisoning */
315 poisontell(typ, exclaim)
316 int typ; /* which attribute */
317 boolean exclaim; /* emphasis */
319 void VDECL((*func), (const char *, ...)) = poiseff[typ].delivery_func;
321 (*func)("%s%c", poiseff[typ].effect_msg, exclaim ? '!' : '.');
324 /* called when an attack or trap has poisoned the hero (used to be in mon.c)
327 poisoned(reason, typ, pkiller, fatal, thrown_weapon)
328 const char *reason, /* controls what messages we display */
329 *pkiller; /* for score+log file if fatal */
330 int typ, fatal; /* if fatal is 0, limit damage to adjattrib */
331 boolean thrown_weapon; /* thrown weapons are less deadly */
333 int i, loss, kprefix = KILLED_BY_AN;
335 /* inform player about being poisoned unless that's already been done;
336 "blast" has given a "blast of poison gas" message; "poison arrow",
337 "poison dart", etc have implicitly given poison messages too... */
339 if (strcmp(reason, "blast") && !strstri(reason, "poison")) {
341 if (strcmp(reason, "
\95\97") && strcmp(reason, "
\91§") && !strstri(reason, "
\93Å")) {
344 boolean plural = (reason[strlen(reason) - 1] == 's') ? 1 : 0;
347 /* avoid "The" Orcus's sting was poisoned... */
349 pline("%s%s %s poisoned!", isupper(*reason) ? "" : "The ", reason,
350 plural ? "were" : "was");
352 pline("%s
\82Í
\93Å
\82É
\82¨
\82©
\82³
\82ê
\82Ä
\82¢
\82é
\81I", reason);
355 if (Poison_resistance) {
357 if (!strcmp(reason, "blast"))
359 if (!strcmp(reason, "
\95\97") || !strcmp(reason, "
\91§"))
361 shieldeff(u.ux, u.uy);
363 pline_The("poison doesn't seem to affect you.");
365 pline("
\93Å
\82Í
\8cø
\82©
\82È
\82©
\82Á
\82½
\82æ
\82¤
\82¾
\81D");
369 #if 0 /*JP*//*
\93ú
\96{
\8cê
\82Å
\82Í
\95s
\97v*/
370 /* suppress killer prefix if it already has one */
371 i = name_to_mon(pkiller);
372 if (i >= LOW_PM && (mons[i].geno & G_UNIQ)) {
374 if (!type_is_pname(&mons[i]))
375 pkiller = the(pkiller);
376 } else if (!strncmpi(pkiller, "the ", 4) || !strncmpi(pkiller, "an ", 3)
377 || !strncmpi(pkiller, "a ", 2)) {
378 /*[ does this need a plural check too? ]*/
383 i = !fatal ? 1 : rn2(fatal + (thrown_weapon ? 20 : 0));
384 if (i == 0 && typ != A_CHA) {
388 pline_The("poison was deadly...");
390 pline("
\93Å
\82Í
\92v
\8e\80\97Ê
\82¾
\82Á
\82½
\81D
\81D
\81D");
392 /* HP damage; more likely--but less severe--with missiles */
393 loss = thrown_weapon ? rnd(6) : rn1(10, 6);
394 losehp(loss, pkiller, kprefix); /* poison damage */
396 /* attribute loss; if typ is A_STR, reduction in current and
397 maximum HP will occur once strength has dropped down to 3 */
398 loss = (thrown_weapon || !fatal) ? 1 : d(2, 2); /* was rn1(3,3) */
399 /* check that a stat change was made */
400 if (adjattrib(typ, -loss, 1))
401 poisontell(typ, TRUE);
405 killer.format = kprefix;
406 Strcpy(killer.name, pkiller);
408 /* "Poisoned by a poisoned ___" is redundant */
409 done(strstri(pkiller, "poison") ? DIED : POISONING);
410 #else /*JP:
\93ú
\96{
\8cê
\82Å
\82Í
\8bæ
\95Ê
\82µ
\82Ä
\82¢
\82È
\82¢*/
414 (void) encumber_msg();
422 if (u.uluck < 0 && u.uluck < LUCKMIN)
424 if (u.uluck > 0 && u.uluck > LUCKMAX)
429 stone_luck(parameter)
430 boolean parameter; /* So I can't think up of a good name. So sue me. --KAA */
432 register struct obj *otmp;
433 register long bonchance = 0;
435 for (otmp = invent; otmp; otmp = otmp->nobj)
436 if (confers_luck(otmp)) {
438 bonchance -= otmp->quan;
439 else if (otmp->blessed)
440 bonchance += otmp->quan;
442 bonchance += otmp->quan;
445 return sgn((int) bonchance);
448 /* there has just been an inventory change affecting a luck-granting item */
452 int luckbon = stone_luck(TRUE);
454 if (!luckbon && !carrying(LUCKSTONE))
456 else if (luckbon >= 0)
457 u.moreluck = LUCKADD;
459 u.moreluck = -LUCKADD;
467 for (i = 0; i < A_MAX; i++) { /* all temporary losses/gains */
469 if (ATEMP(i) && ATIME(i)) {
470 if (!(--(ATIME(i)))) { /* countdown for change */
471 ATEMP(i) += ATEMP(i) > 0 ? -1 : 1;
473 if (ATEMP(i)) /* reset timer */
474 ATIME(i) = 100 / ACURR(A_CON);
478 (void) encumber_msg();
481 #define AVAL 50 /* tune value for exercise gains */
484 exercise(i, inc_or_dec)
488 debugpline0("Exercise:");
489 if (i == A_INT || i == A_CHA)
490 return; /* can't exercise these */
492 /* no physical exercise while polymorphed; the body's temporary */
493 if (Upolyd && i != A_WIS)
496 if (abs(AEXE(i)) < AVAL) {
498 * Law of diminishing returns (Part I):
500 * Gain is harder at higher attribute values.
501 * 79% at "3" --> 0% at "18"
502 * Loss is even at all levels (50%).
504 * Note: *YES* ACURR is the right one to use.
506 AEXE(i) += (inc_or_dec) ? (rn2(19) > ACURR(i)) : -rn2(2);
507 debugpline3("%s, %s AEXE = %d",
508 (i == A_STR) ? "Str" : (i == A_WIS) ? "Wis" : (i == A_DEX)
511 (inc_or_dec) ? "inc" : "dec", AEXE(i));
513 if (moves > 0 && (i == A_STR || i == A_CON))
514 (void) encumber_msg();
523 int hs = (u.uhunger > 1000) ? SATIATED : (u.uhunger > 150)
531 debugpline0("exerper: Hunger checks");
534 exercise(A_DEX, FALSE);
535 if (Role_if(PM_MONK))
536 exercise(A_WIS, FALSE);
539 exercise(A_CON, TRUE);
542 exercise(A_STR, FALSE);
543 if (Role_if(PM_MONK)) /* fasting */
544 exercise(A_WIS, TRUE);
548 exercise(A_CON, FALSE);
552 /* Encumbrance Checks */
553 debugpline0("exerper: Encumber checks");
554 switch (near_capacity()) {
556 exercise(A_STR, TRUE);
559 exercise(A_STR, TRUE);
560 exercise(A_DEX, FALSE);
563 exercise(A_DEX, FALSE);
564 exercise(A_CON, FALSE);
571 debugpline0("exerper: Status checks");
572 if ((HClairvoyant & (INTRINSIC | TIMEOUT)) && !BClairvoyant)
573 exercise(A_WIS, TRUE);
575 exercise(A_STR, TRUE);
577 if (Sick || Vomiting)
578 exercise(A_CON, FALSE);
579 if (Confusion || Hallucination)
580 exercise(A_WIS, FALSE);
581 if ((Wounded_legs && !u.usteed) || Fumbling || HStun)
582 exercise(A_DEX, FALSE);
586 /* exercise/abuse text (must be in attribute order, not botl order);
587 phrased as "You must have been [][0]." or "You haven't been [][1]." */
588 static NEARDATA const char *const exertext[A_MAX][2] = {
590 { "exercising diligently", "exercising properly" }, /* Str */
592 { "very observant", "paying attention" }, /* Wis */
593 { "working on your reflexes", "working on reflexes lately" }, /* Dex */
594 { "leading a healthy life-style", "watching your health" }, /* Con */
597 { "
\94O
\93ü
\82è
\82É
\89^
\93®
\82µ
\82Ä
\82¢
\82½", "
\93K
\90Ø
\82É
\89^
\93®
\82µ
\82Ä
\82¢
\82È
\82©
\82Á
\82½" }, /* Str */
599 { "
\90T
\8fd
\82É
\8ds
\93®
\82µ
\82Ä
\82¢
\82½", "
\92\8d\88Ó
\95s
\91«
\82¾
\82Á
\82½" }, /* Wis */
600 { "
\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 */
601 { "
\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 */
609 int i, ax, mod_val, lolim, hilim;
611 /* Check out the periodic accumulations */
614 if (moves >= context.next_attrib_check) {
615 debugpline1("exerchk: ready to test. multi = %d.", multi);
617 /* Are we ready for a test? */
618 if (moves >= context.next_attrib_check && !multi) {
619 debugpline0("exerchk: testing.");
621 * Law of diminishing returns (Part II):
623 * The effects of "exercise" and "abuse" wear
624 * off over time. Even if you *don't* get an
625 * increase/decrease, you lose some of the
626 * accumulated effects.
628 for (i = 0; i < A_MAX; ++i) {
630 /* nothing to do here if no exercise or abuse has occurred
631 (Int and Cha always fall into this category) */
633 continue; /* ok to skip nextattrib */
635 mod_val = sgn(ax); /* +1 or -1; used below */
636 /* no further effect for exercise if at max or abuse if at min;
637 can't exceed 18 via exercise even if actual max is higher */
638 lolim = ATTRMIN(i); /* usually 3; might be higher */
639 hilim = ATTRMAX(i); /* usually 18; maybe lower or higher */
642 if ((ax < 0) ? (ABASE(i) <= lolim) : (ABASE(i) >= hilim))
644 /* can't exercise non-Wisdom while polymorphed; previous
645 exercise/abuse gradually wears off without impact then */
646 if (Upolyd && i != A_WIS)
649 debugpline2("exerchk: testing %s (%d).",
665 * Law of diminishing returns (Part III):
667 * You don't *always* gain by exercising.
668 * [MRS 92/10/28 - Treat Wisdom specially for balance.]
670 if (rn2(AVAL) > ((i != A_WIS) ? (abs(ax) * 2 / 3) : abs(ax)))
673 debugpline1("exerchk: changing %d.", i);
674 if (adjattrib(i, mod_val, -1)) {
675 debugpline1("exerchk: changed %d.", i);
676 /* if you actually changed an attrib - zero accumulation */
678 /* then print an explanation */
681 (mod_val > 0) ? "must have been" : "haven't been",
682 exertext[i][(mod_val > 0) ? 0 : 1]);
684 You("%s
\82É
\88á
\82¢
\82È
\82¢
\81D",
685 exertext[i][(mod_val > 0) ? 0 : 1]);
689 /* this used to be ``AEXE(i) /= 2'' but that would produce
690 platform-dependent rounding/truncation for negative vals */
691 AEXE(i) = (abs(ax) / 2) * mod_val;
693 context.next_attrib_check += rn1(200, 800);
694 debugpline1("exerchk: next check at %ld.", context.next_attrib_check);
702 register int i, x, tryct;
704 for (i = 0; i < A_MAX; i++) {
705 ABASE(i) = AMAX(i) = urole.attrbase[i];
706 ATEMP(i) = ATIME(i) = 0;
707 np -= urole.attrbase[i];
711 while (np > 0 && tryct < 100) {
713 for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++)
716 continue; /* impossible */
718 if (ABASE(i) >= ATTRMAX(i)) {
729 while (np < 0 && tryct < 100) { /* for redistribution */
732 for (i = 0; (i < A_MAX) && ((x -= urole.attrdist[i]) > 0); i++)
735 continue; /* impossible */
737 if (ABASE(i) <= ATTRMIN(i)) {
753 for (i = 0; i < A_MAX; i++) {
754 if (i == A_INT || i == A_WIS)
756 /* Polymorphing doesn't change your mind */
758 AMAX(i) += (rn2(5) - 2);
759 if (AMAX(i) > ATTRMAX(i))
760 AMAX(i) = ATTRMAX(i);
761 if (AMAX(i) < ATTRMIN(i))
762 AMAX(i) = ATTRMIN(i);
763 ABASE(i) = ABASE(i) * AMAX(i) / tmp;
764 /* ABASE(i) > ATTRMAX(i) is impossible */
765 if (ABASE(i) < ATTRMIN(i))
766 ABASE(i) = ATTRMIN(i);
768 (void) encumber_msg();
778 if (ability == &(HWarning) || ability == &(HSee_invisible))
782 STATIC_OVL const struct innate *
783 check_innate_abil(ability, frommask)
787 const struct innate *abil = 0;
789 if (frommask == FROMEXPER)
790 switch (Role_switch) {
791 case PM_ARCHEOLOGIST:
833 else if (frommask == FROMRACE)
834 switch (Race_switch) {
848 while (abil && abil->ability) {
849 if ((abil->ability == ability) && (u.ulevel >= abil->ulevel))
853 return (struct innate *) 0;
857 * returns 1 if FROMRACE or FROMEXPER and exper level == 1
858 * returns 2 if FROMEXPER and exper level > 1
859 * otherwise returns 0
865 const struct innate *iptr;
867 if ((iptr = check_innate_abil(ability, FROMRACE)) != 0)
869 else if ((iptr = check_innate_abil(ability, FROMEXPER)) != 0)
870 return (iptr->ulevel == 1) ? 1 : 2;
878 if (propidx == BLINDED && !haseyes(youmonst.data))
880 return innately(&u.uprops[propidx].intrinsic);
885 int propidx; /* special cases can have negative values */
887 static char buf[BUFSZ];
891 * Restrict the source of the attributes just to debug mode for now
893 /*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¤*/
894 /*JP:
\96{
\97\88\82Íminimal_xname()
\82ð
\8eg
\82¤
\82×
\82«
\82¾
\82ªstatic
\82È
\82Ì
\82Å
\91ã
\97p*/
897 static NEARDATA const char because_of[] = " because of %s";
899 static NEARDATA const char because_of[] = "%s
\82É
\82æ
\82Á
\82Ä";
903 struct obj *obj = (struct obj *) 0;
904 int innate = is_innate(propidx);
908 Strcpy(buf, " because of your experience");
910 Strcpy(buf, "
\8co
\8c±
\82É
\82æ
\82Á
\82Ä");
911 else if (innate == 1)
913 Strcpy(buf, " innately");
915 Strcpy(buf, "
\90¶
\82Ü
\82ê
\82È
\82ª
\82ç
\82É");
917 && (obj = what_gives(&u.uprops[propidx].extrinsic)))
918 Sprintf(buf, because_of, obj->oartifact
919 ? bare_artifactname(obj)
921 : ysimple_name(obj));
923 : simpleonames(obj));
924 else if (propidx == BLINDED && u.uroleplay.blind)
926 Sprintf(buf, " from birth");
928 Sprintf(buf, "
\90¶
\82Ü
\82ê
\82Ä
\82©
\82ç
\82¸
\82Á
\82Æ");
929 else if (propidx == BLINDED && Blindfolded_only)
931 Sprintf(buf, because_of, ysimple_name(ublindf));
933 Sprintf(buf, because_of, simpleonames(ublindf));
935 #if 0 /*JP*//*
\95s
\97v*/
936 /* remove some verbosity and/or redundancy */
937 if ((p = strstri(buf, " pair of ")) != 0)
938 copynchars(p + 1, p + 9, BUFSZ); /* overlapping buffers ok */
939 else if (propidx == STRANGLED
940 && (p = strstri(buf, " of strangulation")) != 0)
944 } else { /* negative property index */
945 /* if more blocking capabilities get implemented we'll need to
946 replace this with what_blocks() comparable to what_gives() */
950 && ublindf->oartifact == ART_EYES_OF_THE_OVERWORLD)
951 Sprintf(buf, because_of, bare_artifactname(ublindf));
954 if (u.uprops[INVIS].blocked & W_ARMC)
955 Sprintf(buf, because_of,
957 ysimple_name(uarmc)); /* mummy wrapping */
959 simpleonames(uarmc)); /* mummy wrapping */
963 if (wizard && (u.uprops[CLAIRVOYANT].blocked & W_ARMH))
964 Sprintf(buf, because_of,
966 ysimple_name(uarmh)); /* cornuthaum */
968 simpleonames(uarmh)); /* cornuthaum */
979 adjabil(oldlevel, newlevel)
980 int oldlevel, newlevel;
982 register const struct innate *abil, *rabil;
983 long prevabil, mask = FROMEXPER;
985 switch (Role_switch) {
986 case PM_ARCHEOLOGIST:
1030 switch (Race_switch) {
1045 while (abil || rabil) {
1046 /* Have we finished with the intrinsics list? */
1047 if (!abil || !abil->ability) {
1048 /* Try the race intrinsics */
1049 if (!rabil || !rabil->ability)
1055 prevabil = *(abil->ability);
1056 if (oldlevel < abil->ulevel && newlevel >= abil->ulevel) {
1057 /* Abilities gained at level 1 can never be lost
1058 * via level loss, only via means that remove _any_
1059 * sort of ability. A "gain" of such an ability from
1060 * an outside source is devoid of meaning, so we set
1061 * FROMOUTSIDE to avoid such gains.
1063 if (abil->ulevel == 1)
1064 *(abil->ability) |= (mask | FROMOUTSIDE);
1066 *(abil->ability) |= mask;
1067 if (!(*(abil->ability) & INTRINSIC & ~mask)) {
1068 if (*(abil->gainstr))
1069 You_feel("%s!", abil->gainstr);
1071 } else if (oldlevel >= abil->ulevel && newlevel < abil->ulevel) {
1072 *(abil->ability) &= ~mask;
1073 if (!(*(abil->ability) & INTRINSIC)) {
1074 if (*(abil->losestr))
1075 You_feel("%s!", abil->losestr);
1076 else if (*(abil->gainstr))
1077 You_feel("less %s!", abil->gainstr);
1080 if (prevabil != *(abil->ability)) /* it changed */
1081 postadjabil(abil->ability);
1086 if (newlevel > oldlevel)
1087 add_weapon_skill(newlevel - oldlevel);
1089 lose_weapon_skill(oldlevel - newlevel);
1098 if (u.ulevel == 0) {
1099 /* Initialize hit points */
1100 hp = urole.hpadv.infix + urace.hpadv.infix;
1101 if (urole.hpadv.inrnd > 0)
1102 hp += rnd(urole.hpadv.inrnd);
1103 if (urace.hpadv.inrnd > 0)
1104 hp += rnd(urace.hpadv.inrnd);
1105 if (moves <= 1L) { /* initial hero; skip for polyself to new man */
1106 /* Initialize alignment stuff */
1107 u.ualign.type = aligns[flags.initalign].value;
1108 u.ualign.record = urole.initrecord;
1110 /* no Con adjustment for initial hit points */
1112 if (u.ulevel < urole.xlev) {
1113 hp = urole.hpadv.lofix + urace.hpadv.lofix;
1114 if (urole.hpadv.lornd > 0)
1115 hp += rnd(urole.hpadv.lornd);
1116 if (urace.hpadv.lornd > 0)
1117 hp += rnd(urace.hpadv.lornd);
1119 hp = urole.hpadv.hifix + urace.hpadv.hifix;
1120 if (urole.hpadv.hirnd > 0)
1121 hp += rnd(urole.hpadv.hirnd);
1122 if (urace.hpadv.hirnd > 0)
1123 hp += rnd(urace.hpadv.hirnd);
1125 if (ACURR(A_CON) <= 3)
1127 else if (ACURR(A_CON) <= 6)
1129 else if (ACURR(A_CON) <= 14)
1131 else if (ACURR(A_CON) <= 16)
1133 else if (ACURR(A_CON) == 17)
1135 else if (ACURR(A_CON) == 18)
1143 if (u.ulevel < MAXULEV)
1144 u.uhpinc[u.ulevel] = (xchar) hp;
1152 register int tmp = (u.abon.a[x] + u.atemp.a[x] + u.acurr.a[x]);
1155 if (tmp >= 125 || (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER))
1159 return (x = ((tmp <= 3) ? 3 : tmp));
1161 return (schar) ((tmp <= 3) ? 3 : tmp);
1163 } else if (x == A_CHA) {
1165 && (youmonst.data->mlet == S_NYMPH || u.umonnum == PM_SUCCUBUS
1166 || u.umonnum == PM_INCUBUS))
1168 } else if (x == A_INT || x == A_WIS) {
1169 /* yes, this may raise int/wis if player is sufficiently
1170 * stupid. there are lower levels of cognition than "dunce".
1172 if (uarmh && uarmh->otyp == DUNCE_CAP)
1176 return (x = ((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp));
1178 return (schar) ((tmp >= 25) ? 25 : (tmp <= 3) ? 3 : tmp);
1182 /* condense clumsy ACURR(A_STR) value into value that fits into game formulas
1187 register int str = ACURR(A_STR);
1192 return (schar) (19 + str / 50); /* map to 19..21 */
1194 return (schar) (min(str, 125) - 100); /* 22..25 */
1197 /* when wearing (or taking off) an unID'd item, this routine is used
1198 to distinguish between observable +0 result and no-visible-effect
1199 due to an attribute not being able to exceed maximum or minimum */
1201 extremeattr(attrindx) /* does attrindx's value match its max or min? */
1204 /* Fixed_abil and racial MINATTR/MAXATTR aren't relevant here */
1205 int lolimit = 3, hilimit = 25, curval = ACURR(attrindx);
1207 /* upper limit for Str is 25 but its value is encoded differently */
1208 if (attrindx == A_STR) {
1209 hilimit = STR19(25); /* 125 */
1210 /* lower limit for Str can also be 25 */
1211 if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER)
1214 /* this exception is hypothetical; the only other worn item affecting
1215 Int or Wis is another helmet so can't be in use at the same time */
1216 if (attrindx == A_INT || attrindx == A_WIS) {
1217 if (uarmh && uarmh->otyp == DUNCE_CAP)
1218 hilimit = lolimit = 6;
1221 /* are we currently at either limit? */
1222 return (curval == lolimit || curval == hilimit) ? TRUE : FALSE;
1225 /* avoid possible problems with alignment overflow, and provide a centralized
1226 location for any future alignment limits */
1231 int newalign = u.ualign.record + n;
1234 if (newalign < u.ualign.record)
1235 u.ualign.record = newalign;
1236 } else if (newalign > u.ualign.record) {
1237 u.ualign.record = newalign;
1238 if (u.ualign.record > ALIGNLIM)
1239 u.ualign.record = ALIGNLIM;
1243 /* change hero's alignment type, possibly losing use of artifacts */
1245 uchangealign(newalign, reason)
1247 int reason; /* 0==conversion, 1==helm-of-OA on, 2==helm-of-OA off */
1249 aligntyp oldalign = u.ualign.type;
1251 u.ublessed = 0; /* lose divine protection */
1252 context.botl = 1; /* status line needs updating */
1254 /* conversion via altar */
1255 u.ualignbase[A_CURRENT] = (aligntyp) newalign;
1256 /* worn helm of opposite alignment might block change */
1257 if (!uarmh || uarmh->otyp != HELM_OF_OPPOSITE_ALIGNMENT)
1258 u.ualign.type = u.ualignbase[A_CURRENT];
1259 You("have a %ssense of a new direction.",
1260 (u.ualign.type != oldalign) ? "sudden " : "");
1262 /* putting on or taking off a helm of opposite alignment */
1263 u.ualign.type = (aligntyp) newalign;
1265 Your("mind oscillates %s.", Hallucination ? "wildly" : "briefly");
1266 else if (reason == 2)
1267 Your("mind is %s.", Hallucination
1268 ? "much of a muchness"
1269 : "back in sync with your body");
1272 if (u.ualign.type != oldalign) {
1273 u.ualign.record = 0; /* slate is wiped clean */
1274 retouch_equipment(0);