(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.

This commit is contained in:
frosch 2012-05-26 14:15:52 +00:00
parent c796801c4d
commit 00b3ff80bb
5 changed files with 20 additions and 26 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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));
}