mirror of https://github.com/OpenTTD/OpenTTD
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
parent
67782add11
commit
525409b0fc
|
@ -124,6 +124,7 @@ struct Aircraft : public Vehicle {
|
||||||
Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; }
|
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); }
|
bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
|
||||||
void Tick();
|
void Tick();
|
||||||
|
void OnNewDay();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* AIRCRAFT_H */
|
#endif /* AIRCRAFT_H */
|
||||||
|
|
|
@ -723,27 +723,27 @@ static void CheckIfAircraftNeedsService(Vehicle *v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNewDay_Aircraft(Vehicle *v)
|
void Aircraft::OnNewDay()
|
||||||
{
|
{
|
||||||
if (!IsNormalAircraft(v)) return;
|
if (!IsNormalAircraft(this)) return;
|
||||||
|
|
||||||
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
|
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
||||||
|
|
||||||
CheckOrders(v);
|
CheckOrders(this);
|
||||||
|
|
||||||
CheckVehicleBreakdown(v);
|
CheckVehicleBreakdown(this);
|
||||||
AgeVehicle(v);
|
AgeVehicle(this);
|
||||||
CheckIfAircraftNeedsService(v);
|
CheckIfAircraftNeedsService(this);
|
||||||
|
|
||||||
if (v->vehstatus & VS_STOPPED) return;
|
if (this->vehstatus & VS_STOPPED) return;
|
||||||
|
|
||||||
CommandCost cost = CommandCost(EXPENSES_AIRCRAFT_RUN, GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364);
|
CommandCost cost = CommandCost(EXPENSES_AIRCRAFT_RUN, GetVehicleProperty(this, 0x0E, AircraftVehInfo(this->engine_type)->running_cost) * _price.aircraft_running / 364);
|
||||||
|
|
||||||
v->profit_this_year -= cost.GetCost() >> 8;
|
this->profit_this_year -= cost.GetCost() >> 8;
|
||||||
|
|
||||||
SubtractMoneyFromPlayerFract(v->owner, cost);
|
SubtractMoneyFromPlayerFract(this->owner, cost);
|
||||||
|
|
||||||
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
||||||
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
src/date.cpp
20
src/date.cpp
|
@ -165,24 +165,6 @@ Date ConvertYMDToDate(Year year, Month month, Day day)
|
||||||
|
|
||||||
/** Functions used by the IncreaseDate function */
|
/** Functions used by the IncreaseDate function */
|
||||||
|
|
||||||
extern void OnNewDay_Train(Vehicle *v);
|
|
||||||
extern void OnNewDay_RoadVeh(Vehicle *v);
|
|
||||||
extern void OnNewDay_Aircraft(Vehicle *v);
|
|
||||||
extern void OnNewDay_Ship(Vehicle *v);
|
|
||||||
static void OnNewDay_EffectVehicle(Vehicle *v) { /* empty */ }
|
|
||||||
extern void OnNewDay_DisasterVehicle(Vehicle *v);
|
|
||||||
|
|
||||||
typedef void OnNewVehicleDayProc(Vehicle *v);
|
|
||||||
|
|
||||||
static OnNewVehicleDayProc * _on_new_vehicle_day_proc[] = {
|
|
||||||
OnNewDay_Train,
|
|
||||||
OnNewDay_RoadVeh,
|
|
||||||
OnNewDay_Ship,
|
|
||||||
OnNewDay_Aircraft,
|
|
||||||
OnNewDay_EffectVehicle,
|
|
||||||
OnNewDay_DisasterVehicle,
|
|
||||||
};
|
|
||||||
|
|
||||||
extern void WaypointsDailyLoop();
|
extern void WaypointsDailyLoop();
|
||||||
extern void ChatMessageDailyLoop();
|
extern void ChatMessageDailyLoop();
|
||||||
extern void EnginesDailyLoop();
|
extern void EnginesDailyLoop();
|
||||||
|
@ -225,7 +207,7 @@ static void RunVehicleDayProc(uint daytick)
|
||||||
if (v->IsValid()) {
|
if (v->IsValid()) {
|
||||||
/* Call the 32-day callback if needed */
|
/* Call the 32-day callback if needed */
|
||||||
CheckVehicle32Day(v);
|
CheckVehicle32Day(v);
|
||||||
_on_new_vehicle_day_proc[v->type](v);
|
v->OnNewDay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -749,12 +749,6 @@ void DisasterVehicle::Tick()
|
||||||
_disastervehicle_tick_procs[this->subtype](this);
|
_disastervehicle_tick_procs[this->subtype](this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnNewDay_DisasterVehicle(Vehicle *v)
|
|
||||||
{
|
|
||||||
// not used
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef void DisasterInitProc();
|
typedef void DisasterInitProc();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ struct RoadVehicle : public Vehicle {
|
||||||
Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running; }
|
Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running; }
|
||||||
bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; }
|
bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; }
|
||||||
void Tick();
|
void Tick();
|
||||||
|
void OnNewDay();
|
||||||
};
|
};
|
||||||
|
|
||||||
byte GetRoadVehLength(const Vehicle *v);
|
byte GetRoadVehLength(const Vehicle *v);
|
||||||
|
|
|
@ -2004,33 +2004,33 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNewDay_RoadVeh(Vehicle *v)
|
void RoadVehicle::OnNewDay()
|
||||||
{
|
{
|
||||||
CommandCost cost(EXPENSES_ROADVEH_RUN);
|
CommandCost cost(EXPENSES_ROADVEH_RUN);
|
||||||
|
|
||||||
if (!IsRoadVehFront(v)) return;
|
if (!IsRoadVehFront(this)) return;
|
||||||
|
|
||||||
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
|
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
||||||
if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v);
|
if (this->u.road.blocked_ctr == 0) CheckVehicleBreakdown(this);
|
||||||
|
|
||||||
AgeVehicle(v);
|
AgeVehicle(this);
|
||||||
CheckIfRoadVehNeedsService(v);
|
CheckIfRoadVehNeedsService(this);
|
||||||
|
|
||||||
CheckOrders(v);
|
CheckOrders(this);
|
||||||
|
|
||||||
/* Current slot has expired */
|
/* Current slot has expired */
|
||||||
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot != NULL && v->u.road.slot_age-- == 0) {
|
if (this->current_order.type == OT_GOTO_STATION && this->u.road.slot != NULL && this->u.road.slot_age-- == 0) {
|
||||||
DEBUG(ms, 3, "Slot expired for vehicle %d (index %d) at stop 0x%X",
|
DEBUG(ms, 3, "Slot expired for vehicle %d (index %d) at stop 0x%X",
|
||||||
v->unitnumber, v->index, v->u.road.slot->xy);
|
this->unitnumber, this->index, this->u.road.slot->xy);
|
||||||
ClearSlot(v);
|
ClearSlot(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->vehstatus & VS_STOPPED) return;
|
if (this->vehstatus & VS_STOPPED) return;
|
||||||
|
|
||||||
/* update destination */
|
/* update destination */
|
||||||
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) {
|
if (this->current_order.type == OT_GOTO_STATION && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
|
||||||
Station *st = GetStation(v->current_order.dest);
|
Station *st = GetStation(this->current_order.dest);
|
||||||
RoadStop *rs = st->GetPrimaryRoadStop(v);
|
RoadStop *rs = st->GetPrimaryRoadStop(this);
|
||||||
RoadStop *best = NULL;
|
RoadStop *best = NULL;
|
||||||
|
|
||||||
if (rs != NULL) {
|
if (rs != NULL) {
|
||||||
|
@ -2040,16 +2040,16 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
||||||
* 2) we're somewhere close to the station rectangle (to make sure we do assign
|
* 2) we're somewhere close to the station rectangle (to make sure we do assign
|
||||||
* slots even if the station and its road stops are incredibly spread out)
|
* slots even if the station and its road stops are incredibly spread out)
|
||||||
*/
|
*/
|
||||||
if (DistanceManhattan(v->tile, rs->xy) < 16 || st->rect.PtInExtendedRect(TileX(v->tile), TileY(v->tile), 2)) {
|
if (DistanceManhattan(this->tile, rs->xy) < 16 || st->rect.PtInExtendedRect(TileX(this->tile), TileY(this->tile), 2)) {
|
||||||
uint dist, badness;
|
uint dist, badness;
|
||||||
uint minbadness = UINT_MAX;
|
uint minbadness = UINT_MAX;
|
||||||
|
|
||||||
DEBUG(ms, 2, "Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%X)",
|
DEBUG(ms, 2, "Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%X)",
|
||||||
v->unitnumber, v->index, st->index, st->xy
|
this->unitnumber, this->index, st->index, st->xy
|
||||||
);
|
);
|
||||||
/* Now we find the nearest road stop that has a free slot */
|
/* Now we find the nearest road stop that has a free slot */
|
||||||
for (; rs != NULL; rs = rs->GetNextRoadStop(v)) {
|
for (; rs != NULL; rs = rs->GetNextRoadStop(this)) {
|
||||||
dist = RoadFindPathToStop(v, rs->xy);
|
dist = RoadFindPathToStop(this, rs->xy);
|
||||||
if (dist == UINT_MAX) {
|
if (dist == UINT_MAX) {
|
||||||
DEBUG(ms, 4, " stop 0x%X is unreachable, not treating further", rs->xy);
|
DEBUG(ms, 4, " stop 0x%X is unreachable, not treating further", rs->xy);
|
||||||
continue;
|
continue;
|
||||||
|
@ -2070,29 +2070,29 @@ void OnNewDay_RoadVeh(Vehicle *v)
|
||||||
best->num_vehicles++;
|
best->num_vehicles++;
|
||||||
DEBUG(ms, 3, "Assigned to stop 0x%X", best->xy);
|
DEBUG(ms, 3, "Assigned to stop 0x%X", best->xy);
|
||||||
|
|
||||||
v->u.road.slot = best;
|
this->u.road.slot = best;
|
||||||
v->dest_tile = best->xy;
|
this->dest_tile = best->xy;
|
||||||
v->u.road.slot_age = 14;
|
this->u.road.slot_age = 14;
|
||||||
} else {
|
} else {
|
||||||
DEBUG(ms, 3, "Could not find a suitable stop");
|
DEBUG(ms, 3, "Could not find a suitable stop");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DEBUG(ms, 5, "Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%X)",
|
DEBUG(ms, 5, "Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%X)",
|
||||||
v->unitnumber, v->index, st->index, st->xy);
|
this->unitnumber, this->index, st->index, st->xy);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DEBUG(ms, 4, "No road stop for vehicle %d (index %d) at station %d (0x%X)",
|
DEBUG(ms, 4, "No road stop for vehicle %d (index %d) at station %d (0x%X)",
|
||||||
v->unitnumber, v->index, st->index, st->xy);
|
this->unitnumber, this->index, st->index, st->xy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cost = CommandCost(EXPENSES_ROADVEH_RUN, RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364);
|
cost = CommandCost(EXPENSES_ROADVEH_RUN, RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running / 364);
|
||||||
|
|
||||||
v->profit_this_year -= cost.GetCost() >> 8;
|
this->profit_this_year -= cost.GetCost() >> 8;
|
||||||
|
|
||||||
SubtractMoneyFromPlayerFract(v->owner, cost);
|
SubtractMoneyFromPlayerFract(this->owner, cost);
|
||||||
|
|
||||||
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
||||||
InvalidateWindowClasses(WC_ROADVEH_LIST);
|
InvalidateWindowClasses(WC_ROADVEH_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ struct Ship: public Vehicle {
|
||||||
Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; }
|
Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; }
|
||||||
bool IsInDepot() const { return this->u.ship.state == 0x80; }
|
bool IsInDepot() const { return this->u.ship.state == 0x80; }
|
||||||
void Tick();
|
void Tick();
|
||||||
|
void OnNewDay();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SHIP_H */
|
#endif /* SHIP_H */
|
||||||
|
|
|
@ -170,27 +170,27 @@ static void CheckIfShipNeedsService(Vehicle *v)
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNewDay_Ship(Vehicle *v)
|
void Ship::OnNewDay()
|
||||||
{
|
{
|
||||||
CommandCost cost(EXPENSES_SHIP_RUN);
|
CommandCost cost(EXPENSES_SHIP_RUN);
|
||||||
|
|
||||||
if ((++v->day_counter & 7) == 0)
|
if ((++this->day_counter & 7) == 0)
|
||||||
DecreaseVehicleValue(v);
|
DecreaseVehicleValue(this);
|
||||||
|
|
||||||
CheckVehicleBreakdown(v);
|
CheckVehicleBreakdown(this);
|
||||||
AgeVehicle(v);
|
AgeVehicle(this);
|
||||||
CheckIfShipNeedsService(v);
|
CheckIfShipNeedsService(this);
|
||||||
|
|
||||||
CheckOrders(v);
|
CheckOrders(this);
|
||||||
|
|
||||||
if (v->vehstatus & VS_STOPPED) return;
|
if (this->vehstatus & VS_STOPPED) return;
|
||||||
|
|
||||||
cost.AddCost(GetVehicleProperty(v, 0x0F, ShipVehInfo(v->engine_type)->running_cost) * _price.ship_running / 364);
|
cost.AddCost(GetVehicleProperty(this, 0x0F, ShipVehInfo(this->engine_type)->running_cost) * _price.ship_running / 364);
|
||||||
v->profit_this_year -= cost.GetCost() >> 8;
|
this->profit_this_year -= cost.GetCost() >> 8;
|
||||||
|
|
||||||
SubtractMoneyFromPlayerFract(v->owner, cost);
|
SubtractMoneyFromPlayerFract(this->owner, cost);
|
||||||
|
|
||||||
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
||||||
/* we need this for the profit */
|
/* we need this for the profit */
|
||||||
InvalidateWindowClasses(WC_SHIPS_LIST);
|
InvalidateWindowClasses(WC_SHIPS_LIST);
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,6 +304,7 @@ struct Train : public Vehicle {
|
||||||
bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
|
bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
|
||||||
bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
|
bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
|
||||||
void Tick();
|
void Tick();
|
||||||
|
void OnNewDay();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TRAIN_H */
|
#endif /* TRAIN_H */
|
||||||
|
|
|
@ -3625,38 +3625,38 @@ static void CheckIfTrainNeedsService(Vehicle *v)
|
||||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNewDay_Train(Vehicle *v)
|
void Train::OnNewDay()
|
||||||
{
|
{
|
||||||
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
|
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
||||||
|
|
||||||
if (IsFrontEngine(v)) {
|
if (IsFrontEngine(this)) {
|
||||||
CheckVehicleBreakdown(v);
|
CheckVehicleBreakdown(this);
|
||||||
AgeVehicle(v);
|
AgeVehicle(this);
|
||||||
|
|
||||||
CheckIfTrainNeedsService(v);
|
CheckIfTrainNeedsService(this);
|
||||||
|
|
||||||
CheckOrders(v);
|
CheckOrders(this);
|
||||||
|
|
||||||
/* update destination */
|
/* update destination */
|
||||||
if (v->current_order.type == OT_GOTO_STATION) {
|
if (this->current_order.type == OT_GOTO_STATION) {
|
||||||
TileIndex tile = GetStation(v->current_order.dest)->train_tile;
|
TileIndex tile = GetStation(this->current_order.dest)->train_tile;
|
||||||
if (tile != 0) v->dest_tile = tile;
|
if (tile != 0) this->dest_tile = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((v->vehstatus & VS_STOPPED) == 0) {
|
if ((this->vehstatus & VS_STOPPED) == 0) {
|
||||||
/* running costs */
|
/* running costs */
|
||||||
CommandCost cost(EXPENSES_TRAIN_RUN, v->GetRunningCost() / 364);
|
CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() / 364);
|
||||||
|
|
||||||
v->profit_this_year -= cost.GetCost() >> 8;
|
this->profit_this_year -= cost.GetCost() >> 8;
|
||||||
|
|
||||||
SubtractMoneyFromPlayerFract(v->owner, cost);
|
SubtractMoneyFromPlayerFract(this->owner, cost);
|
||||||
|
|
||||||
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
|
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
||||||
InvalidateWindowClasses(WC_TRAINS_LIST);
|
InvalidateWindowClasses(WC_TRAINS_LIST);
|
||||||
}
|
}
|
||||||
} else if (IsTrainEngine(v)) {
|
} else if (IsTrainEngine(this)) {
|
||||||
/* Also age engines that aren't front engines */
|
/* Also age engines that aren't front engines */
|
||||||
AgeVehicle(v);
|
AgeVehicle(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -425,6 +425,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void Tick() {};
|
virtual void Tick() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the new day handler of the vehicle
|
||||||
|
*/
|
||||||
|
virtual void OnNewDay() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
|
* Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
|
||||||
* @return the vehicle's running cost
|
* @return the vehicle's running cost
|
||||||
|
|
Loading…
Reference in New Issue