OpenXcom Forum

Modding => Work In Progress => Topic started by: Falko on November 20, 2014, 01:59:15 pm

Title: Mapscript Questions
Post by: Falko on November 20, 2014, 01:59:15 pm
warboy commited his mapscripts
https://openxcom.org/forum/index.php?topic=2934.msg35920#msg35920
yeah!
now some questions will appear

i start with my questions hopefully we can keep these (+answers) in one thread to make a easier documentation possible
Title: Re: Mapscript Questions
Post by: Falko on November 20, 2014, 01:59:27 pm

lets start
Code: [Select]
mapScripts:
  - type: DEFAULT # forest, mountain
    commands:
    - type: addUFO
    - type: addCraft
    - type: addBlock
      size: 2
      executions: 2
    - type: fillArea
i assume  "size: 2 " means blocks of size 20x20
but can oxc handle non quadratic blocks 10x20 or 30*20 ?
can i use "size: [2,3]" to have a fixed 20x30 block?


Code: [Select]
  - type: FARM
    commands:
    - type: addUFO
    - type: addCraft
    - 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]
i believe the blocks number corresponds with the position in the terrainlist
but do what is the number for the first entry in the list 0 or 1 ?

Code: [Select]
    - type: addLine
      label: 1
      direction: vertical
      executionChances: 50
      rects:
        - [1, 1, 4, 1]
label defines what block groups are used in this operation can i have multiple groups here ?
(if not i have to add a groups to the terrain for every operation with multiple blocktype sources)

i suppose "rects" defines where this operation takes place
since its a list you can select a bunch of possible regions
where is 1,1 ? most north, south,west or east blockposition?
is there a 0,0 position?

Code: [Select]
  - type: URBAN
    commands:
    - type: addCraft
    - type: addLine
      label: 1
      direction: vertical
      executionChances: 50
      rects:
        - [1, 1, 4, 1]
    - type: addLine
      label: 2
      conditionals: -1
      executionChances: 50
      direction: horizontal
      rects:
        - [1, 1, 1, 3]
    - type: addLine
      conditionals: [-1, -2]
ok does [-1,-2] means this:
if the last (-1) operation failed and the operation before last (-1) failed execute this operation
(with negative=failed , positive = succes )

Code: [Select]
  - type: ALIENBASE
    commands:
    - type: addBlock
      groups: 2
      executions: 2
    - type: addBlock
      size: 2
      groups: 3
    - type: addBlock
      size: 2
      executions: 3
    - type: fillArea
      groups: [0, 1]
      freqs: [3, 2]
    - type: digTunnel
      direction: both
      tunnelData:
        level: 0
        MCDReplacements:
          - type: westWall
            set: 2
            entry: 18
          - type: northWall
            set: 2
            entry: 17
          - type: corner
            set: 2
            entry: 19
          - type: floor
            set: 1
            entry: 63
...
  - type: XBASE
    commands:
    - type: digTunnel
      direction: both
      tunnelData:
        level: 0
        MCDReplacements:
          - type: westWall
            set: 1
            entry: 13
          - type: northWall
            set: 1
            entry: 14
    - type: fillArea
      blocks: 20
in xcombase you do tunnel command before you fill the map
in alienbase you make the tunnel after you fill it
is there a reason for each operation position?
why does the alienbase need more mcd changes than the xcombase?
can i define the size of the tunnel and make small tunnels between blocks  (make mansized "service-tunnel" in the upper layer of the xbase terrain)

Code: [Select]
  - type: URBAN
    commands:
    - type: addCraft
    - type: addLine
      label: 1
      direction: vertical
      executionChances: 50
      rects:
        - [1, 1, 4, 1]
    - type: addLine
      label: 2
      conditionals: -1
      executionChances: 50
      direction: horizontal
      rects:
        - [1, 1, 1, 3]
    - type: addLine
      conditionals: [-1, -2]
      direction: both
      rects:
        - [1, 1, 3, 3]
here you give group 1 and 2 as blockgroups for the vertical/horizontal streets
but there is no such definition for the "direction: both" entry
how can i define these there and how can i say crossroads comes from group 56 ?
are the default values addlines/addcraft/addufo uses?

Code: [Select]
removeBlock
checkBlock

there is no example for the removeBlock /checkBlock  command i found in the source :)


Title: Re: Mapscript Questions
Post by: Falko on November 20, 2014, 02:06:35 pm
next questions :)
Code: [Select]
      maxUses: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]is there a minUses ?
Code: [Select]
    - type: addLine
      label: 1
      direction: vertical
      executionChances: 50
      rects:
        - [1, 1, 4, 1]
i suppose the rect definition here creates the starting point for the line?

related: does this
Code: [Select]
    - type: addLine
      conditionals: [-1, -2]
      direction: both
      rects:
        - [1, 1, 3, 3]
rect define the possible "crossroad" position?
Title: Re: Mapscript Questions
Post by: robin on December 06, 2014, 05:10:35 pm
I started using it a bit.

1)
can I drop the "addCraft" part if I add a enter point map block (like the green-floored one for aliens bases)(and drop "addUFO" part too)?

2)
is there a way to add coordinates to the "addBlock" / "addCraft" / "addUFO" part? Like forcing the craft on one corner (or one random corner), the ufo on the center and so on? Maybe "rects" is used for this but I don't understand how.

3)
does "groups" replace "type" and "subtype"?
Title: Re: Mapscript Questions
Post by: Falko on December 06, 2014, 06:21:37 pm
FYI
i added the current mapblock ruleset stuff to the wiki
hobbes or warboy? reverted the cahnges and split the rulset documentation in two
the info specific for the nightly ruleset has now their own place
https://www.ufopaedia.org/index.php?title=Ruleset_Reference_Nightly_%28OpenXcom%29

1) what is "point map block" ?
if you do not have craft or ufo in a mission you dont need these commands
2) yes you can use rects
if you add this at the start of the farm script you set small ufo in one of the corner of the map (bigger UFO crash in this simple example)
Code: [Select]
  - type: FARM
    commands:
    - type: resize
      size: [6,6,6]
    - type: addUFO
      rects:
        - [0, 0, 1, 1]
        - [0, 5, 1, 6]
        - [5, 0, 6, 1]
        - [5, 5, 6, 6]
3)
yes

i currently work on a bit of documentation/examples
Title: Re: Mapscript Questions
Post by: Hobbes on December 06, 2014, 06:30:56 pm
I started using it a bit.

1)
can I drop the "addCraft" part if I add a enter point map block (like the green-floored one for aliens bases)(and drop "addUFO" part too)?

2)
is there a way to add coordinates to the "addBlock" / "addCraft" / "addUFO" part? Like forcing the craft on one corner (or one random corner), the ufo on the center and so on? Maybe "rects" is used for this but I don't understand how.

The best way to check this and other questions is simply to try it for yourself and post here the results or update the relevant wiki page to share the info with everyone. I'd like to know the answers to these and other questions myself for later use in the future.

Rects are used to define areas for placement. From what Warboy explained to me, the first two coordinates indicate a location and the next ones the length/width of the rectangle. For instance [0,0,4,5], defines a triangle starting in the top left corner and and occupying a 40x50 area. So, it would be possible to limit Skyranger/UFO deployment to predefined areas on the map.

Quote
3)
does "groups" replace "type" and "subtype"?

Yes.
Title: Re: Mapscript Questions
Post by: Hobbes on December 06, 2014, 06:48:36 pm
I'm trying to figure out about the rects on the Urban MapScript that perhaps someone could explain:

Code: [Select]
  - type: URBAN
    commands:
    - type: addCraft
    - type: addLine
      label: 1
      direction: vertical
      executionChances: 50
      rects:
        - [1, 1, 4, 1]
    - type: addLine
      label: 2
      conditionals: -1
      executionChances: 50
      direction: horizontal
      rects:
        - [1, 1, 1, 3]
    - type: addLine
      conditionals: [-1, -2]
      direction: both
      rects:
        - [1, 1, 3, 3]

Now, if I'm understanding this correctly, those rects exclude roads from ever being placed on the 0,0 corner and impose other limitations that didn't exist before. Shouldn't the rects be instead: [0,0,5,1], [0,0,1,5] and [0,0,5,5]?
Title: Re: Mapscript Questions
Post by: Falko on December 06, 2014, 06:57:26 pm
to my understanding
[0,0,5,1]/[0,0,1,5] would allow roads to be at the edge of the map
i do not remember if that was possible in original if yes these number need a change
similar [1, 1, 3, 3] defines the place where the roads can cross so changing them into [0,0,5,5] would also allow roads at the edges
Title: Re: Mapscript Questions
Post by: Hobbes on December 06, 2014, 07:04:05 pm
to my understanding
[0,0,5,1]/[0,0,1,5] would allow roads to be at the edge of the map
i do not remember if that was possible in original if yes these number need a change
similar [1, 1, 3, 3] defines the place where the roads can cross so changing them into [0,0,5,5] would also allow roads at the edges

It's quite possible to have roads at all edges on the original game:
 https://www.youtube.com/watch?v=qqn2qLQ5nq0 (https://www.youtube.com/watch?v=qqn2qLQ5nq0)
https://www.youtube.com/watch?v=A4-YnBYgNaI (https://www.youtube.com/watch?v=A4-YnBYgNaI)
https://www.youtube.com/watch?v=qc1VOfhPdls (https://www.youtube.com/watch?v=qc1VOfhPdls)
Title: Re: Mapscript Questions
Post by: robin on December 06, 2014, 09:14:16 pm
FYI
i added the current mapblock ruleset stuff to the wiki
hobbes or warboy? reverted the cahnges and split the rulset documentation in two
the info specific for the nightly ruleset has now their own place
https://www.ufopaedia.org/index.php?title=Ruleset_Reference_Nightly_%28OpenXcom%29
yay for nightly reference!

1) what is "point map block" ?
By "enter point map block" (sorry for poor terminology) I mean a map block with MCDs on which you soldier can spawn, like the alien base map block I attached below.

AFAIK now the only way to do custom missions is by modifying ufos, so the ufo and the craft are going to be present in the battlescape by default. I'd like to know if it is possible, using map scripting, to remove both ufo and craft (replacing the craft with a map block with "spawning ability" like the one below, and the ufo with a map block like the alien base's Control Center, or even no specific map block at all).


The best way to check this and other questions is simply to try it for yourself.
This is what I wanted to do today; but my ruleset was making the game crash so I spent my day fixing it :'(
Title: Re: Mapscript Questions
Post by: Falko on December 06, 2014, 09:55:43 pm
i removed the - type: addUFO from the farmscript and there was no ufo anymore
but also less aliens then there should be i think they are in the ufo and therefore not placed
just removing addcraft failed because i had no farm-terrain-"enter point map block" available
Title: Re: Mapscript Questions
Post by: Hobbes on December 07, 2014, 12:54:22 am
It is possible to remove the Skyranger. I created a map called CULTA99 with only XCOM spawn points, assigned it to group 5 and then removed the addCraft line and instead added:
Code: [Select]
    - type: addBlock
      groups: 5
      executions: 2

You can see the end result in attachment
Title: Re: Mapscript Questions
Post by: robin on December 07, 2014, 03:16:29 am
This is amazing!
Title: Re: Mapscript Questions
Post by: bladum on December 07, 2014, 12:10:46 pm
aliens attacks village ? x-com village defense ?
Title: Re: Mapscript Questions
Post by: Hobbes on December 07, 2014, 04:57:50 pm
to my understanding
[0,0,5,1]/[0,0,1,5] would allow roads to be at the edge of the map
i do not remember if that was possible in original if yes these number need a change
similar [1, 1, 3, 3] defines the place where the roads can cross so changing them into [0,0,5,5] would also allow roads at the edges

It is possible at the original. I've just tested it with the UFO Defense Gold Edition with the debug mode enabled (allows for visualization of the entire map at the beginning of the mission) and single roads can be placed on all map edges (check attached pics).

I haven't been able yet to see all possible combinations of crossroads being placed at edges though.

EDIT: I've run about 100 tests with the original game. The only setup I haven't seen yet is a crossroad with one of the roads placed on the top left edge. I'll test a bit more to increase the sample size but I'm starting to think that's the only limitation set into the roads at map edges.
Title: Re: Mapscript Questions
Post by: Hobbes on December 08, 2014, 04:40:42 pm
Falko,

Do you think this would be useful to explain the coordinates on the rects?
Title: Re: Mapscript Questions
Post by: Falko on December 10, 2014, 06:52:33 pm
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
Quote
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
Code: [Select]
      - 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
Code: [Select]
      - 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
Code: [Select]
  - 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)

Code: [Select]
      - 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 1507 is arbitrary hint: - 5x5 map resized to 7x7)
Code: [Select]
      #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
Code: [Select]
      #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:

Code: [Select]
  - 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:
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

Code: [Select]
  - 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
Title: Re: Mapscript Questions
Post by: robin on December 25, 2014, 01:29:33 pm
This is my script for the Temple of Sirius maps:

mapScripts:
  - type: TEMPLE
    commands:
    - type: addBlock
      groups: 2
    - type: addBlock
      #..and so on..#

It seems though that that first command, adding the mapblock where xcom agents spawn, sometimes fails/doesn't get executed.
(I then get the error "Can't place xcom unit on map"-or-something, and the game closes up).

this is the mapblock in question:

      - name: CBASE_05
        width: 10
        length: 20
        groups: 2
        revealedFloors: 1


Why it fails, and how can I make  it "not fail ever", since that mapblock is needed?

Title: Re: Mapscript Questions
Post by: Falko on December 25, 2014, 03:48:51 pm
without the map failes or even the full script my geuss would be that this first command does not work
do this
make two different 10x10 blocks with group 3 and 4
use this script 
Code: [Select]
    - type: addBlock
      groups: 2
      label: 1005
      #- type: addUFO
      #- type: addCraft
      #test: if conditionals fit make it a 1 blocktype only map (for visual conditional tests)
      - type: fillArea
        groups: 3
        conditionals: [1005]
      - type: fillArea
        groups: 4
        conditionals: [-1005]
in theory it should alway give a map filled with group3 blocks + one group 2 block
if that always crashes the first command is never executed
next try would be to define the blocksize because width != length
Code: [Select]
    - type: addBlock
      groups: 2
      size: [1, 2] #or [2,1] ?
Title: Re: Mapscript Questions
Post by: robin on December 25, 2014, 04:21:24 pm
Sometimes it works, sometimes it doesn't. I just want it to work all the time.
I'll try with the "size" thing.
Title: Re: Mapscript Questions
Post by: Hobbes on December 25, 2014, 07:26:50 pm
this is the mapblock in question:

      - name: CBASE_05
        width: 10
        length: 20
        groups: 2
        revealedFloors: 1

Why it fails, and how can I make  it "not fail ever", since that mapblock is needed?

The issue might be the rectangular size of the map block. If you're not using rects to define the area on which CBASE_05 can be placed, then you risk that the game will randomly select a location for placement close to one edge of the map where the map block won't fit, and thus it will not be placed, causing the error.
Title: Re: Mapscript Questions
Post by: robin on December 25, 2014, 09:27:08 pm
The issue might be the rectangular size of the map block. If you're not using rects to define the area on which CBASE_05 can be placed, then you risk that the game will randomly select a location for placement close to one edge of the map where the map block won't fit, and thus it will not be placed, causing the error.
The original version of the script actually used rects, but it still failed. So I removed them to be sure the deal wasn't about them. Anyway, I still have to tray Falko's "size" suggestion, will post the results.
Title: Re: Mapscript Questions
Post by: robin on January 01, 2015, 09:54:17 pm
Code: [Select]
    - 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]
i believe the blocks number corresponds with the position in the terrainlist
but do what is the number for the first entry in the list 0 or 1 ?
After some testing I believe the first number for "blocks" list is 0.
Title: Re: Mapscript Questions
Post by: Warboy1982 on January 21, 2015, 10:53:01 pm
The issue might be the rectangular size of the map block. If you're not using rects to define the area on which CBASE_05 can be placed, then you risk that the game will randomly select a location for placement close to one edge of the map where the map block won't fit, and thus it will not be placed, causing the error.

you sure? i thought i accounted for that?
Title: Re: Mapscript Questions
Post by: robin on January 21, 2015, 10:55:29 pm
Sometimes it works, sometimes it doesn't. I just want it to work all the time.
I'll try with the "size" thing.

Right now the script is like this:
  - type: TEMPLE
    commands:
    - type: addBlock
      groups: 2
      size: [1, 2]
      rects:
        - [0, 0, 1, 2]
        - [4, 0, 1, 2]
        - [0, 1, 1, 2]
        - [4, 1, 1, 2]
        - [0, 2, 1, 2]
        - [4, 2, 1, 2]
        - [0, 3, 1, 2]
        - [4, 3, 1, 2]
    - type: fillArea
      size: 2
      blocks: [0, 1, 2, 3, 4, 6, 9]
      maxUses: [1, 1, 1, 1, 1, 1, 1]
    - type: fillArea
      groups: 0
    - type: digTunnel
      direction: both
      tunnelData:
        level: 1
        MCDReplacements:
          - type: corner
            set: 1
            entry: 37
          - type: westWall
            set: 1
            entry: 32
          - type: northWall
            set: 1
            entry: 31
          - type: floor
            set: 1
            entry: 73

maps size is 50x50.

I think that changing "size: 2" to "size: [1, 2]" (see bolded part), did the trick.
Title: Re: Mapscript Questions
Post by: Hobbes on January 21, 2015, 11:35:14 pm
      rects:
        - [0, 0, 1, 2]
        - [4, 0, 1, 2]
        - [0, 1, 1, 2]
        - [4, 1, 1, 2]
        - [0, 2, 1, 2]
        - [4, 2, 1, 2]
        - [0, 3, 1, 2]
        - [4, 3, 1, 2]

This might be unnecessary, unless you want the 1x2 map to be specifically generated at those corners.
Title: Re: Mapscript Questions
Post by: Falko on January 21, 2015, 11:52:50 pm
during my first look at the temple script robin posted
i stumbled on
Code: [Select]
      rects:
        - [0, 0, 1, 2]
        - [4, 0, 1, 2]
        - [0, 1, 1, 2]
        - [4, 1, 1, 2]
        - [0, 2, 1, 2]
        - [4, 2, 1, 2]
        - [0, 3, 1, 2]
        - [4, 3, 1, 2]
i had a short discussion with robin/warboy in irc and try to use this script as an example how "rects" works
the temple map is a 50x50 map
Code: [Select]
xxxxx
xxxxx
xxxxx
xxxxx
xxxxx
robin has a non quadratic mapblock (size: [1, 2]) he wants to place it on the edge of the map
i will reorder the rects here
Code: [Select]
      rects:
        - [0, 0, 1, 2]#A
        - [0, 1, 1, 2]#B
        - [0, 2, 1, 2]#C
        - [0, 3, 1, 2]#D
        - [4, 0, 1, 2]#E
        - [4, 1, 1, 2]#F
        - [4, 2, 1, 2]#G
        - [4, 3, 1, 2]#H
here two "maps" with the possible positions
Code: [Select]
AxxxE
AxxxE
CxxxG
CxxxG
xxxxx
Code: [Select]
xxxxx
BxxxF
BxxxF
DxxxH
DxxxH

the temple has 8 positions
and the rectlist with these 8 position works fine that way
but one can make it shorter
Code: [Select]
      rects:
        - [0, 0, 1, 5]#M
        - [4, 0, 1, 5]#N
the rects declares these ranges within the map
Code: [Select]
MxxxN
MxxxN
MxxxN
MxxxN
MxxxN

during the execution the script chooses at random one position within the rects where the block fits

hopefully my rambling did not lead to more confusion
Title: Re: Mapscript Questions
Post by: Warboy1982 on January 22, 2015, 01:02:33 am
your ramblings are correct, Falko.
i'd also like to point out that overlaps don't increase the likelihood of any position being picked.

so for example:
Code: [Select]
[0,0,4,4] A
[1,1,4,4] B

gives us:
Code: [Select]
AAAAx        xxxxx
AAAAx        xBBBB
AAAAx        xBBBB
AAAAx        xBBBB
xxxxx        xBBBB

which produces an overlap, C:
Code: [Select]
AAAAx
ACCCB
ACCCB
ACCCB
xBBBB

all positions marked A,B or C in the above example are equally likely
Title: Re: Mapscript Questions
Post by: robin on February 06, 2015, 02:44:09 pm
Provided I understood correctly, Warboy said to me that the mapscript indicated in the alienDeployment (by the "script" entry)  is superseded by the one found in the terrain definition, the script in the deployments is intended to be a fallback if no scritp is defined in the terrain definition.

But then the alienDeployment itself dictates the size of the map, thus potentially making mapscipts defined in the terrains, inadequate.

I understand the terrains should bring their mapscripts from their definitions, so that multiple of them can be assigned to the same alienDeployments, each using its own rules to make the map.
But then again how would you deal with the fact that the terrain you want to use has a "wrong" script fro the map size of the Deployment? Make a clone terrain with a script tweaked for the size requested?
Title: Re: Mapscript Questions
Post by: Hobbes on February 06, 2015, 04:28:14 pm
But then the alienDeployment itself dictates the size of the map, thus potentially making mapscipts defined in the terrains, inadequate.

There's a certain hierarchy involved:
* alienMissions define for each UFO listed its alienDeployment and ufo map.
* alienDeployments define the aliens present in the alienMission and their weapons, and set the battlescape size and define the number of civilians present. They can also be used to set the terrain type, if you want it to override the one assigned to the Geoscape texture
* terrains are used to define their Geoscape textures, MapDataSets, Mapblocks and civilian types used.
* Mapscripts are used to build the battlescape from the rules contained within.
* crafts/ufos define the mapDataSets and mapblocks used to place craft/UFOs - but this is only used if the mapscript has rules for placing them.

I haven't tried using the terrains to define the size of the map but to me it makes no sense to define it there since it will prevent the size of the battlescape to be dependent on any UFO placed. If Forest is set for 40x40 on terrains but it places a Battleship there then there won't be much space left.

Quote
I understand the terrains should bring their mapscripts from their definitions, so that multiple of them can be assigned to the same alienDeployments, each using its own rules to make the map.
But then again how would you deal with the fact that the terrain you want to use has a "wrong" script fro the map size of the Deployment? Make a clone terrain with a script tweaked for the size requested?

I'm currently using cloned terrains because some missions have UFOs assigned but I don't want them to be generated in the battlescape. But to have separate map sizes I'd do it through cloned alienDeployments, since you can adjust the number of aliens to the size. But this depends on what type of alienMission you're trying to design, because you'll need to use alienMission for those cloned deployments to run.

Cloning terrains brings the question of how to get the program to use them: you can assign them to specific textures, but you can't yet have multiple terrains assigned to a texture; you can also call them through alienDeployments, setting several random terrains, each with its determined size, and not having any size definitions on the alienDeployment entry (the wiki says that length/width/height isn't required for alienDeployments so it should work). 

The issue here is also designing the scripts to allow them to be used in different map sizes (which eliminates the need for cloned terrains) but the rules aren't too friendly on that matter. Placement of specific map blocks on the top right/left usually works without a problem on any battlescape size, but there will be issues if you need to place specific mapblocks on the bottom left/right.
Title: Re: Mapscript Questions
Post by: robin on February 06, 2015, 04:43:47 pm
The issue here is also designing the scripts to allow them to be used in different map sizes (which eliminates the need for cloned terrains) but the rules aren't too friendly on that matter. Placement of specific map blocks on the top right/left usually works without a problem on any battlescape size, but there will be issues if you need to place specific mapblocks on the bottom left/right.
This is my "issue". I'm not setting map size in the script/terrain, but I'm placing down blocks which, if the maps size changes, are not where they're supposed to be anymore :P. It's not a big deal cloning the terrain, I was just wondering if there was a more elegant solution.
Title: Re: Mapscript Questions
Post by: Hobbes on February 06, 2015, 05:34:57 pm
This is my "issue". I'm not setting map size in the script/terrain, but I'm placing down blocks which, if the maps size changes, are not where they're supposed to be anymore :P. It's not a big deal cloning the terrain, I was just wondering if there was a more elegant solution.

Yeah, I've run into this issue as well while adding the original Port terrain - map size needs to be 50x50, otherwise the waterfront won't be correctly placed. It may be possible to overcome this using conditionals though:
    - type: addBlock
      rects:
        - [5, 0, 1, 6]
      executions: 6
      label: 1
    - type: addBlock
      rects:
        - [4, 0, 1, 5]
      executions: 5
      conditionals: -1
     
The 1st command tries to place the waterfront on a 60x60 map. If it fails then it the 2nd command is run, to place the waterfront in a 50x50 map. Haven't tried this but theoretically it should work.
Title: Re: Mapscript Questions
Post by: robin on February 06, 2015, 06:01:11 pm
Yeah I guess the solution is an complex script with lost of conditionals.
For now I'm duplicating the terrain :-[