Skip to content

Commit

Permalink
disallow attacking with disabled attacks via [do_command]
Browse files Browse the repository at this point in the history
this fixes some rare cheats in mp.

(cherry-picked from commit 26b5ca5)
  • Loading branch information
gfgtdf committed Oct 7, 2018
1 parent 27ea9cc commit 2709456
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions data/test/scenarios/feeding.cfg
Expand Up @@ -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|}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/actions/attack.cpp
Expand Up @@ -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_));

Expand All @@ -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();
}
Expand Down

0 comments on commit 2709456

Please sign in to comment.