Making an Elevator

By Richard Clark

Elevator
Figure 1: Elevator

When the Doom source code was first released, one of the first ports to really extend the Doom environment was Boom, developed by the Doom experts of TeamTNT. Randy had the foresight to include the Boom extensions in ZDoom and one of those extensions is the elevator.

An elevator is a sector that moves up and down, maintaining the same distance between floor and ceiling as it moves. With the elevator you can replace those lifts and have a natural looking environment. The sample wad, elevator.wad has an example of using the elevator.

Elevator
Figure 2: Map Layout

The map setup seems a little complicated at first, but is pretty simple once you understand the mechanics of an elevator. You need to have a reason for an elevator so you need two sectors of different heights. In Figure 2, sectors A and B are on different levels. Sector C is the elevator between the two different floors.

Remember that an elevator keeps the same distance between floor and ceiling so the initial floor and ceiling heights of the elevator will be maintained when the sector moves. Since the elevator switch texture is 72 units tall, the elevator has a floor and ceiling distance of 72. When the elevator moves the switch texture will also move.

The elevator uses three specials to move. These are Elevator_MoveToFloor (# 246), Elevator_RaiseToNearest (# 245)and Elevator_LowerToNearest (# 247).

Elevator_MoveToFloor(tag, speed)

This special will move the elevator to the floor where the special is activated. In Figure 2, the two switches in sectors A and B will call the elevator to the corresponding sector. This is needed in case the elevator happens to be at the other floor.

Elevator_RaiseToNearest(tag, speed), Elevator_LowerToNearest(tag, speed)

These specials are used to move the elevator from floor to floor. In Figure 2, the elevator switch activates a script that calls one or the other special depending on which floor the elevator is at. Since the switch has to execute two specials (RaiseToNearest and LowerToNearest) this is handled better with a script. Here is the script:

#include "zcommon.acs"

// Flag to keep track of what floor elevator is on.
int floor;

// This script is activated from the 
// elevator switch.
script 1 (void)
{
	if (floor == 1)
	{
		Elevator_LowerToNearest (1, 16);
		floor = 0;
	}
	else
	{
		Elevator_RaiseToNearest (1, 16);
		floor = 1;
	}
}

// This script is activated from the lower sector switch. 
// This sets the floor flag to indicate where the elevator 
// is currently at; in this case 0 = lower sector.
script 2 (void)
{
	Elevator_MoveToFloor (1, 16);
	floor = 0;
}

// This script is activated from the upper sector switch. 
// This sets the floor flag to indicate where the elevator 
// is currently at; in this case 1 = upper sector.
script 3 (void)
{
	Elevator_MoveToFloor (1, 16);
	floor = 1;
}

The script is quite simple but effective. Keep in mind that elevators can visit more than two floors. If you have a three or four level structure, calling RaiseToNearest or LowerToNearest will cause the elevator to stop at each floor.

Sources

ZDoom reference by Randy Heit.

Back