Author Topic: [EXE] Geoscape Generator  (Read 6989 times)

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
[EXE] Geoscape Generator
« on: January 22, 2018, 04:01:44 am »
Hi Everyone! I've been working on a new coding project that would allow for the generation of a completely new geoscape with just a few clicks!  It's in an alpha state right now, so it only can generate a new look for the globe, not also a corresponding set of regions, countries, cities, etc. - those things will come with time.

The globe is generated in a method similar to the fractal world generator at http://donjon.bin.sh/, creating a series of polygons and giving them a texture according to their altitude; the generated globe ruleset file is saved in user/xcom1/geoscapeGeneratorOutput.yml, and can be used directly in a mod if renamed to .rul.  If you'd like to try out the code, the source is available at my GitHub page, or I've attached a .zip file with a self-contained installation of the executable for Windows or Ubuntu 16.04.  To install from the archive attached here, unzip it somewhere on your computer, copy the files from the original X-Com into the UFO folder, and then run the executable that applies for your OS.

I'm also looking for some help with this project, as there are a couple issues that I only have half-formed ideas how to solve:
  • Some of the polygons around the 0/360 longitude line do not have their vertices ordered properly on output, so they look like a series of triangular lakes.
  • Having enough polygons to make a decent looking globe often causes to game to slow down; I'm looking for a way to optimize the number of polygons by combining those that share a texture in contiguous areas without sacrificing the detail along borders between textures.
  • I need tectonic and climate models to flesh our how textures are assigned - right now they're assigned by altitude and proximity to poles, but this doesn't work well for making deserts, mountain ranges, archipelagos, fertile regions, etc.
  • Defining continents, countries, and cities, with proper borders - I have a few plans for how to do this, but it will take some time.
  • Interfaces and designing an editor for globe rulesets. More of a stretch goal, but I think it'd be really cool if it was possible to edit the globe in-game, either just tweaking Earth or doing more complicated things with a generated world.

And now for some examples of globes I've generated using this code!
« Last Edit: January 22, 2018, 04:32:50 am by ohartenstein23 »

Hyper2Snyper

  • Guest
Re: [EXE] Geoscape Generator
« Reply #1 on: January 22, 2018, 05:11:50 am »
cool. is there a way to make the water transperant?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #2 on: January 22, 2018, 05:16:59 am »
cool. is there a way to make the water transperant?

Not through this code, and such an engine edit is beyond the scope of what I'm doing here; it has nothing with the generation of the geoscape, and is all on the rendering side of things.  You might get away with something like covering large swaths of the globe in a transparent texture (editing TEXTURE.DAT), or it might need a change in how the world is rendered.

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1510
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #3 on: January 22, 2018, 07:31:42 am »
This is amazing! It's too bad the modding community didn't have access to this tool sooner! Still, I'll be interested to see if it injects a bit of activity into this community! I really hope you continue developing this tool!

Online bulletdesigner

  • Commander
  • *****
  • Posts: 676
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #4 on: January 22, 2018, 04:33:13 pm »
WOW like reaver said is really amazing! this should been a deluxe feature in vanilla that randomly generates a new globe on a new game!

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11408
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [EXE] Geoscape Generator
« Reply #5 on: January 22, 2018, 04:49:13 pm »
Or we could even have many planets in one campaign, to travel between. ;)

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #6 on: January 22, 2018, 05:16:51 pm »
This is amazing! It's too bad the modding community didn't have access to this tool sooner! Still, I'll be interested to see if it injects a bit of activity into this community! I really hope you continue developing this tool!

Glad you like it! And yes, I do plan on slowly continuing development on it.

WOW like reaver said is really amazing! this should been a deluxe feature in vanilla that randomly generates a new globe on a new game!

The new Earth on new game is the main goal here, I'll do my best to make it possible to just push a button for a completely new world for vanilla UFO/maybe TFTD.

Or we could even have many planets in one campaign, to travel between. ;)

Far future stretch goal. Would probably be possible with clever save editing before then...

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #7 on: January 22, 2018, 09:33:12 pm »
Some of the polygons around the 0/360 longitude line do not have their vertices ordered properly on output, so they look like a series of triangular lakes.
Why not simply detect this and "flip" this triangle? All triangles lay in [0, 360] even if it should cross border, it probably need different vertex order to work correctly.
Another possible solution is prevent triangles to pass 0/360 longitude, if one cross it it should be split in half in two parts that do not cross it.

Having enough polygons to make a decent looking globe often causes to game to slow down; I'm looking for a way to optimize the number of polygons by combining those that share a texture in contiguous areas without sacrificing the detail along borders between textures.
Probably another solution would be change how texturing work, first apply only flat colors (SDL will probably do it faster that with textures) and then in second pass use textures. This could work in similar way as current poor man dithering work on globe (it could fetch texture pixel before applying shade).

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #8 on: January 22, 2018, 09:44:24 pm »
Why not simply detect this and "flip" this triangle? All triangles lay in [0, 360] even if it should cross border, it probably need different vertex order to work correctly.
Another possible solution is prevent triangles to pass 0/360 longitude, if one cross it it should be split in half in two parts that do not cross it.

I've got a function that detects which triangles fall across this line, the problem is that the sorting of the vertices doesn't produce a correct result here.  It might be simpler to use your second idea - I create the polygons by intersecting random great circles on the globe, I could just add one that falls exactly on this line, which would prevent the problem from occurring.

Probably another solution would be change how texturing work, first apply only flat colors (SDL will probably do it faster that with textures) and then in second pass use textures. This could work in similar way as current poor man dithering work on globe (it could fetch texture pixel before applying shade).

Sure, it would be nice if the globe drawing functions were optimized for higher polygon counts, but I'd like to have something that runs well on our current engine first.

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #9 on: January 22, 2018, 09:55:57 pm »
I've got a function that detects which triangles fall across this line, the problem is that the sorting of the vertices doesn't produce a correct result here.  It might be simpler to use your second idea - I create the polygons by intersecting random great circles on the globe, I could just add one that falls exactly on this line, which would prevent the problem from occurring.
How you sort them? In same order as others? It probably should be in other way around.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #10 on: January 22, 2018, 10:03:22 pm »
How you sort them? In same order as others? It probably should be in other way around.

Here's the sort function I wrote; it orders the points in the polygon clockwise around their center in the (lon, lat) plane.  If the polygon crosses that line, then I add 360 degrees to any point that lies in the region from 0-90 degrees, and subtract 360 again once the points have been sorted.

Edit: Huh, I don't sort the polygons after I split n > 3 sections into triangles.  Maybe that's the issue.
« Last Edit: January 22, 2018, 10:08:14 pm by ohartenstein23 »

Offline clownagent

  • Colonel
  • ****
  • Posts: 380
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #11 on: February 04, 2018, 04:30:29 pm »
This looks very nice!

One thing I noticed some time ago when I modified the globe is that overlapping polygons might be a problem.
(not sure if they are overlapping in this script, but it might be relevant for this):

If two or more polygons are overlapping you can naturally only see the last one drawn.
However, the polygon first drawn is used for the texture deciding the mission terrain.
So for example if you draw a forest polygon on top of a desert polygon you will see a forest in globe view but the missions will be in desert terrain.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [EXE] Geoscape Generator
« Reply #12 on: February 04, 2018, 05:01:49 pm »
Thanks for the tip, but this generator doesn't overlap polygons as it uses the boundary lines to split the globe into increasingly smaller sections.