AI/Actions: use an initializer list for the error code name map
This commit is contained in:
parent
64bd866ef2
commit
344d7c6799
1 changed files with 38 additions and 44 deletions
|
@ -1054,50 +1054,46 @@ synced_command_result_ptr actions::execute_synced_command_action( side_number si
|
|||
return action;
|
||||
}
|
||||
|
||||
std::map<int, std::string> actions::error_names_ {
|
||||
{ action_result::AI_ACTION_SUCCESS, "action_result::AI_ACTION_SUCCESS" },
|
||||
{ action_result::AI_ACTION_STARTED, "action_result::AI_ACTION_STARTED" },
|
||||
{ action_result::AI_ACTION_FAILURE, "action_result::AI_ACTION_FAILURE" },
|
||||
{ attack_result::E_EMPTY_ATTACKER, "attack_result::E_EMPTY_ATTACKER" },
|
||||
{ attack_result::E_EMPTY_DEFENDER, "attack_result::E_EMPTY_DEFENDER" },
|
||||
{ attack_result::E_INCAPACITATED_ATTACKER, "attack_result::E_INCAPACITATED_ATTACKER" },
|
||||
{ attack_result::E_INCAPACITATED_DEFENDER, "attack_result::E_INCAPACITATED_DEFENDER" },
|
||||
{ attack_result::E_NOT_OWN_ATTACKER, "attack_result::E_NOT_OWN_ATTACKER" },
|
||||
{ attack_result::E_NOT_ENEMY_DEFENDER, "attack_result::E_NOT_ENEMY_DEFENDER" },
|
||||
{ attack_result::E_NO_ATTACKS_LEFT, "attack_result::E_NO_ATTACKS_LEFT" },
|
||||
{ attack_result::E_WRONG_ATTACKER_WEAPON, "attack_result::E_WRONG_ATTACKER_WEAPON" },
|
||||
{ attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON, "attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON" },
|
||||
{ attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACENT," attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACE" },
|
||||
{ move_result::E_EMPTY_MOVE, "move_result::E_EMPTY_MOVE" },
|
||||
{ move_result::E_NO_UNIT, "move_result::E_NO_UNIT" },
|
||||
{ move_result::E_NOT_OWN_UNIT, "move_result::E_NOT_OWN_UNIT" },
|
||||
{ move_result::E_INCAPACITATED_UNIT, "move_result::E_INCAPACITATED_UNIT" },
|
||||
{ move_result::E_AMBUSHED, "move_result::E_AMBUSHED" },
|
||||
{ move_result::E_FAILED_TELEPORT, "move_result::E_FAILED_TELEPORT" },
|
||||
{ move_result::E_NOT_REACHED_DESTINATION, "move_result::E_NOT_REACHED_DESTINATION" },
|
||||
{ move_result::E_NO_ROUTE, "move_result::E_NO_ROUTE" },
|
||||
{ recall_result::E_NOT_AVAILABLE_FOR_RECALLING, "recall_result::E_NOT_AVAILABLE_FOR_RECALLING" },
|
||||
{ recall_result::E_NO_GOLD, "recall_result::E_NO_GOLD" },
|
||||
{ recall_result::E_NO_LEADER," recall_result::E_NO_LEADER" },
|
||||
{ recall_result::E_LEADER_NOT_ON_KEEP, "recall_result::E_LEADER_NOT_ON_KEEP" },
|
||||
{ recall_result::E_BAD_RECALL_LOCATION, "recall_result::E_BAD_RECALL_LOCATION" },
|
||||
{ recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING, "recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING" },
|
||||
{ recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE, "recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE" },
|
||||
{ recruit_result::E_NO_GOLD, "recruit_result::E_NO_GOLD" },
|
||||
{ recruit_result::E_NO_LEADER, "recruit_result::E_NO_LEADER" },
|
||||
{ recruit_result::E_LEADER_NOT_ON_KEEP, "recruit_result::E_LEADER_NOT_ON_KEEP" },
|
||||
{ recruit_result::E_BAD_RECRUIT_LOCATION, "recruit_result::E_BAD_RECRUIT_LOCATION" },
|
||||
{ stopunit_result::E_NO_UNIT, "stopunit_result::E_NO_UNIT" },
|
||||
{ stopunit_result::E_NOT_OWN_UNIT, "stopunit_result::E_NOT_OWN_UNIT" },
|
||||
{ stopunit_result::E_INCAPACITATED_UNIT, "stopunit_result::E_INCAPACITATED_UNIT" },
|
||||
};
|
||||
|
||||
const std::string& actions::get_error_name(int error_code)
|
||||
{
|
||||
if (error_names_.empty()){
|
||||
error_names_.emplace(action_result::AI_ACTION_SUCCESS, "action_result::AI_ACTION_SUCCESS");
|
||||
error_names_.emplace(action_result::AI_ACTION_STARTED, "action_result::AI_ACTION_STARTED");
|
||||
error_names_.emplace(action_result::AI_ACTION_FAILURE, "action_result::AI_ACTION_FAILURE");
|
||||
|
||||
error_names_.emplace(attack_result::E_EMPTY_ATTACKER, "attack_result::E_EMPTY_ATTACKER");
|
||||
error_names_.emplace(attack_result::E_EMPTY_DEFENDER, "attack_result::E_EMPTY_DEFENDER");
|
||||
error_names_.emplace(attack_result::E_INCAPACITATED_ATTACKER, "attack_result::E_INCAPACITATED_ATTACKER");
|
||||
error_names_.emplace(attack_result::E_INCAPACITATED_DEFENDER, "attack_result::E_INCAPACITATED_DEFENDER");
|
||||
error_names_.emplace(attack_result::E_NOT_OWN_ATTACKER, "attack_result::E_NOT_OWN_ATTACKER");
|
||||
error_names_.emplace(attack_result::E_NOT_ENEMY_DEFENDER, "attack_result::E_NOT_ENEMY_DEFENDER");
|
||||
error_names_.emplace(attack_result::E_NO_ATTACKS_LEFT, "attack_result::E_NO_ATTACKS_LEFT");
|
||||
error_names_.emplace(attack_result::E_WRONG_ATTACKER_WEAPON, "attack_result::E_WRONG_ATTACKER_WEAPON");
|
||||
error_names_.emplace(attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON, "attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON");
|
||||
error_names_.emplace(attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACENT," attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACENT");
|
||||
|
||||
error_names_.emplace(move_result::E_EMPTY_MOVE, "move_result::E_EMPTY_MOVE");
|
||||
error_names_.emplace(move_result::E_NO_UNIT, "move_result::E_NO_UNIT");
|
||||
error_names_.emplace(move_result::E_NOT_OWN_UNIT, "move_result::E_NOT_OWN_UNIT");
|
||||
error_names_.emplace(move_result::E_INCAPACITATED_UNIT, "move_result::E_INCAPACITATED_UNIT");
|
||||
error_names_.emplace(move_result::E_AMBUSHED, "move_result::E_AMBUSHED");
|
||||
error_names_.emplace(move_result::E_FAILED_TELEPORT, "move_result::E_FAILED_TELEPORT");
|
||||
error_names_.emplace(move_result::E_NOT_REACHED_DESTINATION, "move_result::E_NOT_REACHED_DESTINATION");
|
||||
error_names_.emplace(move_result::E_NO_ROUTE, "move_result::E_NO_ROUTE");
|
||||
|
||||
error_names_.emplace(recall_result::E_NOT_AVAILABLE_FOR_RECALLING, "recall_result::E_NOT_AVAILABLE_FOR_RECALLING");
|
||||
error_names_.emplace(recall_result::E_NO_GOLD, "recall_result::E_NO_GOLD");
|
||||
error_names_.emplace(recall_result::E_NO_LEADER," recall_result::E_NO_LEADER");
|
||||
error_names_.emplace(recall_result::E_LEADER_NOT_ON_KEEP, "recall_result::E_LEADER_NOT_ON_KEEP");
|
||||
error_names_.emplace(recall_result::E_BAD_RECALL_LOCATION, "recall_result::E_BAD_RECALL_LOCATION");
|
||||
|
||||
error_names_.emplace(recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING, "recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING");
|
||||
error_names_.emplace(recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE, "recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE");
|
||||
error_names_.emplace(recruit_result::E_NO_GOLD, "recruit_result::E_NO_GOLD");
|
||||
error_names_.emplace(recruit_result::E_NO_LEADER, "recruit_result::E_NO_LEADER");
|
||||
error_names_.emplace(recruit_result::E_LEADER_NOT_ON_KEEP, "recruit_result::E_LEADER_NOT_ON_KEEP");
|
||||
error_names_.emplace(recruit_result::E_BAD_RECRUIT_LOCATION, "recruit_result::E_BAD_RECRUIT_LOCATION");
|
||||
|
||||
error_names_.emplace(stopunit_result::E_NO_UNIT, "stopunit_result::E_NO_UNIT");
|
||||
error_names_.emplace(stopunit_result::E_NOT_OWN_UNIT, "stopunit_result::E_NOT_OWN_UNIT");
|
||||
error_names_.emplace(stopunit_result::E_INCAPACITATED_UNIT, "stopunit_result::E_INCAPACITATED_UNIT");
|
||||
}
|
||||
std::map<int,std::string>::iterator i = error_names_.find(error_code);
|
||||
if (i==error_names_.end()){
|
||||
ERR_AI_ACTIONS << "error name not available for error #"<<error_code << std::endl;
|
||||
|
@ -1107,8 +1103,6 @@ const std::string& actions::get_error_name(int error_code)
|
|||
return i->second;
|
||||
}
|
||||
|
||||
std::map<int,std::string> actions::error_names_;
|
||||
|
||||
void sim_gamestate_changed(action_result *result, bool gamestate_changed){
|
||||
if(gamestate_changed){
|
||||
result->set_gamestate_changed();
|
||||
|
|
Loading…
Add table
Reference in a new issue