coding:wolf4sdl:mapplanes

How do I add more Map Planes to my game?

Most modern Wolfenstein 3D Editors allow for editing maps with more than just the Walls and Objects planes. But to use this, a minor change needs to be made to the engine itself.

This assumes you've started a new project in Code::Blocks that successfully builds. If you haven't yet, then click here to start.

This tutorial is adapted to Wolf4SDL from the one included in WDC's help files

The third map plane will be automatically enabled when the included Floor and Ceiling texture code is enabled. If you only need this third plane, you're done! Otherwise, read on to learn how to enable more Map Planes.

In your project files, navigate to ID_CA.H and locate the following lines:

#ifdef USE_FLOORCEILINGTEX
    #define MAPPLANES       3
#else
    #define MAPPLANES       2
#endif

You will want to change the numbers following MAPPLANES to match the number you require. Change both, if you're planning to use floor and ceiling textures along with other features.

#ifdef USE_FLOORCEILINGTEX
    #define MAPPLANES       5
#else
    #define MAPPLANES       5
#endif

The game assumes in some places that there can only be a maximum of 3 planes possible, so first we need to make some changes.

In ID_CA.CPP, scroll down to the following code

typedef struct
{
    word RLEWtag;
    int32_t headeroffsets[100];
} mapfiletype;

Inside the brackets, add the line word numplanes;

Then, in the ID_CA.H file, locate this code:

typedef struct
{
    int32_t planestart[3];
    word    planelength[3];
    word    width,height;
    char    name[16];
} maptype;

Change the numbers in planestate and planelength to read MAPPLANES

typedef struct
{
    int32_t planestart[MAPPLANES];
    word    planelength[MAPPLANES];
    word    width,height;
    char    name[16];
} maptype;

By changing the numbers to the MAPPLANES definition, the limit of planes is dictated by whatever value you made MAPPLANES.

Save and compile your code, and you should now have additional planes enabled.

Unless you have Floor and Ceiling Textures enabled, the extra planes won't actually do anything yet. To make them have an effect, look at the following line

#define MAPSPOT(x,y,plane) (mapsegs[plane][((y)*180)+(x)])

This line lets you call the value of a tile's plane using the code MAPSPOT(x,y,plane). x and y stand for the coordinates of the map tile, and plane represents the map plane you want to check the value of.

Substitute the values with the coordinates for the tile you would want to target and what plane to check, minus 1. The reason the numbers are reduced by one, is because the engine considers 0 to be the first entry number. Thus, (0,0) would be the coordinates for the tile in the top left corner.

For example, if you wanted to check the value of the fourth plane the second tile of the first row from the top of the map, you would call MAPSPOT(1,0,3).

Let's say you wanted the game to check that tile when the player dies, and determine the amount of ammo they start with by the fourth plane.

Go to WL_GAME.CPP and find this code in the Died function.

        gamestate.health = 100;
        gamestate.weapon = gamestate.bestweapon
            = gamestate.chosenweapon = wp_pistol;
        gamestate.ammo = STARTAMMO;
        gamestate.keys = 0;
        pwallstate = pwallpos = 0;
        gamestate.attackframe = gamestate.attackcount =
            gamestate.weaponframe = 0;

Change the ammo line to read as follows

        gamestate.ammo = MAPSPOT(1,0,3);

Now, whatever the value of the fourth plane in that tile will dictate the Player's starting ammo upon death, allowing you to customize it per level from within the map editor, instead of hardcoding it individually.

To learn how to set up WDC's map editor to use extra planes, click here.

  • coding/wolf4sdl/mapplanes.txt
  • Last modified: 2020/03/27 08:51
  • by zombie