Replacing specific terrain

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
michaelan
Posts: 30
Joined: April 21st, 2013, 6:42 pm

Replacing specific terrain

Post by michaelan »

Hello, I'm an amateur WML coder, and I'm wondering if there's a way to change a map's terrain by filtering the terrain type instead of its location. For example, let's say I'm making a scenario where I want every water hex to be replaced with an ice hex.

Code: Select all

	[event]
     name= turn 3
	 [terrain]
	  [filter]
	   [filter_location]
	    terrain=Wwg
	   [/filter_location]
	  [/filter]
	  terrain=Ai
	 [/terrain]
	[/event]
This was my attempt, but it didn't work. I'd appreciate it if someone could tell me if this is possible and give me a sample code if it is. Thanks!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Replacing specific terrain

Post by zookeeper »

Code: Select all

	[event]
     name= turn 3
	 [terrain]
	  [and]
	    terrain=Wwg
	  [/and]
	  terrain=Ai
	 [/terrain]
	[/event]
User avatar
UnwiseOwl
Posts: 516
Joined: April 9th, 2010, 4:58 am

Re: Replacing specific terrain

Post by UnwiseOwl »

Zookeeper: That always seems like strange syntax.
Why is this preferable to the old=/new= like the [terrain_mask]?
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Replacing specific terrain

Post by zookeeper »

UnwiseOwl wrote:Zookeeper: That always seems like strange syntax.
Why is this preferable to the old=/new= like the [terrain_mask]?
It wouldn't make sense. Apples and oranges.
User avatar
UnwiseOwl
Posts: 516
Joined: April 9th, 2010, 4:58 am

Re: Replacing specific terrain

Post by UnwiseOwl »

To me
[terrain]
[and]... is complete gibberish.

But I guess this is why you're the coder and I'm not :P
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Replacing specific terrain

Post by gfgtdf »

i agree that this syntax is rather strange, if we would implement [terrain] now it'd probably have a [filter_location] tag or a new_terrain= attribtue, and work similar to how michaelan though it would. The reason why is has the current syntax is that [terrain] used to only have terrain=,x=,y= attributes and no location filter support and then the x=,y= syntax was exteded with complate location filter support so the terrain= attribute clashed with the terrain= attribute in location filters.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
michaelan
Posts: 30
Joined: April 21st, 2013, 6:42 pm

Re: Replacing specific terrain

Post by michaelan »

Thanks so much for the help, Zookeeper. It worked perfectly.

The syntax for this specific code is rather unintuitive. Will this potentially be changed in the future?
Fabluiso
Posts: 1
Joined: April 29th, 2017, 4:20 pm

Re: Replacing specific terrain

Post by Fabluiso »

what if i want to store a location variable so that the terrain changes at a later point. like, lets say that i have a map with both ice and water terrain. then, i change all the water to become ice, with zookeeper's code. later, i want all the ice terrain that used to be water to go back to being water, with the original ice terrain staying the same. how do i store the original water terrain into a variable so that i can change it back later?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Replacing specific terrain

Post by zookeeper »

Fabluiso wrote:what if i want to store a location variable so that the terrain changes at a later point. like, lets say that i have a map with both ice and water terrain. then, i change all the water to become ice, with zookeeper's code. later, i want all the ice terrain that used to be water to go back to being water, with the original ice terrain staying the same. how do i store the original water terrain into a variable so that i can change it back later?
Then what you want to do is to store all the water locations for example in a prestart event like this:

Code: Select all

[store_locations]
    terrain=Wwg
    variable=water_locs
[/store_locations]
And then whenever you want to change the terrain on all of those locations at once, you just do this:

Code: Select all

[terrain]
    find_in=water_locs
    terrain=Ai
[/terrain]
Then to make sure the variables don't stay cluttering up your savefiles forever, just do {CLEAR_VARIABLE water_locs} in your victory event or whenever you don't need them anymore.
Post Reply