summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2006-04-12 09:36:27 +0000
committercelestar <celestar@openttd.org>2006-04-12 09:36:27 +0000
commit923a0e60d6df0b334dd9371ef8a8f486295ea421 (patch)
tree066651be5c87829c223c0fbe9b4d2d77c77bbe76
parent5ae9a03a1f1afcb417a7805b5ccda9a56b47c5d1 (diff)
downloadopenttd-923a0e60d6df0b334dd9371ef8a8f486295ea421.tar.xz
(svn r4378) -Add and make use of an accessor function two-way => one-way => one-way => two-way signal cycling
-rw-r--r--rail_cmd.c21
-rw-r--r--rail_map.h11
2 files changed, 12 insertions, 20 deletions
diff --git a/rail_cmd.c b/rail_cmd.c
index a4e013f9f..a3ca08a20 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -703,26 +703,7 @@ int32 CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
SetSignalType(tile, type == SIGTYPE_COMBO ? SIGTYPE_NORMAL : type + 1);
} else {
- // cycle between two-way -> one-way -> one-way -> ...
- /* TODO: Rewrite switch into something more general */
- switch (track) {
- case TRACK_LOWER:
- case TRACK_RIGHT: {
- byte signal = (_m[tile].m3 - 0x10) & 0x30;
- if (signal == 0) signal = 0x30;
- _m[tile].m3 &= ~0x30;
- _m[tile].m3 |= signal;
- break;
- }
-
- default: {
- byte signal = (_m[tile].m3 - 0x40) & 0xC0;
- if (signal == 0) signal = 0xC0;
- _m[tile].m3 &= ~0xC0;
- _m[tile].m3 |= signal;
- break;
- }
- }
+ CycleSignalSide(tile, track);
}
}
} else {
diff --git a/rail_map.h b/rail_map.h
index da72d0250..f3a7a4626 100644
--- a/rail_map.h
+++ b/rail_map.h
@@ -174,6 +174,17 @@ static inline bool IsPresignalExit(TileIndex t)
return GetSignalType(t) == SIGTYPE_EXIT || GetSignalType(t) == SIGTYPE_COMBO;
}
+static inline void CycleSignalSide(TileIndex t, Track track)
+{
+ byte sig;
+ byte pos = 6;
+ if (track == TRACK_LOWER || track == TRACK_RIGHT) pos = 4;
+
+ sig = GB(_m[t].m3, pos, 2);
+ if (--sig == 0) sig = 3;
+ SB(_m[t].m3, pos, 2, sig);
+}
+
typedef enum SignalVariant {
SIG_ELECTRIC = 0,