From fa43f2aabe8d51acdaca885fd386d5229ab37738 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Sat, 9 Jan 2016 08:01:23 -0500 Subject: [PATCH] Fixed the experimental fighter not running away from chargers. This oddity was caused by exactly what I thought it was caused by: the code assumed that all bullets are created equal, and each bullet had a 1 in 50 chance of causing the ship to run away. Well, the charger inflicts so much damage that 50 shots would be a ridiculous amount of damage for even the experimental fighter. So now, except in Classic difficulty, whether or not it runs away is determined partly by how much damage a weapon inflicts. Specifically, the chance is now the damage of the bullet out of 150. High-damage weapons are still a useful idea; after all, a 100 damage weapon is 100 guaranteed damage, even if the fighter is likely to flee. However, it gets rid of the skewed nature of the fleeing behavior and prevents the charger from subverting the purpose of the behavior. --- src/alien.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/alien.cpp b/src/alien.cpp index 7364d35..cce78c6 100644 --- a/src/alien.cpp +++ b/src/alien.cpp @@ -1772,6 +1772,8 @@ void alien_destroy(object *alien, object *attacker) void alien_hurt(object *alien, object *attacker, int damage, bool ion) { + double run_chance; + if (ion) alien->systemPower -= damage; else @@ -1828,7 +1830,9 @@ void alien_hurt(object *alien, object *attacker, int damage, bool ion) } } - if ((alien->flags & FL_RUNSAWAY) && ((rand() % 50) == 0)) + run_chance = (game.difficulty == DIFFICULTY_ORIGINAL) ? 0.2 : damage / 150.; + + if ((alien->flags & FL_RUNSAWAY) && CHANCE(run_chance)) { alien->flags |= FL_LEAVESECTOR; }