simplify synced_context::run() calls by ai and whiteboard
- use_undo is not used anymore - ignore_error_function has no effect since to_check() already checks whether the unit exists - show in whiteboard code was the default value. - show is now determined inside the actions handler, this has the advantage that the skip_ai_moves preference now also works for networked ai sides. -the attack code now used run_in_synced_context_if_not_already just like the other commands
This commit is contained in:
parent
715a65438a
commit
7782c50f83
7 changed files with 28 additions and 35 deletions
|
@ -716,6 +716,7 @@ place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_locat
|
|||
void recruit_unit(const unit_type & u_type, int side_num, const map_location & loc,
|
||||
const map_location & from, bool show)
|
||||
{
|
||||
show = show && !resources::controller->is_skipping_actions();
|
||||
const unit_ptr new_unit = unit::create(u_type, side_num, true);
|
||||
|
||||
|
||||
|
@ -740,6 +741,7 @@ bool recall_unit(const std::string & id, team & current_team,
|
|||
const map_location & loc, const map_location & from,
|
||||
map_location::direction facing, bool show)
|
||||
{
|
||||
show = show && !resources::controller->is_skipping_actions();
|
||||
unit_ptr recall = current_team.recall_list().extract_if_matches_id(id);
|
||||
|
||||
if ( !recall )
|
||||
|
|
|
@ -1250,6 +1250,7 @@ namespace { // Private helpers for move_unit()
|
|||
static std::size_t move_unit_internal(undo_list* undo_stack,
|
||||
bool show_move, bool* interrupted, unit_mover& mover)
|
||||
{
|
||||
show_move = show_move && !resources::controller->is_skipping_actions();
|
||||
const events::command_disabler disable_commands;
|
||||
// Default return value.
|
||||
if (interrupted) {
|
||||
|
|
|
@ -287,27 +287,20 @@ void attack_result::do_execute()
|
|||
return;
|
||||
}
|
||||
|
||||
if(!synced_context::is_synced())
|
||||
{
|
||||
synced_context::run_and_throw("attack",
|
||||
replay_helper::get_attack(
|
||||
attacker_loc_,
|
||||
defender_loc_,
|
||||
attacker_weapon,
|
||||
defender_weapon,
|
||||
a_->type_id(),
|
||||
d_->type_id(),
|
||||
a_->level(),
|
||||
d_->level(),
|
||||
resources::tod_manager->turn(),
|
||||
resources::tod_manager->get_time_of_day()
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
attack_unit_and_advance(attacker_loc_, defender_loc_, attacker_weapon, defender_weapon, true);
|
||||
}
|
||||
synced_context::run_in_synced_context_if_not_already("attack",
|
||||
replay_helper::get_attack(
|
||||
attacker_loc_,
|
||||
defender_loc_,
|
||||
attacker_weapon,
|
||||
defender_weapon,
|
||||
a_->type_id(),
|
||||
d_->type_id(),
|
||||
a_->level(),
|
||||
d_->level(),
|
||||
resources::tod_manager->turn(),
|
||||
resources::tod_manager->get_time_of_day()
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
set_gamestate_changed();
|
||||
|
@ -476,7 +469,7 @@ void move_result::do_execute()
|
|||
/*std::vector<map_location> steps*/ route_->steps,
|
||||
/*::actions::undo_list* undo_stack*/ nullptr,
|
||||
/*bool continue_move*/ true,
|
||||
/*bool show_move*/ !prefs::get().skip_ai_moves(),
|
||||
/*bool show_move*/ true,
|
||||
/*bool* interrupted*/ nullptr,
|
||||
/*::actions::move_unit_spectator* move_spectator*/ &move_spectator);
|
||||
|
||||
|
@ -652,14 +645,9 @@ void recall_result::do_execute()
|
|||
}
|
||||
|
||||
// Do the actual recalling.
|
||||
// We ignore possible errors (=unit doesn't exist on the recall list)
|
||||
// because that was the previous behavior.
|
||||
resources::undo_stack->clear();
|
||||
synced_context::run_in_synced_context_if_not_already("recall",
|
||||
replay_helper::get_recall(unit_id_, recall_location_, recall_from_),
|
||||
false,
|
||||
!prefs::get().skip_ai_moves(),
|
||||
synced_context::ignore_error_function);
|
||||
replay_helper::get_recall(unit_id_, recall_location_, recall_from_));
|
||||
|
||||
set_gamestate_changed();
|
||||
try {
|
||||
|
@ -804,7 +792,7 @@ void recruit_result::do_execute()
|
|||
}
|
||||
|
||||
resources::undo_stack->clear();
|
||||
synced_context::run_in_synced_context_if_not_already("recruit", replay_helper::get_recruit(u->id(), recruit_location_, recruit_from_), false, !prefs::get().skip_ai_moves());
|
||||
synced_context::run_in_synced_context_if_not_already("recruit", replay_helper::get_recruit(u->id(), recruit_location_, recruit_from_));
|
||||
|
||||
set_gamestate_changed();
|
||||
try {
|
||||
|
|
|
@ -446,8 +446,7 @@ void menu_handler::recall(int side_num, const map_location& last_hex)
|
|||
if(!pc_.get_whiteboard()
|
||||
|| !pc_.get_whiteboard()->save_recall(*recall_list_team[res].get(), side_num, recall_location)) {
|
||||
bool success = synced_context::run_and_throw("recall",
|
||||
replay_helper::get_recall(recall_list_team[res]->id(), recall_location, recall_from), true, true,
|
||||
synced_context::ignore_error_function);
|
||||
replay_helper::get_recall(recall_list_team[res]->id(), recall_location, recall_from));
|
||||
|
||||
if(!success) {
|
||||
ERR_NG << "menu_handler::recall(): Unit does not exist in the recall list.";
|
||||
|
|
|
@ -1313,6 +1313,11 @@ void play_controller::toggle_skipping_replay()
|
|||
}
|
||||
}
|
||||
|
||||
bool play_controller::is_skipping_actions() const
|
||||
{
|
||||
return is_skipping_replay() || (prefs::get().skip_ai_moves() && current_team().is_ai() && !is_replay());
|
||||
}
|
||||
|
||||
bool play_controller::is_during_turn() const
|
||||
{
|
||||
return gamestate().in_phase(game_data::TURN_PLAYING);
|
||||
|
|
|
@ -209,6 +209,7 @@ public:
|
|||
config to_config() const;
|
||||
|
||||
bool is_skipping_replay() const { return skip_replay_; }
|
||||
bool is_skipping_actions() const;
|
||||
void toggle_skipping_replay();
|
||||
void do_autosave();
|
||||
|
||||
|
|
|
@ -127,10 +127,7 @@ void recall::execute(bool& success, bool& complete)
|
|||
}
|
||||
current_team.get_side_actions()->change_gold_spent_by(-cost);
|
||||
bool const result = synced_context::run_and_throw("recall",
|
||||
replay_helper::get_recall(temp_unit_->id(), recall_hex_, map_location::null_location()),
|
||||
true,
|
||||
true,
|
||||
synced_context::ignore_error_function);
|
||||
replay_helper::get_recall(temp_unit_->id(), recall_hex_, map_location::null_location()));
|
||||
|
||||
if (!result) {
|
||||
current_team.get_side_actions()->change_gold_spent_by(cost);
|
||||
|
|
Loading…
Add table
Reference in a new issue