aliens

Author Topic: [Documentation] Mixing and Matching Terrain with MapScripts!  (Read 21002 times)

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #15 on: December 12, 2016, 08:10:37 pm »
Yes, I plan on having default handling that would make it ignore the terrain: definition for normal maps or bad definitions.

Did the log print a message like "Map generator encountered an error: invalid terrain for adding block from alternate terrain." for the crash?  I put in that error when the command is given the name of a terrain that doesn't exist, or doesn't load a terrain... I think I'll have it load the normal terrain when none is defined.

Edit:  How did you use the command?  Would you mind posting the ruleset you used to try it?

More edit:  For moving the alternate terrain handling into addBlock/fillArea, I would have the code check if there's a valid definition of "terrain:" in the command, and load the map from that if there is.  If there is no definition, or you put "terrain: default" in the ruleset, it pulls the map blocks from the same terrain as the rest of the map.
« Last Edit: December 12, 2016, 08:17:11 pm by ohartenstein23 »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #16 on: December 12, 2016, 08:46:01 pm »
Yes, I plan on having default handling that would make it ignore the terrain: definition for normal maps or bad definitions.

Did the log print a message like "Map generator encountered an error: invalid terrain for adding block from alternate terrain." for the crash?  I put in that error when the command is given the name of a terrain that doesn't exist, or doesn't load a terrain... I think I'll have it load the normal terrain when none is defined.

Edit:  How did you use the command?  Would you mind posting the ruleset you used to try it?

More edit:  For moving the alternate terrain handling into addBlock/fillArea, I would have the code check if there's a valid definition of "terrain:" in the command, and load the map from that if there is.  If there is no definition, or you put "terrain: default" in the ruleset, it pulls the map blocks from the same terrain as the rest of the map.
Other way around, I not ask you to handle default values or invalid data but to define new rulesets in way that OXC will still run. Of corse it not possible to always do this, but at least most typical cases should work.

Exception that stop loading of ruleses is "crash" because you can run game after that.

In case of your `addBlock`. If you add new property inside command then OXC will ignore if it have unique name. Consider something like that:
Code: [Select]
mapScripts:
  - type: CULTA
    commands:
      - #normal commands
    commandsTerrain:
      FOREST:
        - #commands for forest tileset
      DESERT:
        - #commands for desert tileset
When OXC loads this it will ignore `commandsTerrain` and use rest as if it was normal map script.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #17 on: December 12, 2016, 08:52:53 pm »
I'm not sure exactly what you mean.  Do you mean writing the rulesets such that loading a script with the new features into an older version just ignores the new stuff?  My idea is this:
Code: [Select]
mapScripts:
  - type: CULTA
    commands:
    - type: addBlock # this one is loaded normally
    - type: addBlock
      terrain: FOREST # adds a block from FOREST terrain when loaded by OXCE, otherwise it is ignored by OXC

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #18 on: December 12, 2016, 09:47:41 pm »
Yes, this is goal. Your example follow this too but there is danger that in this one command is big dependency between `terrain` and rest of values in it.
I do not do lot of stuff in map script to say how serve it will be, maybe small glitches or game simply refuse to load? I would like to avoid latter.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #19 on: December 12, 2016, 09:57:28 pm »
Without the terrain: in my (hypothetical) version of addBlock, it will simply load a map block from the regular terrain.  The addBlock command also isn't critical if it fails to place a map block, it simply moves to the next command in the list.  It won't cause a crash on map generation if terrain: is lacking, if that's what you're getting at.  It also shouldn't cause a glitched-out map, unless the ruleset for the extended version of the script you're writing heavily relies on the new commands, in which case it shouldn't be run in OXC in the first place.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #20 on: December 12, 2016, 10:35:58 pm »
It also shouldn't cause a glitched-out map, unless the ruleset for the extended version of the script you're writing heavily relies on the new commands, in which case it shouldn't be run in OXC in the first place.
Some thing like thins is acceptable, as you can't make omelettes without breaking some eggs :)

I think you could recreate your commit as you probably change how it work.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #21 on: December 19, 2016, 05:43:14 pm »
I've reworked the map script commands to now include terrain: as an option for addBlock, addLine, addCraft, addUFO, and fillArea, rather than having separate commands.  See my first post for a link to the new windows executable and a link to my GitHub branch for this edit.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #22 on: December 22, 2016, 02:49:19 pm »
I've reworked the map script commands to now include terrain: as an option for addBlock, addLine, addCraft, addUFO, and fillArea, rather than having separate commands.  See my first post for a link to the new windows executable and a link to my GitHub branch for this edit.
I find some merge bug in your last commit:
https://github.com/ohartenstein23/OpenXcom/commit/02143e9983e3803726ba761b5f584da4339f3235#diff-8817a4e728e82fd5808cc76936f5488eR3372
this probably should not be included in there.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #23 on: December 22, 2016, 03:02:42 pm »
Oh, yeah.  I took that out of my working version to prevent merge bugs, but then I did a rebase and forgot that was part of the commit. I'll fix it in a bit.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #24 on: December 22, 2016, 03:34:39 pm »
« Last Edit: December 22, 2016, 03:37:24 pm by Yankes »

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #25 on: December 22, 2016, 04:08:06 pm »
Oh, I didn't realize I deleted that break, I'll be adding it back in.  Thanks for checking it over!

The previous line doesn't cause a bug, I just changed to my local variable terrain which is what allows for the alternate terrain loading, it's equal to _terrain if you don't define an alternate in the ruleset.

Edit: Okay, fixed, amended to the commit, and pushed to GitHub: https://github.com/ohartenstein23/OpenXcom/commit/429382220bae8cab466ee5c1f9b62a9d996f5324

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #26 on: December 22, 2016, 07:55:48 pm »
Oh, I didn't realize I deleted that break, I'll be adding it back in.  Thanks for checking it over!

The previous line doesn't cause a bug, I just changed to my local variable terrain which is what allows for the alternate terrain loading, it's equal to _terrain if you don't define an alternate in the ruleset.
I maybe state is incorrectly, I was referring to `!unit->isOut() &&` in my question.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #27 on: December 22, 2016, 08:10:53 pm »
Oh sorry, that bug.  That was the 2x2 unit death bug that you fixed a few days back.

Offline davide

  • Commander
  • *****
  • Posts: 565
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #28 on: December 23, 2016, 11:56:48 pm »
+100

Your efforts could revive and enhance the openxcom modding scene breaking the MCD limits

Thank you very much


Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #29 on: January 30, 2017, 04:28:28 pm »
This code has now been included in both Yankes' OXCE and Meridian's OXCE+! Thanks guys!