/** Perform the monthly update of open subsidies, and try to create a new one. */ void SubsidyMonthlyLoop() { bool modified = false; Subsidy *s; FOR_ALL_SUBSIDIES(s) { if (--s->remaining == 0) { if (!s->IsAwarded()) { Pair reftype = SetupSubsidyDecodeParam(s, true); AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); AI::BroadcastNewEvent(new ScriptEventSubsidyOfferExpired(s->index)); Game::NewEvent(new ScriptEventSubsidyOfferExpired(s->index)); } else { if (s->awarded == _local_company) { Pair reftype = SetupSubsidyDecodeParam(s, true); AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NT_SUBSIDIES, NF_NORMAL, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); } AI::BroadcastNewEvent(new ScriptEventSubsidyExpired(s->index)); Game::NewEvent(new ScriptEventSubsidyExpired(s->index)); } delete s; modified = true; } } if (modified) RebuildSubsidisedSourceAndDestinationCache(); bool passenger_subsidy = false; bool town_subsidy = false; bool industry_subsidy = false; int random_chance = RandomRange(16); if (random_chance < 2) { /* There is a 1/8 chance each month of generating a passenger subsidy. */ int n = 1000; do { passenger_subsidy = FindSubsidyPassengerRoute(); } while (!passenger_subsidy && n--); } else if (random_chance == 2) { /* Cargo subsidies with a town as a source have a 1/16 chance. */ int n = 1000; do { town_subsidy = FindSubsidyTownCargoRoute(); } while (!town_subsidy && n--); } else if (random_chance == 3) { /* Cargo subsidies with an industry as a source have a 1/16 chance. */ int n = 1000; do { industry_subsidy = FindSubsidyIndustryCargoRoute(); } while (!industry_subsidy && n--); } modified |= passenger_subsidy || town_subsidy || industry_subsidy; if (modified) InvalidateWindowData(WC_SUBSIDIES_LIST, 0); }
void SubsidyMonthlyLoop() { bool modified = false; Subsidy *s; FOR_ALL_SUBSIDIES(s) { if (--s->remaining == 0) { if (!s->IsAwarded()) { Pair reftype = SetupSubsidyDecodeParam(s, 1); AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); AI::BroadcastNewEvent(new AIEventSubsidyOfferExpired(s->index)); } else { if (s->awarded == _local_company) { Pair reftype = SetupSubsidyDecodeParam(s, 1); AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); } AI::BroadcastNewEvent(new AIEventSubsidyExpired(s->index)); } delete s; modified = true; } } if (modified) RebuildSubsidisedSourceAndDestinationCache(); /* 25% chance to go on */ if (Subsidy::CanAllocateItem() && Chance16(1, 4)) { uint n = 1000; do { Subsidy *s = FindSubsidyPassengerRoute(); if (s == NULL) s = FindSubsidyCargoRoute(); if (s != NULL) { s->remaining = SUBSIDY_OFFER_MONTHS; s->awarded = INVALID_COMPANY; Pair reftype = SetupSubsidyDecodeParam(s, 0); AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); SetPartOfSubsidyFlag(s->src_type, s->src, POS_SRC); SetPartOfSubsidyFlag(s->dst_type, s->dst, POS_DST); AI::BroadcastNewEvent(new AIEventSubsidyOffer(s->index)); modified = true; break; } } while (n--); } if (modified) InvalidateWindowData(WC_SUBSIDIES_LIST, 0); }