summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-05-26 14:15:52 +0000
committerfrosch <frosch@openttd.org>2012-05-26 14:15:52 +0000
commit00b3ff80bbc76bc5546239cfcfa9a4c3591404a1 (patch)
treeeb206b8a4320d8da851d723e83379f020573b9f2
parentc796801c4d6c87c554e84312b1c3afd866e0e49c (diff)
downloadopenttd-00b3ff80bbc76bc5546239cfcfa9a4c3591404a1.tar.xz
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/news_func.h16
-rw-r--r--src/order_cmd.cpp6
-rw-r--r--src/train_cmd.cpp6
-rw-r--r--src/vehicle.cpp16
5 files changed, 20 insertions, 26 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index bff07382c..8f5be8da3 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -1862,7 +1862,7 @@ static void AircraftHandleDestTooFar(Aircraft *v, bool too_far)
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;
diff --git a/src/news_func.h b/src/news_func.h
index 542a307e4..e28f446a5 100644
--- a/src/news_func.h
+++ b/src/news_func.h
@@ -27,17 +27,23 @@ static inline void AddCompanyNewsItem(StringID string, CompanyNewsInformation *c
/**
* 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);
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 61ba4e121..d79f1e804 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -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);
}
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 3379bec2a..674da416d 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3771,11 +3771,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
/* 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;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 1513837b3..8a3d4fe68 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -710,7 +710,7 @@ void Vehicle::HandlePathfindingResult(bool path_found)
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));
}