Random terrain modification

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Random terrain modification

Post by Anagkai »

So I got a macro that should randomly make one part of the map desert. Which happens - theoretically - by giving that part's coordinates to the macro shown below.

Code: Select all

#define DESERT X1 Y1 X2 Y2
	[store_locations]
		[filter_location]
			x={X1}-{X2}
			y={Y1}-{Y2}
			terrain=Ss
			[filter_adjacent_location]
				[not]
					terrain=Uu
				[/not]
			[/filter_adjacent_location]
		[/filter_location]
		variable=locs_for_desert
	[/store_locations]
	[foreach]
		array=locs_for_desert
		[do]
			[terrain]
				x,y=$this_item.x,$this_item.y
				terrain=Dd
			[/terrain]
		[/do]
	[/foreach]
	{CLEAR_VARIABLE locs_for_desert}
	[terrain]
		x={X1}-{X2}
		y={Y1}-{Y2}	
		[and]
			terrain=Gs^Fds,Gg,Gs^Fms
		[/and]
		terrain=Dd
	[/terrain]
	[terrain]
		x={X1}-{X2}
		y={Y1}-{Y2}	
		[and]
			terrain=Hh
		[/and]
		terrain=Hd
	[/terrain]
	[terrain]
		x={X1}-{X2}
		y={Y1}-{Y2}	
		[and]
			terrain=Gg^Fet
		[/and]
		terrain=Dd^Do
	[/terrain]	
#enddef
Unfortunately the macro doesn't work - it seems the first part with foreach loop will make almost the complete map desert while the rest does nothing if I remove the first part. In case I give the impression of being dumb: It's been a year, I think, that I wrote this and I have absolutely no idea how I came to write this code.

Maybe someone else can give some insight on the problem. Any help is appreciated.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)

User avatar
skeptical_troll
Posts: 440
Joined: August 31st, 2015, 11:06 pm

Re: Random terrain modification

Post by skeptical_troll »

I guess this should be moved to the WML workshop section.
Anyway, I think your problem is that you don't need the [filter_location] tag inside the [store_location], so it's taking the whole map by default. Just put the filter without tag. Once the map is all desert you don't find appropriate terrain for the replacements below.

Tad_Carlucci
Developer
Posts: 499
Joined: April 24th, 2016, 4:18 pm

Re: Random terrain modification

Post by Tad_Carlucci »

I had problems with both performance and clarity doing random snow, so did it using in-line Lua in HttT S13
I forked real life and now I'm getting merge conflicts.

gfgtdf
Developer
Posts: 1215
Joined: February 10th, 2013, 2:25 pm

Re: Random terrain modification

Post by gfgtdf »

You can use the [random_placement] wml tag , it also has an explicit option for only doing the change for a fraction of randomly chosen tiles.
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.

Anagkai
Posts: 58
Joined: February 12th, 2012, 10:05 am

Re: Random terrain modification

Post by Anagkai »

I fixed it; there were two mistakes: The first one was the one suggested by skeptical_troll, the other was that I accidentally swapped X and Y in the macro call.
My campaigns: Princess Nilwyn (available) & Home of the Undead (available)

Post Reply