Modding Maps

STF Map Concepts
The basic components of map generation in STF are:


 * the world maps layouts (./modversion/maps/world_map.tmx=v1 default map & world_map2.tmx=v2 default map )
 * the files do not contain ANY gates connections/edges info at all => we must generate them in table map_x.MapGate (this is one of the most important tables!)
 * the quadrant maps layouts (all the ./modversion/maps/region_x_map_1.tmx with x in [1,74] also see table data.Region column tmxPath):
 * _id in table mapquadrant references [objects].name in world map if you export tmx in json
 * regionId in table mapquadrant references the tmx file to be used (ex in old default map Orion Expanse quadrant _id=25 uses regionId=2)
 * data.Region table : driver table for all the quadrant assignment to their layouts (.tmx)
 * quad danger (data.Region fields minLevel and MaxLevel are added together)
 * respawnDice => 40% of economies will be this type
 * restorePurge => Default Faction Owner, 0 for random weighted TO DO: more info
 * data.RegionMapWorld table: all the positions/coordinates of planets from all quad map layouts
 * data.RegionMapGate table: all the positions/coordinates of gates from all quad map layouts
 * data.RegionMapData table: quad layout max tiles (30x30 -> 70x70)
 * all the other tables described in Map Database Modding

The game constructs a full graph of the world map using Nodes=quadrants & Edges=gates.

A v1-default-map-like should have 90 gates/edges and 63 quadrants/nodes as an example.

Important notes:


 * 4 gates/edges max per quadrant/node, even the full graph has this property
 * BE CAREFUL when modifying static/story quads (or any zone that has a storyId >0 for that matter) like:
 * quad _id=42=>Alzean Core
 * quad _id=31=>Farfallen Rim (FFR)
 * quad _id=9=>Cirm Sector
 * this list could change with new STF updates

In order to create a pseudo random map the following steps are performed (very simplistic educated guess description)


 * 1) some nodes and edges will be set to inactive (see below how to detect them) => subgraph to be shown => create MapGate, MapQuadrant accordingly (they contain full graph info with only the subgraph being active =1)
 * 2) reconstruct the map_x.MapRouteDistance accordingly using the subgraph
 * 3) populate the MapZone, MapPlanet tables for the subgraph only -- Note :not all planets defined in the quad layout have to be shown, some of them can be hidden (if they do not exist in map_x.MapPlanet corresponding columns regionId worldId -- see difference with data.RegionMapWorld )
 * 4) populate table MapResourceQuadrant (quad _id with RareTradeGoods)



=> the FINAL result is the player seed map

Example 1: Modify coordinates of quadrants w/o changing gates/edges data
Use Tiled, open one of the existing world_map (tmx), modify the node/quadrants coordinates as you like.

Make sure that gate lines don't intersect (I haven't tested this to see if it crashes STF)

Make sure you copy your modded world_map.tmx file in the ./modversion/maps/ folder

Test your mod.

Example 2: Modify coordinates of quadrants and change gates/edges data (no changes to the quadrants layouts, planets or zones)
Use Tiled, open one of the existing world_map (tmx), modify the node/quadrants coordinates as you like.

Make sure you copy your modded world_map.tmx file in the ./modversion/maps/ folder

Recreate/Update the map_x.MapGate (all gates either active and inactive -- 1 row for each edge in the full graph => number of full graph edges = number of rows in MapGate table) and

recreate/update the map_x.MapQuadrant(all nodes either active and inactive -- 1 row for each quadrant in the full graph => number of full graph nodes = number of rows in MapQuadrant table):


 * remember the max 4 gates per quad rule!
 * reposition the quadrant_dir1 and quadrant_dir2 directions of gates accordingly (1=North, 2=East, 3 South, 4=West)
 * if you wish modify the following:
 * the gate names
 * gate length --> for a realistic distance a good rule of thumb: math.floor(math.sqrt( x*x + y*y )/38) with 38=tmx file tile dimension and x, y = distances between nodes on X,Y axis
 * gates danger
 * reconstruct the map_x.MapRouteDistance using whichever algorithm you like (I used Breadth-first_search for example)

Copy your modded map db in %LOCALAPPDATA%\StarTradersFrontiersMods\

Test your mod.

Tiled files (.tmx) structure in json
Tiled is cool and you can use it to export your map in json format for further manipulation.

This file contains only the nodes(quadrant locations) and not the edges(gates connections).

Important note: importing an enriched STF map json(with edges/gates) works as long as the structure is respected. ....................