mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Codechange: Document the _ship_subcoord table
This commit is contained in:
parent
c6e4fa7df1
commit
588fee5473
@ -516,38 +516,53 @@ static inline TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir)
|
|||||||
return tracks;
|
return tracks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const byte _ship_subcoord[4][6][3] = {
|
/** Structure for ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track. */
|
||||||
|
struct ShipSubcoordData {
|
||||||
|
byte x_subcoord; ///< New X sub-coordinate on the new tile
|
||||||
|
byte y_subcoord; ///< New Y sub-coordinate on the new tile
|
||||||
|
Direction dir; ///< New Direction to move in on the new track
|
||||||
|
};
|
||||||
|
/** Ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track.
|
||||||
|
* Array indexes are Diagdir, Track.
|
||||||
|
* There will always be three possible tracks going into an adjacent tile via a Diagdir,
|
||||||
|
* so each Diagdir sub-array will have three valid and three invalid structures per Track.
|
||||||
|
*/
|
||||||
|
static const ShipSubcoordData _ship_subcoord[DIAGDIR_END][TRACK_END] = {
|
||||||
|
// DIAGDIR_NE
|
||||||
{
|
{
|
||||||
{15, 8, 1},
|
{15, 8, DIR_NE}, // TRACK_X
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_Y
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_UPPER
|
||||||
{15, 8, 2},
|
{15, 8, DIR_E}, // TRACK_LOWER
|
||||||
{15, 7, 0},
|
{15, 7, DIR_N}, // TRACK_LEFT
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_RIGHT
|
||||||
},
|
},
|
||||||
|
// DIAGDIR_SE
|
||||||
{
|
{
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_X
|
||||||
{ 8, 0, 3},
|
{ 8, 0, DIR_SE}, // TRACK_Y
|
||||||
{ 7, 0, 2},
|
{ 7, 0, DIR_E}, // TRACK_UPPER
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_LOWER
|
||||||
{ 8, 0, 4},
|
{ 8, 0, DIR_S}, // TRACK_LEFT
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_RIGHT
|
||||||
},
|
},
|
||||||
|
// DIAGDIR_SW
|
||||||
{
|
{
|
||||||
{ 0, 8, 5},
|
{ 0, 8, DIR_SW}, // TRACK_X
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_Y
|
||||||
{ 0, 7, 6},
|
{ 0, 7, DIR_W}, // TRACK_UPPER
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_LOWER
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_LEFT
|
||||||
{ 0, 8, 4},
|
{ 0, 8, DIR_S}, // TRACK_RIGHT
|
||||||
},
|
},
|
||||||
|
// DIAGDIR_NW
|
||||||
{
|
{
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_X
|
||||||
{ 8, 15, 7},
|
{ 8, 15, DIR_NW}, // TRACK_Y
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_UPPER
|
||||||
{ 8, 15, 6},
|
{ 8, 15, DIR_W}, // TRACK_LOWER
|
||||||
{ 0, 0, 0},
|
{ 0, 0, INVALID_DIR}, // TRACK_LEFT
|
||||||
{ 7, 15, 0},
|
{ 7, 15, DIR_N}, // TRACK_RIGHT
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -627,7 +642,6 @@ bool IsShipDestinationTile(TileIndex tile, StationID station)
|
|||||||
static void ShipController(Ship *v)
|
static void ShipController(Ship *v)
|
||||||
{
|
{
|
||||||
uint32 r;
|
uint32 r;
|
||||||
const byte *b;
|
|
||||||
Track track;
|
Track track;
|
||||||
TrackBits tracks;
|
TrackBits tracks;
|
||||||
GetNewVehiclePosResult gp;
|
GetNewVehiclePosResult gp;
|
||||||
@ -744,10 +758,10 @@ static void ShipController(Ship *v)
|
|||||||
track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
|
track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
|
||||||
if (track == INVALID_TRACK) goto reverse_direction;
|
if (track == INVALID_TRACK) goto reverse_direction;
|
||||||
|
|
||||||
b = _ship_subcoord[diagdir][track];
|
const ShipSubcoordData &b = _ship_subcoord[diagdir][track];
|
||||||
|
|
||||||
gp.x = (gp.x & ~0xF) | b[0];
|
gp.x = (gp.x & ~0xF) | b.x_subcoord;
|
||||||
gp.y = (gp.y & ~0xF) | b[1];
|
gp.y = (gp.y & ~0xF) | b.y_subcoord;
|
||||||
|
|
||||||
/* Call the landscape function and tell it that the vehicle entered the tile */
|
/* Call the landscape function and tell it that the vehicle entered the tile */
|
||||||
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
|
||||||
@ -763,7 +777,7 @@ static void ShipController(Ship *v)
|
|||||||
if (old_wc != new_wc) v->UpdateCache();
|
if (old_wc != new_wc) v->UpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
Direction new_direction = (Direction)b[2];
|
Direction new_direction = b.dir;
|
||||||
DirDiff diff = DirDifference(new_direction, v->direction);
|
DirDiff diff = DirDifference(new_direction, v->direction);
|
||||||
switch (diff) {
|
switch (diff) {
|
||||||
case DIRDIFF_SAME:
|
case DIRDIFF_SAME:
|
||||||
|
Loading…
Reference in New Issue
Block a user