mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
This commit is contained in:
parent
c796801c4d
commit
00b3ff80bb
|
@ -1862,7 +1862,7 @@ static void AircraftHandleDestTooFar(Aircraft *v, bool too_far)
|
||||||
if (v->owner == _local_company) {
|
if (v->owner == _local_company) {
|
||||||
/* Post a news message. */
|
/* Post a news message. */
|
||||||
SetDParam(0, v->index);
|
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;
|
return;
|
||||||
|
|
|
@ -27,17 +27,23 @@ static inline void AddCompanyNewsItem(StringID string, CompanyNewsInformation *c
|
||||||
/**
|
/**
|
||||||
* Adds a newsitem referencing a vehicle.
|
* Adds a newsitem referencing a vehicle.
|
||||||
*
|
*
|
||||||
* @warning
|
* @warning The DParams may not reference the vehicle due to autoreplace stuff. See AddVehicleAdviceNewsItem for how that can be done.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
static inline void AddVehicleNewsItem(StringID string, NewsSubtype subtype, VehicleID vehicle, StationID station = INVALID_STATION)
|
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);
|
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)
|
static inline void AddIndustryNewsItem(StringID string, NewsSubtype subtype, IndustryID industry)
|
||||||
{
|
{
|
||||||
AddNewsItem(string, subtype, NR_INDUSTRY, industry);
|
AddNewsItem(string, subtype, NR_INDUSTRY, industry);
|
||||||
|
|
|
@ -1698,11 +1698,7 @@ void CheckOrders(const Vehicle *v)
|
||||||
//DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index);
|
//DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index);
|
||||||
|
|
||||||
SetDParam(0, v->index);
|
SetDParam(0, v->index);
|
||||||
AddVehicleNewsItem(
|
AddVehicleAdviceNewsItem(message, v->index);
|
||||||
message,
|
|
||||||
NS_ADVICE,
|
|
||||||
v->index
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3771,11 +3771,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
||||||
/* Show message to player. */
|
/* Show message to player. */
|
||||||
if (_settings_client.gui.lost_vehicle_warn && v->owner == _local_company) {
|
if (_settings_client.gui.lost_vehicle_warn && v->owner == _local_company) {
|
||||||
SetDParam(0, v->index);
|
SetDParam(0, v->index);
|
||||||
AddVehicleNewsItem(
|
AddVehicleAdviceNewsItem(STR_NEWS_TRAIN_IS_STUCK, v->index);
|
||||||
STR_NEWS_TRAIN_IS_STUCK,
|
|
||||||
NS_ADVICE,
|
|
||||||
v->index
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
v->wait_counter = 0;
|
v->wait_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -710,7 +710,7 @@ void Vehicle::HandlePathfindingResult(bool path_found)
|
||||||
AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index));
|
AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index));
|
||||||
if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) {
|
if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) {
|
||||||
SetDParam(0, this->index);
|
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(0, v->index);
|
||||||
SetDParam(1, error_message);
|
SetDParam(1, error_message);
|
||||||
AddVehicleNewsItem(message, NS_ADVICE, v->index);
|
AddVehicleAdviceNewsItem(message, v->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_company.Restore();
|
cur_company.Restore();
|
||||||
|
@ -1225,7 +1225,7 @@ void AgeVehicle(Vehicle *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDParam(0, v->index);
|
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) {
|
if (v->owner == _local_company) {
|
||||||
/* Notify the user that we stopped the vehicle */
|
/* Notify the user that we stopped the vehicle */
|
||||||
SetDParam(0, v->index);
|
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) {
|
} else if (cost.GetCost() != 0) {
|
||||||
v->profit_this_year -= cost.GetCost() << 8;
|
v->profit_this_year -= cost.GetCost() << 8;
|
||||||
|
@ -1383,7 +1383,7 @@ void VehicleEnterDepot(Vehicle *v)
|
||||||
_vehicles_to_autoreplace[v] = false;
|
_vehicles_to_autoreplace[v] = false;
|
||||||
if (v->owner == _local_company) {
|
if (v->owner == _local_company) {
|
||||||
SetDParam(0, v->index);
|
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));
|
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) {
|
if (_settings_client.gui.vehicle_income_warn && v->owner == _local_company) {
|
||||||
SetDParam(0, v->index);
|
SetDParam(0, v->index);
|
||||||
SetDParam(1, profit);
|
SetDParam(1, profit);
|
||||||
AddVehicleNewsItem(
|
AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_IS_UNPROFITABLE, v->index);
|
||||||
STR_NEWS_VEHICLE_IS_UNPROFITABLE,
|
|
||||||
NS_ADVICE,
|
|
||||||
v->index
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
AI::NewEvent(v->owner, new ScriptEventVehicleUnprofitable(v->index));
|
AI::NewEvent(v->owner, new ScriptEventVehicleUnprofitable(v->index));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue