adjust an attribute; return TRUE if change is made, FALSE otherwise */
| 114 | |
| 115 | /* adjust an attribute; return TRUE if change is made, FALSE otherwise */ |
| 116 | boolean |
| 117 | adjattrib( |
| 118 | int ndx, /* which characteristic */ |
| 119 | int incr, /* amount of change */ |
| 120 | int msgflg) /* positive => no message, zero => message, and */ |
| 121 | { /* negative => conditional (msg if change made) */ |
| 122 | int old_acurr, old_abase, old_amax, decr; |
| 123 | boolean abonflg; |
| 124 | const char *attrstr; |
| 125 | |
| 126 | if (Fixed_abil || !incr) |
| 127 | return FALSE; |
| 128 | |
| 129 | if ((ndx == A_INT || ndx == A_WIS) && uarmh && uarmh->otyp == DUNCE_CAP) { |
| 130 | if (msgflg == 0) |
| 131 | Your("cap constricts briefly, then relaxes again."); |
| 132 | return FALSE; |
| 133 | } |
| 134 | |
| 135 | old_acurr = ACURR(ndx); |
| 136 | old_abase = ABASE(ndx); |
| 137 | old_amax = AMAX(ndx); |
| 138 | ABASE(ndx) += incr; /* when incr is negative, this reduces ABASE() */ |
| 139 | if (incr > 0) { |
| 140 | if (ABASE(ndx) > AMAX(ndx)) { |
| 141 | AMAX(ndx) = ABASE(ndx); |
| 142 | if (AMAX(ndx) > ATTRMAX(ndx)) |
| 143 | ABASE(ndx) = AMAX(ndx) = ATTRMAX(ndx); |
| 144 | } |
| 145 | attrstr = plusattr[ndx]; |
| 146 | abonflg = (ABON(ndx) < 0); |
| 147 | } else { /* incr is negative */ |
| 148 | if (ABASE(ndx) < ATTRMIN(ndx)) { |
| 149 | /* |
| 150 | * If base value has dropped so low that it is trying to be |
| 151 | * taken below the minimum, reduce max value (peak reached) |
| 152 | * instead. That means that restore ability and repeated |
| 153 | * applications of unicorn horn will not be able to recover |
| 154 | * all the lost value. As of 3.6.2, we only take away |
| 155 | * some (average half, possibly zero) of the excess from max |
| 156 | * instead of all of it, but without intervening recovery, it |
| 157 | * can still eventually drop to the minimum allowed. After |
| 158 | * that, it can't be recovered, only improved with new gains. |
| 159 | * |
| 160 | * This used to assign a new negative value to incr and then |
| 161 | * add it, but that could affect messages below, possibly |
| 162 | * making a large decrease be described as a small one. |
| 163 | * |
| 164 | * decr = rn2(-(ABASE - ATTRMIN) + 1); |
| 165 | */ |
| 166 | decr = rn2(ATTRMIN(ndx) - ABASE(ndx) + 1); |
| 167 | ABASE(ndx) = ATTRMIN(ndx); |
| 168 | AMAX(ndx) -= decr; |
| 169 | if (AMAX(ndx) < ATTRMIN(ndx)) |
| 170 | AMAX(ndx) = ATTRMIN(ndx); |
| 171 | } |
| 172 | attrstr = minusattr[ndx]; |
| 173 | abonflg = (ABON(ndx) > 0); |
no test coverage detected