Use the incoming value of recall/recruited_from as a hint...

...for finding a leader in check/find_recall/recruit_location().
This commit is contained in:
J. Tyne 2013-02-08 17:18:49 +00:00
parent e2d39ece5b
commit 0214c1b22f
2 changed files with 36 additions and 12 deletions

View file

@ -543,6 +543,9 @@ RECRUIT_CHECK check_recall_location(const int side, map_location& recall_locatio
map_location& recall_from,
const unit &unit_recall)
{
const unit_map & units = *resources::units;
const unit_map::const_iterator u_end = units.end();
map_location check_location = recall_location;
map_location alternative; // Set by check_unit_recall_location().
@ -555,10 +558,15 @@ RECRUIT_CHECK check_recall_location(const int side, map_location& recall_locatio
RECRUIT_ALTERNATE_LOCATION;
RECRUIT_CHECK best_result = RECRUIT_NO_LEADER;
// Test the specified recaller (if there is one).
unit_map::const_iterator u = units.find(recall_from);
if ( u != u_end && u->side() == side ) {
best_result =
check_unit_recall_location(*u, unit_recall, check_location, alternative);
}
// Loop through all units on the specified side.
unit_map::const_iterator const u_end = resources::units->end();
unit_map::const_iterator u = resources::units->begin();
for ( ; best_result < goal_result && u != u_end; ++u ) {
for ( u = units.begin(); best_result < goal_result && u != u_end; ++u ) {
if ( u->side() != side )
continue;
@ -665,6 +673,9 @@ RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_locat
map_location& recruited_from,
const std::string& unit_type)
{
const unit_map & units = *resources::units;
const unit_map::const_iterator u_end = units.end();
map_location check_location = recruit_location;
std::string check_type = unit_type;
map_location alternative; // Set by check_unit_recruit_location().
@ -683,10 +694,15 @@ RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_locat
RECRUIT_ALTERNATE_LOCATION;
RECRUIT_CHECK best_result = RECRUIT_NO_LEADER;
// Test the specified recruiter (if there is one).
unit_map::const_iterator u = units.find(recruited_from);
if ( u != u_end && u->side() == side ) {
best_result =
check_unit_recruit_location(*u, check_type, check_location, alternative);
}
// Loop through all units on the specified side.
unit_map::const_iterator const u_end = resources::units->end();
unit_map::const_iterator u = resources::units->begin();
for ( ; best_result < goal_result && u != u_end; ++u ) {
for ( u = units.begin(); best_result < goal_result && u != u_end; ++u ) {
if ( u->side() != side )
continue;

View file

@ -107,7 +107,9 @@ enum RECRUIT_CHECK {
* occur.
*
* The location of the recruiting leader is stored in @a recruited_from.
* (The incoming value of this parameter is ignored.)
* The incoming value of this parameter is used as a hint for finding a
* legal recruiter, but this hint is given lower priority than finding a
* leader who can recruit at recruit_location.
*
* The @a unit_type is needed in case this is a leader-specific recruit.
*/
@ -124,8 +126,10 @@ RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_locat
* If no errors are encountered, the location where a unit can be recruited
* is stored in @a recruit_location. Its value is considered first, if it is a
* legal option.
* Also, the location of the recruiting leader is stored in @a recruited_from
* (whose value is not considered first).
* Also, the location of the recruiting leader is stored in @a recruited_from.
* The incoming value of recruited_from is used as a hint for finding a
* legal recruiter, but this hint is given lower priority than finding a
* leader who can recruit at recruit_location.
*
* The @a unit_type is needed in case this is a leader-specific recruit.
*
@ -145,7 +149,9 @@ std::string find_recruit_location(const int side, map_location &recruit_location
* occur.
*
* The location of the recalling leader is stored in @a recall_from.
* (The incoming value of this parameter is ignored.)
* The incoming value of this parameter is used as a hint for finding a
* legal recaller, but this hint is given lower priority than finding a
* leader who can recall at recall_location.
*/
RECRUIT_CHECK check_recall_location(const int side, map_location& recall_location,
map_location& recall_from,
@ -160,8 +166,10 @@ RECRUIT_CHECK check_recall_location(const int side, map_location& recall_locatio
* If no errors are encountered, the location where a unit can be recalled
* is stored in @a recall_location. Its value is considered first, if it is a
* legal option.
* Also, the location of the recalling leader is stored in @a recall_from
* (whose value is not considered first).
* Also, the location of the recalling leader is stored in @a recall_from.
* The incoming value of this parameter is used as a hint for finding a
* legal recaller, but this hint is given lower priority than finding a
* leader who can recall at recall_location.
*
* @return an empty string on success. Otherwise a human-readable message
* describing the failure is returned.