mirror of https://github.com/OpenTTD/OpenTTD
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
-Fix: some minor fixes around GetTileTrackStatus (blathijs)release/0.4.5
parent
1846563cf8
commit
10d54ac604
8
ai.c
8
ai.c
|
@ -47,7 +47,7 @@ enum {
|
||||||
#include "table/ai_rail.h"
|
#include "table/ai_rail.h"
|
||||||
|
|
||||||
static byte GetRailTrackStatus(TileIndex tile) {
|
static byte GetRailTrackStatus(TileIndex tile) {
|
||||||
uint32 r = GetTileTrackStatus(tile, 0);
|
uint32 r = GetTileTrackStatus(tile, TRANSPORT_RAIL);
|
||||||
return (byte) (r | r >> 8);
|
return (byte) (r | r >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1849,7 +1849,7 @@ static bool AiDoFollowTrack(Player *p)
|
||||||
arpfd.tile2 = p->ai.cur_tile_a;
|
arpfd.tile2 = p->ai.cur_tile_a;
|
||||||
arpfd.flag = false;
|
arpfd.flag = false;
|
||||||
arpfd.count = 0;
|
arpfd.count = 0;
|
||||||
FollowTrack(p->ai.cur_tile_a + _tileoffs_by_dir[p->ai.cur_dir_a], 0x2000, p->ai.cur_dir_a^2,
|
FollowTrack(p->ai.cur_tile_a + _tileoffs_by_dir[p->ai.cur_dir_a], 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2,
|
||||||
(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
|
(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
|
||||||
return arpfd.count > 8;
|
return arpfd.count > 8;
|
||||||
}
|
}
|
||||||
|
@ -2782,7 +2782,7 @@ bool AiCheckRoadFinished(Player *p)
|
||||||
are.dest = p->ai.cur_tile_b;
|
are.dest = p->ai.cur_tile_b;
|
||||||
tile = TILE_MASK(p->ai.cur_tile_a + _tileoffs_by_dir[dir]);
|
tile = TILE_MASK(p->ai.cur_tile_a + _tileoffs_by_dir[dir]);
|
||||||
|
|
||||||
bits = GetTileTrackStatus(tile, 2) & _ai_road_table_and[dir];
|
bits = GetTileTrackStatus(tile, TRANSPORT_ROAD) & _ai_road_table_and[dir];
|
||||||
if (bits == 0) {
|
if (bits == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2790,7 +2790,7 @@ bool AiCheckRoadFinished(Player *p)
|
||||||
are.best_dist = (uint)-1;
|
are.best_dist = (uint)-1;
|
||||||
|
|
||||||
for_each_bit(i, bits) {
|
for_each_bit(i, bits) {
|
||||||
FollowTrack(tile, 0x3002, _dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
|
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetTileDist(tile, are.dest) <= are.best_dist)
|
if (GetTileDist(tile, are.dest) <= are.best_dist)
|
||||||
|
|
|
@ -757,7 +757,7 @@ static void ClickTile_Clear(uint tile)
|
||||||
/* not used */
|
/* not used */
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 GetTileTrackStatus_Clear(uint tile, int mode)
|
uint32 GetTileTrackStatus_Clear(uint tile, TransportType mode)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -641,7 +641,7 @@ static void DisasterTick_5_and_6(Vehicle *v)
|
||||||
|
|
||||||
tile = v->tile + _tileoffs_by_dir[v->direction >> 1];
|
tile = v->tile + _tileoffs_by_dir[v->direction >> 1];
|
||||||
if (IsValidTile(tile) &&
|
if (IsValidTile(tile) &&
|
||||||
(r=GetTileTrackStatus(tile,4),(byte)(r+(r >> 8)) == 0x3F) &&
|
(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) &&
|
||||||
!CHANCE16(1,90)) {
|
!CHANCE16(1,90)) {
|
||||||
GetNewVehiclePos(v, &gp);
|
GetNewVehiclePos(v, &gp);
|
||||||
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void ChangeTileOwner_Dummy(uint tile, byte old_player, byte new_player)
|
||||||
/* not used */
|
/* not used */
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32 GetTileTrackStatus_Dummy(uint tile, int mode)
|
static uint32 GetTileTrackStatus_Dummy(uint tile, TransportType mode)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ void RunTileLoop();
|
||||||
|
|
||||||
uint GetPartialZ(int x, int y, int corners);
|
uint GetPartialZ(int x, int y, int corners);
|
||||||
uint GetSlopeZ(int x, int y);
|
uint GetSlopeZ(int x, int y);
|
||||||
uint32 GetTileTrackStatus(uint tile, int mode);
|
uint32 GetTileTrackStatus(uint tile, TransportType mode);
|
||||||
void GetAcceptedCargo(uint tile, AcceptedCargo *ac);
|
void GetAcceptedCargo(uint tile, AcceptedCargo *ac);
|
||||||
void ChangeTileOwner(uint tile, byte old_player, byte new_player);
|
void ChangeTileOwner(uint tile, byte old_player, byte new_player);
|
||||||
void AnimateTile(uint tile);
|
void AnimateTile(uint tile);
|
||||||
|
|
|
@ -820,7 +820,7 @@ static void ClickTile_Industry(uint tile)
|
||||||
ShowIndustryViewWindow(_map2[tile]);
|
ShowIndustryViewWindow(_map2[tile]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32 GetTileTrackStatus_Industry(uint tile, int mode)
|
static uint32 GetTileTrackStatus_Industry(uint tile, TransportType mode)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,7 @@ void DoClearSquare(uint tile)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 GetTileTrackStatus(uint tile, int mode)
|
uint32 GetTileTrackStatus(uint tile, TransportType mode)
|
||||||
{
|
{
|
||||||
return _tile_type_procs[GET_TILETYPE(tile)]->get_tile_track_status_proc(tile, mode);
|
return _tile_type_procs[GET_TILETYPE(tile)]->get_tile_track_status_proc(tile, mode);
|
||||||
}
|
}
|
||||||
|
|
13
pathfind.c
13
pathfind.c
|
@ -190,7 +190,7 @@ static const int8 _get_tunlen_inc[5] = { -16, 0, 16, 0, -16 };
|
||||||
/* Returns the end tile and the length of a tunnel. The length does not
|
/* Returns the end tile and the length of a tunnel. The length does not
|
||||||
* include the starting tile (entry), it does include the end tile (exit).
|
* include the starting tile (entry), it does include the end tile (exit).
|
||||||
*/
|
*/
|
||||||
FindLengthOfTunnelResult FindLengthOfTunnel(uint tile, int direction, byte type)
|
FindLengthOfTunnelResult FindLengthOfTunnel(uint tile, int direction)
|
||||||
{
|
{
|
||||||
FindLengthOfTunnelResult flotr;
|
FindLengthOfTunnelResult flotr;
|
||||||
int x,y;
|
int x,y;
|
||||||
|
@ -213,7 +213,8 @@ FindLengthOfTunnelResult FindLengthOfTunnel(uint tile, int direction, byte type)
|
||||||
|
|
||||||
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) &&
|
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) &&
|
||||||
(_map5[tile] & 0xF0) == 0 &&
|
(_map5[tile] & 0xF0) == 0 &&
|
||||||
((_map5[tile]>>1)&6) == type &&
|
//((_map5[tile]>>2)&3) == type && // This is
|
||||||
|
//not necesary to check, right?
|
||||||
((_map5[tile] & 3)^2) == direction &&
|
((_map5[tile] & 3)^2) == direction &&
|
||||||
GetSlopeZ(x+8, y+8) == z)
|
GetSlopeZ(x+8, y+8) == z)
|
||||||
break;
|
break;
|
||||||
|
@ -228,7 +229,7 @@ static const uint16 _tpfmode1_and[4] = { 0x1009, 0x16, 0x520, 0x2A00 };
|
||||||
static uint SkipToEndOfTunnel(TrackPathFinder *tpf, uint tile, int direction) {
|
static uint SkipToEndOfTunnel(TrackPathFinder *tpf, uint tile, int direction) {
|
||||||
FindLengthOfTunnelResult flotr;
|
FindLengthOfTunnelResult flotr;
|
||||||
TPFSetTileBit(tpf, tile, 14);
|
TPFSetTileBit(tpf, tile, 14);
|
||||||
flotr = FindLengthOfTunnel(tile, direction, tpf->tracktype);
|
flotr = FindLengthOfTunnel(tile, direction);
|
||||||
tpf->rd.cur_length += flotr.length;
|
tpf->rd.cur_length += flotr.length;
|
||||||
TPFSetTileBit(tpf, flotr.tile, 14);
|
TPFSetTileBit(tpf, flotr.tile, 14);
|
||||||
return flotr.tile;
|
return flotr.tile;
|
||||||
|
@ -601,7 +602,7 @@ restart:
|
||||||
/* We are not driving into the tunnel, or it
|
/* We are not driving into the tunnel, or it
|
||||||
* is an invalid tunnel */
|
* is an invalid tunnel */
|
||||||
goto popnext;
|
goto popnext;
|
||||||
flotr = FindLengthOfTunnel(tile, direction, tpf->tracktype);
|
flotr = FindLengthOfTunnel(tile, direction);
|
||||||
si.cur_length += flotr.length;
|
si.cur_length += flotr.length;
|
||||||
tile = flotr.tile;
|
tile = flotr.tile;
|
||||||
}
|
}
|
||||||
|
@ -619,7 +620,7 @@ restart:
|
||||||
|
|
||||||
// not a regular rail tile?
|
// not a regular rail tile?
|
||||||
if (!IS_TILETYPE(tile, MP_RAILWAY) || (bits = _map5[tile]) & 0xC0) {
|
if (!IS_TILETYPE(tile, MP_RAILWAY) || (bits = _map5[tile]) & 0xC0) {
|
||||||
bits = GetTileTrackStatus(tile, 0) & _tpfmode1_and[direction];
|
bits = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _tpfmode1_and[direction];
|
||||||
bits = (bits | (bits >> 8)) & 0x3F;
|
bits = (bits | (bits >> 8)) & 0x3F;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -711,7 +712,7 @@ popnext:
|
||||||
void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache)
|
void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache)
|
||||||
{
|
{
|
||||||
if (!_patches.new_pathfinding) {
|
if (!_patches.new_pathfinding) {
|
||||||
FollowTrack(tile, 0x3000, direction, enum_proc, NULL, data);
|
FollowTrack(tile, 0x3000 | TRANSPORT_RAIL, direction, enum_proc, NULL, data);
|
||||||
} else {
|
} else {
|
||||||
NewTrackPathFinder *tpf;
|
NewTrackPathFinder *tpf;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ typedef struct {
|
||||||
uint tile;
|
uint tile;
|
||||||
int length;
|
int length;
|
||||||
} FindLengthOfTunnelResult;
|
} FindLengthOfTunnelResult;
|
||||||
FindLengthOfTunnelResult FindLengthOfTunnel(uint tile, int direction, byte type);
|
FindLengthOfTunnelResult FindLengthOfTunnel(uint tile, int direction);
|
||||||
|
|
||||||
void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache);
|
void NewTrainPathfind(uint tile, byte direction, TPFEnumProc *enum_proc, void *data, byte *cache);
|
||||||
|
|
||||||
|
|
|
@ -1762,7 +1762,7 @@ bool UpdateSignalsOnSegment(uint tile, byte direction)
|
||||||
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
|
ssd.cur = ssd.presignal_exits = ssd.presignal_exits_free = 0;
|
||||||
ssd.has_presignal = false;
|
ssd.has_presignal = false;
|
||||||
|
|
||||||
FollowTrack(tile, 0xC000, direction, (TPFEnumProc*)SetSignalsEnumProc, SetSignalsAfterProc, &ssd);
|
FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, (TPFEnumProc*)SetSignalsEnumProc, SetSignalsAfterProc, &ssd);
|
||||||
ChangeSignalStates(&ssd);
|
ChangeSignalStates(&ssd);
|
||||||
|
|
||||||
// remember the result only for the first iteration.
|
// remember the result only for the first iteration.
|
||||||
|
@ -1933,11 +1933,11 @@ modify_me:;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint32 GetTileTrackStatus_Track(uint tile, int mode) {
|
static uint32 GetTileTrackStatus_Track(uint tile, TransportType mode) {
|
||||||
byte m5, a, b;
|
byte m5, a, b;
|
||||||
uint32 ret;
|
uint32 ret;
|
||||||
|
|
||||||
if (mode != 0)
|
if (mode != TRANSPORT_RAIL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
m5 = _map5[tile];
|
m5 = _map5[tile];
|
||||||
|
|
|
@ -145,7 +145,7 @@ static void GenericPlaceSignals(uint tile)
|
||||||
uint trackstat;
|
uint trackstat;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
trackstat = (byte)GetTileTrackStatus(tile,0);
|
trackstat = (byte)GetTileTrackStatus(tile, TRANSPORT_RAIL);
|
||||||
|
|
||||||
if ((trackstat & 0x30) == 0x30) {
|
if ((trackstat & 0x30) == 0x30) {
|
||||||
trackstat = (_tile_fract_coords.x <= _tile_fract_coords.y) ? 0x20 : 0x10;
|
trackstat = (_tile_fract_coords.x <= _tile_fract_coords.y) ? 0x20 : 0x10;
|
||||||
|
|
20
road_cmd.c
20
road_cmd.c
|
@ -6,6 +6,7 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
#include "table/directions.h"
|
||||||
|
|
||||||
/* When true, GetTrackStatus for roads will treat roads under reconstruction
|
/* When true, GetTrackStatus for roads will treat roads under reconstruction
|
||||||
* as normal roads instead of impassable. This is used when detecting whether
|
* as normal roads instead of impassable. This is used when detecting whether
|
||||||
|
@ -119,7 +120,7 @@ bool IsRoadDepotTile(TileIndex tile)
|
||||||
|
|
||||||
uint GetRoadBitsByTile(TileIndex tile)
|
uint GetRoadBitsByTile(TileIndex tile)
|
||||||
{
|
{
|
||||||
uint32 r = GetTileTrackStatus(tile, 2);
|
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
|
||||||
return (byte)(r | (r >> 8));
|
return (byte)(r | (r >> 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,18 +1024,20 @@ static const byte _road_trackbits[16] = {
|
||||||
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
|
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint32 GetTileTrackStatus_Road(uint tile, int mode) {
|
static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) {
|
||||||
if (mode == 0) {
|
if (mode == TRANSPORT_RAIL) {
|
||||||
if ((_map5[tile] & 0xF0) != 0x10)
|
if ((_map5[tile] & 0xF0) != 0x10)
|
||||||
return 0;
|
return 0;
|
||||||
return _map5[tile] & 8 ? 0x101 : 0x202;
|
return _map5[tile] & 8 ? 0x101 : 0x202;
|
||||||
} else if (mode == 2) {
|
} else if (mode == TRANSPORT_ROAD) {
|
||||||
byte b = _map5[tile];
|
byte b = _map5[tile];
|
||||||
if ((b & 0xF0) == 0) {
|
if ((b & 0xF0) == 0) {
|
||||||
|
/* Ordinary road */
|
||||||
if (!_road_special_gettrackstatus && (_map2[tile]&7) >= 6)
|
if (!_road_special_gettrackstatus && (_map2[tile]&7) >= 6)
|
||||||
return 0;
|
return 0;
|
||||||
return _road_trackbits[b&0xF] * 0x101;
|
return _road_trackbits[b&0xF] * 0x101;
|
||||||
} else if ((b&0xE0) == 0) {
|
} else if ((b&0xF0) == 0x10) {
|
||||||
|
/* Crossing */
|
||||||
uint32 r = 0x101;
|
uint32 r = 0x101;
|
||||||
if (b&8) r <<= 1;
|
if (b&8) r <<= 1;
|
||||||
|
|
||||||
|
@ -1042,6 +1045,13 @@ static uint32 GetTileTrackStatus_Road(uint tile, int mode) {
|
||||||
r *= 0x10001;
|
r *= 0x10001;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
} else if ((b&0xF0) == 0x20) {
|
||||||
|
/* Depot */
|
||||||
|
/* We reverse the dir because it points out of the
|
||||||
|
* exit, and we want to get in. Maybe we should return
|
||||||
|
* both dirs here? */
|
||||||
|
byte dir = _reverse_dir[b&3];
|
||||||
|
return 1 << _dir_to_straight_trackdir[dir];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -371,7 +371,7 @@ static int FindClosestRoadDepot(Vehicle *v)
|
||||||
|
|
||||||
/* search in all directions */
|
/* search in all directions */
|
||||||
for(i=0; i!=4; i++)
|
for(i=0; i!=4; i++)
|
||||||
FollowTrack(tile, 0x2002, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd);
|
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd);
|
||||||
|
|
||||||
if (rfdd.best_length == (uint)-1)
|
if (rfdd.best_length == (uint)-1)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -898,7 +898,7 @@ static bool FindRoadVehToOvertake(OvertakeData *od)
|
||||||
{
|
{
|
||||||
uint32 bits;
|
uint32 bits;
|
||||||
|
|
||||||
bits = GetTileTrackStatus(od->tile, 2)&0x3F;
|
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F;
|
||||||
|
|
||||||
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000))
|
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000))
|
||||||
return true;
|
return true;
|
||||||
|
@ -924,7 +924,7 @@ static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
|
||||||
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 )
|
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tt = (byte)(GetTileTrackStatus(v->tile, 2) & 0x3F);
|
tt = (byte)(GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F);
|
||||||
if ((tt & 3) == 0)
|
if ((tt & 3) == 0)
|
||||||
return;
|
return;
|
||||||
if ((tt & 0x3C) != 0)
|
if ((tt & 0x3C) != 0)
|
||||||
|
@ -1020,31 +1020,24 @@ static int RoadFindPathToDest(Vehicle *v, uint tile, int direction)
|
||||||
|
|
||||||
{
|
{
|
||||||
uint32 r;
|
uint32 r;
|
||||||
r = GetTileTrackStatus(tile, 2);
|
r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
|
||||||
signal = (uint16)(r >> 16);
|
signal = (uint16)(r >> 16);
|
||||||
bitmask = (uint16)r;
|
bitmask = (uint16)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_TILETYPE(tile, MP_STREET)) {
|
|
||||||
|
|
||||||
if ((_map5[tile]&0xF0) == 0x20 && v->owner == _map_owner[tile])
|
|
||||||
bitmask |= _road_veh_fp_ax_or[_map5[tile]&3];
|
|
||||||
|
|
||||||
} else if (IS_TILETYPE(tile, MP_STATION)) {
|
/* Most of the checks that used to be here, are now integrated into
|
||||||
if (_map_owner[tile] == OWNER_NONE || _map_owner[tile] == v->owner) {
|
* GetTileTrackStatus now. The only thing still remaining is the
|
||||||
Station *st = DEREF_STATION(_map2[tile]);
|
* owner check for stations and depots, since GetTileTrackStatus
|
||||||
byte val = _map5[tile];
|
* doesn't know about owner */
|
||||||
|
if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile]&0xF0) == 0x20 && v->owner != _map_owner[tile])
|
||||||
if (v->cargo_type != CT_PASSENGERS) {
|
/* Depot not owned by us */
|
||||||
if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stop_status&3))
|
bitmask = 0;
|
||||||
bitmask |= _road_veh_fp_ax_or[(val-0x43)&3];
|
if (IS_TILETYPE(tile, MP_STATION) && _map_owner[tile] != OWNER_NONE && _map_owner[tile] != v->owner)
|
||||||
} else {
|
/* Station not owned by us */
|
||||||
if (IS_BYTE_INSIDE(val, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stop_status&3))
|
bitmask = 0;
|
||||||
bitmask |= _road_veh_fp_ax_or[(val-0x47)&3];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* remove unreachable tracks */
|
||||||
bitmask &= _road_veh_fp_ax_and[direction];
|
bitmask &= _road_veh_fp_ax_and[direction];
|
||||||
if (bitmask == 0) {
|
if (bitmask == 0) {
|
||||||
// reverse
|
// reverse
|
||||||
|
@ -1096,7 +1089,7 @@ do_it:;
|
||||||
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a direction
|
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a direction
|
||||||
frd.maxtracklen = (uint)-1;
|
frd.maxtracklen = (uint)-1;
|
||||||
frd.mindist = (uint)-1;
|
frd.mindist = (uint)-1;
|
||||||
FollowTrack(tile, 0x3002, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd);
|
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd);
|
||||||
|
|
||||||
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) {
|
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) {
|
||||||
best_dist = frd.mindist;
|
best_dist = frd.mindist;
|
||||||
|
|
|
@ -15,7 +15,7 @@ static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
|
||||||
static const byte _ship_sometracks[4] = {0x19, 0x16, 0x25, 0x2A};
|
static const byte _ship_sometracks[4] = {0x19, 0x16, 0x25, 0x2A};
|
||||||
|
|
||||||
static byte GetTileShipTrackStatus(uint tile) {
|
static byte GetTileShipTrackStatus(uint tile) {
|
||||||
uint32 r = GetTileTrackStatus(tile, 4);
|
uint32 r = GetTileTrackStatus(tile, TRANSPORT_WATER);
|
||||||
return r | r >> 8;
|
return r | r >> 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,7 +492,7 @@ static uint FindShipTrack(Vehicle *v, uint tile, int dir, uint bits, uint skipti
|
||||||
pfs.best_bird_dist = (uint)-1;
|
pfs.best_bird_dist = (uint)-1;
|
||||||
pfs.best_length = (uint)-1;
|
pfs.best_length = (uint)-1;
|
||||||
|
|
||||||
FollowTrack(tile, 0x3804, _ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs);
|
FollowTrack(tile, 0x3800 | TRANSPORT_WATER, _ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs);
|
||||||
|
|
||||||
if (best_track >= 0) {
|
if (best_track >= 0) {
|
||||||
if (pfs.best_bird_dist != 0) {
|
if (pfs.best_bird_dist != 0) {
|
||||||
|
@ -569,7 +569,7 @@ static int ShipGetNewDirection(Vehicle *v, int x, int y)
|
||||||
|
|
||||||
static int GetAvailShipTracks(uint tile, int dir)
|
static int GetAvailShipTracks(uint tile, int dir)
|
||||||
{
|
{
|
||||||
uint32 r = GetTileTrackStatus(tile, 4);
|
uint32 r = GetTileTrackStatus(tile, TRANSPORT_WATER);
|
||||||
return (byte) ((r | r >> 8)) & _ship_sometracks[dir];
|
return (byte) ((r | r >> 8)) & _ship_sometracks[dir];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "airport.h"
|
#include "airport.h"
|
||||||
|
#include "table/directions.h"
|
||||||
|
|
||||||
// FIXME -- need to be embedded into Airport variable. Is dynamically
|
// FIXME -- need to be embedded into Airport variable. Is dynamically
|
||||||
// deducteable from graphics-tile array, so will not be needed
|
// deducteable from graphics-tile array, so will not be needed
|
||||||
|
@ -1837,21 +1838,34 @@ static void GetTileDesc_Station(uint tile, TileDesc *td)
|
||||||
|
|
||||||
static const byte _tile_track_status_rail[8] = { 1,2,1,2,1,2,1,2 };
|
static const byte _tile_track_status_rail[8] = { 1,2,1,2,1,2,1,2 };
|
||||||
|
|
||||||
static uint32 GetTileTrackStatus_Station(uint tile, int mode) {
|
static uint32 GetTileTrackStatus_Station(uint tile, TransportType mode) {
|
||||||
uint i = _map5[tile];
|
uint i = _map5[tile];
|
||||||
uint j = 0;
|
uint j = 0;
|
||||||
|
|
||||||
if (mode == 0) {
|
if (mode == TRANSPORT_RAIL) {
|
||||||
if (i < 8)
|
if (i < 8)
|
||||||
j = _tile_track_status_rail[i];
|
j = _tile_track_status_rail[i];
|
||||||
} else if (mode == 2) {
|
j += (j << 8);
|
||||||
// not needed
|
} else if (mode == TRANSPORT_ROAD) {
|
||||||
} else if (mode == 4) {
|
Station *st = DEREF_STATION(_map2[tile]);
|
||||||
// buoy
|
if ( (IS_BYTE_INSIDE(i, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stop_status&3)) ||
|
||||||
|
(IS_BYTE_INSIDE(i, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stop_status&3)) ) {
|
||||||
|
/* This is a bus/truck stop, and there is free space
|
||||||
|
* (or we allow queueing) */
|
||||||
|
|
||||||
|
/* We reverse the dir because it points out of the
|
||||||
|
* exit, and we want to get in. Maybe we should return
|
||||||
|
* both dirs here? */
|
||||||
|
byte dir = _reverse_dir[(i-0x43)&3];
|
||||||
|
j = 1 << _dir_to_straight_trackdir[dir];
|
||||||
|
}
|
||||||
|
} else if (mode == TRANSPORT_WATER) {
|
||||||
|
// buoy is coded as a station, it is always on open water
|
||||||
|
// (0x3F, all tracks available)
|
||||||
if (i == 0x52) j = 0x3F;
|
if (i == 0x52) j = 0x3F;
|
||||||
|
j += (j << 8);
|
||||||
}
|
}
|
||||||
|
return j;
|
||||||
return j + (j << 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TileLoop_Station(uint tile)
|
static void TileLoop_Station(uint tile)
|
||||||
|
|
|
@ -319,7 +319,7 @@ static void GetTileDesc_Town(uint tile, TileDesc *td)
|
||||||
td->owner = OWNER_TOWN;
|
td->owner = OWNER_TOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32 GetTileTrackStatus_Town(uint tile, int mode)
|
static uint32 GetTileTrackStatus_Town(uint tile, TransportType mode)
|
||||||
{
|
{
|
||||||
/* not used */
|
/* not used */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -540,7 +540,7 @@ static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
|
||||||
|
|
||||||
// Reached a tunnel? Then continue at the other side of it.
|
// Reached a tunnel? Then continue at the other side of it.
|
||||||
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && (_map5[tile]&~3)==4) {
|
if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && (_map5[tile]&~3)==4) {
|
||||||
FindLengthOfTunnelResult flotr = FindLengthOfTunnel(tile, _map5[tile]&3, 2);
|
FindLengthOfTunnelResult flotr = FindLengthOfTunnel(tile, _map5[tile]&3);
|
||||||
*tile_ptr = flotr.tile;
|
*tile_ptr = flotr.tile;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2035,7 +2035,7 @@ static void TrainController(Vehicle *v)
|
||||||
|
|
||||||
/* Get the status of the tracks in the new tile and mask
|
/* Get the status of the tracks in the new tile and mask
|
||||||
* away the bits that aren't reachable. */
|
* away the bits that aren't reachable. */
|
||||||
ts = GetTileTrackStatus(gp.new_tile, 0) & _reachable_tracks[dir >> 1];
|
ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL) & _reachable_tracks[dir >> 1];
|
||||||
|
|
||||||
/* Combine the from & to directions.
|
/* Combine the from & to directions.
|
||||||
* Now, the lower byte contains the track status, and the byte at bit 16 contains
|
* Now, the lower byte contains the track status, and the byte at bit 16 contains
|
||||||
|
@ -2347,7 +2347,7 @@ static void TrainCheckIfLineEnds(Vehicle *v)
|
||||||
/* Calculate next tile */
|
/* Calculate next tile */
|
||||||
tile += _tileoffs_by_dir[t];
|
tile += _tileoffs_by_dir[t];
|
||||||
// determine the track status on the next tile.
|
// determine the track status on the next tile.
|
||||||
ts = GetTileTrackStatus(tile, 0) & _reachable_tracks[t];
|
ts = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _reachable_tracks[t];
|
||||||
|
|
||||||
/* Calc position within the current tile ?? */
|
/* Calc position within the current tile ?? */
|
||||||
x = v->x_pos & 0xF;
|
x = v->x_pos & 0xF;
|
||||||
|
|
35
ttd.h
35
ttd.h
|
@ -86,6 +86,20 @@ enum MapTileTypes {
|
||||||
MP_UNMOVABLE
|
MP_UNMOVABLE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum TransportTypes {
|
||||||
|
/* These constants are for now linked to the representation of bridges
|
||||||
|
* and tunnels, so they can be used by GetTileTrackStatus_TunnelBridge
|
||||||
|
* to compare against the map5 array. In an ideal world, these
|
||||||
|
* constants would be used everywhere when accessing tunnels and
|
||||||
|
* bridges. For now, you should just not change the values for road
|
||||||
|
* and rail.
|
||||||
|
*/
|
||||||
|
TRANSPORT_RAIL = 0,
|
||||||
|
TRANSPORT_ROAD = 1,
|
||||||
|
TRANSPORT_WATER,
|
||||||
|
TRANSPORT_MAX
|
||||||
|
} TransportType;
|
||||||
|
|
||||||
typedef struct TileInfo {
|
typedef struct TileInfo {
|
||||||
uint x;
|
uint x;
|
||||||
uint y;
|
uint y;
|
||||||
|
@ -231,7 +245,26 @@ typedef uint GetSlopeZProc(TileInfo *ti);
|
||||||
typedef int32 ClearTileProc(uint tile, byte flags);
|
typedef int32 ClearTileProc(uint tile, byte flags);
|
||||||
typedef void GetAcceptedCargoProc(uint tile, AcceptedCargo *res);
|
typedef void GetAcceptedCargoProc(uint tile, AcceptedCargo *res);
|
||||||
typedef void GetTileDescProc(uint tile, TileDesc *td);
|
typedef void GetTileDescProc(uint tile, TileDesc *td);
|
||||||
typedef uint32 GetTileTrackStatusProc(uint tile, int mode);
|
/* GetTileTrackStatusProcs return a value that contains the possible tracks
|
||||||
|
* that can be taken on a given tile by a given transport. The return value is
|
||||||
|
* composed as follows: 0xaabbccdd. ccdd and aabb are bitmasks of trackdirs,
|
||||||
|
* where bit n corresponds to trackdir n. ccdd are the trackdirs that are
|
||||||
|
* present in the tile (1==present, 0==not present), aabb is the signal
|
||||||
|
* status, if applicable (0==green/no signal, 1==red, note that this is
|
||||||
|
* reversed from map3/2[tile] for railway signals).
|
||||||
|
*
|
||||||
|
* The result (let's call it ts) is often used as follows:
|
||||||
|
* tracks = (byte)(ts | ts >>8)
|
||||||
|
* This effectively converts the present part of the result (ccdd) to a
|
||||||
|
* track bitmask, which disregards directions. Normally, this is the same as just
|
||||||
|
* doing (byte)ts I think, although I am not really sure
|
||||||
|
*
|
||||||
|
* A trackdir is combination of a track and a dir, where the lower three bits
|
||||||
|
* are a track, the fourth bit is the direction. these give 12 (or 14)
|
||||||
|
* possible options: 0-5 and 8-13, so we need 14 bits for a trackdir bitmask
|
||||||
|
* above.
|
||||||
|
*/
|
||||||
|
typedef uint32 GetTileTrackStatusProc(uint tile, TransportType mode);
|
||||||
typedef void GetProducedCargoProc(uint tile, byte *b);
|
typedef void GetProducedCargoProc(uint tile, byte *b);
|
||||||
typedef void ClickTileProc(uint tile);
|
typedef void ClickTileProc(uint tile);
|
||||||
typedef void AnimateTileProc(uint tile);
|
typedef void AnimateTileProc(uint tile);
|
||||||
|
|
|
@ -1296,34 +1296,49 @@ static void ClickTile_TunnelBridge(uint tile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint32 GetTileTrackStatus_TunnelBridge(uint tile, int mode)
|
static uint32 GetTileTrackStatus_TunnelBridge(uint tile, TransportType mode)
|
||||||
{
|
{
|
||||||
uint32 result;
|
uint32 result;
|
||||||
byte t, m5 = _map5[tile];
|
byte m5 = _map5[tile];
|
||||||
|
|
||||||
if ((m5 & 0xF0) == 0) {
|
if ((m5 & 0xF0) == 0) {
|
||||||
if (((m5 & 0xC) >> 1) == mode) { /* XXX: possible problem when switching mode constants */
|
/* This is a tunnel */
|
||||||
|
if (((m5 & 0xC) >> 2) == mode) {
|
||||||
|
/* Tranport in the tunnel is compatible */
|
||||||
return m5&1 ? 0x202 : 0x101;
|
return m5&1 ? 0x202 : 0x101;
|
||||||
}
|
}
|
||||||
} else if (m5 & 0x80) {
|
} else if (m5 & 0x80) {
|
||||||
|
/* This is a bridge */
|
||||||
result = 0;
|
result = 0;
|
||||||
if ((m5 & 6) == mode) {
|
if (((m5 & 0x6) >> 1) == mode) {
|
||||||
|
/* Transport over the bridge is compatible */
|
||||||
result = m5&1 ? 0x202 : 0x101;
|
result = m5&1 ? 0x202 : 0x101;
|
||||||
}
|
}
|
||||||
if (m5 & 0x40) {
|
if (m5 & 0x40) {
|
||||||
t = m5;
|
/* Bridge middle part */
|
||||||
if (!(t & 0x20)) {
|
if (!(m5 & 0x20)) {
|
||||||
if ((t &= 0x18) != 8)
|
/* Clear ground or water underneath */
|
||||||
|
if ((m5 &= 0x18) != 8)
|
||||||
|
/* Clear ground */
|
||||||
|
return result;
|
||||||
|
else
|
||||||
|
if (mode != TRANSPORT_WATER)
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
/* Transport underneath */
|
||||||
|
if ((m5 & 0x18) >> 3 != mode)
|
||||||
|
/* Incompatible transport underneath */
|
||||||
return result;
|
return result;
|
||||||
t = (t&0xE7) | 0x30;
|
|
||||||
}
|
}
|
||||||
|
/* If we've not returned yet, there is a compatible
|
||||||
if ((t & 0x18) >> 2 != mode)
|
* transport or water beneath, so we can add it to
|
||||||
return result;
|
* result */
|
||||||
|
/* Why is this xor'd ? Can't it just be or'd? */
|
||||||
result ^= m5&1 ? 0x101 : 0x202;
|
result ^= m5&1 ? 0x101 : 0x202;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
} else {
|
||||||
|
assert(0); /* This should never occur */
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -600,12 +600,12 @@ void TileLoop_Water(uint tile)
|
||||||
static const byte _coast_tracks[16] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
|
static const byte _coast_tracks[16] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};
|
||||||
static const byte _shipdepot_tracks[4] = {1,1,2,2};
|
static const byte _shipdepot_tracks[4] = {1,1,2,2};
|
||||||
static const byte _shiplift_tracks[12] = {1,2,1,2,1,2,1,2,1,2,1,2};
|
static const byte _shiplift_tracks[12] = {1,2,1,2,1,2,1,2,1,2,1,2};
|
||||||
static uint32 GetTileTrackStatus_Water(uint tile, int mode)
|
static uint32 GetTileTrackStatus_Water(uint tile, TransportType mode)
|
||||||
{
|
{
|
||||||
uint m5;
|
uint m5;
|
||||||
uint b;
|
uint b;
|
||||||
|
|
||||||
if (mode != 4)
|
if (mode != TRANSPORT_WATER)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
m5 = _map5[tile];
|
m5 = _map5[tile];
|
||||||
|
|
Loading…
Reference in New Issue