Removed now useless end_level exception delaying.

This commit is contained in:
Guillaume Melquiond 2009-08-03 12:39:37 +00:00
parent 39a8620156
commit 5e08ac6df4
7 changed files with 24 additions and 87 deletions

View file

@ -865,16 +865,13 @@ void attack::fire_event(const std::string& n)
}
if(n == "attack_end") {
// We want to fire attack_end event in any case! Even if one of units was removed by WML
DELAY_END_LEVEL(delayed_exception, game_events::fire(n,
a_.loc_,
d_.loc_, ev_data));
game_events::fire(n, a_.loc_, d_.loc_, ev_data);
return;
}
const int defender_side = d_.get_unit().side();
const int attacker_side = a_.get_unit().side();
DELAY_END_LEVEL(delayed_exception, game_events::fire(n,
game_events::entity_location(a_.loc_,a_.id_),
game_events::entity_location(d_.loc_,d_.id_),ev_data));
game_events::fire(n, game_events::entity_location(a_.loc_, a_.id_),
game_events::entity_location(d_.loc_, d_.id_), ev_data);
// The event could have killed either the attacker or
// defender, so we have to make sure they still exist
@ -947,7 +944,6 @@ void attack::refresh_bc()
attack::~attack()
{
delete delayed_exception;
delete bc_;
}
@ -999,8 +995,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
units_(units),
errbuf_(),
update_display_(update_display),
OOS_error_(false),
delayed_exception(0)
OOS_error_(false)
{
// Stop the user from issuing any commands while the units are fighting
const events::command_disabler disable_commands;
@ -1260,7 +1255,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
dat.add_child("first", d_weapon_cfg);
dat.add_child("second", a_weapon_cfg);
DELAY_END_LEVEL(delayed_exception, game_events::fire("last breath", death_loc, attacker_loc, dat));
game_events::fire("last breath", death_loc, attacker_loc, dat);
if(!d_.valid() || d_.get_unit().hitpoints() > 0) {
// WML has invalidated the dying unit, abort
@ -1274,7 +1269,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
unit_display::unit_die(d_.iter_->first, d_.get_unit(),a_stats_->weapon,d_stats_->weapon,a_.iter_->first, &(a_.get_unit()));
}
DELAY_END_LEVEL(delayed_exception, game_events::fire("die",death_loc,attacker_loc, dat));
game_events::fire("die", death_loc, attacker_loc, dat);
if(!d_.valid()) {
// WML has invalidated the dying unit, abort
@ -1342,7 +1337,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
update_def_fog = true;
a_.n_attacks_ = 0;
d_.n_attacks_ = 0;
DELAY_END_LEVEL(delayed_exception, game_events::fire(petrify_string, d_.iter_->first, a_.iter_->first));
game_events::fire(petrify_string, d_.iter_->first, a_.iter_->first);
refresh_bc();
}
@ -1530,7 +1525,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
dat.add_child("first" , a_weapon_cfg);
dat.add_child("second", d_weapon_cfg);
DELAY_END_LEVEL(delayed_exception, game_events::fire("last breath", death_loc, defender_loc,dat));
game_events::fire("last breath", death_loc, defender_loc, dat);
if(!a_.valid() || a_.get_unit().hitpoints() > 0) {
// WML has invalidated the dying unit, abort
@ -1544,7 +1539,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
unit_display::unit_die(a_.loc_, a_.get_unit(),a_stats_->weapon,d_stats_->weapon,d_.loc_, &(d_.get_unit()));
}
DELAY_END_LEVEL(delayed_exception, game_events::fire("die",death_loc,defender_loc,dat));
game_events::fire("die", death_loc, defender_loc, dat);
// Don't try to call refresh_bc() here the attacker or defender might have
// been replaced by another unit, which might have a lower number of weapons.
@ -1613,7 +1608,7 @@ attack::attack(const map_location &attacker, const map_location &defender,
d_.n_attacks_ = 0;
a_.n_attacks_ = 0;
DELAY_END_LEVEL(delayed_exception, game_events::fire(petrify_string,a_.iter_->first,d_.iter_->first));
game_events::fire(petrify_string, a_.iter_->first, d_.iter_->first);
refresh_bc();
}
}
@ -1679,9 +1674,6 @@ attack::attack(const map_location &attacker, const map_location &defender,
if(OOS_error_) {
replay::throw_error(errbuf_.str());
}
THROW_END_LEVEL(delayed_exception);
}

View file

@ -212,8 +212,6 @@ class attack {
bool update_display_;
bool OOS_error_;
end_level_exception* delayed_exception;
};

View file

@ -294,31 +294,15 @@ void attack_result::do_execute()
}
recorder.add_attack(attacker_loc_, defender_loc_, attacker_weapon, defender_weapon);
try {
rand_rng::invalidate_seed();
rand_rng::clear_new_seed_callback();
while (!rand_rng::has_valid_seed()) {
manager::raise_user_interact();
manager::raise_sync_network();
SDL_Delay(10);
}
recorder.add_seed("attack", rand_rng::get_last_seed());
attack(attacker_loc_, defender_loc_, attacker_weapon, defender_weapon, get_info().units);
}
catch (end_level_exception&)
{
dialogs::advance_unit(attacker_loc_, true);
const unit_map::const_iterator defender = get_info().units.find(defender_loc_);
if(defender != get_info().units.end()) {
const size_t defender_team = size_t(defender->second.side()) - 1;
if(defender_team < get_info().teams.size()) {
dialogs::advance_unit(defender_loc_, !get_info().teams[defender_team].is_human());
}
}
throw;
rand_rng::invalidate_seed();
rand_rng::clear_new_seed_callback();
while (!rand_rng::has_valid_seed()) {
manager::raise_user_interact();
manager::raise_sync_network();
SDL_Delay(10);
}
recorder.add_seed("attack", rand_rng::get_last_seed());
attack(attacker_loc_, defender_loc_, attacker_weapon, defender_weapon, get_info().units);
dialogs::advance_unit(attacker_loc_, true);
const unit_map::const_iterator defender = get_info().units.find(defender_loc_);

View file

@ -32,25 +32,6 @@ enum LEVEL_RESULT {
SKIP_TO_LINGER
};
#define DELAY_END_LEVEL(end_ptr, code) try { \
code; \
} catch ( end_level_exception &e) { \
if (end_ptr == 0) { \
end_ptr = new end_level_exception(e); \
} \
}
#define THROW_END_LEVEL_DELETE(end_ptr) if (end_ptr) {\
end_level_exception temp_exception(*end_ptr);\
delete end_ptr; \
end_ptr = 0; \
throw temp_exception; \
}
#define THROW_END_LEVEL(end_ptr) if (end_ptr) {\
throw end_level_exception(*end_ptr); \
}
/**
* Exception used to signal the end of a scenario.
* It also conveys additional information on the game

View file

@ -423,11 +423,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
} else if(end_level.result == DEFEAT) {
gamestate_.classification().completion = "defeat";
log.defeat(turn());
try {
game_events::fire("defeat");
} catch(end_level_exception&) {
ERR_NG << "[endlevel] used in 'defeat' event handler\n";
}
game_events::fire("defeat");
if (!obs) {
const std::string& defeat_music = select_defeat_music();
@ -442,11 +438,8 @@ LEVEL_RESULT playsingle_controller::play_scenario(
{
gamestate_.classification().completion = (!end_level.linger_mode ?
"running" : "victory");
try {
game_events::fire("victory");
} catch(end_level_exception&) {
ERR_NG << "[endlevel] used in 'victory' event handler\n";
}
game_events::fire("victory");
//
// Play victory music once all victory events
// are finished, if we aren't observers.

View file

@ -128,8 +128,7 @@ replay::replay() :
current_(NULL),
skip_(false),
message_locations(),
expected_advancements_(),
delayed_exception_(NULL)
expected_advancements_()
{}
replay::replay(const config& cfg) :
@ -138,8 +137,7 @@ replay::replay(const config& cfg) :
current_(NULL),
skip_(false),
message_locations(),
expected_advancements_(),
delayed_exception_(NULL)
expected_advancements_()
{}
void replay::append(const config& cfg)
@ -790,7 +788,6 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
//if there is nothing more in the records
if(cfg == NULL) {
//replayer.set_skip(false);
THROW_END_LEVEL_DELETE(get_replay_source().delayed_exception());
return false;
}
@ -819,7 +816,6 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
&& cfg->child(do_untill) != NULL)
{
get_replay_source().revert_action();
THROW_END_LEVEL_DELETE(get_replay_source().delayed_exception());
return false;
}
@ -893,7 +889,6 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
verify(*resources::units, child);
}
THROW_END_LEVEL_DELETE(get_replay_source().delayed_exception());
return true;
}
@ -1114,8 +1109,7 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
DBG_REPLAY << "Attacker XP (before attack): " << u->second.experience() << "\n";;
DELAY_END_LEVEL(get_replay_source().delayed_exception(),
attack(src, dst, weapon_num, def_weapon_num, *resources::units, !get_replay_source().is_skipping()));
attack(src, dst, weapon_num, def_weapon_num, *resources::units, !get_replay_source().is_skipping());
DBG_REPLAY << "Attacker XP (after attack): " << u->second.experience() << "\n";;

View file

@ -30,7 +30,6 @@ class game_display;
class terrain_label;
class unit_map;
class play_controller;
struct end_level_exception;
class replay: public rand_rng::rng
{
@ -65,8 +64,6 @@ public:
void add_unit_checksum(const map_location& loc,config* const cfg);
void add_checksum_check(const map_location& loc);
end_level_exception* & delayed_exception() { return delayed_exception_; }
/**
* Mark an expected advancement adding it to the queue
*/
@ -167,8 +164,6 @@ private:
* relevant advance (choice) message has not yet been received
*/
std::deque<map_location> expected_advancements_;
end_level_exception* delayed_exception_;
};
replay& get_replay_source();