Multiple-leaders fix:

...if the first leader you see isn't on a castle, check for others.
This commit is contained in:
Alexander van Gessel 2009-07-20 03:21:44 +01:00
parent b99b888929
commit f1f74fd609
3 changed files with 73 additions and 7 deletions

View File

@ -29,6 +29,7 @@
{scenario-formula-recruitment.cfg}
{scenario-poisoning.cfg}
{scenario-lua.cfg}
{scenario-leaders.cfg}
{ai/scenarios/scenario-AI_Arena_small.cfg}
#endif

64
data/scenario-leaders.cfg Normal file
View File

@ -0,0 +1,64 @@
#textdomain wesnoth
[test]
name="Multiple leader test scenario"
map_data="border_size=1
usage=map
Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww
Ww , Ww , Wwr , Wwr , Ch , Wwr , Wwf , Ch , Kh , Ch , Wwf , Ch , Kh , Ch , Wwf , Wwr , Wwf , Ch , Kh , Ch , Wwr , Ww , Ww
Ww , Ww , Wwr , Ch , Kh , Ch , Wwr , Ch , Ch , Ch , Wwr , Ch , Ch , Ch , Wwr , Wwf , Wwr , Ch , Ch , Ch , Wwr , Ww , Ww
Ww , Wwr , Wwr , Ch , Ch , Ch , Wwf , Wwr , Wwf , Wwr , Wwr , Wwr , Wwr , Wwr , Wwr , Wwf , Wwr , Wwr , Wwr , Wwr , Ch , Wwr , Ww
Ww , Wwr , Ch , Wwf , Wwr , Wwf , Ch , Ch , Ch , Wwf , Ch , Wwr , Wwr , Wwr , Ch , Ch , Ch , Wwr , Wwf , Ch , Kh , Ch , Ww
Ww , Ch , Kh , Ch , Wwr , Wwr , Ch , 1 Kh , Ch , Wwr , Wwr , Kh , Ch , Wwr , Ch , 2 Kh , Ch , Wwf , Wwr , Ch , Ch , Ch , Ww
Ww , Ch , Ch , Ch , Wwr , Wwr , Wwf , Ch , Wwr , Wwf , Ch , Wwr , Wwr , Wwf , Wwr , Ch , Wwr , Wwr , Wwr , Wwf , Wwr , Wwr , Ww
Ww , Wwr , Wwf , Wwf , Wwf , Wwr , Ch , Wwr , Wwr , Ch , Kh , Ch , Wwr , Wwr , Ch , Wwr , Wwr , Wwr , Ch , Ch , Ch , Wwr , Ww
Ww , Wwr , Wwf , Wwr , Wwr , Ch , Kh , Ch , Wwf , Ch , Ch , Ch , Wwf , Ch , Kh , Ch , Wwf , Wwr , Ch , Kh , Ch , Wwr , Ww
Ww , Wwr , Ch , Wwr , Wwf , Ch , Ch , Ch , Wwr , Wwr , Wwf , Wwr , Wwr , Ch , Ch , Ch , Wwr , Wwf , Wwr , Ch , Wwr , Wwr , Ww
Ww , Ch , Kh , Ch , Wwr , Wwr , Wwr , Wwr , Wwr , Wwr , Ch , Ch , Ch , Wwf , Wwr , Wwr , Ch , Ch , Ch , Wwr , Wwr , Wwr , Ww
Ww , Ch , Ch , Ch , Wwr , Wwr , Ww , Wwr , Ww , Wwr , Ch , Kh , Ch , Wwr , Wwr , Wwr , Ch , Kh , Ch , Wwr , Wwr , Ww , Ww
Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww , Ww
"
turns=-1
id=leaders
victory_when_enemies_defeated=no
{DEFAULT_SCHEDULE}
[side]
side=1
type=Sergeant
canrecruit=yes
recruit=Spearman
gold=1000
controller=human
[unit]
side=1
x,y=18,1
type=Lieutenant
canrecruit=yes
[/unit]
[unit]
side=1
x,y=19,8
type=General
canrecruit=yes
[/unit]
[unit]
side=1
x,y=20,4
type=Grand Marshal
canrecruit=yes
[/unit]
[/side]
[side]
side=2
type=Orcish Ruler
canrecruit=yes
recruit=Orcish Grunt
gold=0
[/side]
[/test]

View File

@ -218,26 +218,27 @@ std::string recruit_unit(int side, const unit &new_u,
// Find the unit that can recruit
unit_map::const_iterator u = resources::units->begin(),
u_end = resources::units->end();
u_end = resources::units->end(), leader = u_end;
for(; u != u_end; ++u) {
if(u->second.can_recruit() &&
static_cast<int>(u->second.side()) == side) {
break;
leader = u;
if (!need_castle || resources::game_map->is_keep(leader->first))
break;
}
}
map_location recruit_location = recruit_loc;
if (u == u_end && (need_castle || !resources::game_map->on_board(recruit_location))) {
if (leader == u_end && (need_castle || !resources::game_map->on_board(recruit_location))) {
return _("You don't have a leader to recruit with.");
}
assert(u != u_end || !need_castle);
assert(leader != u_end || !need_castle);
if (need_castle && resources::game_map->is_keep(u->first) == false) {
LOG_NG << "Leader not on start: leader is on " << u->first << '\n';
if (need_castle && resources::game_map->is_keep(leader->first) == false) {
LOG_NG << "Leader not on start: leader is on " << leader->first << '\n';
return _("You must have your leader on a keep to recruit or recall units.");
}