mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
This commit is contained in:
parent
83a880c882
commit
90f85c957a
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user