reverted problematic change to attack:attack.

It needs better fix for attack_end observer crash
This commit is contained in:
Pauli Nieminen 2008-01-30 22:11:22 +00:00
parent b0768d4c0e
commit e7426b9340

View file

@ -736,14 +736,7 @@ void attack::fire_event(const std::string& n)
dat.add_child("first");
dat.add_child("second");
if(a_ != units_.end()) {
if (a_stats_->weapon)
{
(*(dat.child("first")))["weapon"]=a_stats_->weapon->id();
}
else
{
(*(dat.child("first")))["weapon"]="none";
}
(*(dat.child("first")))["weapon"]=a_stats_->weapon->id();
}
if(d_ != units_.end()) {
@ -765,7 +758,8 @@ void attack::fire_event(const std::string& n)
DELAY_END_LEVEL(delayed_exception, game_events::fire(n,
attacker_,
defender_, dat));
refresh_bc();
a_ = units_.find(attacker_);
d_ = units_.find(defender_);
return;
}
const int defender_side = d_->second.side();
@ -799,7 +793,6 @@ void attack::fire_event(const std::string& n)
fire_event("attack_end");
throw attack_end_exception();
}
refresh_bc();
}
void attack::refresh_bc()
@ -903,6 +896,7 @@ attack::attack(game_display& gui, const gamemap& map,
} catch (attack_end_exception) {
return;
}
refresh_bc();
DBG_NG << "getting attack statistics\n";
statistics::attack_context attack_stats(a_->second, d_->second, a_stats_->chance_to_hit, d_stats_->chance_to_hit);
@ -1032,14 +1026,18 @@ attack::attack(game_display& gui, const gamemap& map,
try {
fire_event("attacker_hits");
} catch (attack_end_exception) {
refresh_bc();
break;
}
refresh_bc();
} else {
try {
fire_event("attacker_misses");
} catch (attack_end_exception) {
refresh_bc();
break;
}
refresh_bc();
}
DBG_NG << "done attacking\n";
@ -1069,9 +1067,9 @@ attack::attack(game_display& gui, const gamemap& map,
const int defender_side = d_->second.side();
fire_event("attack_end");
DELAY_END_LEVEL(delayed_exception, game_events::fire("last breath", death_loc, attacker_loc));
a_ == units_.find(attacker_);
d_ == units_.find(defender_);
d_ = units_.find(death_loc);
a_ = units_.find(attacker_loc);
if(d_ == units_.end() || !death_loc.matches_unit(d_->second)
|| d_->second.hitpoints() > 0) {
// WML has invalidated the dying unit, abort
@ -1086,6 +1084,7 @@ attack::attack(game_display& gui, const gamemap& map,
// WML has invalidated the killing unit
attacker_invalid = true;
}
refresh_bc();
if(attacker_invalid) {
unit_display::unit_die(d_->first, d_->second, NULL, d_stats_->weapon, NULL);
} else {
@ -1093,10 +1092,9 @@ attack::attack(game_display& gui, const gamemap& map,
}
DELAY_END_LEVEL(delayed_exception, game_events::fire("die",death_loc,attacker_loc));
a_ == units_.find(attacker_);
d_ == units_.find(defender_);
d_ = units_.find(death_loc);
a_ = units_.find(attacker_loc);
if(d_ == units_.end() || !death_loc.matches_unit(d_->second)) {
// WML has invalidated the dying unit, abort
break;
@ -1110,6 +1108,7 @@ attack::attack(game_display& gui, const gamemap& map,
// WML has invalidated the killing unit, abort
break;
}
refresh_bc();
if(a_stats_->plagues) {
// plague units make new units on the target hex
@ -1281,14 +1280,18 @@ attack::attack(game_display& gui, const gamemap& map,
try {
fire_event("defender_hits");
} catch (attack_end_exception) {
refresh_bc();
break;
}
refresh_bc();
} else {
try {
fire_event("defender_misses");
} catch (attack_end_exception) {
refresh_bc();
break;
}
refresh_bc();
}
attack_stats.defend_result(hits ? (dies ? statistics::attack_context::KILLS : statistics::attack_context::HITS)
: statistics::attack_context::MISSES, defender_damage_);
@ -1320,9 +1323,7 @@ attack::attack(game_display& gui, const gamemap& map,
fire_event("attack_end");
DELAY_END_LEVEL(delayed_exception, game_events::fire("die",death_loc,defender_loc));
a_ == units_.find(attacker_);
d_ == units_.find(defender_);
refresh_bc();
if(a_ == units_.end() || !death_loc.matches_unit(a_->second)) {
// WML has invalidated the dying unit, abort
@ -1405,6 +1406,7 @@ attack::attack(game_display& gui, const gamemap& map,
}
if(n_attacks_ <= 0 && n_defends_ <= 0) {
fire_event("attack_end");
refresh_bc();
}
}