Fix planning mode on attacks

The code checked for `unit.attacks_left() >= attack_count_` even
though _currently_ it seems perfectly legal to invoke an attack
with less attacks left (see the discussion on #7406), although this
will probably be changed soon.

If this is changed in the future, before changing that assert
remember to also change the check in attack::check_validity.

Also it didn't reset the attacks in attack::remove_temp_modifier
properly.
This commit is contained in:
gfgtdf 2023-03-21 05:48:44 +01:00
parent 630464911c
commit d5ef9feefb

View File

@ -161,7 +161,7 @@ void attack::apply_temp_modifier(unit_map& unit_map)
unit& unit = *get_unit();
DBG_WB << unit.name() << " [" << unit.id()
<< "] has " << unit.attacks_left() << " attacks, decreasing by " << attack_count_;
assert(unit.attacks_left() >= attack_count_);
assert(unit.attacks_left() > 0);
//Calculate movement to subtract
temp_movement_subtracted_ = unit.movement_left() >= attack_movement_cost_ ? attack_movement_cost_ : 0 ;
@ -186,12 +186,13 @@ void attack::remove_temp_modifier(unit_map& unit_map)
unit& unit = *get_unit();
DBG_WB << unit.name() << " [" << unit.id()
<< "] has " << unit.attacks_left() << " attacks, increasing by one";
unit.set_attacks(unit.attacks_left() + 1);
unit.set_attacks(unit.attacks_left() + temp_attacks_subtracted_);
DBG_WB << "Attack: Changing movement points for unit " << unit.name() << " [" << unit.id()
<< "] from " << unit.movement_left() << " to "
<< unit.movement_left() + temp_movement_subtracted_ << ".";
unit.set_movement(unit.movement_left() + temp_movement_subtracted_, true);
temp_movement_subtracted_ = 0;
temp_attacks_subtracted_ = 0;
move::remove_temp_modifier(unit_map);
}