|
@@ -48,25 +48,25 @@
|
|
|
*/
|
|
|
void InitializeSubsidies()
|
|
|
{
|
|
|
Subsidy::Clean();
|
|
|
}
|
|
|
|
|
|
Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode)
|
|
|
{
|
|
|
NewsReferenceType reftype1 = NR_NONE;
|
|
|
NewsReferenceType reftype2 = NR_NONE;
|
|
|
|
|
|
/* if mode is false, use the singular form */
|
|
|
const CargoSpec *cs = GetCargo(s->cargo_type);
|
|
|
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
|
|
|
SetDParam(0, mode ? cs->name : cs->name_single);
|
|
|
|
|
|
if (s->age < 12) {
|
|
|
if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL) {
|
|
|
SetDParam(1, STR_INDUSTRY);
|
|
|
SetDParam(2, s->from);
|
|
|
reftype1 = NR_INDUSTRY;
|
|
|
|
|
|
if (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD) {
|
|
|
SetDParam(4, STR_INDUSTRY);
|
|
|
SetDParam(5, s->to);
|
|
|
reftype2 = NR_INDUSTRY;
|
|
@@ -94,39 +94,39 @@ Pair SetupSubsidyDecodeParam(const Subsi
|
|
|
|
|
|
Pair p;
|
|
|
p.a = reftype1;
|
|
|
p.b = reftype2;
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
void DeleteSubsidyWithTown(TownID index)
|
|
|
{
|
|
|
Subsidy *s;
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
|
|
if (s->age < 12) {
|
|
|
const CargoSpec *cs = GetCargo(s->cargo_type);
|
|
|
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
|
|
|
if (((cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) && (index == s->from || index == s->to)) ||
|
|
|
((cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) && index == s->to)) {
|
|
|
s->cargo_type = CT_INVALID;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void DeleteSubsidyWithIndustry(IndustryID index)
|
|
|
{
|
|
|
Subsidy *s;
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
|
|
if (s->age < 12) {
|
|
|
const CargoSpec *cs = GetCargo(s->cargo_type);
|
|
|
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
|
|
|
if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL &&
|
|
|
(index == s->from || (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD && index == s->to))) {
|
|
|
s->cargo_type = CT_INVALID;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void DeleteSubsidyWithStation(StationID index)
|
|
|
{
|
|
|
bool dirty = false;
|
|
|
|
|
@@ -183,25 +183,25 @@ static void FindSubsidyCargoRoute(FoundR
|
|
|
total = i->last_month_production[1];
|
|
|
} else {
|
|
|
cargo = i->produced_cargo[0];
|
|
|
trans = i->last_month_pct_transported[0];
|
|
|
total = i->last_month_production[0];
|
|
|
}
|
|
|
|
|
|
/* Quit if no production in this industry
|
|
|
* or if the cargo type is passengers
|
|
|
* or if the pct transported is already large enough */
|
|
|
if (total == 0 || trans > 42 || cargo == CT_INVALID) return;
|
|
|
|
|
|
const CargoSpec *cs = GetCargo(cargo);
|
|
|
const CargoSpec *cs = CargoSpec::Get(cargo);
|
|
|
if (cs->town_effect == TE_PASSENGERS) return;
|
|
|
|
|
|
fr->cargo = cargo;
|
|
|
|
|
|
if (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) {
|
|
|
/* The destination is a town */
|
|
|
Town *t = Town::GetRandom();
|
|
|
|
|
|
/* Only want big towns */
|
|
|
if (t == NULL || t->population < 900) return;
|
|
|
|
|
|
fr->distance = DistanceManhattan(i->xy, t->xy);
|
|
@@ -278,25 +278,25 @@ void SubsidyMonthlyLoop()
|
|
|
FindSubsidyPassengerRoute(&fr);
|
|
|
if (fr.distance <= 70) {
|
|
|
s->cargo_type = CT_PASSENGERS;
|
|
|
s->from = ((Town*)fr.from)->index;
|
|
|
s->to = ((Town*)fr.to)->index;
|
|
|
goto add_subsidy;
|
|
|
}
|
|
|
FindSubsidyCargoRoute(&fr);
|
|
|
if (fr.distance <= 70) {
|
|
|
s->cargo_type = fr.cargo;
|
|
|
s->from = ((Industry*)fr.from)->index;
|
|
|
{
|
|
|
const CargoSpec *cs = GetCargo(fr.cargo);
|
|
|
const CargoSpec *cs = CargoSpec::Get(fr.cargo);
|
|
|
s->to = (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) ? ((Town*)fr.to)->index : ((Industry*)fr.to)->index;
|
|
|
}
|
|
|
add_subsidy:
|
|
|
if (!CheckSubsidyDuplicate(s)) {
|
|
|
s->age = 0;
|
|
|
Pair reftype = SetupSubsidyDecodeParam(s, 0);
|
|
|
AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->from, (NewsReferenceType)reftype.b, s->to);
|
|
|
AI::BroadcastNewEvent(new AIEventSubsidyOffer(s->Index()));
|
|
|
modified = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -317,25 +317,25 @@ bool CheckSubsidised(const Station *from
|
|
|
if (s->cargo_type == cargo_type &&
|
|
|
s->age >= 12 &&
|
|
|
s->from == from->index &&
|
|
|
s->to == to->index) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* check if there's a new subsidy that applies.. */
|
|
|
FOR_ALL_SUBSIDIES(s) {
|
|
|
if (s->cargo_type == cargo_type && s->age < 12) {
|
|
|
/* Check distance from source */
|
|
|
const CargoSpec *cs = GetCargo(cargo_type);
|
|
|
const CargoSpec *cs = CargoSpec::Get(cargo_type);
|
|
|
if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) {
|
|
|
xy = Town::Get(s->from)->xy;
|
|
|
} else {
|
|
|
xy = Industry::Get(s->from)->xy;
|
|
|
}
|
|
|
if (DistanceMax(xy, from->xy) > 9) continue;
|
|
|
|
|
|
/* Check distance from dest */
|
|
|
switch (cs->town_effect) {
|
|
|
case TE_PASSENGERS:
|
|
|
case TE_MAIL:
|
|
|
case TE_GOODS:
|