From 2709456d2fc133cb682263f24cfb7e317165c671 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Sun, 17 Jun 2018 22:56:50 +0200 Subject: [PATCH] disallow attacking with disabled attacks via [do_command] this fixes some rare cheats in mp. (cherry-picked from commit 26b5ca55e40176f338265b162178df7342ec2882) --- data/test/scenarios/feeding.cfg | 6 ++++++ src/actions/attack.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/data/test/scenarios/feeding.cfg b/data/test/scenarios/feeding.cfg index 42ab3fa6df25..9467dfe222ce 100644 --- a/data/test/scenarios/feeding.cfg +++ b/data/test/scenarios/feeding.cfg @@ -30,6 +30,11 @@ {VARIABLE victim_x $Killer.x} {VARIABLE_OP victim_x sub 1} {VARIABLE victim_y $Killer.y} + {VARIABLE Killer.attacks_left 1} + + [unstore_unit] + variable=Killer + [/unstore_unit] {VARIABLE victim_side 3} {VARIABLE_OP victim_side sub $Killer.side|} @@ -66,6 +71,7 @@ {ASSERT ({VARIABLE_CONDITIONAL Killer.hitpoints equals $Killer_start_hp})} #enddef +## TODO: the original feeding ability is implemented differently, maybe we should update this. {GENERIC_UNIT_TEST "feeding" ( [event] id=ability_feeding_die diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index 32b23cc02ff8..68edb1d52f55 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -1403,6 +1403,11 @@ void attack::perform() return; } + if(a_.get_unit().attacks_left() <= 0) { + LOG_NG << "attack::perform(): not enough ap.\n"; + return; + } + a_.get_unit().set_facing(a_.loc_.get_relative_dir(d_.loc_)); d_.get_unit().set_facing(d_.loc_.get_relative_dir(a_.loc_)); @@ -1424,6 +1429,11 @@ void attack::perform() a_stats_ = &bc_->get_attacker_stats(); d_stats_ = &bc_->get_defender_stats(); + if(a_stats_->disable) { + LOG_NG << "attack::perform(): tried to attack with a disabled attack.\n"; + return; + } + if(a_stats_->weapon) { a_.weap_id_ = a_stats_->weapon->id(); }