version 1.66 | | version 1.67 |
---|
| | |
/* | | /* |
* static char *rcsid_living_c = | | * static char *rcsid_living_c = |
* "$Id: living.c,v 1.66 2005/03/20 16:32:55 akirschbaum Exp $"; | | * "$Id: living.c,v 1.67 2005/03/22 21:44:43 akirschbaum Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
void change_luck(object *op, int value) { | | void change_luck(object *op, int value) { |
object *tmp; | | object *tmp; |
archetype *at; | | archetype *at; |
| | int new_luck; |
| | |
at = find_archetype("luck"); | | at = find_archetype("luck"); |
if (!at) | | if (!at) |
LOG(llevError, "Couldn't find archetype luck.\n"); | | LOG(llevError, "Couldn't find archetype luck.\n"); |
| | |
SET_FLAG(tmp,FLAG_APPLIED); | | SET_FLAG(tmp,FLAG_APPLIED); |
} | | } |
if (value) { | | if (value) { |
| | /* Limit the luck value of the bad luck object to +/-100. This |
| | * (arbitrary) value prevents overflows (both in the bad luck object and |
| | * in op itself). |
| | */ |
| | new_luck = tmp->stats.luck+value; |
| | if (new_luck >= -100 && new_luck <= 100) { |
op->stats.luck+=value; | | op->stats.luck+=value; |
tmp->stats.luck+=value; | | tmp->stats.luck = new_luck; |
| | } |
} else { | | } else { |
if (!tmp->stats.luck) { | | if (!tmp->stats.luck) { |
LOG(llevDebug, "Internal error in change_luck().\n"); | | |
return; | | return; |
} | | } |
/* Randomly change the players luck. Basically, we move it | | /* Randomly change the players luck. Basically, we move it |
* back neutral (if greater>0, subtract, otherwise add) | | * back neutral (if greater>0, subtract, otherwise add) |
* I believe this is supposed to be > and not >= - this means | | |
* if your luck is -1/1, it won't get adjusted - only when your | | |
* luck is worse can you hope for improvment. | | |
* note that if we adjusted it with it is -1/1, that check above | | |
* for 0 luck will happen, resulting in error. | | |
*/ | | */ |
if (RANDOM()%(FABS(tmp->stats.luck)) > RANDOM()%30) { | | if (RANDOM()%(FABS(tmp->stats.luck)) >= RANDOM()%30) { |
int diff = tmp->stats.luck>0?-1:1; | | int diff = tmp->stats.luck>0?-1:1; |
op->stats.luck += diff; | | op->stats.luck += diff; |
tmp->stats.luck += diff; | | tmp->stats.luck += diff; |