Fixed recruit bug from multi-turn moves commit.

This commit is contained in:
Tommy Schmitz 2011-08-19 20:58:08 +00:00
parent adf26fffa0
commit 522228dd47
6 changed files with 51 additions and 8 deletions

View file

@ -282,7 +282,10 @@ void manager::update_plan_hiding() const
{update_plan_hiding(viewer_team());}
void manager::on_viewer_change(size_t team_index)
{update_plan_hiding(team_index);}
{
if(!wait_for_side_init_)
update_plan_hiding(team_index);
}
void manager::on_change_controller(int side, team& t)
{
@ -743,9 +746,12 @@ bool manager::save_recruit(const std::string& name, int side_num, const map_loca
else
{
side_actions& sa = *viewer_actions();
size_t turn = sa.num_turns();
if(turn > 0)
--turn;
unit* recruiter;
{ wb::scoped_planned_unit_map raii;
recruiter = find_recruiter(side_num-1,recruit_hex);
} // end planned unit map scope
assert(recruiter);
size_t turn = sa.get_turn_num_of(*recruiter);
sa.queue_recruit(turn,name,recruit_hex);
created_planned_recruit = true;

View file

@ -56,8 +56,8 @@ public:
*/
virtual map_location get_numbering_hex() const { return recall_hex_; }
/** For recall actions, always returns NULL. */
virtual unit* get_unit() const { return NULL; }
/** @return pointer to a copy of the recall unit. */
virtual unit* get_unit() const { return temp_unit_; }
map_location const get_recall_hex() const { return recall_hex_; }

View file

@ -60,8 +60,8 @@ public:
*/
virtual map_location get_numbering_hex() const { return recruit_hex_; }
/** For recruit actions, always returns NULL. */
virtual unit* get_unit() const { return NULL; }
/** @return pointer to a fake unit representing the one that will eventually be recruited. */
virtual unit* get_unit() const { return temp_unit_; }
map_location const get_recruit_hex() const { return recruit_hex_; }

View file

@ -88,6 +88,24 @@ unit const* find_backup_leader(unit const& leader)
return NULL;
}
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;
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;
}
unit* future_visible_unit(map_location hex, int viewer_side)
{
scoped_planned_unit_map planned_unit_map;

View file

@ -51,6 +51,12 @@ side_actions_ptr current_side_actions();
*/
unit const* find_backup_leader(unit const& leader);
/**
* @return a leader from the specified team who can recruit on the specified hex
* @retval NULL if no such leader has been found
*/
unit* find_recruiter(size_t team_index, map_location const&);
/// Applies the future unit map and @return a pointer to the unit at hex
/// @retval NULL if none is visible to the specified viewer side
unit* future_visible_unit(map_location hex, int viewer_side = wb::viewer_side());

View file

@ -245,6 +245,12 @@ void validate_visitor::visit_recruit(recruit_ptr recruit)
LOG_WB << "Recruit set as invalid, team doesn't have enough gold.\n";
recruit->set_valid(false);
}
//Check that there is a leader available to recruit this unit
if(recruit->is_valid() && !find_recruiter(recruit->team_index(),recruit->get_recruit_hex()))
{
LOG_WB << "Recruit set as invalid, no leader can recruit this unit.\n";
recruit->set_valid(false);
}
if(!recruit->is_valid())
{
@ -288,6 +294,13 @@ void validate_visitor::visit_recall(recall_ptr recall)
LOG_WB << "Recall set as invalid, team doesn't have enough gold.\n";
recall->set_valid(false);
}
//Check that there is a leader available to recall this unit
if(recall->is_valid() && find_recruiter(recall->team_index(),recall->get_recall_hex()))
{
LOG_WB << "Recall set as invalid, no leader can recall this unit.\n";
recall->set_valid(false);
}
if(!recall->is_valid())
{