unit* find_recruiter(size_t team_index, map_location const& hex) { if ( !resources::game_map->is_castle(hex) ) return NULL; BOOST_FOREACH(unit& u, *resources::units) if(u.can_recruit() && u.side() == static_cast<int>(team_index+1) && can_recruit_on(u, hex)) return &u; return NULL; }
unit const* find_backup_leader(unit const& leader) { assert(leader.can_recruit()); assert(resources::game_map->is_keep(leader.get_location())); BOOST_FOREACH(unit const& unit, *resources::units) { if (unit.can_recruit() && unit.id() != leader.id()) { if ( can_recruit_on(unit, leader.get_location()) ) return &unit; } } return NULL; }
bool recruit_result::test_suitable_recruit_location(const gamemap &map, const unit_map &units, const unit &my_leader, bool) { recruit_location_ = where_; //if we have not-on-board location, such as null_location, then the caller wants us to recruit on 'any' possible tile. if (!map.on_board(recruit_location_)) { recruit_location_ = pathfind::find_vacant_tile(map, units, my_leader.get_location(), pathfind::VACANT_CASTLE); } if (!can_recruit_on(map, my_leader.get_location(), recruit_location_)) { set_error(E_BAD_RECRUIT_LOCATION); return false; } return true; }
bool game_state::side_can_recruit_on(int side, map_location hex) const { unit_map::const_iterator leader = board_.units().find(hex); if ( leader != board_.units().end() ) { return leader->can_recruit() && leader->side() == side && can_recruit_from(*leader); } else { // Look for a leader who can recruit on last_hex. for ( leader = board_.units().begin(); leader != board_.units().end(); ++leader) { if ( leader->can_recruit() && leader->side() == side && can_recruit_on(*leader, hex) ) { return true; } } } // No leader found who can recruit at last_hex. return false; }
unit* find_recruiter(size_t team_index, map_location const& hex) { gamemap& map = *resources::game_map; if(!map.on_board(hex)) return NULL; if(!map.is_castle(hex)) return NULL; BOOST_FOREACH(unit& u, *resources::units) if(u.can_recruit() && u.side() == static_cast<int>(team_index+1) && can_recruit_on(map,u.get_location(),hex)) return &u; return NULL; }
bool game_state::can_recruit_on(const unit& leader, const map_location& recruit_loc) const { return can_recruit_on(leader.get_location(), recruit_loc, leader.side()); }