AI/Actions: avoid inline ternaries in place of if blocks

This commit is contained in:
Charles Dang 2018-05-01 12:05:42 +11:00
parent 18d597e374
commit 1c744875d3

View file

@ -1080,6 +1080,15 @@ void synced_command_result::do_init_for_execution()
// STATELESS INTERFACE TO AI ACTIONS
// =======================================================================
static void execute_or_check(action_result& action, bool execute)
{
if(execute) {
action.execute();
} else {
action.check_before();
}
}
attack_result_ptr actions::execute_attack_action(side_number side,
bool execute,
const map_location& attacker_loc,
@ -1089,7 +1098,7 @@ attack_result_ptr actions::execute_attack_action(side_number side,
const unit_advancements_aspect& advancements)
{
attack_result_ptr action(new attack_result(side, attacker_loc, defender_loc, attacker_weapon, aggression, advancements));
execute ? action->execute() : action->check_before();
execute_or_check(*action, execute);
return action;
}
@ -1101,7 +1110,7 @@ move_result_ptr actions::execute_move_action(side_number side,
bool unreach_is_ok)
{
move_result_ptr action(new move_result(side, from, to, remove_movement, unreach_is_ok));
execute ? action->execute() : action->check_before();
execute_or_check(*action, execute);
return action;
}
@ -1109,7 +1118,7 @@ recall_result_ptr actions::execute_recall_action(
side_number side, bool execute, const std::string& unit_id, const map_location& where, const map_location& from)
{
recall_result_ptr action(new recall_result(side, unit_id, where, from));
execute ? action->execute() : action->check_before();
execute_or_check(*action, execute);
return action;
}
@ -1120,7 +1129,7 @@ recruit_result_ptr actions::execute_recruit_action(side_number side,
const map_location& from)
{
recruit_result_ptr action(new recruit_result(side, unit_name, where, from));
execute ? action->execute() : action->check_before();
execute_or_check(*action, execute);
return action;
}
@ -1128,7 +1137,7 @@ stopunit_result_ptr actions::execute_stopunit_action(
side_number side, bool execute, const map_location& unit_location, bool remove_movement, bool remove_attacks)
{
stopunit_result_ptr action(new stopunit_result(side, unit_location, remove_movement, remove_attacks));
execute ? action->execute() : action->check_before();
execute_or_check(*action, execute);
return action;
}
@ -1136,7 +1145,7 @@ synced_command_result_ptr actions::execute_synced_command_action(
side_number side, bool execute, const std::string& lua_code, const map_location& location)
{
synced_command_result_ptr action(new synced_command_result(side, lua_code, location));
execute ? action->execute() : action->check_before();
execute_or_check(*action, execute);
return action;
}