From 74dc4b9e3a22a0886ee14035063863f6176ba8c5 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 16 Feb 2008 18:29:35 +0100 Subject: [PATCH] Simplify take_move_in_mob() Actually, this isn't just simplification. When mobility gain per update was configured to be greater than 128, mobility could go from 1 to less than -127 when assaulting from a landing ship, and thus overflow. Make it saturate at -127. Note that you can expect plenty of trouble elsewhere with such a silly configuration. --- src/lib/subs/attsub.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 7fe008f6..03d1cc3c 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -2523,43 +2523,37 @@ static void take_move_in_mob(int combat_mode, struct ulist *llp, struct combat *off, struct combat *def) { - int mobcost; - int new; + double mob = llp->unit.land.lnd_mobil; + double gain = etu_per_update * land_mob_scale; + double mobcost; switch (combat_mode) { case A_ATTACK: mobcost = lnd_pathcost(&llp->unit.land, att_mobcost(off->own, def, lnd_mobtype(&llp->unit.land))); - new = llp->unit.land.lnd_mobil - mobcost; - if (new < -127) - new = -127; - llp->unit.land.lnd_mobil = new; break; case A_ASSAULT: - if (off->shp_mcp->m_flags & M_LAND) { - if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) - llp->unit.land.lnd_mobil -= - (float)etu_per_update * land_mob_scale * 0.5; - else - llp->unit.land.lnd_mobil -= (float)etu_per_update * - land_mob_scale; - } else { - if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) - llp->unit.land.lnd_mobil = 0; - else - llp->unit.land.lnd_mobil = -(float)etu_per_update * - land_mob_scale; - } + if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) + mobcost = off->shp_mcp->m_flags & M_LAND ? gain / 2.0 : mob; + else + mobcost = off->shp_mcp->m_flags & M_LAND ? gain : mob + gain; break; case A_BOARD: - /* I arbitrarily chose the numbers 10 and 40 below -KHS */ if (((struct lchrstr *)llp->chrp)->l_flags & L_MARINE) - llp->unit.land.lnd_mobil -= 10; + mobcost = 10; else - llp->unit.land.lnd_mobil -= 40; + mobcost = 40; break; + default: + CANT_REACH(); + mobcost = 0; } + + mob -= mobcost; + if (mob < -127.0) + mob = -127.0; + llp->unit.land.lnd_mobil = (signed char)mob; llp->unit.land.lnd_harden = 0; }