summaryrefslogtreecommitdiff
path: root/rail_cmd.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-03-28 07:25:36 +0000
committertron <tron@openttd.org>2005-03-28 07:25:36 +0000
commitbba102e62443ca5d5d85d771982fe8b3817c4ceb (patch)
tree2241d812e15e0120852f45d29e9f9a9e6c3a6b39 /rail_cmd.c
parentae359d0d021a5d6ac9c108c220acf7e3884c968d (diff)
downloadopenttd-bba102e62443ca5d5d85d771982fe8b3817c4ceb.tar.xz
(svn r2095) In CheckTrackCombination(): if () cascade -> switch, improve readability
Diffstat (limited to 'rail_cmd.c')
-rw-r--r--rail_cmd.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/rail_cmd.c b/rail_cmd.c
index 805dc16a4..6c0d1890d 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -113,29 +113,36 @@ static bool CheckTrackCombination(byte map5, byte trackbits, byte flags)
{
_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
- if ((map5&RAIL_TYPE_MASK) == RAIL_TYPE_SIGNALS) {
-
- if (map5 & trackbits) {
- _error_message = STR_1007_ALREADY_BUILT;
- return false;
- }
+ switch (map5 & RAIL_TYPE_MASK) {
+ case RAIL_TYPE_NORMAL:
+ if (map5 & trackbits) {
+ _error_message = STR_1007_ALREADY_BUILT;
+ return false;
+ }
- map5 |= trackbits;
- return (map5 == (RAIL_TYPE_SIGNALS|RAIL_BIT_UPPER|RAIL_BIT_LOWER) || map5 == (RAIL_TYPE_SIGNALS|RAIL_BIT_LEFT|RAIL_BIT_RIGHT));
+ if (flags & DC_NO_RAIL_OVERLAP) {
+ // Computer players are not allowed to intersect pieces of rail.
+ map5 |= trackbits;
+ return
+ map5 == (RAIL_BIT_UPPER | RAIL_BIT_LOWER) ||
+ map5 == (RAIL_BIT_LEFT | RAIL_BIT_RIGHT);
+ } else {
+ return true;
+ }
- } else if ((map5&RAIL_TYPE_MASK) == RAIL_TYPE_NORMAL) {
- _error_message = STR_1007_ALREADY_BUILT;
- if (map5 & trackbits)
- return false;
+ case RAIL_TYPE_SIGNALS:
+ if (map5 & trackbits) {
+ _error_message = STR_1007_ALREADY_BUILT;
+ return false;
+ }
- // Computer players are not allowed to intersect pieces of rail.
- if (!(flags&DC_NO_RAIL_OVERLAP))
- return true;
+ map5 |= trackbits;
+ return
+ map5 == (RAIL_TYPE_SIGNALS | RAIL_BIT_UPPER | RAIL_BIT_LOWER) ||
+ map5 == (RAIL_TYPE_SIGNALS | RAIL_BIT_LEFT | RAIL_BIT_RIGHT);
- map5 |= trackbits;
- return (map5 == (RAIL_BIT_UPPER|RAIL_BIT_LOWER) || map5 == (RAIL_BIT_LEFT|RAIL_BIT_RIGHT));
- } else {
- return false;
+ default:
+ return false;
}
}