Changeset - r19367:da2e40bf245d
[Not reviewed]
master
0 5 0
frosch - 12 years ago 2012-05-26 14:15:52
frosch@openttd.org
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
5 files changed with 20 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1862,7 +1862,7 @@ static void AircraftHandleDestTooFar(Air
 
			if (v->owner == _local_company) {
 
				/* Post a news message. */
 
				SetDParam(0, v->index);
 
				AddVehicleNewsItem(STR_NEWS_AIRCRAFT_DEST_TOO_FAR, NS_ADVICE, v->index);
 
				AddVehicleAdviceNewsItem(STR_NEWS_AIRCRAFT_DEST_TOO_FAR, v->index);
 
			}
 
		}
 
		return;
src/news_func.h
Show inline comments
 
@@ -27,17 +27,23 @@ static inline void AddCompanyNewsItem(St
 
/**
 
 * Adds a newsitem referencing a vehicle.
 
 *
 
 * @warning
 
 * Be careful!
 
 * Vehicles are a special case, as news are kept when vehicles are autoreplaced/renewed.
 
 * You have to make sure, #ChangeVehicleNews catches the DParams of your message.
 
 * This is NOT ensured by the references.
 
 * @warning The DParams may not reference the vehicle due to autoreplace stuff. See AddVehicleAdviceNewsItem for how that can be done.
 
 */
 
static inline void AddVehicleNewsItem(StringID string, NewsSubtype subtype, VehicleID vehicle, StationID station = INVALID_STATION)
 
{
 
	AddNewsItem(string, subtype, NR_VEHICLE, vehicle, station == INVALID_STATION ? NR_NONE : NR_STATION, station);
 
}
 

	
 
/**
 
 * Adds a vehicle-advice news item.
 
 *
 
 * @warning DParam 0 must reference the vehicle!
 
 */
 
static inline void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
 
{
 
	AddNewsItem(string, NS_ADVICE, NR_VEHICLE, vehicle);
 
}
 

	
 
static inline void AddIndustryNewsItem(StringID string, NewsSubtype subtype, IndustryID industry)
 
{
 
	AddNewsItem(string, subtype, NR_INDUSTRY, industry);
src/order_cmd.cpp
Show inline comments
 
@@ -1698,11 +1698,7 @@ void CheckOrders(const Vehicle *v)
 
		//DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index);
 

	
 
		SetDParam(0, v->index);
 
		AddVehicleNewsItem(
 
			message,
 
			NS_ADVICE,
 
			v->index
 
		);
 
		AddVehicleAdviceNewsItem(message, v->index);
 
	}
 
}
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -3771,11 +3771,7 @@ static bool TrainLocoHandler(Train *v, b
 
				/* Show message to player. */
 
				if (_settings_client.gui.lost_vehicle_warn && v->owner == _local_company) {
 
					SetDParam(0, v->index);
 
					AddVehicleNewsItem(
 
						STR_NEWS_TRAIN_IS_STUCK,
 
						NS_ADVICE,
 
						v->index
 
					);
 
					AddVehicleAdviceNewsItem(STR_NEWS_TRAIN_IS_STUCK, v->index);
 
				}
 
				v->wait_counter = 0;
 
			}
src/vehicle.cpp
Show inline comments
 
@@ -710,7 +710,7 @@ void Vehicle::HandlePathfindingResult(bo
 
	AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index));
 
	if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) {
 
		SetDParam(0, this->index);
 
		AddVehicleNewsItem(STR_NEWS_VEHICLE_IS_LOST, NS_ADVICE, this->index);
 
		AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_IS_LOST, this->index);
 
	}
 
}
 

	
 
@@ -939,7 +939,7 @@ void CallVehicleTicks()
 

	
 
		SetDParam(0, v->index);
 
		SetDParam(1, error_message);
 
		AddVehicleNewsItem(message, NS_ADVICE, v->index);
 
		AddVehicleAdviceNewsItem(message, v->index);
 
	}
 

	
 
	cur_company.Restore();
 
@@ -1225,7 +1225,7 @@ void AgeVehicle(Vehicle *v)
 
	}
 

	
 
	SetDParam(0, v->index);
 
	AddVehicleNewsItem(str, NS_ADVICE, v->index);
 
	AddVehicleAdviceNewsItem(str, v->index);
 
}
 

	
 
/**
 
@@ -1362,7 +1362,7 @@ void VehicleEnterDepot(Vehicle *v)
 
				if (v->owner == _local_company) {
 
					/* Notify the user that we stopped the vehicle */
 
					SetDParam(0, v->index);
 
					AddVehicleNewsItem(STR_NEWS_ORDER_REFIT_FAILED, NS_ADVICE, v->index);
 
					AddVehicleAdviceNewsItem(STR_NEWS_ORDER_REFIT_FAILED, v->index);
 
				}
 
			} else if (cost.GetCost() != 0) {
 
				v->profit_this_year -= cost.GetCost() << 8;
 
@@ -1383,7 +1383,7 @@ void VehicleEnterDepot(Vehicle *v)
 
			_vehicles_to_autoreplace[v] = false;
 
			if (v->owner == _local_company) {
 
				SetDParam(0, v->index);
 
				AddVehicleNewsItem(STR_NEWS_TRAIN_IS_WAITING + v->type, NS_ADVICE, v->index);
 
				AddVehicleAdviceNewsItem(STR_NEWS_TRAIN_IS_WAITING + v->type, v->index);
 
			}
 
			AI::NewEvent(v->owner, new ScriptEventVehicleWaitingInDepot(v->index));
 
		}
 
@@ -2413,11 +2413,7 @@ void VehiclesYearlyLoop()
 
				if (_settings_client.gui.vehicle_income_warn && v->owner == _local_company) {
 
					SetDParam(0, v->index);
 
					SetDParam(1, profit);
 
					AddVehicleNewsItem(
 
						STR_NEWS_VEHICLE_IS_UNPROFITABLE,
 
						NS_ADVICE,
 
						v->index
 
					);
 
					AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_IS_UNPROFITABLE, v->index);
 
				}
 
				AI::NewEvent(v->owner, new ScriptEventVehicleUnprofitable(v->index));
 
			}
0 comments (0 inline, 0 general)