Changeset - r8467:0ea88f22d4aa
[Not reviewed]
master
0 11 0
glx - 17 years ago 2008-02-01 22:02:14
glx@openttd.org
(svn r12037) -Codechange: replace OnNewDay_(Aircraft|RoadVeh|Ship|Train) with an OnNewDay method in the Vehicle class
11 files changed with 84 insertions and 99 deletions:
0 comments (0 inline, 0 general)
src/aircraft.h
Show inline comments
 
@@ -124,6 +124,7 @@ struct Aircraft : public Vehicle {
 
	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); }
 
	void Tick();
 
	void OnNewDay();
 
};
 

	
 
#endif /* AIRCRAFT_H */
src/aircraft_cmd.cpp
Show inline comments
 
@@ -723,27 +723,27 @@ static void CheckIfAircraftNeedsService(
 
	}
 
}
 

	
 
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);
 
	AgeVehicle(v);
 
	CheckIfAircraftNeedsService(v);
 
	CheckVehicleBreakdown(this);
 
	AgeVehicle(this);
 
	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);
 
}
 

	
src/date.cpp
Show inline comments
 
@@ -165,24 +165,6 @@ Date ConvertYMDToDate(Year year, Month m
 

	
 
/** 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 ChatMessageDailyLoop();
 
extern void EnginesDailyLoop();
 
@@ -225,7 +207,7 @@ static void RunVehicleDayProc(uint dayti
 
		if (v->IsValid()) {
 
			/* Call the 32-day callback if needed */
 
			CheckVehicle32Day(v);
 
			_on_new_vehicle_day_proc[v->type](v);
 
			v->OnNewDay();
 
		}
 
	}
 
}
src/disaster_cmd.cpp
Show inline comments
 
@@ -749,12 +749,6 @@ void DisasterVehicle::Tick()
 
	_disastervehicle_tick_procs[this->subtype](this);
 
}
 

	
 

	
 
void OnNewDay_DisasterVehicle(Vehicle *v)
 
{
 
	// not used
 
}
 

	
 
typedef void DisasterInitProc();
 

	
 

	
src/roadveh.h
Show inline comments
 
@@ -75,6 +75,7 @@ struct RoadVehicle : public Vehicle {
 
	Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running; }
 
	bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; }
 
	void Tick();
 
	void OnNewDay();
 
};
 

	
 
byte GetRoadVehLength(const Vehicle *v);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -2004,33 +2004,33 @@ static void CheckIfRoadVehNeedsService(V
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void OnNewDay_RoadVeh(Vehicle *v)
 
void RoadVehicle::OnNewDay()
 
{
 
	CommandCost cost(EXPENSES_ROADVEH_RUN);
 

	
 
	if (!IsRoadVehFront(v)) return;
 
	if (!IsRoadVehFront(this)) return;
 

	
 
	if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
 
	if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v);
 
	if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
 
	if (this->u.road.blocked_ctr == 0) CheckVehicleBreakdown(this);
 

	
 
	AgeVehicle(v);
 
	CheckIfRoadVehNeedsService(v);
 
	AgeVehicle(this);
 
	CheckIfRoadVehNeedsService(this);
 

	
 
	CheckOrders(v);
 
	CheckOrders(this);
 

	
 
	/* 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",
 
			v->unitnumber, v->index, v->u.road.slot->xy);
 
		ClearSlot(v);
 
			this->unitnumber, this->index, this->u.road.slot->xy);
 
		ClearSlot(this);
 
	}
 

	
 
	if (v->vehstatus & VS_STOPPED) return;
 
	if (this->vehstatus & VS_STOPPED) return;
 

	
 
	/* update destination */
 
	if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) {
 
		Station *st = GetStation(v->current_order.dest);
 
		RoadStop *rs = st->GetPrimaryRoadStop(v);
 
	if (this->current_order.type == OT_GOTO_STATION && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
 
		Station *st = GetStation(this->current_order.dest);
 
		RoadStop *rs = st->GetPrimaryRoadStop(this);
 
		RoadStop *best = 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
 
			 *    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 minbadness = UINT_MAX;
 

	
 
				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 */
 
				for (; rs != NULL; rs = rs->GetNextRoadStop(v)) {
 
					dist = RoadFindPathToStop(v, rs->xy);
 
				for (; rs != NULL; rs = rs->GetNextRoadStop(this)) {
 
					dist = RoadFindPathToStop(this, rs->xy);
 
					if (dist == UINT_MAX) {
 
						DEBUG(ms, 4, " stop 0x%X is unreachable, not treating further", rs->xy);
 
						continue;
 
@@ -2070,29 +2070,29 @@ void OnNewDay_RoadVeh(Vehicle *v)
 
					best->num_vehicles++;
 
					DEBUG(ms, 3, "Assigned to stop 0x%X", best->xy);
 

	
 
					v->u.road.slot = best;
 
					v->dest_tile = best->xy;
 
					v->u.road.slot_age = 14;
 
					this->u.road.slot = best;
 
					this->dest_tile = best->xy;
 
					this->u.road.slot_age = 14;
 
				} else {
 
					DEBUG(ms, 3, "Could not find a suitable stop");
 
				}
 
			} else {
 
				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 {
 
			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);
 
}
 

	
src/ship.h
Show inline comments
 
@@ -41,6 +41,7 @@ struct Ship: public Vehicle {
 
	Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; }
 
	bool IsInDepot() const { return this->u.ship.state == 0x80; }
 
	void Tick();
 
	void OnNewDay();
 
};
 

	
 
#endif /* SHIP_H */
src/ship_cmd.cpp
Show inline comments
 
@@ -170,27 +170,27 @@ static void CheckIfShipNeedsService(Vehi
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
}
 

	
 
void OnNewDay_Ship(Vehicle *v)
 
void Ship::OnNewDay()
 
{
 
	CommandCost cost(EXPENSES_SHIP_RUN);
 

	
 
	if ((++v->day_counter & 7) == 0)
 
		DecreaseVehicleValue(v);
 
	if ((++this->day_counter & 7) == 0)
 
		DecreaseVehicleValue(this);
 

	
 
	CheckVehicleBreakdown(v);
 
	AgeVehicle(v);
 
	CheckIfShipNeedsService(v);
 
	CheckVehicleBreakdown(this);
 
	AgeVehicle(this);
 
	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);
 
	v->profit_this_year -= cost.GetCost() >> 8;
 
	cost.AddCost(GetVehicleProperty(this, 0x0F, ShipVehInfo(this->engine_type)->running_cost) * _price.ship_running / 364);
 
	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 */
 
	InvalidateWindowClasses(WC_SHIPS_LIST);
 
}
src/train.h
Show inline comments
 
@@ -304,6 +304,7 @@ struct Train : public Vehicle {
 
	bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
 
	bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
 
	void Tick();
 
	void OnNewDay();
 
};
 

	
 
#endif /* TRAIN_H */
src/train_cmd.cpp
Show inline comments
 
@@ -3625,38 +3625,38 @@ static void CheckIfTrainNeedsService(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 (IsFrontEngine(v)) {
 
		CheckVehicleBreakdown(v);
 
		AgeVehicle(v);
 

	
 
		CheckIfTrainNeedsService(v);
 

	
 
		CheckOrders(v);
 
	if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
 

	
 
	if (IsFrontEngine(this)) {
 
		CheckVehicleBreakdown(this);
 
		AgeVehicle(this);
 

	
 
		CheckIfTrainNeedsService(this);
 

	
 
		CheckOrders(this);
 

	
 
		/* update destination */
 
		if (v->current_order.type == OT_GOTO_STATION) {
 
			TileIndex tile = GetStation(v->current_order.dest)->train_tile;
 
			if (tile != 0) v->dest_tile = tile;
 
		if (this->current_order.type == OT_GOTO_STATION) {
 
			TileIndex tile = GetStation(this->current_order.dest)->train_tile;
 
			if (tile != 0) this->dest_tile = tile;
 
		}
 

	
 
		if ((v->vehstatus & VS_STOPPED) == 0) {
 
		if ((this->vehstatus & VS_STOPPED) == 0) {
 
			/* running costs */
 
			CommandCost cost(EXPENSES_TRAIN_RUN, v->GetRunningCost() / 364);
 

	
 
			v->profit_this_year -= cost.GetCost() >> 8;
 

	
 
			SubtractMoneyFromPlayerFract(v->owner, cost);
 

	
 
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
			CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() / 364);
 

	
 
			this->profit_this_year -= cost.GetCost() >> 8;
 

	
 
			SubtractMoneyFromPlayerFract(this->owner, cost);
 

	
 
			InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
 
			InvalidateWindowClasses(WC_TRAINS_LIST);
 
		}
 
	} else if (IsTrainEngine(v)) {
 
	} else if (IsTrainEngine(this)) {
 
		/* Also age engines that aren't front engines */
 
		AgeVehicle(v);
 
		AgeVehicle(this);
 
	}
 
}
 

	
src/vehicle_base.h
Show inline comments
 
@@ -426,6 +426,11 @@ public:
 
	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.
 
	 * @return the vehicle's running cost
 
	 */
0 comments (0 inline, 0 general)