(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.

This commit is contained in:
rubidium 2007-07-01 19:24:54 +00:00
parent 83a880c882
commit 90f85c957a
11 changed files with 40 additions and 46 deletions

View File

@ -137,6 +137,7 @@ struct Aircraft : public Vehicle {
WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; } WindowClass GetVehicleListWindowClass() const { return WC_AIRCRAFT_LIST; }
bool IsPrimaryVehicle() const { return IsNormalAircraft(this); } bool IsPrimaryVehicle() const { return IsNormalAircraft(this); }
int GetImage(Direction direction) const; int GetImage(Direction direction) const;
void Tick();
}; };
#endif /* AIRCRAFT_H */ #endif /* AIRCRAFT_H */

View File

@ -2110,17 +2110,17 @@ static void AircraftEventHandler(Vehicle *v, int loop)
AirportGoToNextPosition(v); 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++) { for (uint i = 0; i != 2; i++) {
AircraftEventHandler(v, i); AircraftEventHandler(this, i);
if (v->type != VEH_AIRCRAFT) // In case it was deleted if (this->type != VEH_AIRCRAFT) // In case it was deleted
break; break;
} }
} }

View File

@ -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);
} }

View File

@ -82,6 +82,7 @@ struct RoadVehicle : public Vehicle {
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); } bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
bool HasFront() const { return true; } bool HasFront() const { return true; }
int GetImage(Direction direction) const; int GetImage(Direction direction) const;
void Tick();
}; };
byte GetRoadVehLength(const Vehicle *v); byte GetRoadVehLength(const Vehicle *v);

View File

@ -1829,11 +1829,11 @@ static void AgeRoadVehCargo(Vehicle *v)
v->cargo.AgeCargo(); 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) static void CheckIfRoadVehNeedsService(Vehicle *v)

View File

@ -47,6 +47,7 @@ struct Ship: public Vehicle {
void PlayLeaveStationSound() const; void PlayLeaveStationSound() const;
bool IsPrimaryVehicle() const { return true; } bool IsPrimaryVehicle() const { return true; }
int GetImage(Direction direction) const; int GetImage(Direction direction) const;
void Tick();
}; };
#endif /* SHIP_H */ #endif /* SHIP_H */

View File

@ -787,10 +787,10 @@ static void AgeShipCargo(Vehicle *v)
v->cargo.AgeCargo(); v->cargo.AgeCargo();
} }
void Ship_Tick(Vehicle *v) void Ship::Tick()
{ {
AgeShipCargo(v); AgeShipCargo(this);
ShipController(v); ShipController(this);
} }

View File

@ -273,6 +273,7 @@ struct Train : public Vehicle {
bool IsPrimaryVehicle() const { return IsFrontEngine(this); } bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
bool HasFront() const { return true; } bool HasFront() const { return true; }
int GetImage(Direction direction) const; int GetImage(Direction direction) const;
void Tick();
}; };
#endif /* TRAIN_H */ #endif /* TRAIN_H */

View File

@ -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)) { if (IsFrontEngine(this)) {
v->current_order_time++; this->current_order_time++;
TrainLocoHandler(v, false); TrainLocoHandler(this, false);
/* make sure vehicle wasn't deleted. */ /* make sure vehicle wasn't deleted. */
if (v->type == VEH_TRAIN && IsFrontEngine(v)) if (this->type == VEH_TRAIN && IsFrontEngine(this))
TrainLocoHandler(v, true); TrainLocoHandler(this, true);
} else if (IsFreeWagon(v) && HASBITS(v->vehstatus, VS_CRASHED)) { } else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) {
/* Delete flooded standalone wagon */ /* Delete flooded standalone wagon */
if (++v->u.rail.crash_anim_pos >= 4400) if (++this->u.rail.crash_anim_pos >= 4400)
DeleteVehicle(v); DeleteVehicle(this);
} }
} }

View File

@ -726,14 +726,6 @@ void DeleteVehicleChain(Vehicle *v)
} while (v != NULL); } 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 */ /** head of the linked list to tell what vehicles that visited a depot in a tick */
static Vehicle* _first_veh_in_depot_list; 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() void CallVehicleTicks()
{ {
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick _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; Vehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {
_vehicle_tick_procs[v->type](v); v->Tick();
switch (v->type) { switch (v->type) {
default: break; 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); 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) Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y)

View File

@ -427,6 +427,11 @@ struct Vehicle {
* @return the sprite for the given vehicle in the given direction * @return the sprite for the given vehicle in the given direction
*/ */
virtual int GetImage(Direction direction) const { return 0; } 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"; } const char *GetTypeString() const { return "special vehicle"; }
void UpdateDeltaXY(Direction direction); void UpdateDeltaXY(Direction direction);
void Tick();
}; };
/** /**
@ -472,6 +478,7 @@ struct DisasterVehicle : public Vehicle {
const char *GetTypeString() const { return "disaster vehicle"; } const char *GetTypeString() const { return "disaster vehicle"; }
void UpdateDeltaXY(Direction direction); void UpdateDeltaXY(Direction direction);
void Tick();
}; };
/** /**
@ -490,6 +497,7 @@ struct InvalidVehicle : public Vehicle {
virtual ~InvalidVehicle() {} virtual ~InvalidVehicle() {}
const char *GetTypeString() const { return "invalid vehicle"; } const char *GetTypeString() const { return "invalid vehicle"; }
void Tick() {}
}; };
#define is_custom_sprite(x) (x >= 0xFD) #define is_custom_sprite(x) (x >= 0xFD)