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

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
[Documentation] Mixing and Matching Terrain with MapScripts!
« on: December 03, 2016, 08:58:36 pm »
Hi Everyone!

1/ I've been working on another coding project for the OXCE+ version of the engine, and just got a new feature working: using map scripts to add map blocks from other terrains.  This allows you to do things like adding some forest to a simple farmland ufo mission, like in the screenshot I've attached.  The original intent was to start adding support for having an above-ground portion to base defense maps, but it turned into making more general tools for this purpose.  Map scripts can be given an optional command terrain:, which allows you to pull in a map block from any defined terrain. This works for addBlock, addLine, addCraft, addUFO, and fillArea.

For the example of the farm/forest hybrid map, the script looks like this:
Code: [Select]
mapScripts:
  - type: FARM
    commands:
    - type: addUFO
    - type: addCraft
    - type: addBlock
      terrain: FOREST
      size: 2
      executions: 2
    - 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]

2/ The second part of the new code is adding special 'filler' terrains for base defense missions.  In globe.rul, where terrain: is defined by geoscape texture, I've added the possibility to define baseTerrain: in the exact same way - these are to replace the nondescript dirt fill-in with whatever you want.  Maybe you want your base to be placed right next to a charming little farm?  Or have snow cover in the arctic?  The commands I described above will do this with the base squares not filled with facilities by setting the terrain: in the command to "baseTerrain" as in the script example below.  I also added an option baseDefenseMapFromLocation to seed the RNG for generating the base defense maps from the latitude and longitude of the base, so your bases won't have an overactive ground crew completely redoing the landscaping in-between every time your base is attacked.

Edit by Meridian: baseDefenseMapFromLocation seems to be mandatory, not optional, for "baseTerrain" to work

Code: [Select]
terrains:
  - name: XBASE_FILL
    mapDataSets:
      - FOREST
    mapBlocks:
      - name: XBASE_FOREST00
        width: 10
        length: 10
      - name: XBASE_FOREST01
        width: 10
        length: 10
      - name: XBASE_FOREST02
        width: 10
        length: 10
      - name: XBASE_FOREST03
        width: 10
        length: 10
      - name: XBASE_FOREST04
        width: 10
        length: 10

  - 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
      terrain: baseTerrain

globe:
  textures:
    - id: 0
      terrain:
        - name: FOREST
          area: [0, 360, -90, 0]
        - name: JUNGLE
          area: [0, 360, 0, 90]
      baseTerrain:
        - name: XBASE_FILL
    - id: 1
      terrain:
        - name: CULTA
      baseTerrain:
        - name: XBASE_FILL
#... etc, adding baseTerrain for each texture id: ...

The second attached image shows an example of this at work, though it's not as nice since I messed up making/editing the maps.

Note:  This code has been included in Yankes' OXCE and Meridian's OXCE+ executables, see their threads for source code and .exe's!
« Last Edit: January 21, 2019, 12:02:01 pm by Meridian »

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3349
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #1 on: December 04, 2016, 01:53:52 am »
It looks simple and yet powerful. When you consider this finished I will grab it to my branch.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #2 on: December 04, 2016, 05:01:13 pm »
I'll be doing some cleanup today and tomorrow, it should be ready sometime tomorrow.

Offline Hobbes

  • Commander
  • *****
  • Posts: 2102
  • Infiltration subroutine in progress
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #3 on: December 04, 2016, 07:11:00 pm »
Interesting tools :)

The funcionalities allowed by addBlockFromTerrain and fillAreaFromTerrain can be already done with the 'addUFO' command to mix terrains, but with this I think you've just made it even easier to overcome the 256 MCD entries limit of the map block files when designing terrains. But it will require terrains specifically designed to make full use of this function.

As for 'baseTerrain' I have wished for something different but with a similar objective: being able to determine Base Defense terrain depending on the globe texture, as the current nightlies allow for alien bases.

In short, there would be the vanilla Base Defense + modded terrains that could be used for base defense, depending on the base's location on the globe. Since each texture would have alienDeployments assigned to it, you could have the vanilla underground base, or a version of it with a ground level, or even a base fully on the surface.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #4 on: December 05, 2016, 05:12:45 pm »
@Yankes: Here's the branch I created from OXCE+ 3.5 that contains this code.

@Hobbes:  It wouldn't be too hard to make baseTerrain also change the facilities maps, and that's eventually my goal, but by a different method.  My next experiment is figuring out how to load one map on top of another (possible allowing for vertical maps), in particular, to allow for having a standard base defense terrain (maps by facility) and decorate them with some sparse maps overlaid on them taken from globe location.  I can take a look into having completely new terrain by globe texture too, but this is all further down the road.

Offline Hobbes

  • Commander
  • *****
  • Posts: 2102
  • Infiltration subroutine in progress
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #5 on: December 05, 2016, 05:27:26 pm »
My next experiment is figuring out how to load one map on top of another (possible allowing for vertical maps), in particular, to allow for having a standard base defense terrain (maps by facility) and decorate them with some sparse maps overlaid on them taken from globe location.

Unless you redesign the XBase terrain, or at least some map blocks of it, it will be impossible (or almost) for the ground maps to be used other than for decoration since there will be no access between the ground and underground levels. And with no access you'll need to remove all the .RMP nodes from the ground levels otherwise aliens will spawn above ground and you won't be able to reach their locations.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #6 on: December 05, 2016, 05:38:22 pm »
Aye, using all of this for base defense maps would require significant rework of the XBASE terrain, I just wanted to lay the groundwork in mapScript commands, so that modders can make use of these things.

I have plans to use this for other things (a mod with no underground facilities), but to use in vanilla, I'd add a surface level to all the XBASE maps, including making hangars open-air and making the access lift the way to get to ground level, plus nodes to encourage any accidentally-surface-spawned aliens to make their way below ground.

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3349
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #7 on: December 05, 2016, 08:05:56 pm »
@Yankes: Here's the branch I created from OXCE+ 3.5 that contains this code.
Could you squash this commits? I prefer if all required changes for some feature are in one commit, 1 commit == 1 feature. This will simplify cherry picking.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #8 on: December 05, 2016, 08:25:02 pm »
Sure, the branch has been updated with the squashed commits.

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3349
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #9 on: December 05, 2016, 08:43:10 pm »
One last request, I have txt file: https://github.com/ohartenstein23/OpenXcom/blob/3f2d577c4e95e088a948a66151e2fe454cd8543a/Extended.txt#L548
And I would like if you add description of your new functionality there. I use this file to crate documentation for mod page and my topic.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #10 on: December 05, 2016, 09:14:38 pm »
https://github.com/ohartenstein23/OpenXcom/commit/c9b3a34003d9cf0b109c841b0810fabc232f8ce9

Here's some documentation on what I added in these features.

Offline Hobbes

  • Commander
  • *****
  • Posts: 2102
  • Infiltration subroutine in progress
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #11 on: December 06, 2016, 02:58:17 am »
Aye, using all of this for base defense maps would require significant rework of the XBASE terrain, I just wanted to lay the groundwork in mapScript commands, so that modders can make use of these things.

I have plans to use this for other things (a mod with no underground facilities), but to use in vanilla, I'd add a surface level to all the XBASE maps, including making hangars open-air and making the access lift the way to get to ground level, plus nodes to encourage any accidentally-surface-spawned aliens to make their way below ground.

Well, there's already a terrain developed for UFO2000 called XBase+ that you might be interested:



It adds two extra levels and the top and adapts most XBase maps so that the aliens can have multiple entry points. The only downside of it is that it currently doesn't have any .RMP files, but it would be just a matter of adapting the vanilla ones.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #12 on: December 06, 2016, 02:54:01 pm »
Thanks Hobbes, I'll take a look at it.  That is the kind of aesthetic I have in mind as a goal for making these map script commands, but as you said earlier, with the ability to surpass the 256 MCD limit without abusing addUfo.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #13 on: December 12, 2016, 03:40:26 pm »
Hey Yankes, what would you think about rolling the terrain definition into the regular addBlock/fillBlock commands? I have some ideas for other mapscript features, and I think it might be easier to have them be options for already implemented commands than to make a new one for each feature.

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3349
    • View Profile
Re: [EXE] Mixing and Matching Terrain with MapScripts!
« Reply #14 on: December 12, 2016, 08:06:39 pm »
Hey Yankes, what would you think about rolling the terrain definition into the regular addBlock/fillBlock commands? I have some ideas for other mapscript features, and I think it might be easier to have them be options for already implemented commands than to make a new one for each feature.
One question how normal OXC will behave if encounter that command? Can this be ignored without any crash?

I checked current solution, and I see that it will crash when OXC try load your command.
It would be better if it could will be safely ignored by normal version or older OXCE.