removed unused function unit::add_recruit,
merged 2 remaining syntaxes for the type-check into 1 and corrected the unit type in the error message
This commit is contained in:
parent
cb3f6c0cd8
commit
0e27ce0456
3 changed files with 10 additions and 44 deletions
|
@ -892,7 +892,7 @@ static int impl_unit_get(lua_State *L)
|
|||
return_bool_attrib("canrecruit", u.can_recruit());
|
||||
|
||||
if (strcmp(m, "extra_recruit") == 0) {
|
||||
std::set<std::string> const &recruits = u.recruits();
|
||||
std::vector<std::string> const &recruits = u.recruits();
|
||||
lua_createtable(L, recruits.size(), 0);
|
||||
int i = 1;
|
||||
foreach (std::string const &r, recruits) {
|
||||
|
@ -957,14 +957,14 @@ static int impl_unit_set(lua_State *L)
|
|||
modify_bool_attrib("hidden", u.set_hidden(value));
|
||||
|
||||
if (strcmp(m, "extra_recruit") == 0) {
|
||||
std::set<std::string> recruits;
|
||||
std::vector<std::string> recruits;
|
||||
char const* message = "table with unnamed indices holding type id strings required";
|
||||
if (!lua_istable(L, 3)) return luaL_argerror(L, 3, message);
|
||||
for (unsigned i = 1; i <= lua_objlen(L, 3); ++i) {
|
||||
lua_rawgeti(L, 3, i);
|
||||
char const* type = lua_tostring(L, 4);
|
||||
if(!type) return luaL_argerror(L, 2 + i, message);
|
||||
recruits.insert(type);
|
||||
recruits.push_back(type);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
u.set_recruits(recruits);
|
||||
|
|
41
src/unit.cpp
41
src/unit.cpp
|
@ -480,22 +480,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
cfg_["upkeep"] = "full";
|
||||
}
|
||||
|
||||
std::vector<std::string> recruits = utils::split(cfg["extra_recruit"]);
|
||||
for(std::vector<std::string>::const_iterator i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
|
||||
const unit_type *recruit_type = unit_types.find(*i);
|
||||
|
||||
if (!recruit_type) {
|
||||
std::string error_message = _("Unknown unit type '$type|' in extra_recruit attribute");
|
||||
utils::string_map symbols;
|
||||
symbols["type"] = *i;
|
||||
error_message = utils::interpolate_variables_into_string(error_message, &symbols);
|
||||
ERR_NG << "unit of type " << *i << " not found!\n";
|
||||
throw game::game_error(error_message);
|
||||
} else {
|
||||
recruit_list_.insert(*i);
|
||||
}
|
||||
}
|
||||
set_recruits(utils::split(cfg["extra_recruit"]));
|
||||
|
||||
/** @todo Are these modified by read? if not they can be removed. */
|
||||
getsHit_=0;
|
||||
|
@ -1002,16 +987,16 @@ SDL_Color unit::xp_color() const
|
|||
return(color);
|
||||
}
|
||||
|
||||
void unit::set_recruits(const std::set<std::string>& recruits)
|
||||
void unit::set_recruits(const std::vector<std::string>& recruits)
|
||||
{
|
||||
foreach (std::string const &unit, recruits) {
|
||||
const unit_type *type = unit_types.find(unit);
|
||||
if (!type) {
|
||||
std::string error_message = _("Unknown unit type '$type|' while setting extra recruit list");
|
||||
utils::string_map symbols;
|
||||
symbols["type"] = type_id();
|
||||
symbols["type"] = unit;
|
||||
error_message = utils::interpolate_variables_into_string(error_message, &symbols);
|
||||
ERR_NG << "unit of type " << type_id() << " not found!\n";
|
||||
ERR_NG << "unit of type " << unit << " not found!\n";
|
||||
throw game::game_error(error_message);
|
||||
}
|
||||
}
|
||||
|
@ -1022,24 +1007,6 @@ void unit::set_recruits(const std::set<std::string>& recruits)
|
|||
//ai::manager::raise_recruit_list_changed();
|
||||
}
|
||||
|
||||
void unit::add_recruit(const std::string &recruit)
|
||||
{
|
||||
const unit_type *type = unit_types.find(recruit);
|
||||
if (!type) {
|
||||
std::string error_message = _("Unknown unit type '$type|' while adding extra recruit");
|
||||
utils::string_map symbols;
|
||||
symbols["type"] = type->type_name();
|
||||
error_message = utils::interpolate_variables_into_string(error_message, &symbols);
|
||||
ERR_NG << "unit of type " << type->type_name() << " not found!\n";
|
||||
throw game::game_error(error_message);
|
||||
} else {
|
||||
recruit_list_.insert(recruit);
|
||||
}
|
||||
//TODO
|
||||
//info_.minimum_recruit_price = 0;
|
||||
//ai::manager::raise_recruit_list_changed();
|
||||
}
|
||||
|
||||
std::string unit::side_id() const {return teams_manager::get_teams()[side()-1].save_id(); }
|
||||
|
||||
void unit::set_movement(int moves)
|
||||
|
|
|
@ -127,10 +127,9 @@ public:
|
|||
fixed_t alpha() const { return alpha_; }
|
||||
|
||||
bool can_recruit() const { return canrecruit_; }
|
||||
const std::set<std::string>& recruits() const
|
||||
const std::vector<std::string>& recruits() const
|
||||
{ return recruit_list_; }
|
||||
void add_recruit(const std::string &);
|
||||
void set_recruits(const std::set<std::string>& recruits);
|
||||
void set_recruits(const std::vector<std::string>& recruits);
|
||||
|
||||
bool incapacitated() const { return get_state(STATE_PETRIFIED); }
|
||||
int total_movement() const { return max_movement_; }
|
||||
|
@ -377,7 +376,7 @@ private:
|
|||
int max_experience_;
|
||||
int level_;
|
||||
bool canrecruit_;
|
||||
std::set<std::string> recruit_list_;
|
||||
std::vector<std::string> recruit_list_;
|
||||
unit_type::ALIGNMENT alignment_;
|
||||
std::string flag_rgb_;
|
||||
std::string image_mods_;
|
||||
|
|
Loading…
Add table
Reference in a new issue