How to make a map a little more fun : using randomisation.

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
Niborelf
Posts: 10
Joined: October 23rd, 2008, 2:34 pm

How to make a map a little more fun : using randomisation.

Post by Niborelf »

I want in this topic to explain how we can easily with no too knowledge in WML, make a map which change in each game.

I made theses macros for one of my project, and IMO that can be useful to a lot of map's makers.

Code: Select all

#define IF_TERRAIN X Y TERRAIN CONTENTS
    [store_locations]
        x={X}
        y={Y}
        terrain={TERRAIN}
        variable=IF_TERRAIN_temp
    [/store_locations]
 
    [if]
        [variable]
            name=IF_TERRAIN_temp.length
            not_equals=0
        [/variable]
 
        {CONTENTS}
    [/if]
 
    {CLEAR_VARIABLE IF_TERRAIN_temp}
#enddef

#define ITERATE FROM TO VAR CONTENTS
    {VARIABLE {VAR} {FROM}}

    [while]
        [variable]
            name={VAR}
            less_than_equal_to={TO}
        [/variable]

        [do]
            {CONTENTS}

            {VARIABLE_OP {VAR} add 1}
        [/do]
    [/while]
#enddef

#define TRANSFORM_RANDOM X Y TERRAIN_INIT TERRAIN_RANDOM
    {IF_TERRAIN ${X}| ${Y}| {TERRAIN_INIT} (
    [then]
      {IF_VAR done_${X}|_${Y}| not_equals yes (
      [then]
        {VARIABLE done_${X}|_${Y}| yes}
        {RANDOM {TERRAIN_RANDOM}}
        {MODIFY_TERRAIN $random ${X}| ${Y}|}
      [/then]
    )}
    [/then])}
#enddef

#define TRANSFORM_AREA X1 Y1 X2 Y2 ACTION
    {ITERATE {X1} {X2} i (
        {ITERATE {Y1} {Y2} j (
            {ACTION}
          )}
        )}
    {CLEAR_VARIABLE i}
    {CLEAR_VARIABLE j}
#enddef

#define CLEAR_DONE_AREA X1 Y1 X2 Y2
    {ITERATE {X1} {X2} i (
        {ITERATE {Y1} {Y2} j(
            {CLEAR_VARIABLE done_$i|_$j|}
          )}
        )}
    {CLEAR_VARIABLE i}
    {CLEAR_VARIABLE j}
#enddef
{IF_TERRAIN} and {ITERATE} come from the wiki.

for use they, just put in an [event] tag something than that:

Code: Select all

{TRANSFORM_AREA 10 15 35 25 ({TRANSFORM_RANDOM i j "Mm" "Mm,Mm,Hh"}
                              {TRANSFORM_RANDOM i j "Gs^Fp" "Gs^Fp,Gg"})}
{CLEAR_DONE_AREA 10 15 35 25}
Some explications: this code transform a third of the mountains tiles into hills, and a half of the forests tiles into grassland. And only in area defined by the two locations (10,15) and (35,25).


I hope this post will be useful, and my English is correct...
Attachments
The map after modifications:<br />The road is in the same place.<br />Some tiles have changed.<br />Villages have appeared.
The map after modifications:
The road is in the same place.
Some tiles have changed.
Villages have appeared.
The map before modifications
The map before modifications
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: How to make a map a little more fun : using randomisation.

Post by opensourcejunkie »

nice work! You can definitely appreciate the improvement of map quality that these bring to the table.
--OSJ
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...
User avatar
TL
Posts: 511
Joined: March 3rd, 2007, 3:02 am

Re: How to make a map a little more fun : using randomisation.

Post by TL »

Nifty! I've been using a similar process overlaid on top of the default map generator in order to produce more interesting random maps with good results, but this is a much cleaner and more extensible implementation.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to make a map a little more fun : using randomisation.

Post by zookeeper »

TL wrote:Nifty! I've been using a similar process overlaid on top of the default map generator in order to produce more interesting random maps with good results, but this is a much cleaner and more extensible implementation.
You gotta be kidding. :shock:

Code: Select all

#define RANDOMIZE_TERRAIN LOCATIONS RANDOM_TERRAINS
    [store_locations]
        {LOCATIONS}
        variable=temp
    [/store_locations]
    
    {FOREACH temp i}
        {RANDOM {RANDOM_TERRAINS}}
        
        [terrain]
            x,y=$temp[$i].x,$temp[$i].y
            terrain=$random
        [/terrain]
    {NEXT i}

    {CLEAR_VARIABLE temp}
#enddef

{RANDOMIZE_TERRAIN (
    x=10-35
    y=15-25
    terrain=Mm
) "Mm,Mm,Hh"}

{RANDOMIZE_TERRAIN (
    x=10-35
    y=15-25
    terrain=Gs^Fp
) "Gs^Fp,Gg"}
User avatar
TL
Posts: 511
Joined: March 3rd, 2007, 3:02 am

Re: How to make a map a little more fun : using randomisation.

Post by TL »

You've never seen the kind of WML I hack together at 2 AM. :P

For sake of simplicity yours is probably better, but the original version has the nice feature that you can prevent randomized terrains from getting re-randomized if you have overlapping areas and terrain shifts, which you've excised.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to make a map a little more fun : using randomisation.

Post by zookeeper »

TL wrote:You've never seen the kind of WML I hack together at 2 AM. :P

For sake of simplicity yours is probably better, but the original version has the nice feature that you can prevent randomized terrains from getting re-randomized if you have overlapping areas and terrain shifts, which you've excised.
Well, that's true. But since you can use a full SLF instead of just a rectangular range + initial terrain, I don't see why you'd need to use overlapping areas in the first place. ;)
User avatar
TL
Posts: 511
Joined: March 3rd, 2007, 3:02 am

Re: How to make a map a little more fun : using randomisation.

Post by TL »

zookeeper wrote:Well, that's true. But since you can use a full SLF instead of just a rectangular range + initial terrain, I don't see why you'd need to use overlapping areas in the first place. ;)
Maybe I'm just too sleep-deprived right now, but I don't think any amount of filter wizardry will get around this problem if you want to mix two terrain types. Say you want to take a given region (or heck, the whole map) and turn 25% of hills into grassland and 25% of hills into forest, and also turn 25% of forest into grassland and 25% of forest into hills. How exactly do you propose setting up your filters to avoid hitting some of the same hexes twice (e.g. a hill turning into forest and then back into a hill?)

Mind you, I'm not really that picky, and you can probably jigger the probabilities to compensate anyhow.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to make a map a little more fun : using randomisation.

Post by zookeeper »

TL wrote:
zookeeper wrote:Well, that's true. But since you can use a full SLF instead of just a rectangular range + initial terrain, I don't see why you'd need to use overlapping areas in the first place. ;)
Maybe I'm just too sleep-deprived right now, but I don't think any amount of filter wizardry will get around this problem if you want to mix two terrain types. Say you want to take a given region (or heck, the whole map) and turn 25% of hills into grassland and 25% of hills into forest, and also turn 25% of forest into grassland and 25% of forest into hills. How exactly do you propose setting up your filters to avoid hitting some of the same hexes twice (e.g. a hill turning into forest and then back into a hill?)

Mind you, I'm not really that picky, and you can probably jigger the probabilities to compensate anyhow.
Well, sure, you can't do such a complicated case without extra hassle. The simplest would just be to use an otherwise unused terrain as an intermediary. First change 25% of hills into, say, ice, then 25% of forest into ice, then change all ice into grassland, etc.

Anyway, if you wanted to, my macro could be extended to support something like that. All I'm saying is that the one Niborelf posted would have been an ok workaround maybe 2-3 years ago, but is really, really hideously unnecessarily complicated today. ;) I mean...urgh, IF_TERRAIN. :augh:
Niborelf
Posts: 10
Joined: October 23rd, 2008, 2:34 pm

Re: How to make a map a little more fun : using randomisation.

Post by Niborelf »

That is true than my code is not the better. My principal will is to encourage campaigns' makers to make theirs maps different in each game. In order to more fun and game difficult. People who restart a campaigns in another difficult level must adapt their strategy to the map variation which be created. Another reason to use this type of random map is to play multiplayers maps with the shroud mode.
And in the case anyone want to modify only specifics locations, not only one simple area, it is possible to create the map with any tile which is not used in this area and transform totally this tile with a random choice. This is can take longer, but not if it is used in the same time than others transformations.
And what is the problem with IF_TERRAIN? That's one of the wiki examples... I take it here...
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: How to make a map a little more fun : using randomisation.

Post by Ken_Oh »

zoo is just a WML snob. It's common knowledge here. ;)

Either way, Niborelf, I'm glad you at least brought the topic up. I'm going to using whatever comes out of it.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to make a map a little more fun : using randomisation.

Post by zookeeper »

Niborelf wrote:And what is the problem with IF_TERRAIN? That's one of the wiki examples... I take it here...
It's an ancient hack which hasn't been needed for anything for a long time now. There has been a very widely used [have_location] condition tag available in [if] for who knows how long.

Most of the wiki pages featuring macros or whatever other code (maybe with the exception of the basic tutorials) are hopelessly outdated. :|
Post Reply