summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskidd13 <skidd13@openttd.org>2007-11-20 12:57:24 +0000
committerskidd13 <skidd13@openttd.org>2007-11-20 12:57:24 +0000
commit795174edf13e99cdef7eda73fbc088e2b06df051 (patch)
tree487a548f1b88867f43c97812272e16f5a70337bf
parent6801cceda1cb1d81c627b6d30c19933d81179ce9 (diff)
downloadopenttd-795174edf13e99cdef7eda73fbc088e2b06df051.tar.xz
(svn r11483) -Codechange: Replace codeparts with functions that do the same to increase readability
-rw-r--r--src/map.cpp8
-rw-r--r--src/pathfind.cpp20
2 files changed, 12 insertions, 16 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 00e155c04..7035f955c 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -218,7 +218,7 @@ uint DistanceMax(TileIndex t0, TileIndex t1)
{
const uint dx = delta(TileX(t0), TileX(t1));
const uint dy = delta(TileY(t0), TileY(t1));
- return dx > dy ? dx : dy;
+ return max(dx, dy);
}
@@ -248,9 +248,9 @@ uint DistanceFromEdge(TileIndex tile)
const uint yl = TileY(tile);
const uint xh = MapSizeX() - 1 - xl;
const uint yh = MapSizeY() - 1 - yl;
- const uint minl = xl < yl ? xl : yl;
- const uint minh = xh < yh ? xh : yh;
- return minl < minh ? minl : minh;
+ const uint minl = min(xl, yl);
+ const uint minh = min(xh, yh);
+ return min(minl, minh);
}
/*!
diff --git a/src/pathfind.cpp b/src/pathfind.cpp
index 68602667f..4541e9a9a 100644
--- a/src/pathfind.cpp
+++ b/src/pathfind.cpp
@@ -140,7 +140,6 @@ static const byte _otherdir_mask[4] = {
static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
{
uint bits;
- int i;
RememberData rd;
assert(tpf->tracktype == TRANSPORT_WATER);
@@ -160,19 +159,16 @@ static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
- if ( (bits & (bits - 1)) == 0 ) {
- /* only one direction */
- i = 0;
- while (!(bits & 1))
- i++, bits >>= 1;
-
+ uint i = 0;
+ /* only one direction */
+ if (KillFirstBit(bits) == 0) {
+ i = FindFirstBit(bits);
rd = tpf->rd;
goto continue_here;
}
/* several directions */
- i=0;
do {
- if (!(bits & 1)) continue;
+ i = FindFirstBit(bits);
rd = tpf->rd;
/* Change direction 4 times only */
@@ -184,7 +180,7 @@ static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
tpf->rd.pft_var6 = (byte)i;
}
-continue_here:;
+continue_here:
tpf->the_dir = (Trackdir)(i + (HasBit(_otherdir_mask[direction], i) ? 8 : 0));
if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length, NULL)) {
@@ -192,7 +188,7 @@ continue_here:;
}
tpf->rd = rd;
- } while (++i, bits >>= 1);
+ } while (ClrBit(bits, i) != 0);
}
@@ -293,7 +289,7 @@ static inline void TPFMode1_NormalCase(TrackPathFinder* tpf, TileIndex tile, Til
if ((byte)bits != tpf->var2) {
bits &= _tpfmode1_and[direction];
- bits = bits | (bits >> 8);
+ bits |= bits >> 8;
}
bits &= 0xBF;