refactor team to use MAKE_ENUM macro for team::DEFEAT_CONDITION
This commit is contained in:
parent
215de94390
commit
ea428a506c
3 changed files with 16 additions and 37 deletions
|
@ -1182,7 +1182,7 @@ static int impl_side_get(lua_State *L)
|
|||
return_string_attrib("name", t.name());
|
||||
return_string_attrib("color", t.color());
|
||||
return_cstring_attrib("controller", t.controller_string());
|
||||
return_string_attrib("defeat_condition", team::defeat_condition_to_string(t.defeat_condition()));
|
||||
return_string_attrib("defeat_condition", lexical_cast<std::string>(t.defeat_condition()));
|
||||
return_bool_attrib("lost", t.lost());
|
||||
|
||||
if (strcmp(m, "recruit") == 0) {
|
||||
|
|
34
src/team.cpp
34
src/team.cpp
|
@ -70,36 +70,6 @@ const std::vector<team>& teams_manager::get_teams()
|
|||
return *teams;
|
||||
}
|
||||
|
||||
team::DEFEAT_CONDITION team::parse_defeat_condition(const std::string& cond, team::DEFEAT_CONDITION def)
|
||||
{
|
||||
if(cond == "no_leader_left")
|
||||
return team::NO_LEADER;
|
||||
else if (cond == "no_units_left")
|
||||
return team::NO_UNITS;
|
||||
else if (cond == "never")
|
||||
return team::NEVER;
|
||||
else if (cond == "always")
|
||||
return team::ALWAYS;
|
||||
else
|
||||
return def;
|
||||
//throw game::game_error("Cannot parse string " + cond +" to a DEFEAT_CONDITION");
|
||||
}
|
||||
std::string team::defeat_condition_to_string(DEFEAT_CONDITION cond)
|
||||
{
|
||||
switch(cond)
|
||||
{
|
||||
case team::NO_LEADER:
|
||||
return "no_leader_left";
|
||||
case team::NO_UNITS:
|
||||
return "no_units_left";
|
||||
case team::NEVER:
|
||||
return "never";
|
||||
case team::ALWAYS:
|
||||
return "always";
|
||||
default:
|
||||
throw game::game_error("Found corrupted DEFEAT_CONDITION");
|
||||
}
|
||||
}
|
||||
team::team_info::team_info() :
|
||||
name(),
|
||||
gold(0),
|
||||
|
@ -161,7 +131,7 @@ void team::team_info::read(const config &cfg)
|
|||
allow_player = cfg["allow_player"].to_bool(true);
|
||||
chose_random = cfg["chose_random"].to_bool(false);
|
||||
no_leader = cfg["no_leader"].to_bool();
|
||||
defeat_condition = team::parse_defeat_condition(cfg["defeat_condition"], team::NO_LEADER);
|
||||
defeat_condition = team::string_to_DEFEAT_CONDITION_default(cfg["defeat_condition"], team::NO_LEADER);
|
||||
hidden = cfg["hidden"].to_bool();
|
||||
no_turn_confirmation = cfg["suppress_end_turn_confirmation"].to_bool();
|
||||
side = cfg["side"].to_int(1);
|
||||
|
@ -288,7 +258,7 @@ void team::team_info::write(config& cfg) const
|
|||
cfg["allow_player"] = allow_player;
|
||||
cfg["chose_random"] = chose_random;
|
||||
cfg["no_leader"] = no_leader;
|
||||
cfg["defeat_condition"] = team::defeat_condition_to_string(defeat_condition);
|
||||
cfg["defeat_condition"] = team::DEFEAT_CONDITION_to_string(defeat_condition);
|
||||
cfg["hidden"] = hidden;
|
||||
cfg["suppress_end_turn_confirmation"] = no_turn_confirmation;
|
||||
cfg["scroll_to_leader"] = scroll_to_leader;
|
||||
|
|
17
src/team.hpp
17
src/team.hpp
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "color_range.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "make_enum.hpp"
|
||||
#include "savegame_config.hpp"
|
||||
#include "unit.hpp"
|
||||
|
||||
|
@ -33,9 +34,15 @@ class team : public savegame::savegame_config
|
|||
{
|
||||
public:
|
||||
enum CONTROLLER { HUMAN, AI, NETWORK, NETWORK_AI, IDLE, EMPTY };
|
||||
enum DEFEAT_CONDITION {NO_LEADER, NO_UNITS, NEVER, ALWAYS};
|
||||
static DEFEAT_CONDITION parse_defeat_condition(const std::string& cond, team::DEFEAT_CONDITION def);
|
||||
static std::string defeat_condition_to_string(DEFEAT_CONDITION cond);
|
||||
//enum DEFEAT_CONDITION {NO_LEADER, NO_UNITS, NEVER, ALWAYS};
|
||||
|
||||
MAKE_ENUM(DEFEAT_CONDITION,
|
||||
(NO_LEADER, "no_leader_left")
|
||||
(NO_UNITS, "no_units_left")
|
||||
(NEVER, "never")
|
||||
(ALWAYS, "always")
|
||||
)
|
||||
|
||||
private:
|
||||
class shroud_map {
|
||||
public:
|
||||
|
@ -270,7 +277,7 @@ public:
|
|||
DEFEAT_CONDITION defeat_condition() const { return info_.defeat_condition; }
|
||||
void set_defeat_condition(DEFEAT_CONDITION value) { info_.defeat_condition = value; }
|
||||
///sets the defeat condition if @param value is a valid defeat condition, otherwise nothing happes.
|
||||
void set_defeat_condition_string(const std::string& value) { info_.defeat_condition = parse_defeat_condition(value, info_.defeat_condition); }
|
||||
void set_defeat_condition_string(const std::string& value) { info_.defeat_condition = string_to_DEFEAT_CONDITION_default(value, info_.defeat_condition); }
|
||||
void have_leader(bool value=true) { info_.no_leader = !value; }
|
||||
bool hidden() const { return info_.hidden; }
|
||||
void set_hidden(bool value) { info_.hidden=value; }
|
||||
|
@ -344,6 +351,8 @@ private:
|
|||
boost::shared_ptr<wb::side_actions> planned_actions_;
|
||||
};
|
||||
|
||||
MAKE_ENUM_STREAM_OPS2(team, DEFEAT_CONDITION)
|
||||
|
||||
namespace teams_manager {
|
||||
const std::vector<team> &get_teams();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue