/* Fear Saving Throws Odds that 1dM <= 1dN. There are 2 cases: [1] M<=N: p = (2N-M+1)/2N [2] M>N : p = (N+1)/2M */ bool fear_save_p(int ml) { int pl; int rolls; int i; if (!hack_mind) return TRUE; if (ml <= 1) return TRUE; /* Immunity to Fear?*/ if (res_pct(RES_FEAR) >= 100) return TRUE; pl = _plev() + adj_stat_save_fear[p_ptr->stat_ind[A_CHR]]; if (pl < 1) pl = 1; rolls = 1 + p_ptr->resist[RES_FEAR]; /* Vulnerability to Fear? At least give the player a chance! */ if (rolls < 1) { rolls = 1; pl = (pl + 1)/2; } for (i = 0; i < rolls; i++) { if (randint1(ml) <= randint1(pl)) { equip_learn_resist(OF_RES_FEAR); return TRUE; } } return FALSE; }
void vampire_check_light_status(void) { static int _last_light_penalty = -1; if ((cave[py][px].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) { _light_penalty = 1; if (!dun_level && is_daytime()) _light_penalty++; if (res_pct(RES_LITE) < 0) _light_penalty++; } else _light_penalty = 0; if (_light_penalty != _last_light_penalty) { _last_light_penalty = _light_penalty; if (_light_penalty) { int n = _light_penalty * _light_penalty * _light_penalty * MAX(1, dun_level/5); if (!fear_save_p(n)) { msg_print("You fear the light!"); fear_add_p(FEAR_SCARED); } } p_ptr->update |= PU_BONUS; p_ptr->redraw |= PR_STATUS; } }
bool res_can_ignore(int which) { int power = res_is_low(which) ? 55 : 33; if (res_pct(which) >= power) return TRUE; return FALSE; }
bool res_save(int which, int power) { int pct = res_pct(which); int roll = randint0(power); if (roll < pct) return TRUE; return FALSE; }
int res_calc_dam(int which, int dam) { int pct1 = res_pct(which); int pct2 = _randomize(pct1); int result = dam; result -= pct2 * dam / 100; if (result < 0) result = 0; return result; }