[terrain] & [filter_location]

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
SigurdFireDragon
Developer
Posts: 546
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

[terrain] & [filter_location]

Post by SigurdFireDragon »

wiki wrote:[terrain]
Changes the terrain on the map.

terrain: the character of the terrain to use. See TerrainCodesWML to see what letter a type of terrain uses.
x,y: the position (or range of positions) to change. (Version 1.9 and later only) : [terrain] accepts a StandardLocationFilter. This StandardLocationFilter's terrain= key is used for the new terrain, filtering by terrain can be done with a nested StandardLocationFilter: [and]terrain=terrain_string_to_be_filtered_for.
On my map I want to change all Castles (Ch) to Desert Castles (Cd)
I thought

Code: Select all

				[terrain]
					terrain=Cd
					[filter_location]
						terrain=Ch
					[/filter_location]
				[/terrain]
inside of an (event name=prestart) would work, but it changed every hex on the map to a (Cd), not just the (Ch).

I tried a couple other things, but can't figure out what to do from the wiki & can't find an example. How would I do this?
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [terrain] & [filter_location]

Post by Sapient »

If it's on 1.9 then this should work:

Code: Select all

            [terrain]
               terrain=Cd
               [and]
                  terrain=Ch
               [/and]
            [/terrain]
yeah... part of me thinks it should be changed to work like you wrote it though, since that would be more intuitive.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: [terrain] & [filter_location]

Post by Anonymissimus »

Sapient wrote:yeah... part of me thinks it should be changed to work like you wrote it though, since that would be more intuitive.
It would break backwards compatibility.
Previously the syntax was [terrain]x,y= without SLF. I however suggested to reintroduce the former letter= key substituting [terrain]terrain= to [terrain]letter= to solve the issue. The problem is that the argument specifying the new terrain collides with the SLF's terrain= key.
What was unclear about my wiki docs btw:
This StandardLocationFilter's terrain= key is used for the new terrain, filtering by terrain can be done with a nested StandardLocationFilter: [and]terrain=terrain_string_to_be_filtered_for.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [terrain] & [filter_location]

Post by Sapient »

Anonymissimus wrote: It would break backwards compatibility.
Not necessarily... it could convert convert the terrain filter to this if either x or y are supplied:

Code: Select all

  [and]
     x={OUTER_X} # if supplied
     y={OUTER_Y} # if supplied
  [/and]
  [and]
    {INNER_FILTER}
  [/and]
Maybe better or worse, just throwing it out for discussion.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
SigurdFireDragon
Developer
Posts: 546
Joined: January 12th, 2011, 2:18 am
Location: Pennsylvania, USA

Re: [terrain] & [filter_location]

Post by SigurdFireDragon »

Thanks Sapient, that worked.

Is there a way to do it under 1.8 without a SLF?

Anonymissimus wrote:What was unclear about my wiki docs btw:
This StandardLocationFilter's terrain= key is used for the new terrain, filtering by terrain can be done with a nested StandardLocationFilter: [and]terrain=terrain_string_to_be_filtered_for.
Maybe a journey over my point of view might explain it.

1. I want to swap (Ch) for (Cd) in an event. I realize that [terrain] can do this. Never used [terrain] before.
2. go to [terrain] wiki on the DirectWML page. Seems simple enough, just have to specify original terrain and new terrain. Oh, in 1.9 I can use a SLF. Never used that before.
3. I go the the StandardLocationFilter wiki page. No examples, but I see the bit about 'terrain' key.
4. I check the FilterWML page. Ohhhh..an example under the subheading 'Filtering Terrains'. I try that. (First what I posted above, then [filter]&[filter_location] nested in[terrain])Doesn't work right.
4a. I'm a little confused. I used a ([filter] id=Dummy [/filter] ) in a [store_unit] tag before. Thought that [filter_location] terrain=Ch [/filter_location] would have worked similarly.
5. I review SLFWML & FilterWML, & [terrain]. I notice again the [and]. Realizing it must be there intentionally, and noting the comments under FilterWML calling [and] an extra location filter, which I find confusing for my purposes, I try the following:

Code: Select all

			[terrain]
				terrain=Cd
				[filter_location]
					[and]
						terrain=Ch
					[/and]
				[/filter_location]
			[/terrain]
6. Doesn't work. I am stumped. I think it must be another nuance of the code I'm just not getting. I post to the forums.
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: [terrain] & [filter_location]

Post by Anonymissimus »

SigurdTheDragon wrote:Is there a way to do it under 1.8 without a SLF?
You'd need to [store_locations]terrain=Ch and {FOREACH } over the resulting array while doing [terrain]x,y=$current_hex.x etc in the loop in the same way like e.g. modifying several units at once.

Thanks for that review - so you got confused whether you need to put a [filter_location] tag or not. I agree that it is confusing, the SUF suffers from the same problem because there are some situations where a [filter] tag is needed while in other situations it is not. Analogically for the SLF with its [filter_location] tag...

EDIT
I added something in the SLF's documentation so that its definition is analog to the SUF one and that it's clear that the [filter_location] tag isn't always needed...
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Post Reply