aliens

Author Topic: more advanced map scripting (for vanilla)  (Read 5785 times)

Offline bladum

  • Colonel
  • ****
  • Posts: 213
  • Bladum
    • View Profile
more advanced map scripting (for vanilla)
« on: December 15, 2014, 04:21:03 pm »
Hi,

Idea is simple

Change this

Code: [Select]
  - name: JUNGLE
    textures: [6]
    script: JUNGLE
    mapDataSets:
      - BLANKS
      - JUNGLE

Into this
Code: [Select]
  - name: JUNGLE
    textures: [6]
    script:
      - JUNGLE01
      - JUNGLE02
      - JUNGLE03
    mapDataSets:
      - BLANKS
      - JUNGLE

Game would pick one of scripts from the list, instead of one. For more variety of randomly generated maps even for vanilla.

Tom

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #1 on: December 15, 2014, 04:32:31 pm »
you can basically already do this using labels and conditionals

Offline bladum

  • Colonel
  • ****
  • Posts: 213
  • Bladum
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #2 on: December 15, 2014, 07:13:40 pm »
thanks, but could you show simple example how to do it ?

Offline Falko

  • Commander
  • *****
  • Posts: 802
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #3 on: December 15, 2014, 07:28:47 pm »
Code: [Select]
      - type: addBlock
        label: 2001
        size: 1
        rects:
          - [0, 0, 1, 1]
        executionChances: 33
      - type: addBlock
        label: 2002
        size: 1
        rects:
          - [0, 0, 1, 1]
        executionChances: 33
        conditionals: [-2001]
      - type: addBlock
        label: 2003
        size: 1
        rects:
          - [0, 0, 1, 1]
        conditionals: [-2001, -2002]
      - type: removeBlock
        rects:
          - [0, 0, 1, 1]
###2001=true => script1 2002=true=>script2 2003=true =>script3
#just put         conditionals: [2001,..] to each script one block


Offline bladum

  • Colonel
  • ****
  • Posts: 213
  • Bladum
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #4 on: December 17, 2014, 01:23:42 pm »
Thanks Falko, but this is quite complex to implement for a modder.

Having set of few scripts for game to pick one randomly with default value of single script is much more generic one. This is already implemented in several other places like civilianUnits for example.

Tom

Offline Firestorm

  • Sergeant
  • **
  • Posts: 19
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #5 on: December 21, 2014, 03:16:04 am »
Okay I keep looking at how these scripts are being coded, and maybe I don't know enough about the underlying code, but I keep getting a nagging in the back of my brain that they're not being coded correctly.  So someone check my math and explain to me the errors?

Trying to run 1 of 3 scripts.
The example above says:

33% chance of running script 1.
If that script is not run, 33% chance of running script 2.
If neither script runs, 100% chance of running script 3.

Now, if script 1 fails, script 2's probability of running is independent of script 1's chance, so it's only given a 33% TIMES 33% chance of running, or 1/6 chance, because the first test has no impact on the second.
The remainder of the time, of course, the final script runs.

Shouldn't it look more like this?

33% chance of running script 1
if script 1 fails, 50% of REMAINING probability of running script 2.
Otherwise, run script 3.

Or is my math and/or understanding of the code faulty?

Offline Hobbes

  • Commander
  • *****
  • Posts: 2102
  • Infiltration subroutine in progress
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #6 on: December 21, 2014, 03:51:17 am »
33% chance of running script 1.
If that script is not run, 33% chance of running script 2.
If neither script runs, 100% chance of running script 3.

Now, if script 1 fails, script 2's probability of running is independent of script 1's chance, so it's only given a 33% TIMES 33% chance of running, or 1/6 chance, because the first test has no impact on the second.
The remainder of the time, of course, the final script runs.

Shouldn't it look more like this?

33% chance of running script 1
if script 1 fails, 50% of REMAINING probability of running script 2.
Otherwise, run script 3.

Or is my math and/or understanding of the code faulty?

Yes, the issue is that statistically the odds are not independent from one another. As it is, 1st script has 33% of being run, but 2nd strip has only 22% actual chance of being run (33% of 66%) and script 3 has 44%.

Offline Firestorm

  • Sergeant
  • **
  • Posts: 19
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #7 on: December 21, 2014, 03:58:33 am »
LOL Oh yeah.  I guess my math is wrong even when it's right  :-\

Offline Falko

  • Commander
  • *****
  • Posts: 802
    • View Profile
Re: more advanced map scripting (for vanilla)
« Reply #8 on: December 21, 2014, 08:35:17 am »
yeah that was sloppy copy pasting on my part :(
as i explained in my wall of text regareding map resize here
https://openxcom.org/forum/index.php/topic,3138.msg36694.html#msg36694
...
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...