Mercurial > hg > openttd
changeset 7135:45123abbc930 draft
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 01 Jul 2007 19:24:54 +0000 |
parents | e1c4f52f82cd |
children | a5ce22d5af7f |
files | src/aircraft.h src/aircraft_cmd.cpp src/disaster_cmd.cpp src/roadveh.h src/roadveh_cmd.cpp src/ship.h src/ship_cmd.cpp src/train.h src/train_cmd.cpp src/vehicle.cpp src/vehicle.h |
diffstat | 11 files changed, 43 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft.h +++ b/src/aircraft.h @@ -137,6 +137,7 @@ WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; } bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } int GetImage(Direction direction) const; + void Tick(); }; #endif /* AIRCRAFT_H */
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -2110,17 +2110,17 @@ 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; } }
--- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -741,9 +741,9 @@ }; -void DisasterVehicle_Tick(Vehicle *v) +void DisasterVehicle::Tick() { - _disastervehicle_tick_procs[v->subtype](v); + _disastervehicle_tick_procs[this->subtype](this); }
--- a/src/roadveh.h +++ b/src/roadveh.h @@ -82,6 +82,7 @@ bool IsPrimaryVehicle() const { return IsRoadVehFront(this); } bool HasFront() const { return true; } int GetImage(Direction direction) const; + void Tick(); }; byte GetRoadVehLength(const Vehicle *v);
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1829,11 +1829,11 @@ 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)
--- a/src/ship.h +++ b/src/ship.h @@ -47,6 +47,7 @@ void PlayLeaveStationSound() const; bool IsPrimaryVehicle() const { return true; } int GetImage(Direction direction) const; + void Tick(); }; #endif /* SHIP_H */
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -787,10 +787,10 @@ v->cargo.AgeCargo(); } -void Ship_Tick(Vehicle *v) +void Ship::Tick() { - AgeShipCargo(v); - ShipController(v); + AgeShipCargo(this); + ShipController(this); }
--- a/src/train.h +++ b/src/train.h @@ -273,6 +273,7 @@ bool IsPrimaryVehicle() const { return IsFrontEngine(this); } bool HasFront() const { return true; } int GetImage(Direction direction) const; + void Tick(); }; #endif /* TRAIN_H */
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3305,24 +3305,24 @@ } -void Train_Tick(Vehicle *v) +void Train::Tick() { - if (_age_cargo_skip_counter == 0) v->cargo.AgeCargo(); - - v->tick_counter++; - - if (IsFrontEngine(v)) { - v->current_order_time++; - - TrainLocoHandler(v, false); + if (_age_cargo_skip_counter == 0) this->cargo.AgeCargo(); + + this->tick_counter++; + + if (IsFrontEngine(this)) { + this->current_order_time++; + + 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); } }
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -726,14 +726,6 @@ } 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 @@ } } -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 @@ Vehicle *v; FOR_ALL_VEHICLES(v) { - _vehicle_tick_procs[v->type](v); + v->Tick(); switch (v->type) { default: break; @@ -1532,9 +1514,9 @@ 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)
--- a/src/vehicle.h +++ b/src/vehicle.h @@ -427,6 +427,11 @@ * @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 @@ const char *GetTypeString() const { return "special vehicle"; } void UpdateDeltaXY(Direction direction); + void Tick(); }; /** @@ -472,6 +478,7 @@ const char *GetTypeString() const { return "disaster vehicle"; } void UpdateDeltaXY(Direction direction); + void Tick(); }; /** @@ -490,6 +497,7 @@ virtual ~InvalidVehicle() {} const char *GetTypeString() const { return "invalid vehicle"; } + void Tick() {} }; #define is_custom_sprite(x) (x >= 0xFD)