diff options
author | matthijs <matthijs@openttd.org> | 2005-05-02 23:59:11 +0000 |
---|---|---|
committer | matthijs <matthijs@openttd.org> | 2005-05-02 23:59:11 +0000 |
commit | 6eb094c72622b39bceff8293c3446e57d21c62f0 (patch) | |
tree | cad8daa1ee5542d4e8fefcbf2e2825e3f35fdb47 | |
parent | 2ab5eee78b495ec73049c8446a0ed37ab4ff0920 (diff) | |
download | openttd-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.
-rw-r--r-- | aircraft_cmd.c | 1 | ||||
-rw-r--r-- | misc.c | 1 | ||||
-rw-r--r-- | network_server.c | 3 | ||||
-rw-r--r-- | order_cmd.c | 1 | ||||
-rw-r--r-- | order_gui.c | 2 | ||||
-rw-r--r-- | roadveh_cmd.c | 6 | ||||
-rw-r--r-- | ship_cmd.c | 10 | ||||
-rw-r--r-- | train_cmd.c | 10 | ||||
-rw-r--r-- | ttd.h | 9 | ||||
-rw-r--r-- | vehicle.c | 33 | ||||
-rw-r--r-- | vehicle.h | 100 | ||||
-rw-r--r-- | vehicle_gui.c | 2 | ||||
-rw-r--r-- | vehicle_gui.h | 10 | ||||
-rw-r--r-- | water_cmd.c | 1 |
14 files changed, 123 insertions, 66 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c index f16d4a75b..025fc2343 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -13,6 +13,7 @@ #include "sound.h" #include "player.h" #include "airport.h" +#include "vehicle_gui.h" static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport); static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport); @@ -12,6 +12,7 @@ #include "network_data.h" #include "network_server.h" #include "engine.h" +#include "vehicle_gui.h" extern void StartupEconomy(void); extern void InitNewsItemStructs(void); diff --git a/network_server.c b/network_server.c index cc01c7dc5..6aa8209b3 100644 --- a/network_server.c +++ b/network_server.c @@ -1291,6 +1291,9 @@ void NetworkPopulateCompanyInfo(void) case VEH_Ship: _network_player_info[v->owner].num_vehicle[4]++; break; + case VEH_Special: + case VEH_Disaster: + break; } } diff --git a/order_cmd.c b/order_cmd.c index 5bdabc899..ee82c1e3d 100644 --- a/order_cmd.c +++ b/order_cmd.c @@ -10,6 +10,7 @@ #include "player.h" #include "news.h" #include "saveload.h" +#include "vehicle_gui.h" enum { /* Max orders: 64000 (64 * 1000) */ diff --git a/order_gui.c b/order_gui.c index 0a92caa84..9ec762475 100644 --- a/order_gui.c +++ b/order_gui.c @@ -118,6 +118,8 @@ static void DrawOrdersWindow(Window *w) case VEH_Train: s = STR_880E_GO_TO_TRAIN_DEPOT; break; case VEH_Road: s = STR_9038_GO_TO_ROADVEH_DEPOT; break; case VEH_Ship: s = STR_GO_TO_SHIP_DEPOT; break; + default: + break; } } if (v->type == VEH_Train && order->flags & OF_NON_STOP) diff --git a/roadveh_cmd.c b/roadveh_cmd.c index b349bd8cc..670af9f6a 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -15,6 +15,7 @@ #include "player.h" #include "sound.h" #include "depot.h" +#include "vehicle_gui.h" void ShowRoadVehViewWindow(Vehicle *v); @@ -316,7 +317,7 @@ static Depot *FindClosestRoadDepot(Vehicle *v) * v->direction won't contain anything usefule than */ trackdir = _dir_to_diag_trackdir[GetRoadStationDir(tile)]; else - trackdir = _dir_to_diag_trackdir[(v->direction>>1)&3]; + trackdir = GetVehicleTrackdir(v); ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner); if (ftd.best_bird_dist == 0) @@ -1160,7 +1161,8 @@ found_best_track:; static uint RoadFindPathToStation(const Vehicle *v, TileIndex tile) { NPFFindStationOrTileData fstd; - byte trackdir = _dir_to_diag_trackdir[(v->direction >> 1) & 3]; + byte trackdir = GetVehicleTrackdir(v); + assert(trackdir != 0xFF); fstd.dest_coords = tile; fstd.station_index = -1; // indicates that the destination is a tile, not a station diff --git a/ship_cmd.c b/ship_cmd.c index 5e5c5c022..75ef25736 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -73,7 +73,7 @@ static Depot *FindClosestShipDepot(Vehicle *v) if (_patches.new_pathfinding_all) { NPFFoundTargetData ftd; - byte trackdir = _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction]; + byte trackdir = GetVehicleTrackdir(v); ftd = NPFRouteToDepotTrialError(v->tile, trackdir, TRANSPORT_WATER, v->owner); if (ftd.best_bird_dist == 0) best_depot = GetDepotByTile(ftd.node.tile); /* Found target */ @@ -567,14 +567,12 @@ static int ChooseShipTrack(Vehicle *v, uint tile, int enterdir, uint tracks) NPFFindStationOrTileData fstd; NPFFoundTargetData ftd; uint src_tile = TILE_ADD(tile, TileOffsByDir(_reverse_dir[enterdir])); - byte track = FIND_FIRST_BIT(v->u.ship.state); - assert (KILL_FIRST_BIT(v->u.ship.state) == 0); /* Check that only one bit is set in state */ - assert (v->u.ship.state != 0x80); /* Check that we are not in a depot */ - assert (track < 6); + byte trackdir = GetVehicleTrackdir(v); + assert (trackdir != 0xFF); /* Check that we are not in a depot */ NPFFillWithOrderData(&fstd, v); - ftd = NPFRouteToStationOrTile(src_tile, _track_direction_to_trackdir[track][v->direction], &fstd, TRANSPORT_WATER, v->owner); + ftd = NPFRouteToStationOrTile(src_tile, trackdir, &fstd, TRANSPORT_WATER, v->owner); if (ftd.best_trackdir != 0xff) /* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains diff --git a/train_cmd.c b/train_cmd.c index 844d09153..ebbb129ef 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -16,6 +16,7 @@ #include "sound.h" #include "depot.h" #include "waypoint.h" +#include "vehicle_gui.h" #define is_firsthead_sprite(spritenum) \ (is_custom_sprite(spritenum) \ @@ -1317,7 +1318,8 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v) if (_patches.new_pathfinding_all) { NPFFoundTargetData ftd; - byte trackdir = _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction]; + byte trackdir = GetVehicleTrackdir(v); + assert (trackdir != 0xFF); ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_RAIL, v->owner); if (ftd.best_bird_dist == 0) { /* Found target */ @@ -1668,7 +1670,7 @@ static byte ChooseTrainTrack(Vehicle *v, uint tile, int enterdir, byte trackbits NPFFillWithOrderData(&fstd, v); /* The enterdir for the new tile, is the exitdir for the old tile */ - trackdir = _track_exitdir_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][enterdir]; + trackdir = GetVehicleTrackdir(v); assert(trackdir != 0xff); ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner); @@ -1804,8 +1806,8 @@ static bool CheckReverseTrain(Vehicle *v) NPFFillWithOrderData(&fstd, v); - trackdir = _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.rail.track)][v->direction]; - trackdir_rev = REVERSE_TRACKDIR(_track_direction_to_trackdir[FIND_FIRST_BIT(last->u.rail.track)][last->direction]); + trackdir = GetVehicleTrackdir(v); + trackdir_rev = REVERSE_TRACKDIR(GetVehicleTrackdir(v)); assert(trackdir != 0xff); assert(trackdir_rev != 0xff); @@ -25,6 +25,15 @@ typedef struct Pair { int b; } Pair; +/** + * Is used as a general sortable struct (using qsort and friends). Is used for + * sorting vehicles and stations at the moment + */ +typedef struct SortStruct { + uint32 index; + byte owner; +} SortStruct; + typedef struct YearMonthDay { int year, month, day; } YearMonthDay; @@ -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}, }; - - @@ -2,9 +2,49 @@ #define VEHICLE_H #include "pool.h" -#include "vehicle_gui.h" #include "order.h" +typedef enum VehicleTypes{ + VEH_Train = 0x10, + VEH_Road = 0x11, + VEH_Ship = 0x12, + VEH_Aircraft = 0x13, + VEH_Special = 0x14, + VEH_Disaster = 0x15, +} VehicleType; + +enum VehStatus { + VS_HIDDEN = 1, + VS_STOPPED = 2, + VS_UNCLICKABLE = 4, + VS_DEFPAL = 0x8, + VS_TRAIN_SLOWING = 0x10, + VS_DISASTER = 0x20, + VS_AIRCRAFT_BROKEN = 0x40, + VS_CRASHED = 0x80, +}; + +// 1 and 3 do not appear to be used +typedef enum TrainSubtypes { + TS_Front_Engine = 0, + TS_Not_First = 2, + TS_Free_Car = 4, +} TrainSubtype; + +/* Effect vehicle types */ +typedef enum EffectVehicle { + EV_CHIMNEY_SMOKE = 0, + EV_STEAM_SMOKE = 1, + EV_DIESEL_SMOKE = 2, + EV_ELECTRIC_SPARK = 3, + EV_SMOKE = 4, + EV_EXPLOSION_LARGE = 5, + EV_BREAKDOWN_SMOKE = 6, + EV_EXPLOSION_SMALL = 7, + EV_BULLDOZER = 8, + EV_BUBBLE = 9 +} EffectVehicle; + typedef struct VehicleRail { uint16 last_speed; // NOSAVE: only used in UI uint16 crash_anim_pos; @@ -91,8 +131,8 @@ struct WorldSprite { }; struct Vehicle { - byte type; // type, ie roadven,train,ship,aircraft,special - byte subtype; // subtype (for trains, 0 == loco, 4 wagon ??) + VehicleType type; // type, ie roadven,train,ship,aircraft,special + byte subtype; // subtype (Filled with values from EffectVehicles or TrainSubTypes)(Filled with values from EffectVehicles or TrainSubTypes) uint16 index; // NOSAVE: Index in vehicle array @@ -199,47 +239,6 @@ struct Vehicle { #define is_custom_firsthead_sprite(x) (x == 0xfd) #define is_custom_secondhead_sprite(x) (x == 0xfe) -enum { - VEH_Train = 0x10, - VEH_Road = 0x11, - VEH_Ship = 0x12, - VEH_Aircraft = 0x13, - VEH_Special = 0x14, - VEH_Disaster = 0x15, -}; - -enum VehStatus { - VS_HIDDEN = 1, - VS_STOPPED = 2, - VS_UNCLICKABLE = 4, - VS_DEFPAL = 0x8, - VS_TRAIN_SLOWING = 0x10, - VS_DISASTER = 0x20, - VS_AIRCRAFT_BROKEN = 0x40, - VS_CRASHED = 0x80, -}; - -// 1 and 3 do not appear to be used -enum TrainSubtype { - TS_Front_Engine = 0, - TS_Not_First = 2, - TS_Free_Car = 4, -}; - -/* Effect vehicle types */ -typedef enum EffectVehicle { - EV_CHIMNEY_SMOKE = 0, - EV_STEAM_SMOKE = 1, - EV_DIESEL_SMOKE = 2, - EV_ELECTRIC_SPARK = 3, - EV_SMOKE = 4, - EV_EXPLOSION_LARGE = 5, - EV_BREAKDOWN_SMOKE = 6, - EV_EXPLOSION_SMALL = 7, - EV_BULLDOZER = 8, - EV_BUBBLE = 9 -} EffectVehicle; - typedef void VehicleTickProc(Vehicle *v); typedef void *VehicleFromPosProc(Vehicle *v, void *data); @@ -320,6 +319,19 @@ typedef struct GetNewVehiclePosResult { uint new_tile; } GetNewVehiclePosResult; +/** + * Returns the Trackdir on which the vehicle is currently located. + * Works for trains and ships. + * Currently works only sortof for road vehicles, since they have a fuzzy + * concept of being "on" a trackdir. Dunno really what it returns for a road + * vehicle that is halfway a tile, never really understood that part. For road + * vehicles that are at the beginning or end of the tile, should just return + * the diagonal trackdir on which they are driving. I _think_. + * For other vehicles types, or vehicles with no clear trackdir (such as those + * in depots), returns 0xFF. + */ +byte GetVehicleTrackdir(const Vehicle* v); + /* returns true if staying in the same tile */ bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp); byte GetDirectionTowards(Vehicle *v, int x, int y); diff --git a/vehicle_gui.c b/vehicle_gui.c index 5832498e8..4d6d07420 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -73,7 +73,7 @@ void ResortVehicleLists(void) } } -void BuildVehicleList(vehiclelist_d *vl, int type, int owner, int station) +void BuildVehicleList(vehiclelist_d *vl, VehicleType type, int owner, int station) { int subtype = (type != VEH_Aircraft) ? TS_Front_Engine : 2; int n = 0; diff --git a/vehicle_gui.h b/vehicle_gui.h index 487653b88..efbd458fd 100644 --- a/vehicle_gui.h +++ b/vehicle_gui.h @@ -1,6 +1,8 @@ #ifndef VEHICLE_GUI_H #define VEHICLE_GUI_H +#include "vehicle.h" + struct vehiclelist_d; void DrawVehicleProfitButton(Vehicle *v, int x, int y); @@ -10,16 +12,10 @@ void InitializeVehiclesGuiList(void); void RebuildVehicleLists(void); void ResortVehicleLists(void); -void BuildVehicleList(struct vehiclelist_d *vl, int type, int owner, int station); +void BuildVehicleList(struct vehiclelist_d *vl, VehicleType type, int owner, int station); void SortVehicleList(struct vehiclelist_d *vl); -typedef struct SortStruct { // store owner through sorting process - uint32 index; - byte owner; -} SortStruct; - int CDECL GeneralOwnerSorter(const void *a, const void *b); -void VehicleSorter(SortStruct *firstelement, uint32 n, uint16 size); VARDEF uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names VARDEF uint32 _last_vehicle_idx; // cached index to hopefully speed up name-sorting VARDEF bool _internal_sort_order; // descending/ascending diff --git a/water_cmd.c b/water_cmd.c index 6a55e131e..a3c8fcd3f 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -11,6 +11,7 @@ #include "news.h" #include "sound.h" #include "depot.h" +#include "vehicle_gui.h" static void FloodVehicle(Vehicle *v); |