# HG changeset patch # User rubidium # Date 1188424148 0 # Node ID 881998b115c2cd4f38ac23f3bbd3185b6c07d3cf # Parent c7b966f7592e4de0a303a3520d3bae32cc71eb48 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot. diff -r c7b966f7592e -r 881998b115c2 src/ai/default/default.cpp --- a/src/ai/default/default.cpp Wed Aug 29 21:30:03 2007 +0000 +++ b/src/ai/default/default.cpp Wed Aug 29 21:49:08 2007 +0000 @@ -338,7 +338,7 @@ BackuppedOrders orderbak[1]; EngineID veh; - if (!IsRoadVehInDepotStopped(v)) { + if (!v->IsStoppedInDepot()) { AiHandleGotoDepot(p, CMD_SEND_ROADVEH_TO_DEPOT); return; } @@ -367,7 +367,7 @@ BackuppedOrders orderbak[1]; EngineID veh; - if (!IsAircraftInHangarStopped(v)) { + if (!v->IsStoppedInDepot()) { AiHandleGotoDepot(p, CMD_SEND_AIRCRAFT_TO_HANGAR); return; } @@ -3578,7 +3578,7 @@ DoCommand(v->tile, v->index, 1, DC_EXEC, CMD_SELL_RAIL_WAGON); } else if (v->type == VEH_ROAD) { - if (!IsRoadVehInDepotStopped(v)) { + if (!v->IsStoppedInDepot()) { if (v->current_order.type != OT_GOTO_DEPOT) DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT); goto going_to_depot; @@ -3586,7 +3586,7 @@ DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH); } else if (v->type == VEH_AIRCRAFT) { - if (!IsAircraftInHangarStopped(v)) { + if (!v->IsStoppedInDepot()) { if (v->current_order.type != OT_GOTO_DEPOT) DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); goto going_to_depot; diff -r c7b966f7592e -r 881998b115c2 src/aircraft.h --- a/src/aircraft.h Wed Aug 29 21:30:03 2007 +0000 +++ b/src/aircraft.h Wed Aug 29 21:49:08 2007 +0000 @@ -33,25 +33,6 @@ return v->subtype <= AIR_AIRCRAFT; } -/** Check if this aircraft is in a hangar - * @param v vehicle to check - * @return true if in hangar - */ -static inline bool IsAircraftInHangar(const Vehicle *v) -{ - assert(v->type == VEH_AIRCRAFT); - return v->vehstatus & VS_HIDDEN && IsHangarTile(v->tile); -} - -/** Check if this aircraft is in a hangar and stopped - * @param v vehicle to check - * @return true if in hangar and stopped - */ -static inline bool IsAircraftInHangarStopped(const Vehicle *v) -{ - return IsAircraftInHangar(v) && v->vehstatus & VS_STOPPED; -} - /** Checks if an aircraft is buildable at the tile in question * @param engine The engine to test * @param tile The tile where the hangar is @@ -133,6 +114,7 @@ int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; } Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; } + bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); } void Tick(); }; diff -r c7b966f7592e -r 881998b115c2 src/aircraft_cmd.cpp --- a/src/aircraft_cmd.cpp Wed Aug 29 21:30:03 2007 +0000 +++ b/src/aircraft_cmd.cpp Wed Aug 29 21:49:08 2007 +0000 @@ -485,7 +485,7 @@ Vehicle *v = GetVehicle(p1); if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; - if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); + if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); @@ -526,7 +526,7 @@ } if (flags & DC_EXEC) { - if (IsAircraftInHangarStopped(v)) { + if (v->IsStoppedInDepot()) { DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN); } @@ -560,7 +560,7 @@ Vehicle *v = GetVehicle(p1); - if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner) || IsAircraftInHangar(v)) return CMD_ERROR; + if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner) || v->IsInDepot()) return CMD_ERROR; if (v->current_order.type == OT_GOTO_DEPOT && !(p2 & DEPOT_LOCATE_HANGAR)) { if (!!(p2 & DEPOT_SERVICE) == HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT)) { @@ -634,7 +634,7 @@ Vehicle *v = GetVehicle(p1); if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; - if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); + if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); /* Check cargo */ CargoID new_cid = GB(p2, 0, 8); @@ -706,7 +706,7 @@ if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; - if (IsAircraftInHangar(v)) { + if (v->IsInDepot()) { VehicleServiceInDepot(v); return; } diff -r c7b966f7592e -r 881998b115c2 src/group_gui.cpp --- a/src/group_gui.cpp Wed Aug 29 21:30:03 2007 +0000 +++ b/src/group_gui.cpp Wed Aug 29 21:49:08 2007 +0000 @@ -458,7 +458,7 @@ DrawVehicleProfitButton(v, x, y2 + 13); SetDParam(0, v->unitnumber); - DrawString(x, y2 + 2, IsVehicleInDepot(v) ? STR_021F : (v->age > v->max_age - 366 ? STR_00E3 : STR_00E2), 0); + DrawString(x, y2 + 2, v->IsInDepot() ? STR_021F : (v->age > v->max_age - 366 ? STR_00E3 : STR_00E2), 0); if (w->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_BIG2) DrawSmallOrderList(v, x + 138, y2); diff -r c7b966f7592e -r 881998b115c2 src/roadveh.h --- a/src/roadveh.h Wed Aug 29 21:30:03 2007 +0000 +++ b/src/roadveh.h Wed Aug 29 21:49:08 2007 +0000 @@ -45,17 +45,6 @@ } -static inline bool IsRoadVehInDepot(const Vehicle *v) -{ - assert(v->type == VEH_ROAD); - return v->u.road.state == 254; -} - -static inline bool IsRoadVehInDepotStopped(const Vehicle *v) -{ - return IsRoadVehInDepot(v) && v->vehstatus & VS_STOPPED; -} - void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2); @@ -85,6 +74,7 @@ int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; } int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; } Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running; } + bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; } void Tick(); }; diff -r c7b966f7592e -r 881998b115c2 src/roadveh_cmd.cpp --- a/src/roadveh_cmd.cpp Wed Aug 29 21:30:03 2007 +0000 +++ b/src/roadveh_cmd.cpp Wed Aug 29 21:49:08 2007 +0000 @@ -304,7 +304,7 @@ } if (flags & DC_EXEC) { - if (IsRoadVehInDepotStopped(v)) { + if (v->IsStoppedInDepot()) { DeleteVehicleNews(p1, STR_9016_ROAD_VEHICLE_IS_WAITING); } @@ -469,7 +469,7 @@ if (v->vehstatus & VS_CRASHED) return CMD_ERROR; - if (IsRoadVehInDepot(v)) return CMD_ERROR; + if (v->IsInDepot()) return CMD_ERROR; /* If the current orders are already goto-depot */ if (v->current_order.type == OT_GOTO_DEPOT) { @@ -538,7 +538,7 @@ v->breakdown_ctr != 0 || v->u.road.overtaking != 0 || v->u.road.state == RVSB_WORMHOLE || - IsRoadVehInDepot(v) || + v->IsInDepot() || v->cur_speed < 5) { return CMD_ERROR; } @@ -865,7 +865,7 @@ return v->type == VEH_ROAD && - !IsRoadVehInDepot(v) && + !v->IsInDepot() && myabs(v->z_pos - rvf->veh->z_pos) < 6 && v->direction == rvf->dir && GetFirstVehicleInChain(rvf->veh) != GetFirstVehicleInChain(v) && @@ -1439,7 +1439,7 @@ /* If this vehicle is in a depot and we've reached this point it must be * one of the articulated parts. It will stay in the depot until activated * by the previous vehicle in the chain when it gets to the right place. */ - if (IsRoadVehInDepot(v)) return true; + if (v->IsInDepot()) return true; /* Save old vehicle position to use at end of move to set viewport area dirty */ BeginVehicleMove(v); @@ -1817,7 +1817,7 @@ if (v->current_order.type == OT_LOADING) return; - if (IsRoadVehInDepot(v) && RoadVehLeaveDepot(v, true)) return; + if (v->IsInDepot() && RoadVehLeaveDepot(v, true)) return; /* Check if vehicle needs to proceed, return if it doesn't */ if (!RoadVehAccelerate(v)) return; @@ -1858,7 +1858,7 @@ /* If we already got a slot at a stop, use that FIRST, and go to a depot later */ if (v->u.road.slot != NULL) return; - if (IsRoadVehInDepot(v)) { + if (v->IsInDepot()) { VehicleServiceInDepot(v); return; } diff -r c7b966f7592e -r 881998b115c2 src/ship.h --- a/src/ship.h Wed Aug 29 21:30:03 2007 +0000 +++ b/src/ship.h Wed Aug 29 21:49:08 2007 +0000 @@ -13,18 +13,6 @@ void RecalcShipStuff(Vehicle *v); void GetShipSpriteSize(EngineID engine, uint &width, uint &height); -static inline bool IsShipInDepot(const Vehicle *v) -{ - assert(v->type == VEH_SHIP); - return v->u.ship.state == 0x80; -} - -static inline bool IsShipInDepotStopped(const Vehicle *v) -{ - return IsShipInDepot(v) && v->vehstatus & VS_STOPPED; -} - - /** * This class 'wraps' Vehicle; you do not actually instantiate this class. * You create a Vehicle using AllocateVehicle, so it is added to the pool @@ -51,6 +39,7 @@ int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; } int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; } Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; } + bool IsInDepot() const { return this->u.ship.state == 0x80; } void Tick(); }; diff -r c7b966f7592e -r 881998b115c2 src/ship_cmd.cpp --- a/src/ship_cmd.cpp Wed Aug 29 21:30:03 2007 +0000 +++ b/src/ship_cmd.cpp Wed Aug 29 21:49:08 2007 +0000 @@ -152,7 +152,7 @@ if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; - if (IsShipInDepot(v)) { + if (v->IsInDepot()) { VehicleServiceInDepot(v); return; } @@ -355,7 +355,7 @@ Axis axis; uint m; - if (!IsShipInDepot(v)) return; + if (!v->IsInDepot()) return; tile = v->tile; axis = GetShipDepotAxis(tile); @@ -678,7 +678,7 @@ GetNewVehiclePosResult gp = GetNewVehiclePos(v); if (gp.old_tile == gp.new_tile) { /* Staying in tile */ - if (IsShipInDepot(v)) { + if (v->IsInDepot()) { gp.x = v->x_pos; gp.y = v->y_pos; } else { @@ -925,7 +925,7 @@ SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); - if (!IsShipInDepotStopped(v)) { + if (!v->IsStoppedInDepot()) { return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); } @@ -967,7 +967,7 @@ } if (flags & DC_EXEC) { - if (IsShipInDepotStopped(v)) { + if (v->IsStoppedInDepot()) { DeleteVehicleNews(p1, STR_981C_SHIP_IS_WAITING_IN_DEPOT); } @@ -1007,7 +1007,7 @@ if (v->vehstatus & VS_CRASHED) return CMD_ERROR; - if (IsShipInDepot(v)) return CMD_ERROR; + if (v->IsInDepot()) return CMD_ERROR; /* If the current orders are already goto-depot */ if (v->current_order.type == OT_GOTO_DEPOT) { @@ -1079,7 +1079,7 @@ if (v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR; - if (!IsShipInDepotStopped(v)) { + if (!v->IsStoppedInDepot()) { return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); } diff -r c7b966f7592e -r 881998b115c2 src/train.h --- a/src/train.h Wed Aug 29 21:30:03 2007 +0000 +++ b/src/train.h Wed Aug 29 21:49:08 2007 +0000 @@ -248,6 +248,9 @@ byte FreightWagonMult(CargoID cargo); +int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped); +int CheckTrainStoppedInDepot(const Vehicle *v); + /** * This class 'wraps' Vehicle; you do not actually instantiate this class. * You create a Vehicle using AllocateVehicle, so it is added to the pool @@ -275,6 +278,8 @@ int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed * 10 / 16; } Money GetRunningCost() const; + bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; } + bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; } void Tick(); }; diff -r c7b966f7592e -r 881998b115c2 src/vehicle.cpp --- a/src/vehicle.cpp Wed Aug 29 21:30:03 2007 +0000 +++ b/src/vehicle.cpp Wed Aug 29 21:49:08 2007 +0000 @@ -1700,7 +1700,7 @@ CommandCost ret; /* Ensure that the vehicle completely in the depot */ - if (!IsVehicleInDepot(v)) continue; + if (!v->IsInDepot()) continue; x = v->x_pos; y = v->y_pos; @@ -1958,7 +1958,7 @@ case VEH_ROAD: FOR_ALL_VEHICLES(v) { - if (v->tile == tile && v->type == VEH_ROAD && IsRoadVehInDepot(v) && IsRoadVehFront(v)) { + if (v->tile == tile && v->type == VEH_ROAD && v->IsInDepot() && IsRoadVehFront(v)) { if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); (*engine_list)[(*engine_count)++] = v; } @@ -1967,7 +1967,7 @@ case VEH_SHIP: FOR_ALL_VEHICLES(v) { - if (v->tile == tile && v->type == VEH_SHIP && IsShipInDepot(v)) { + if (v->tile == tile && v->type == VEH_SHIP && v->IsInDepot()) { if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); (*engine_list)[(*engine_count)++] = v; } @@ -1978,7 +1978,7 @@ FOR_ALL_VEHICLES(v) { if (v->tile == tile && v->type == VEH_AIRCRAFT && IsNormalAircraft(v) && - v->vehstatus & VS_HIDDEN) { + v->IsInDepot()) { if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); (*engine_list)[(*engine_count)++] = v; } @@ -2133,30 +2133,6 @@ return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR; } -bool IsVehicleInDepot(const Vehicle *v) -{ - switch (v->type) { - case VEH_TRAIN: return CheckTrainInDepot(v, false) != -1; - case VEH_ROAD: return IsRoadVehInDepot(v); - case VEH_SHIP: return IsShipInDepot(v); - case VEH_AIRCRAFT: return IsAircraftInHangar(v); - default: NOT_REACHED(); - } - return false; -} - -bool IsVehicleInDepotStopped(const Vehicle *v) -{ - switch (v->type) { - case VEH_TRAIN: return CheckTrainStoppedInDepot(v) >= 0; - case VEH_ROAD: return IsRoadVehInDepotStopped(v); - case VEH_SHIP: return IsShipInDepotStopped(v); - case VEH_AIRCRAFT: return IsAircraftInHangarStopped(v); - default: NOT_REACHED(); - } - return false; -} - /** * Calculates how full a vehicle is. * @param v The Vehicle to check. For trains, use the first engine. @@ -2472,14 +2448,14 @@ return TrackDirectionToTrackdir(FindFirstTrack(v->u.rail.track), v->direction); case VEH_SHIP: - if (IsShipInDepot(v)) + if (v->IsInDepot()) // We'll assume the ship is facing outwards return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile)); return TrackDirectionToTrackdir(FindFirstTrack(v->u.ship.state), v->direction); case VEH_ROAD: - if (IsRoadVehInDepot(v)) // We'll assume the road vehicle is facing outwards + if (v->IsInDepot()) // We'll assume the road vehicle is facing outwards return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile)); if (IsStandardRoadStopTile(v->tile)) // We'll assume the road vehicle is facing outwards diff -r c7b966f7592e -r 881998b115c2 src/vehicle.h --- a/src/vehicle.h Wed Aug 29 21:30:03 2007 +0000 +++ b/src/vehicle.h Wed Aug 29 21:49:08 2007 +0000 @@ -433,6 +433,18 @@ virtual Money GetRunningCost() const { return 0; } /** + * Check whether the vehicle is in the depot. + * @return true if and only if the vehicle is in the depot. + */ + virtual bool IsInDepot() const { return false; } + + /** + * Check whether the vehicle is in the depot *and* stopped. + * @return true if and only if the vehicle is in the depot and stopped. + */ + virtual bool IsStoppedInDepot() const { return this->IsInDepot() && (this->vehstatus & VS_STOPPED) != 0; } + + /** * Calls the tick handler of the vehicle */ virtual void Tick() {}; @@ -573,15 +585,11 @@ void TrainPowerChanged(Vehicle *v); Money GetTrainRunningCost(const Vehicle *v); -int CheckTrainStoppedInDepot(const Vehicle *v); - bool VehicleNeedsService(const Vehicle *v); uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type); void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count); CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id); -bool IsVehicleInDepot(const Vehicle *v); -bool IsVehicleInDepotStopped(const Vehicle *v); void VehicleEnterDepot(Vehicle *v); void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g); diff -r c7b966f7592e -r 881998b115c2 src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp Wed Aug 29 21:30:03 2007 +0000 +++ b/src/vehicle_gui.cpp Wed Aug 29 21:49:08 2007 +0000 @@ -1021,7 +1021,7 @@ if (w->resize.step_height == PLY_WND_PRC__SIZE_OF_ROW_BIG) DrawSmallOrderList(v, x + 138, y); - if (IsVehicleInDepot(v)) { + if (v->IsInDepot()) { str = STR_021F; } else { str = (v->age > v->max_age - 366) ? STR_00E3 : STR_00E2; @@ -1546,9 +1546,9 @@ */ switch (v->type) { case VEH_TRAIN: return false; - case VEH_ROAD: return EngInfo(v->engine_type)->refit_mask != 0 && IsVehicleInDepotStopped(v); - case VEH_SHIP: return ShipVehInfo(v->engine_type)->refittable && IsVehicleInDepotStopped(v); - case VEH_AIRCRAFT: return IsVehicleInDepotStopped(v); + case VEH_ROAD: return EngInfo(v->engine_type)->refit_mask != 0 && v->IsStoppedInDepot(); + case VEH_SHIP: return ShipVehInfo(v->engine_type)->refittable && v->IsStoppedInDepot(); + case VEH_AIRCRAFT: return v->IsStoppedInDepot(); default: NOT_REACHED(); } } @@ -1790,7 +1790,7 @@ case WE_MOUSELOOP: { const Vehicle *v = GetVehicle(w->window_number); - bool veh_stopped = IsVehicleInDepotStopped(v); + bool veh_stopped = v->IsStoppedInDepot(); /* Widget VVW_WIDGET_GOTO_DEPOT must be hidden if the vehicle is already * stopped in depot.