mirror of https://github.com/OpenTTD/OpenTTD
(svn r3369) - Codechange: Replace tables _signals_table, _signals_table_other and _signals_table_both by the equivalent calls to rail.h functions.
- Codechange: Add a few constants.release/0.4.5
parent
72b70fa042
commit
08a3e346cd
47
rail_cmd.c
47
rail_cmd.c
|
@ -385,22 +385,6 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
return cost + _price.build_rail;
|
return cost + _price.build_rail;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const byte _signals_table[] = {
|
|
||||||
0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0, // direction 1
|
|
||||||
0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0 // direction 2
|
|
||||||
};
|
|
||||||
|
|
||||||
static const byte _signals_table_other[] = {
|
|
||||||
0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0, // direction 1
|
|
||||||
0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0 // direction 2
|
|
||||||
};
|
|
||||||
|
|
||||||
static const byte _signals_table_both[] = {
|
|
||||||
0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30, 0, 0, // both directions combined
|
|
||||||
0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30, 0, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/** Remove a single piece of track
|
/** Remove a single piece of track
|
||||||
* @param x,y coordinates for removal of track
|
* @param x,y coordinates for removal of track
|
||||||
* @param p1 unused
|
* @param p1 unused
|
||||||
|
@ -1091,14 +1075,15 @@ static int32 ClearTile_Track(TileIndex tile, byte flags)
|
||||||
cost = 0;
|
cost = 0;
|
||||||
|
|
||||||
switch (GetRailTileType(tile)) {
|
switch (GetRailTileType(tile)) {
|
||||||
|
/* XXX: Why the fuck do we remove these thow signals first? */
|
||||||
case RAIL_TYPE_SIGNALS:
|
case RAIL_TYPE_SIGNALS:
|
||||||
if (_m[tile].m3 & _signals_table_both[0]) {
|
if(HasSignalOnTrack(tile, TRACK_DIAG1)) {
|
||||||
ret = DoCommandByTile(tile, 0, 0, flags, CMD_REMOVE_SIGNALS);
|
ret = DoCommandByTile(tile, TRACK_DIAG1, 0, flags, CMD_REMOVE_SIGNALS);
|
||||||
if (CmdFailed(ret)) return CMD_ERROR;
|
if (CmdFailed(ret)) return CMD_ERROR;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
}
|
}
|
||||||
if (_m[tile].m3 & _signals_table_both[3]) {
|
if(HasSignalOnTrack(tile, TRACK_LOWER)) {
|
||||||
ret = DoCommandByTile(tile, 3, 0, flags, CMD_REMOVE_SIGNALS);
|
ret = DoCommandByTile(tile, TRACK_LOWER, 0, flags, CMD_REMOVE_SIGNALS);
|
||||||
if (CmdFailed(ret)) return CMD_ERROR;
|
if (CmdFailed(ret)) return CMD_ERROR;
|
||||||
cost += ret;
|
cost += ret;
|
||||||
}
|
}
|
||||||
|
@ -1638,7 +1623,7 @@ static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, u
|
||||||
// the tile has signals?
|
// the tile has signals?
|
||||||
if (IsTileType(tile, MP_RAILWAY)) {
|
if (IsTileType(tile, MP_RAILWAY)) {
|
||||||
if (HasSignalOnTrack(tile, TrackdirToTrack(track))) {
|
if (HasSignalOnTrack(tile, TrackdirToTrack(track))) {
|
||||||
if ((_m[tile].m3 & _signals_table[track]) != 0) {
|
if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) {
|
||||||
// yes, add the signal to the list of signals
|
// yes, add the signal to the list of signals
|
||||||
if (ssd->cur != NUM_SSD_ENTRY) {
|
if (ssd->cur != NUM_SSD_ENTRY) {
|
||||||
ssd->tile[ssd->cur] = tile; // remember the tile index
|
ssd->tile[ssd->cur] = tile; // remember the tile index
|
||||||
|
@ -1646,8 +1631,8 @@ static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, u
|
||||||
ssd->cur++;
|
ssd->cur++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PBSIsPbsSignal(tile, ReverseTrackdir(track)))
|
if (PBSIsPbsSignal(tile, ReverseTrackdir(track)))
|
||||||
SETBIT(ssd->has_pbssignal, 2);
|
SETBIT(ssd->has_pbssignal, 2);
|
||||||
|
|
||||||
// remember if this block has a presignal.
|
// remember if this block has a presignal.
|
||||||
ssd->has_presignal |= (_m[tile].m4&1);
|
ssd->has_presignal |= (_m[tile].m4&1);
|
||||||
|
@ -1660,16 +1645,14 @@ static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, u
|
||||||
ssd->has_pbssignal |= num;
|
ssd->has_pbssignal |= num;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_m[tile].m3 & _signals_table_both[track]) != 0) {
|
ssd->pbs_tile[ssd->pbs_cur] = tile; // remember the tile index
|
||||||
ssd->pbs_tile[ssd->pbs_cur] = tile; // remember the tile index
|
ssd->pbs_cur++;
|
||||||
ssd->pbs_cur++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_m[tile].m3&_signals_table_other[track]) {
|
if (HasSignalOnTrackdir(tile, track)) {
|
||||||
if (_m[tile].m4&2) {
|
if (_m[tile].m4&2) {
|
||||||
// this is an exit signal that points out from the segment
|
// this is an exit signal that points out from the segment
|
||||||
ssd->presignal_exits++;
|
ssd->presignal_exits++;
|
||||||
if ((_m[tile].m2&_signals_table_other[track]) != 0)
|
if (GetSignalState(tile, track) != SIGNAL_STATE_RED)
|
||||||
ssd->presignal_exits_free++;
|
ssd->presignal_exits_free++;
|
||||||
}
|
}
|
||||||
if (PBSIsPbsSignal(tile, track))
|
if (PBSIsPbsSignal(tile, track))
|
||||||
|
@ -1819,7 +1802,7 @@ static void ChangeSignalStates(SetSignalsData *ssd)
|
||||||
// then mark the signals in the segment accordingly
|
// then mark the signals in the segment accordingly
|
||||||
for (i = 0; i != ssd->cur; i++) {
|
for (i = 0; i != ssd->cur; i++) {
|
||||||
TileIndex tile = ssd->tile[i];
|
TileIndex tile = ssd->tile[i];
|
||||||
byte bit = _signals_table[ssd->bit[i]];
|
byte bit = SignalAgainstTrackdir(ssd->bit[i]);
|
||||||
uint16 m2 = _m[tile].m2;
|
uint16 m2 = _m[tile].m2;
|
||||||
|
|
||||||
// presignals don't turn green if there is at least one presignal exit and none are free
|
// presignals don't turn green if there is at least one presignal exit and none are free
|
||||||
|
@ -1827,9 +1810,9 @@ static void ChangeSignalStates(SetSignalsData *ssd)
|
||||||
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
|
int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free;
|
||||||
|
|
||||||
// subtract for dual combo signals so they don't count themselves
|
// subtract for dual combo signals so they don't count themselves
|
||||||
if (_m[tile].m4&2 && _m[tile].m3&_signals_table_other[ssd->bit[i]]) {
|
if (_m[tile].m4&2 && HasSignalOnTrackdir(tile, ssd->bit[i])) {
|
||||||
ex--;
|
ex--;
|
||||||
if ((_m[tile].m2&_signals_table_other[ssd->bit[i]]) != 0) exfree--;
|
if (GetSignalState(tile, ssd->bit[i]) != SIGNAL_STATE_RED) exfree--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have exits and none are free, make red.
|
// if we have exits and none are free, make red.
|
||||||
|
|
Loading…
Reference in New Issue