diff options
-rw-r--r-- | src/aircraft.h | 1 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 12 | ||||
-rw-r--r-- | src/disaster_cmd.cpp | 4 | ||||
-rw-r--r-- | src/roadveh.h | 1 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 6 | ||||
-rw-r--r-- | src/ship.h | 1 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 6 | ||||
-rw-r--r-- | src/train.h | 1 | ||||
-rw-r--r-- | src/train_cmd.cpp | 22 | ||||
-rw-r--r-- | src/vehicle.cpp | 24 | ||||
-rw-r--r-- | src/vehicle.h | 8 |
11 files changed, 40 insertions, 46 deletions
diff --git a/src/aircraft.h b/src/aircraft.h index 22a3e1a2b..255225db9 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -137,6 +137,7 @@ struct Aircraft : public Vehicle { WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; } bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } int GetImage(Direction direction) const; + void Tick(); }; #endif /* AIRCRAFT_H */ diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 99a3b7e2d..8e06f31cb 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -2110,17 +2110,17 @@ static void AircraftEventHandler(Vehicle *v, int loop) AirportGoToNextPosition(v); } -void Aircraft_Tick(Vehicle *v) +void Aircraft::Tick() { - if (!IsNormalAircraft(v)) return; + if (!IsNormalAircraft(this)) return; - if (v->subtype == AIR_HELICOPTER) HelicopterTickHandler(v); + if (this->subtype == AIR_HELICOPTER) HelicopterTickHandler(this); - AgeAircraftCargo(v); + AgeAircraftCargo(this); for (uint i = 0; i != 2; i++) { - AircraftEventHandler(v, i); - if (v->type != VEH_AIRCRAFT) // In case it was deleted + AircraftEventHandler(this, i); + if (this->type != VEH_AIRCRAFT) // In case it was deleted break; } } diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index db065caae..41956ae63 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -741,9 +741,9 @@ static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = { }; -void DisasterVehicle_Tick(Vehicle *v) +void DisasterVehicle::Tick() { - _disastervehicle_tick_procs[v->subtype](v); + _disastervehicle_tick_procs[this->subtype](this); } diff --git a/src/roadveh.h b/src/roadveh.h index f623317a8..59097d177 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -82,6 +82,7 @@ struct RoadVehicle : public Vehicle { bool IsPrimaryVehicle() const { return IsRoadVehFront(this); } bool HasFront() const { return true; } int GetImage(Direction direction) const; + void Tick(); }; byte GetRoadVehLength(const Vehicle *v); diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 5217e3b8a..5faf41e24 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1829,11 +1829,11 @@ static void AgeRoadVehCargo(Vehicle *v) v->cargo.AgeCargo(); } -void RoadVeh_Tick(Vehicle *v) +void RoadVehicle::Tick() { - AgeRoadVehCargo(v); + AgeRoadVehCargo(this); - if (IsRoadVehFront(v)) RoadVehController(v); + if (IsRoadVehFront(this)) RoadVehController(this); } static void CheckIfRoadVehNeedsService(Vehicle *v) diff --git a/src/ship.h b/src/ship.h index 200c1016c..37657e7e6 100644 --- a/src/ship.h +++ b/src/ship.h @@ -47,6 +47,7 @@ struct Ship: public Vehicle { void PlayLeaveStationSound() const; bool IsPrimaryVehicle() const { return true; } int GetImage(Direction direction) const; + void Tick(); }; #endif /* SHIP_H */ diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 555af11b5..b71d00b02 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -787,10 +787,10 @@ static void AgeShipCargo(Vehicle *v) v->cargo.AgeCargo(); } -void Ship_Tick(Vehicle *v) +void Ship::Tick() { - AgeShipCargo(v); - ShipController(v); + AgeShipCargo(this); + ShipController(this); } diff --git a/src/train.h b/src/train.h index 33d500a26..54eb23442 100644 --- a/src/train.h +++ b/src/train.h @@ -273,6 +273,7 @@ struct Train : public Vehicle { bool IsPrimaryVehicle() const { return IsFrontEngine(this); } bool HasFront() const { return true; } int GetImage(Direction direction) const; + void Tick(); }; #endif /* TRAIN_H */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 3102d2e55..283e43332 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3305,24 +3305,24 @@ static void TrainLocoHandler(Vehicle *v, bool mode) } -void Train_Tick(Vehicle *v) +void Train::Tick() { - if (_age_cargo_skip_counter == 0) v->cargo.AgeCargo(); + if (_age_cargo_skip_counter == 0) this->cargo.AgeCargo(); - v->tick_counter++; + this->tick_counter++; - if (IsFrontEngine(v)) { - v->current_order_time++; + if (IsFrontEngine(this)) { + this->current_order_time++; - TrainLocoHandler(v, false); + TrainLocoHandler(this, false); /* make sure vehicle wasn't deleted. */ - if (v->type == VEH_TRAIN && IsFrontEngine(v)) - TrainLocoHandler(v, true); - } else if (IsFreeWagon(v) && HASBITS(v->vehstatus, VS_CRASHED)) { + if (this->type == VEH_TRAIN && IsFrontEngine(this)) + TrainLocoHandler(this, true); + } else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) { /* Delete flooded standalone wagon */ - if (++v->u.rail.crash_anim_pos >= 4400) - DeleteVehicle(v); + if (++this->u.rail.crash_anim_pos >= 4400) + DeleteVehicle(this); } } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 8b17afdb9..dea86bc01 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -726,14 +726,6 @@ void DeleteVehicleChain(Vehicle *v) } while (v != NULL); } - -void Aircraft_Tick(Vehicle *v); -void RoadVeh_Tick(Vehicle *v); -void Ship_Tick(Vehicle *v); -void Train_Tick(Vehicle *v); -static void EffectVehicle_Tick(Vehicle *v); -void DisasterVehicle_Tick(Vehicle *v); - /** head of the linked list to tell what vehicles that visited a depot in a tick */ static Vehicle* _first_veh_in_depot_list; @@ -763,16 +755,6 @@ void VehicleEnteredDepotThisTick(Vehicle *v) } } -typedef void VehicleTickProc(Vehicle*); -static VehicleTickProc* _vehicle_tick_procs[] = { - Train_Tick, - RoadVeh_Tick, - Ship_Tick, - Aircraft_Tick, - EffectVehicle_Tick, - DisasterVehicle_Tick, -}; - void CallVehicleTicks() { _first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick @@ -782,7 +764,7 @@ void CallVehicleTicks() Vehicle *v; FOR_ALL_VEHICLES(v) { - _vehicle_tick_procs[v->type](v); + v->Tick(); switch (v->type) { default: break; @@ -1532,9 +1514,9 @@ Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVeh return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); } -static void EffectVehicle_Tick(Vehicle *v) +void SpecialVehicle::Tick() { - _effect_tick_procs[v->subtype](v); + _effect_tick_procs[this->subtype](this); } Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) diff --git a/src/vehicle.h b/src/vehicle.h index 8d2ac0e08..07d2e3acd 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -427,6 +427,11 @@ struct Vehicle { * @return the sprite for the given vehicle in the given direction */ virtual int GetImage(Direction direction) const { return 0; } + + /** + * Calls the tick handler of the vehicle + */ + virtual void Tick() = 0; }; /** @@ -453,6 +458,7 @@ struct SpecialVehicle : public Vehicle { const char *GetTypeString() const { return "special vehicle"; } void UpdateDeltaXY(Direction direction); + void Tick(); }; /** @@ -472,6 +478,7 @@ struct DisasterVehicle : public Vehicle { const char *GetTypeString() const { return "disaster vehicle"; } void UpdateDeltaXY(Direction direction); + void Tick(); }; /** @@ -490,6 +497,7 @@ struct InvalidVehicle : public Vehicle { virtual ~InvalidVehicle() {} const char *GetTypeString() const { return "invalid vehicle"; } + void Tick() {} }; #define is_custom_sprite(x) (x >= 0xFD) |