Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "action.hpp"
00021 #include "move.hpp"
00022 #include "attack.hpp"
00023 #include "recruit.hpp"
00024 #include "recall.hpp"
00025 #include "suppose_dead.hpp"
00026
00027 #include "resources.hpp"
00028 #include "team.hpp"
00029
00030 namespace wb {
00031
00032 std::ostream& operator<<(std::ostream& s, action_ptr action)
00033 {
00034 assert(action);
00035 return action->print(s);
00036 }
00037
00038 std::ostream& operator<<(std::ostream& s, action_const_ptr action)
00039 {
00040 assert(action);
00041 return action->print(s);
00042 }
00043
00044 std::ostream& action::print(std::ostream& s) const
00045 {
00046 return s;
00047 }
00048
00049 config action::to_config() const
00050 {
00051 config final_cfg;
00052 final_cfg["type"]="action";
00053 final_cfg["team_index_"]=static_cast<int>(team_index_);
00054 return final_cfg;
00055 }
00056
00057
00058 action_ptr action::from_config(config const& cfg, bool hidden)
00059 {
00060 std::string type = cfg["type"];
00061
00062 try {
00063 if(type=="move")
00064 return action_ptr(new move(cfg,hidden));
00065 else if(type=="attack")
00066 return action_ptr(new attack(cfg,hidden));
00067 else if(type=="recruit")
00068 return action_ptr(new recruit(cfg,hidden));
00069 else if(type=="recall")
00070 return action_ptr(new recall(cfg,hidden));
00071 else if(type=="suppose_dead")
00072 return action_ptr(new suppose_dead(cfg,hidden));
00073 } catch(action::ctor_err const&) {}
00074
00075 return action_ptr();
00076 }
00077
00078 void action::hide()
00079 {
00080 if(hidden_)
00081 return;
00082 hidden_ = true;
00083 do_hide();
00084 }
00085
00086 void action::show()
00087 {
00088 if(!hidden_)
00089 return;
00090 hidden_ = false;
00091 do_show();
00092 }
00093
00094 action::action(size_t team_index, bool hidden)
00095 : team_index_(team_index)
00096 , hidden_(hidden)
00097 {
00098 }
00099
00100 action::action(config const& cfg, bool hidden)
00101 : team_index_()
00102 , hidden_(hidden)
00103 {
00104
00105 int team_index_temp = cfg["team_index_"].to_int(-1);
00106 if(team_index_temp < 0
00107 || team_index_temp >= static_cast<int>(resources::teams->size()))
00108 throw ctor_err("action: Invalid team_index_");
00109 team_index_ = team_index_temp;
00110 }
00111
00112 action::~action()
00113 {
00114 }
00115
00116 }