Map Location Data (4) Stairs - HoraceAndTheSpider/Bloodwych-68k GitHub Wiki

A staircase is identified within the map data, in the second byte within the location's map data word (AB CD), whereby the lowest three bits of the final digit (D) give the value '4'. The other bit in D is a flag and does not change the location type.

To best understand the definition of the staircase, we can translate the two bytes (AB) and (CD) to binary, and consider which binary bits (right to left) contain defining information.

The type of Staircase

The type of staircase, is changeable between the 'up' type staircase, and the 'down' type stair case. This is defined in bit 0 of the (AB) byte. If the bit is 'off' the staircase goes upwards, and if the bit is 'on' the staircase goes downwards.

The Direction of the Staircase

A Staircase can face N/E/S/W, and this is defined by bits 1-2 of the (AB) byte, which should be translated into a value from 0-3.

0 = North
1 = East
2 = South
3 = West

Additional Considerations

Although a staircase will appear the same regardless of it's direction set, it should be allocated the correct direction in order to ensure correct operation.

When leaving a floor by a staircase, the player lands two map spaces forward from the stair itself. For an ordinary pair of stairs, this means lining them up on the two floors with one space between them in their operating direction. Remember to allow for the X/Y offsets of each floor when comparing their positions.

This is the usual arrangement, rather than a rule the game insists on. A staircase can lead to a location without another staircase, which allows for unusual stair tricks.

Staircases are usually surrounded by walls. If the space behind the staircase is not solid, it is possible to move backwards whilst standing on the staircase, and move into the unoccupied space. There is one occurrence of this in Bloodwych, on the staircase closest to the Chaos Tower entrance, within the Keep.

Location Occupancy

The value of C determines the current occupancy of this location, as previously defined in: Map-Location Data - (0) Spaces

Further source details (SPS 439)

The travel direction used by the SPS 439 transition is the opposite of the stored facing: (detail_byte >> 1) XOR 2. The source does not mask away upper detail bits before using that result; ordinary stair data should keep unused upper bits clear.

Landing coordinates

From the source stair cell, the transition:

  1. Chooses the adjacent floor using detail bit 0.
  2. Adds the source floor's alignment and subtracts the destination floor's alignment.
  3. Adds the travel direction's X and Y deltas twice.
  4. Checks the destination cell's occupied flag.
  5. Commits the new floor and coordinates, and takes the new facing from the destination cell's first byte shifted right by one.

For example, a stair at local (5, 8) with source alignment (2, 3) has world coordinate (7, 11). Travelling north lands at world (7, 9). If the destination alignment is (4, 1), its local landing is (3, 8).

For a conventional reciprocal pair, the opposite-floor stair occupies that landing cell, has the opposite up/down bit, and reverses travel direction. In shared tower coordinates, the stair cells are two cells apart along the travel direction, with one intervening cell.

What the game actually checks

The landing check in original adrCd006EE8 tests second-byte bit 7. If occupied, it restores the previous floor geometry and the source cell's occupied flag without committing the move.

It does not require a corresponding stair type or a reciprocal direction at the destination. Nonstandard stair tricks can therefore be intentional. An unpaired staircase is therefore not, by itself, proof that the game will reject the transition.

The facing update still reads the destination detail byte even when that destination is not a stair. Invalid coordinates or unexpected detail bits can consequently produce unintended behaviour.

The player-movement path also distinguishes attempting to traverse a stair in its permitted direction from ordinary movement around it. Surrounding walls are a design convention, not a property enforced merely by assigning cell type 4.

Source evidence

The original SPS 439 source implements stair-direction selection in adrCd006DFC and adrCd006EA8, floor selection in adrCd006ED0, coordinate rebasing/two-step movement in adrCd006EE8, and the accepted landing in adrCd006F24.

See Map Data Structure for header alignment and the movement-delta table, and Pads, Triggers & Holes for vertical pit falls.