mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
This commit is contained in:
parent
ca46154068
commit
f5929d413b
|
@ -1902,7 +1902,7 @@ struct AiRailPathFindData {
|
||||||
bool flag;
|
bool flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, uint length, byte *state)
|
static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, uint length)
|
||||||
{
|
{
|
||||||
if (a->flag) return true;
|
if (a->flag) return true;
|
||||||
|
|
||||||
|
@ -2848,7 +2848,7 @@ static bool AiCheckRoadPathBetter(AiRoadFinder *arf, const byte *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool AiEnumFollowRoad(TileIndex tile, AiRoadEnum *a, int track, uint length, byte *state)
|
static bool AiEnumFollowRoad(TileIndex tile, AiRoadEnum *a, int track, uint length)
|
||||||
{
|
{
|
||||||
uint dist = DistanceManhattan(tile, a->dest);
|
uint dist = DistanceManhattan(tile, a->dest);
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,6 @@ static const byte _otherdir_mask[4] = {
|
||||||
|
|
||||||
static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
|
static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
|
||||||
{
|
{
|
||||||
uint bits;
|
|
||||||
RememberData rd;
|
RememberData rd;
|
||||||
|
|
||||||
assert(tpf->tracktype == TRANSPORT_WATER);
|
assert(tpf->tracktype == TRANSPORT_WATER);
|
||||||
|
@ -153,43 +152,35 @@ static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
|
||||||
if (++tpf->rd.cur_length > 50)
|
if (++tpf->rd.cur_length > 50)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bits = GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type);
|
uint32 ts = GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type);
|
||||||
bits = (byte)((bits | (bits >> 8)) & _bits_mask[direction]);
|
TrackBits bits = (TrackBits)((byte)((ts | (ts >> 8)) & _bits_mask[direction]));
|
||||||
if (bits == 0)
|
if (bits == TRACK_BIT_NONE) return;
|
||||||
return;
|
|
||||||
|
|
||||||
assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
|
assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY());
|
||||||
|
|
||||||
uint i = 0;
|
bool only_one_track = true;
|
||||||
/* only one direction */
|
|
||||||
if (KillFirstBit(bits) == 0) {
|
|
||||||
i = FindFirstBit(bits);
|
|
||||||
rd = tpf->rd;
|
|
||||||
goto continue_here;
|
|
||||||
}
|
|
||||||
/* several directions */
|
|
||||||
do {
|
do {
|
||||||
i = FindFirstBit(bits);
|
Track track = RemoveFirstTrack(&bits);
|
||||||
|
if (bits != TRACK_BIT_NONE) only_one_track = false;
|
||||||
rd = tpf->rd;
|
rd = tpf->rd;
|
||||||
|
|
||||||
/* Change direction 4 times only */
|
/* Change direction 4 times only */
|
||||||
if ((byte)i != tpf->rd.pft_var6) {
|
if (!only_one_track && track != tpf->rd.last_choosen_track) {
|
||||||
if (++tpf->rd.depth > 4) {
|
if (++tpf->rd.depth > 4) {
|
||||||
tpf->rd = rd;
|
tpf->rd = rd;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tpf->rd.pft_var6 = (byte)i;
|
tpf->rd.last_choosen_track = track;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue_here:
|
tpf->the_dir = (Trackdir)(track + (HasBit(_otherdir_mask[direction], track) ? 8 : 0));
|
||||||
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)) {
|
if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length)) {
|
||||||
TPFMode2(tpf, tile, _tpf_new_direction[tpf->the_dir]);
|
TPFMode2(tpf, tile, _tpf_new_direction[tpf->the_dir]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tpf->rd = rd;
|
tpf->rd = rd;
|
||||||
} while (ClrBit(bits, i) != 0);
|
} while (bits != TRACK_BIT_NONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +280,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
|
||||||
|
|
||||||
/* make sure we are not leaving from invalid side */
|
/* make sure we are not leaving from invalid side */
|
||||||
if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) &&
|
if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) &&
|
||||||
!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length, &tpf->rd.pft_var6) ) {
|
!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length) ) {
|
||||||
TPFMode1(tpf, tile, _tpf_new_direction[tpf->the_dir]);
|
TPFMode1(tpf, tile, _tpf_new_direction[tpf->the_dir]);
|
||||||
}
|
}
|
||||||
tpf->rd = rd;
|
tpf->rd = rd;
|
||||||
|
@ -312,7 +303,7 @@ void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection dire
|
||||||
|
|
||||||
tpf.rd.cur_length = 0;
|
tpf.rd.cur_length = 0;
|
||||||
tpf.rd.depth = 0;
|
tpf.rd.depth = 0;
|
||||||
tpf.rd.pft_var6 = 0;
|
tpf.rd.last_choosen_track = INVALID_TRACK;
|
||||||
|
|
||||||
tpf.var2 = HasBit(flags, 15) ? 0x43 : 0xFF; // 0x8000
|
tpf.var2 = HasBit(flags, 15) ? 0x43 : 0xFF; // 0x8000
|
||||||
|
|
||||||
|
@ -323,8 +314,7 @@ void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection dire
|
||||||
tpf.sub_type = sub_type;
|
tpf.sub_type = sub_type;
|
||||||
|
|
||||||
if (HasBit(flags, 11)) {
|
if (HasBit(flags, 11)) {
|
||||||
tpf.rd.pft_var6 = 0xFF;
|
tpf.enum_proc(tile, data, INVALID_TRACKDIR, 0);
|
||||||
tpf.enum_proc(tile, data, INVALID_TRACKDIR, 0, 0);
|
|
||||||
TPFMode2(&tpf, tile, direction);
|
TPFMode2(&tpf, tile, direction);
|
||||||
} else {
|
} else {
|
||||||
/* clear the hash_heads */
|
/* clear the hash_heads */
|
||||||
|
|
|
@ -16,7 +16,7 @@ enum {
|
||||||
//supported on all archs)
|
//supported on all archs)
|
||||||
|
|
||||||
struct TrackPathFinder;
|
struct TrackPathFinder;
|
||||||
typedef bool TPFEnumProc(TileIndex tile, void *data, Trackdir trackdir, uint length, byte *state);
|
typedef bool TPFEnumProc(TileIndex tile, void *data, Trackdir trackdir, uint length);
|
||||||
typedef void TPFAfterProc(TrackPathFinder *tpf);
|
typedef void TPFAfterProc(TrackPathFinder *tpf);
|
||||||
|
|
||||||
typedef bool NTPEnumProc(TileIndex tile, void *data, int track, uint length);
|
typedef bool NTPEnumProc(TileIndex tile, void *data, int track, uint length);
|
||||||
|
@ -40,7 +40,7 @@ struct TrackPathFinderLink {
|
||||||
struct RememberData {
|
struct RememberData {
|
||||||
uint16 cur_length;
|
uint16 cur_length;
|
||||||
byte depth;
|
byte depth;
|
||||||
byte pft_var6;
|
Track last_choosen_track;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TrackPathFinder {
|
struct TrackPathFinder {
|
||||||
|
|
|
@ -398,7 +398,7 @@ static const DiagDirection _road_pf_directions[] = {
|
||||||
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, INVALID_DIAGDIR, INVALID_DIAGDIR
|
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, INVALID_DIAGDIR, INVALID_DIAGDIR
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool EnumRoadSignalFindDepot(TileIndex tile, void* data, Trackdir trackdir, uint length, byte* state)
|
static bool EnumRoadSignalFindDepot(TileIndex tile, void* data, Trackdir trackdir, uint length)
|
||||||
{
|
{
|
||||||
RoadFindDepotData* rfdd = (RoadFindDepotData*)data;
|
RoadFindDepotData* rfdd = (RoadFindDepotData*)data;
|
||||||
|
|
||||||
|
@ -1119,7 +1119,7 @@ struct FindRoadToChooseData {
|
||||||
uint mindist;
|
uint mindist;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool EnumRoadTrackFindDist(TileIndex tile, void* data, Trackdir trackdir, uint length, byte* state)
|
static bool EnumRoadTrackFindDist(TileIndex tile, void* data, Trackdir trackdir, uint length)
|
||||||
{
|
{
|
||||||
FindRoadToChooseData* frd = (FindRoadToChooseData*)data;
|
FindRoadToChooseData* frd = (FindRoadToChooseData*)data;
|
||||||
uint dist = DistanceManhattan(tile, frd->dest);
|
uint dist = DistanceManhattan(tile, frd->dest);
|
||||||
|
|
|
@ -428,7 +428,7 @@ struct PathFindShip {
|
||||||
uint best_length;
|
uint best_length;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool ShipTrackFollower(TileIndex tile, PathFindShip *pfs, int track, uint length, byte *state)
|
static bool ShipTrackFollower(TileIndex tile, PathFindShip *pfs, int track, uint length)
|
||||||
{
|
{
|
||||||
/* Found dest? */
|
/* Found dest? */
|
||||||
if (tile == pfs->dest_coords) {
|
if (tile == pfs->dest_coords) {
|
||||||
|
|
Loading…
Reference in New Issue