[special_filter] now works with 'attack' event.

This commit is contained in:
Dominic Bolin 2006-02-20 14:44:34 +00:00
parent 788373699d
commit b83ccd632e
4 changed files with 29 additions and 25 deletions

View file

@ -719,7 +719,30 @@ void attack(display& gui, const gamemap& map,
units, state);
statistics::attack_context attack_stats(a->second,d->second,stats);
LOG_NG << "firing attack event\n";
config dat;
dat.add_child("first");
dat.add_child("second");
(*(dat.child("first")))["weapon"]=a->second.attacks()[attack_with].name();
(*(dat.child("second")))["weapon"]=stats.defend_with != -1 ? d->second.attacks()[stats.defend_with].name() : "none";
gamemap::TERRAIN att_terrain = map[attacker.x][attacker.y];
std::string terrain_letter("");
terrain_letter += att_terrain;
(*(dat.child("first")))["terrain"]=terrain_letter;
gamemap::TERRAIN dtt_terrain = map[defender.x][defender.y];
terrain_letter = "";
terrain_letter += dtt_terrain;
(*(dat.child("second")))["terrain"]=terrain_letter;
game_events::fire("attack",attacker,defender,dat);
//the event could have killed either the attacker or
//defender, so we have to make sure they still exist
a = units.find(attacker);
d = units.find(defender);
if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
return;
}
int orig_attacks = stats.nattacks;
int orig_defends = stats.ndefends;
@ -802,7 +825,7 @@ void attack(display& gui, const gamemap& map,
game_events::fire("attacker_hits",attacker,defender,dat);
a = units.find(attacker);
d = units.find(defender);
if(a == units.end() || d == units.end()) {
if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
recalculate_fog(map,state,info,units,teams,attacker_side-1);
recalculate_fog(map,state,info,units,teams,defender_side-1);
gui.recalculate_minimap();
@ -833,7 +856,7 @@ void attack(display& gui, const gamemap& map,
game_events::fire("attacker_misses",attacker,defender,dat);
a = units.find(attacker);
d = units.find(defender);
if(a == units.end() || d == units.end()) {
if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
recalculate_fog(map,state,info,units,teams,attacker_side-1);
recalculate_fog(map,state,info,units,teams,defender_side-1);
gui.recalculate_minimap();
@ -1048,7 +1071,7 @@ void attack(display& gui, const gamemap& map,
game_events::fire("defender_hits",attacker,defender,dat);
a = units.find(attacker);
d = units.find(defender);
if(a == units.end() || d == units.end()) {
if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
recalculate_fog(map,state,info,units,teams,attacker_side-1);
recalculate_fog(map,state,info,units,teams,defender_side-1);
gui.recalculate_minimap();
@ -1077,7 +1100,7 @@ void attack(display& gui, const gamemap& map,
game_events::fire("defender_misses",attacker,defender,dat);
a = units.find(attacker);
d = units.find(defender);
if(a == units.end() || d == units.end()) {
if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
recalculate_fog(map,state,info,units,teams,attacker_side-1);
recalculate_fog(map,state,info,units,teams,defender_side-1);
gui.recalculate_minimap();

View file

@ -1008,7 +1008,6 @@ void ai_interface::attack_enemy(const location& u, const location& target, int w
}
recorder.add_attack(u,target,weapon);
game_events::fire("attack",u,target);
attack(info_.disp, info_.map, info_.teams, u, target, weapon, info_.units, info_.state, info_.gameinfo);
check_victory(info_.units,info_.teams);

View file

@ -756,17 +756,6 @@ bool turn_info::attack_enemy(unit_map::iterator attacker, unit_map::iterator def
current_paths_ = paths();
gui_.unhighlight_reach();
game_events::fire("attack",attacker_loc,defender_loc);
//the event could have killed either the attacker or
//defender, so we have to make sure they still exist
attacker = units_.find(attacker_loc);
defender = units_.find(defender_loc);
if(attacker == units_.end() || defender == units_.end() || size_t(weapons[res]) >= attacks.size()) {
return true;
}
gui_.invalidate_all();
gui_.draw();

View file

@ -898,14 +898,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
if (!game_config::ignore_replay_errors) throw replay::error();
}
game_events::fire("attack",src,dst);
u = units.find(src);
tgt = units.find(dst);
if(u != units.end() && tgt != units.end()) {
attack(disp, map, teams, src, dst, weapon_num, units, state, gameinfo);
}
attack(disp, map, teams, src, dst, weapon_num, units, state, gameinfo);
u = units.find(src);
tgt = units.find(dst);