summaryrefslogtreecommitdiff
path: root/vehicle.c
diff options
context:
space:
mode:
authormatthijs <matthijs@openttd.org>2005-05-02 23:59:11 +0000
committermatthijs <matthijs@openttd.org>2005-05-02 23:59:11 +0000
commit6eb094c72622b39bceff8293c3446e57d21c62f0 (patch)
treecad8daa1ee5542d4e8fefcbf2e2825e3f35fdb47 /vehicle.c
parent2ab5eee78b495ec73049c8446a0ed37ab4ff0920 (diff)
downloadopenttd-6eb094c72622b39bceff8293c3446e57d21c62f0.tar.xz
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
- Add: GetVehicleTrackdir() helper function. - Codechange: Moved SortStruct from vehicle_gui.h to ttd.h, so the dependency from vehicle.h on vehicle_gui.h could be removed. - Codechange: Typedeffed the VehicleTypes struct so it can be used as the type for Vehicle.type instead of "byte". - Codechange: Removed prototype for VehicleSorter(), which had no implementation anymore and was never called.
Diffstat (limited to 'vehicle.c')
-rw-r--r--vehicle.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/vehicle.c b/vehicle.c
index e5ad39534..03da2fdbe 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -15,6 +15,8 @@
#include "engine.h"
#include "sound.h"
#include "debug.h"
+#include "npf.h"
+#include "vehicle_gui.h"
#define INVALID_COORD (-0x8000)
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0)))
@@ -1707,6 +1709,35 @@ byte GetDirectionTowards(Vehicle *v, int x, int y)
return (dir+((dirdiff&7)<5?1:-1)) & 7;
}
+byte GetVehicleTrackdir(const Vehicle* v)
+{
+ switch(v->type)
+ {
+ case VEH_Train:
+ if (v->u.rail.track == 0x80)
+ return 0xFF; /* Train in depot */
+ else if (v->u.rail.track == 0x40)
+ /* train in tunnel, so just use his direction and assume a diagonal track */
+ return _dir_to_diag_trackdir[(v->direction>>1)&3];
+ else
+ return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction];
+ case VEH_Ship:
+ if (v->u.ship.state == 0x80)
+ return 0xFF; /* Ship in depot */
+ else
+ return _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction];
+ case VEH_Road:
+ if (v->u.road.state == 254)
+ return 0xFF; /* Road vehicle in depot */
+ else
+ return _dir_to_diag_trackdir[(v->direction>>1)&3];
+ case VEH_Aircraft:
+ case VEH_Special:
+ case VEH_Disaster:
+ default:
+ return 0xFF;
+ }
+}
/* Return value has bit 0x2 set, when the vehicle enters a station. Then,
* result << 8 contains the id of the station entered. If the return value has
* bit 0x8 set, the vehicle could not and did not enter the tile. Are there
@@ -2076,5 +2107,3 @@ static void Load_VEHS(void)
const ChunkHandler _veh_chunk_handlers[] = {
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST},
};
-
-