Jump to content

TFTD map generation: the algorithms (derived from the game code)


Maurice76

Recommended Posts

Map building: subroutines in a birds' eye view

 

The game uses various subroutines to build the maps of the game. Most of them require specifics due to the map type in question, but I have not found a good source of information about it anywhere. As a result, I decided to download IDA 5.0 Free and dive into the world of Assembly, a world yet unknown to me. In about a month time, I've managed to learn to read the subroutines made by the original developers of the game and analyse them well enough to be able to present them in detail, including offsets within the .exe file to constants that are defined for each of the subroutines.

 

Although the individual posts (see the links below) are all in the TFTD forum, I figured I would post the master post here, in the modders' section, as it may find most use here. Some of the information may be well known, I don't know - but I do know that the information below is complete and derived from the game's code directly (give or take a typo on my side wink.png ).

 

Most of the map blocks placed through the random map generator are chosen randomly. Except in a few cases, there is no upper limit to the amount of times a specific map block can be selected for placement. Upper limits are noted where applicable. Whenever it makes attempts to place 2x2 map blocks, it commonly does so either 10 or 20 times. For each one of those blocks it tries to place, the number of attempts is first set to zero.

 

Map types 00 through 08: these are USO recovery missions.

 

For USO recovery missions, it will determine whether to use the map type based on geographical location, or to use either the Seabed or Coral map types. This determination has the following chances:

- There is 50% to use the geographical map type;

- There is 25% chance that the Seabed map type is used (note that if the base type was already Seabed, the odds of Seabed are 75%);

- There is 25% chance that the Coral map type is used (note that if the base type was already Coral, the odds of Coral are 75%);

 

The X and Y dimensions of the map will depend on the USO that is being recovered, with one notable exception: the Crashed & Sunken Plane map. The dimension of that map is 5x5, regardless of USO being recovered.

 

It will first randomly determine a location for the USO on the map. Once it has been placed, the X-Com craft is placed on the map, keeping track of the USO that's already there.

 

After that, it will fill the map with map blocks, the placement of which depends on the map type:

 

00 Seabed

Step 1: it will attempt to place up to 3 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

01 Pipes research station

Step 1: it will attempt to place up to 3 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

02 Crashed & Sunken Plane

This map is rather strict in its buildup. For ease of reference, first a map layout.

(0, 0) (1, 0) (2, 0) (3, 0) (4, 0)

(0, 1) (1, 1) (2, 1) (3, 1) (4, 1)

(0, 2) (1, 2) (2, 2) (3, 2) (4, 2)

(0, 3) (1, 3) (2, 3) (3, 3) (4, 3)

(0, 4) (1, 4) (2, 4) (3, 4) (4, 4)

After placing the USO and the X-Com craft, it will proceed to place various plane parts. Each part is randomly selected out of the possible variations. Most have 2 variations, only the middle section without wing connectors has 4, while the tail section only has one.

Step 1: it attempts to place a large left wing in four locations, going over them in sequence (not randomly selected): (2, 0), (3, 0), (2, 1) and (3, 1). If it succeeds, skip to step 2, otherwise continue with step 1a;

Step 1a: if it failed to place a large left wing, it will make one attempt to place a small left wing in location (3, 0);

Step 2: it attempts to place a large right wing in four locations, going over them in sequence (not randomly selected): (2, 2), (3, 2), (2, 3) and (3, 3). If it succeeds, skip to step 3, otherwise continue with step 2a;

Step 2a: if it failed to place a large right wing, it will make one attempt to place a small right wing in location (3, 3) - but note the bug, as it erronously checks (1, 1) to see if it can place it at (3, 3);

Step 3: next part is the tail section. It makes a total of 5 attempts to place one randomly in the blocks of the first column ((0, 0), (0, 1), (0, 2), (0, 3), (0, 4));

Step 4: the next part is then a middle section (without wing connectors). It makes 5 attempts to place it in the central column ((2, 0), (2, 1), (2, 2), (2, 3), (2, 4));

Step 5: another middle section gets attempted (this one with wing connectors). It makes 5 attempts to place it in column 03 ((3, 0), (3, 1), (3, 2), (3, 3), (3, 4));

Step 6: finally, it attempts to place the cockpit in column 04. Like with the other sections, it makes 5 attempts to place it, this time in column 04 ((4, 0), (4, 1), (4, 2), (4, 3), (4, 4));

Step 7: the map is finished by filling up the remaining spots with randomly picked 1x1 map blocks;

Note that the middle section with the wing connectors can only be placed on (3, 1) if it failed to place a large left wing before and likewise, (3, 4) is only possible if it failed to place a large right wing.

 

03 Atlantis

Step 1: it will attempt to place up to 2 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

04 Mayan temple

Step 1: it will attempt to place up to 2 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

05 Sunken galleon

Step 1: it will attempt to place up to 2 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

06 Sunken cargo ship

Step 1: it will attempt to place up to 3 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

07 Volcanic

Step 1: it will attempt to place up to 2 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

08 Coral

Step 1: it will attempt to place up to 3 randomly chosen map blocks of 2x2, each is attempted 20 times;

Step 2: it fills the remainder with 1x1 map blocks chosen randomly;

 

Subsequent map types are not USO recoveries and USO's do not appear in them.

 

09 Artefact stage 1

Step 1: first the X-Com craft is placed on the map;

Step 2: the 2x2 map block with the exit zone is placed on the map;

Step 3: it will make 20 attempts to place 1 additional randomly chosen 2x2 map block on the map;

Step 4: it fills the remainder with 1x1 map blocks chosen randomly;

 

10 Artefact stage 2

Step 1: the 2x2 map block with the Synomium Device is placed on the map;

Step 2: two entrance zones are placed on the map;

Step 3: it then attempts to place up to 2 randomly chosen 2x2 map blocks on the map, attempting each of them 10 times;

Step 4: it fills the remainder with 1x1 map blocks chosen randomly;

 

11 Ship stage 1: it determines the correct type between Cargo Ship and Passenger Liner. In the latter case, it changes the map type to 19. Both map types are static maps.

 

11 Ship stage 2: it determines the correct type between Cargo Ship and Passenger Liner, based on stage 1. In the latter case it changes the map type to 20. Both map types are static maps.

 

12 Port Terror site

Step 1: it places the X-Com craft on the map, making sure it's not in column 04;

Step 2: it fills column 04 with randomly selected 1x1 coastline blocks, working from the top row down to the bottom row;

Step 3: it makes 1 attempt to place the 2x2 map block with the rail carts on the top row;

Step 4: subsequently it makes 20 attempts to place up to 2 randomly selected 2x2 map blocks;

Step 5: it concludes by filling up the remaining blocks with randomly selected 1x1 map blocks;

 

13 Island Terror site

Step 1: it places the X-Com craft on the map, making sure to avoid the two bottom rows (which means that the X-Com craft always occupies the second row, with either the aft section or the nose);

Step 2: it randomly picks one of the two coastal 2x2 map blocks and places it in the bottom left corner of the map;

Step 3: it picks the other one and places it in the bottom right corner of the map;

Step 4: it fills the block at (2, 3) with a randomly selected 1x1 map block;

Step 5: it fills the block at (2, 4) with the 1x1 coastal map block;

Step 6: it makes 20 attempts to place one of the randomly selected 2x2 map blocks on the map. Only one of them is placed;

Step 7: it fills the remaining map blocks with randomly selected 1x1 map blocks;

 

14 Alien Colony stage 2

Step 1: it places the 2x2 map block with the Synomium Device;

Step 2: it places 2 of the 1x1 entrance blocks;

Step 3: it places up to 3 of the 2x2 map blocks, attempting each one a total of 10 times;

Step 4: it fills the remaining blocks with randomly selected 1x1 blocks, but it does give map block special treatment, causing it to appear in roughly 46.4% of all of those positions;

 

15 T'Leth stage 1: it's a random map with some constraints.

Step 1: it places map block 00 in the four corners of the map;

Step 2: it places an exit zone in the bottom row (not in the corners);

Step 3: it places one of the two versions of the entrance zone in the top row (not in the corners);

Step 4: it places the other version of the entrance zone in the top row (not in the corners);

Step 5: it places up to 3 randomly selected 2x2 map blocks, making 20 attempts on each;

Step 6: the rest is filled with randomly selected 1x1 map blocks;

 

16 T'Leth stage 2: it's a static map, no randomisation takes place.

 

17 T'Leth stage 3: it's a static map, no randomisation takes place.

 

18 X-Com base: the layout depends on the players' base design.

 

19 and 20 have already been covered as the Passenger Liner (see 11).

 

21 Alien Colony stage 1: it places the X-Com craft randomly in one of the four quadrants of the map, the map itself is static.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...