Support for recruit lists per leader...
...through a attribute called "unit_recruit" in [unit].
This commit is contained in:
parent
f176010b88
commit
5771e530ef
5 changed files with 56 additions and 6 deletions
|
@ -348,6 +348,29 @@ bool can_recruit_on(const gamemap& map, const map_location& leader, const map_lo
|
|||
return !rt.steps.empty();
|
||||
}
|
||||
|
||||
const std::set<std::string> get_recruits_for_location(int side, const map_location &recruit_loc)
|
||||
{
|
||||
LOG_NG << "getting recruit list for side " << side << "\n";
|
||||
|
||||
std::set<std::string> recruit_list = (*resources::teams)[side -1].recruits();
|
||||
|
||||
unit_map::const_iterator u = resources::units->begin(),
|
||||
u_end = resources::units->end(), leader = u_end, leader_keep = u_end;
|
||||
|
||||
for(; u != u_end; ++u) {
|
||||
if (u->can_recruit() && u->side() == side) {
|
||||
leader = u;
|
||||
if (resources::game_map->is_keep(leader->get_location())) {
|
||||
leader_keep = leader;
|
||||
if (can_recruit_on(*resources::game_map, leader_keep->get_location(), recruit_loc))
|
||||
recruit_list.insert(leader_keep->recruits().begin(), leader_keep->recruits().end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return recruit_list;
|
||||
}
|
||||
|
||||
std::string find_recruit_location(int side, map_location &recruit_loc)
|
||||
{
|
||||
LOG_NG << "finding recruit location for side " << side << "\n";
|
||||
|
|
|
@ -85,6 +85,14 @@ bool can_recruit_on(const gamemap& map, const map_location& leader, const map_lo
|
|||
*/
|
||||
std::string find_recruit_location(int side, map_location &recruit_location);
|
||||
|
||||
/**
|
||||
* Get's the recruitable units from a side's leaders' personal recruit lists who can recruit on a specific hex field.
|
||||
* @param side of the leaders to search for their personal recruit lists.
|
||||
* @param recruit_location the hex field being part of the castle the player wants to recruit on.
|
||||
* @return a set of units that can be recruited by leaders on a keep connected by castle tiles with recruit_loc.
|
||||
*/
|
||||
const std::set<std::string> get_recruits_for_location(int side, const map_location &recruit_loc);
|
||||
|
||||
/**
|
||||
* Place a unit into the game.
|
||||
* The unit will be placed on @a recruit_location, which should be retrieved
|
||||
|
|
|
@ -679,7 +679,11 @@ void menu_handler::recruit(int side_num, const map_location &last_hex)
|
|||
gui_->draw(); //clear the old menu
|
||||
std::vector<std::string> item_keys;
|
||||
std::vector<std::string> items;
|
||||
const std::set<std::string>& recruits = current_team.recruits();
|
||||
|
||||
map_location recruit_loc = last_hex;
|
||||
find_recruit_location(side_num, recruit_loc);
|
||||
std::set<std::string> recruits = get_recruits_for_location(side_num, recruit_loc);
|
||||
|
||||
for(std::set<std::string>::const_iterator it = recruits.begin(); it != recruits.end(); ++it) {
|
||||
const unit_type *type = unit_types.find(*it);
|
||||
if (!type) {
|
||||
|
@ -753,7 +757,8 @@ void menu_handler::do_recruit(const std::string &name, int side_num,
|
|||
|
||||
//search for the unit to be recruited in recruits
|
||||
int recruit_num = 0;
|
||||
const std::set<std::string>& recruits = current_team.recruits();
|
||||
std::set<std::string> recruits = get_recruits_for_location(side_num, last_hex);
|
||||
|
||||
for(std::set<std::string>::const_iterator r = recruits.begin(); ; ++r) {
|
||||
if (r == recruits.end()) {
|
||||
return;
|
||||
|
|
17
src/unit.cpp
17
src/unit.cpp
|
@ -117,7 +117,8 @@ unit::unit(const unit& o):
|
|||
experience_(o.experience_),
|
||||
max_experience_(o.max_experience_),
|
||||
level_(o.level_),
|
||||
canrecruit_(o.canrecruit_),
|
||||
canrecruit_(o.canrecruit_),
|
||||
recruit_list_(o.recruit_list_),
|
||||
alignment_(o.alignment_),
|
||||
flag_rgb_(o.flag_rgb_),
|
||||
image_mods_(o.image_mods_),
|
||||
|
@ -203,6 +204,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
max_experience_(0),
|
||||
level_(0),
|
||||
canrecruit_(cfg["canrecruit"].to_bool()),
|
||||
recruit_list_(),
|
||||
alignment_(),
|
||||
flag_rgb_(),
|
||||
image_mods_(),
|
||||
|
@ -496,7 +498,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
"max_hitpoints", "max_moves", "max_experience",
|
||||
"advances_to", "hitpoints", "goto_x", "goto_y", "moves",
|
||||
"experience", "resting", "unrenamable", "alignment",
|
||||
"canrecruit", "x", "y", "placement",
|
||||
"canrecruit", "unit_recruit", "x", "y", "placement",
|
||||
// Useless attributes created when saving units to WML:
|
||||
"flag_rgb", "language_name" };
|
||||
foreach (const char *attr, internalized_attrs) {
|
||||
|
@ -515,6 +517,11 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
|
|||
if (attr.first == "do_not_list") continue;
|
||||
WRN_UT << "Unknown attribute '" << attr.first << "' discarded.\n";
|
||||
}
|
||||
|
||||
std::vector<std::string> recruits = utils::split(cfg["unit_recruit"]);
|
||||
for(std::vector<std::string>::const_iterator i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
recruit_list_.insert(*i);
|
||||
}
|
||||
}
|
||||
|
||||
void unit::clear_status_caches()
|
||||
|
@ -546,6 +553,7 @@ unit::unit(const unit_type *t, int side, bool real_unit,
|
|||
max_experience_(0),
|
||||
level_(0),
|
||||
canrecruit_(false),
|
||||
recruit_list_(),
|
||||
alignment_(),
|
||||
flag_rgb_(),
|
||||
image_mods_(),
|
||||
|
@ -619,12 +627,13 @@ unit::unit(const unit_type *t, int side, bool real_unit,
|
|||
*/
|
||||
unrenamable_ = false;
|
||||
anim_ = NULL;
|
||||
getsHit_=0;
|
||||
getsHit_ = 0;
|
||||
end_turn_ = false;
|
||||
hold_position_ = false;
|
||||
next_idling_ = 0;
|
||||
frame_begin_time_ = 0;
|
||||
unit_halo_ = halo::NO_HALO;
|
||||
|
||||
}
|
||||
|
||||
unit::~unit()
|
||||
|
@ -1598,6 +1607,8 @@ void unit::write(config& cfg) const
|
|||
if(can_recruit())
|
||||
cfg["canrecruit"] = true;
|
||||
|
||||
cfg["unit_recruit"] = utils::join(recruit_list_);
|
||||
|
||||
cfg["facing"] = map_location::write_direction(facing_);
|
||||
|
||||
cfg["goto_x"] = goto_.x + 1;
|
||||
|
|
|
@ -127,6 +127,8 @@ public:
|
|||
fixed_t alpha() const { return alpha_; }
|
||||
|
||||
bool can_recruit() const { return canrecruit_; }
|
||||
const std::set<std::string>& recruits() const
|
||||
{ return recruit_list_; }
|
||||
bool incapacitated() const { return get_state(STATE_PETRIFIED); }
|
||||
int total_movement() const { return max_movement_; }
|
||||
int movement_left() const { return (movement_ == 0 || incapacitated()) ? 0 : movement_; }
|
||||
|
@ -311,7 +313,7 @@ public:
|
|||
// Only see_all=true use caching
|
||||
bool invisible(const map_location& loc, bool see_all=true) const;
|
||||
|
||||
/** Mark this unit as clone so it can be insterted to unit_map
|
||||
/** Mark this unit as clone so it can be inserted to unit_map
|
||||
* @returns self (for convenience)
|
||||
**/
|
||||
unit& clone(bool is_temporary=true);
|
||||
|
@ -372,6 +374,7 @@ private:
|
|||
int max_experience_;
|
||||
int level_;
|
||||
bool canrecruit_;
|
||||
std::set<std::string> recruit_list_;
|
||||
unit_type::ALIGNMENT alignment_;
|
||||
std::string flag_rgb_;
|
||||
std::string image_mods_;
|
||||
|
|
Loading…
Add table
Reference in a new issue