Filtering for recruiting-capable locations

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
esci
Posts: 42
Joined: September 4th, 2006, 12:07 am

Filtering for recruiting-capable locations

Post by esci »

Does anyone know if there is a way to use the [filter_location] tag to find all locations where a new unit can be recruited or recalled (i.e. all castles connected to a keep)? While for a simple hexagon-shaped castle this is easy using [filter_adjacent_location], it fails for larger or more complicated structures.

A quick search of the game files didn't turn up any [set_menu_item]s for the recruit and recall commands, but if you can point me to a file where they are defined that would be extremely helpful. If it matters, I'm using the 1.9 releases.
Original creator of the campaign Descent Into Darkness
Currently working on Cities of the Frontier
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Filtering for recruiting-capable locations

Post by Sapient »

Do you mean all potential recruitable castle hexes or only those with a specific side's leader currently positioned and able to recruit? Don't forget you can also recruit on connected keeps and the hex must be vacant.

Something like this should work:

Code: Select all

  [filter_location]
   [and]
    terrain=K*
    [filter]
     side={SIDE}
     canrecruit=yes
    [/filter]
    radius=400
    [filter_radius]
     terrain=K*,C*
    [/filter_radius]
   [/and]
   [not]
    [filter]
     # no unit present
    [/filter]
   [/not]
  [/filter_location]
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Filtering for recruiting-capable locations

Post by zookeeper »

I think this ought to allow a menu item on any castle or keep hex which is connected to a leader of the current side who must be standing on a keep.

Code: Select all

[set_menu_item]
    [filter_location]
        [filter]
            side=$side_number
            canrecruit=yes

            [filter_location]
                terrain=K*
            [/filter_location]
        [/filter]

        radius=99

        [filter_radius]
            terrain=C*,K*
        [/filter_radius]
    [/filter_location]
Working on a new campaign? :o
esci
Posts: 42
Joined: September 4th, 2006, 12:07 am

Re: Filtering for recruiting-capable locations

Post by esci »

Thanks to both of you! I hadn't fully understood how [filter_radius] worked.

I've gotten back into Wesnoth lately after a several year hiatus, and have started toying around with a new campaign. It's not yet to the point of being worth uploading, however.
Original creator of the campaign Descent Into Darkness
Currently working on Cities of the Frontier
esci
Posts: 42
Joined: September 4th, 2006, 12:07 am

Re: Filtering for recruiting-capable locations

Post by esci »

In case anyone searches for this in the future, my final solution was slightly different from those posted above. I realized that the previous solutions included all the hexes in my castle, but also included every hex adjacent to the castle. The [filter_radius] tag apparently expands one hex outwards from every hex matching its filter, rather than to hexes matching its filter. So the code that worked for me required an additional filter for only matching castle and hex terrain:

Code: Select all

[filter_location]
	terrain=C*,K*
	[and]
		[filter]
			side=1
			canrecruit=yes
			[filter_location]
				terrain=K*
			[/filter_location]
		[/filter]
		radius=99
		[filter_radius]
			terrain=C*,K*
		[/filter_radius]
	[/and]
[/filter_location]
I placed all of this inside a [show_menu_item] tag.
Original creator of the campaign Descent Into Darkness
Currently working on Cities of the Frontier
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Filtering for recruiting-capable locations

Post by Sapient »

esci wrote:The [filter_radius] tag apparently expands one hex outwards from every hex matching its filter, rather than to hexes matching its filter.
If that is true, then it is most assuredly a bug.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Post Reply