To generate the outside of a base, the 64 x 32 map is initially filled with wall cells.
Creating landThe basic idea to creating land is to have a cursor move around on the map and turn wall cells into land objects. The first step is to randomly select the initial location of this cursor and store it in memory for later use. A direction is randomly selected and the cursor is ready to start converting cells. The cells are converted by batch of land types meaning that the cursor will create a bunch of evergreens, then create a bunch of trees, etc. A decremental counter initialized to 255 is used to determine the current type of land being created.
The cursor begins by making sure that the cell it's about to convert is a wall (ie. not already converted). If it is a wall, the cell is converted, otherwise it is left intact. In either case, the land type counter is decreased by 1 and the cursor repeats this step to a random adjacent cell. This entire conversion is repeated up to 9 times based on the result of the seed number divided by 4. This is why the further we are in the mission, the bigger are the lands. Here's what the outside of the first planet, Butre, looks like only with land objects: The base entranceThe base entrance occupies 3 x 3 cells. The generator selects a random cells and ensures that it is a land object so the droids can reach it. Once found, the related walls are created leaving a hole in a random direction which will be replaced by an iris door. If an already existing wall is in contact with the base, it is replaced by an evergreen which is always making the shape of the base a perfect square. To make life easier for a new player, the location of the first base entrance is hardcoded and its door is forced to be on the north side. Additionally, a message clipboard from Ratt is dropped close to the base to help the player decode the iris door lock mechanism. If the player lands on the landing spot of a planet that doesn't have a base, this process of the map generation is skipped. The player will have the ability to walk around and make a few bucks by killing encounters, but nothing else can be done. The landerYou can guess that the location of the lander is relatively simple. A cell is randomly selected until one is found as not being a wall. Once found, it is converted to be the lander. Once again, the location of the lander is hardcoded on the first planet to be close to the base entrance. WaterEvery cell is inspected one by one. For each cell, the generator counts the number of land objects (not a wall) in the four directions around it. If this count is less or equal to 1, the cell is converted to a water cell. If it's greater than 1, the cell is left intact meaning that it remains a wall since the entire map was initially filled with walls. This tends to leave walls at the edges of land. Not sure why, but it seems the programmer felt it was better to do so. EncountersUp to 64 encounters are created on the map and the quantity depends on how far we are in the mission. If the randomly selected cell is water, the encounter is a diplocus, but if not, it's one of the other encounters that can only be found outside a base. The generator ensures that the selected cell is water, dirt, a tree or grass. If the selected cell is a wall or an evergreen, the encounter creation is skipped to the next encounter. It is unknown if the evergreen land object has simply been forgotten, but according to the code that doesn't simply exclude wall cells for encounter locations, it's assumed to be intentional. You might have noticed that the first planet doesn't have any land encounters. If you wonder if it received special treatment to prevent such a thing, wonder no more: It's not the case. The generator has simply not selected any land cells and this is perfect since the droids are not yet equipped with weapons. Click here to see a video of all this created cell by cell. |