looks good/helpfull@Hobbes
with the newest nightly (thx warboy) it is possible to make a random map resize depending on existing mapsize
this is what i want to explain for now
i underline the words i explain a bit more in the text so the reader can find these parts easier
it also is useful as an explanation how label, conditionals and executionChances work
i use the FARM terrain here so the rul file alone should be enough to test things
i will now explain my approach in testing mapscript and go from smaller steps to the full script at the end there is the full code if you dont want to read this stuff
i just make a new ufo-battle with farm as terrain the principle is usable for all maps
ok whats label?
https://www.ufopaedia.org/index.php?title=Ruleset_Reference_Nightly_%28OpenXcom%29#Map_Scripts says
A numeric label that can be used for conditional execution of commands. Each label should be unique within the command list (0=default no need for uniqueness).
so any command can have a label - if the command is executed successfully (at least once) this
label gets a "true" value
not yet executed or failed labels have a "false" value
so here we add a 10x10 mapblock at the position 4,4 and give the command 1005 as label
- type: addBlock
label: 1005
size: 1
rects:
- [4, 4, 1, 1]
since counting starts with 0 a block can only be placed at 4,4 if the map is at least 5x5
farm maps come in 4x4 and 5x5 version depending on ufo size
here i made a simple test for mapsize
it adds the 4,4 block; the craft and the ufo
after that we use
conditionals - type: fillArea
conditionals: [1005]
..
- type: fillArea
conditionals: [-1005]
only one of these commands will be executed
one of them (placement failed = negative labelnumber) fills the map normally
the other (placement succeded = positive labelnumber) fills the map with just one blocktype
- type: FARM
commands:
#try to add a block at 4,4 position (label 1005) = test for 5x5 map
- type: addBlock
label: 1005
size: 1
rects:
- [4, 4, 1, 1]
- type: addUFO
- type: addCraft
#test: if conditionals fit make it a 1 blocktype only map (for visual conditional tests)
- type: fillArea
blocks: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
maxUses: [300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
freqs: [300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
conditionals: [1005]
- type: fillArea
blocks: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
maxUses: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
conditionals: [-1005]
testing this you will see all medium/small scouts are in normal terrain and all bigger ufos are in a one-type-block terrain (ufo, craft and the 4,4 corner are different)
now we know 1005=true means its a 5x5 map (assuming thats the miximum size for FARM terrain)
i admit i do not know if modder can add ufos bigger than STR_BATTLESHIP and if the starting mapsize grows with it (if yes one need to accomodate for this)
so now we cant just do
addblock ...
if 1005==true: resize..
because resizing with a (partially) filled map is not allowed
so we delete the 4,4-"testblock" (FYI there was a small error in the code that was fixed in the latest nightly)
- type: addBlock
label: 1005
size: 1
rects:
- [4, 4, 1, 1]
#if sucess (1005) delete block
- type: removeBlock
rects:
- [4, 4, 1, 1]
conditionals: [1005]
now we have a empty map and can do the resizing
i keep it simple
4x4 map should have 33% chance to grow to 6x6
4x4 map should have 33% chance to grow to 5x5
4x4 map should have 33% chance to stay the same size
5x5 map should have 33% chance to grow to 7x7
5x5 map should have 33% chance to grow to 6x6
5x5 map should have 33% chance to stay the same size
short explanation to the
resize command
in most cases you just reset the x/y values but you can also resize the height (size: [6,6,8])
we give the execution a propability of 33% (
executionChances: 33) to resize the map to 7x7 if its a 5x5 map (1005==true)
also saving the result of that chance-execution into the label 1507 is important (the label 1
50
7 is arbitrary hint: -
5x
5 map resized to
7x
7)
#if 5x5 map 33% to make it 7x7 map
- type: resize
label: 1507
size: [7,7]
executionChances: 33
conditionals: [1005]
in the next step we use 2 conditionals we want to resize the map to 6x6 ONLY if it starts at 5x5 (1005==true) and the 7x7 resize failed (1507==false)
so we put two number in the
conditionals: [1005, -1507]but why using
executionChances: 50 insted of the 33% we declared above?
the commands are executed one after another so if you create 100 maps the first command will (on average) convert 33 of them into 7x7 maps
if i convert the remaining 67 maps with e 33% executionchance i get 33,22,45
with 50% chance i get 33,33,34 distribution
#if 5x5 map 33%=(100-33)*0.5 to make it 6x6 map else it is not resized
- type: resize
label: 1506
size: [6,6]
executionChances: 50
conditionals: [1005, -1507]
i do not need a command for "not resizing" if 1507 and 1506 failed
in the next steps i just repeat the same steps for the 4x4 maps but with the assumption of 4x4 (1005==false)
the full script:
- type: FARM
commands:
#try to add a block at 4,4 position (label 1005) = test for 5x5 map
- type: addBlock
label: 1005
size: 1
rects:
- [4, 4, 1, 1]
#if sucess (1005) delete block
- type: removeBlock
rects:
- [4, 4, 1, 1]
conditionals: [1005]
#if 5x5 map 33% to make it 7x7 map
- type: resize
label: 1507
size: [7,7]
executionChances: 33
conditionals: [1005]
#if 5x5 map 33%=(100-33)*0.5 to make it 6x6 map else it is not resized
- type: resize
label: 1506
size: [6,6]
executionChances: 50
conditionals: [1005, -1507]
#if NOT 5x5 map (=4x4) 33% to make it 6x6 map
- type: resize
label: 1407
size: [6,6]
executionChances: 33
conditionals: [-1005]
#if NOT 5x5 map (=4x4) 33%=(100-33)*0.5 to make it 5x5 map else it is not resized
- type: resize
label: 1406
size: [5,5]
executionChances: 50
conditionals: [-1005, -1407]
- type: addUFO
- type: addCraft
#test: if conditionals fit make it a 1 blocktype only map (for visual conditional tests)
#- type: fillArea
#blocks: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
#maxUses: [300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#freqs: [300, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#conditionals: [1005]
- type: fillArea
blocks: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
maxUses: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
#conditionals: [-1005]
another approach:
Spoiler:
while writing this i thought about another approach to this
a map should have 33% chance to grow to 6x6
a map should have 33% chance to grow to 5x5
4x4 map should have 33% chance to stay the same size
5x5 map should have 33% chance to grow to 7x7
this approach is shorter but also shows you need to test things for yourself
while this script worked fine for 4x4 map i could not get it to work for 5x5 i got ~10 times a 7x7 map with a starting 5x5 map
- type: FARM
commands:
#try to add a block at 4,4 position (label 1005) = test for 5x5 map
- type: addBlock
label: 1005
size: 1
rects:
- [4, 4, 1, 1]
#if sucess (1005) delete block
- type: removeBlock
rects:
- [4, 4, 1, 1]
conditionals: [1005]
#33% chance for 5x5
- type: resize
label: 2005
size: [5,5]
executionChances: 33
#if 5x5 resized try 6x6 map 33%=(100-33)*0.5
- type: resize
label: 2006
size: [6,6]
conditionals: [-2005]
executionChances: 50
#if its a 5x5 map (1005) and the 5/6 resize failed make it a 7x7 map else no resize (=4x4 map)
- type: resize
label: 2007
size: [7,7]
conditionals: [-2005, -2006, 1005]
i have some ideas why that is but it would need further testing