Changeset - r12654:21eb6d3202f9
[Not reviewed]
master
0 3 0
smatz - 15 years ago 2009-08-08 18:26:25
smatz@openttd.org
(svn r17119) -Codechange: replace constants in subsidy.cpp by enum values
3 files changed with 22 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/saveload/afterload.cpp
Show inline comments
 
@@ -1872,13 +1872,13 @@ bool AfterLoadGame()
 

	
 
	if (CheckSavegameVersion(125)) {
 
		/* Convert old subsidies */
 
		Subsidy *s;
 
		FOR_ALL_SUBSIDIES(s) {
 
			/* Convert only nonawarded subsidies. The original source and destination town/industry
 
			 * anymore for awarded subsidies, so invalidate them. */
 
			 * can't be determined anymore for awarded subsidies, so invalidate them. */
 
			if (s->remaining < 12) {
 
				s->remaining = 12 - s->remaining; // convert "age" to "remaining"
 
				s->awarded = INVALID_COMPANY; // not awarded to anyone
 
				const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 
				switch (cs->town_effect) {
 
					case TE_PASSENGERS:
src/subsidy.cpp
Show inline comments
 
@@ -26,13 +26,13 @@
 
 */
 
void Subsidy::AwardTo(CompanyID company)
 
{
 
	assert(!this->IsAwarded());
 

	
 
	this->awarded = company;
 
	this->remaining = 12;
 
	this->remaining = SUBSIDY_CONTRACT_MONTHS;
 

	
 
	char *company_name = MallocT<char>(MAX_LENGTH_COMPANY_NAME_BYTES);
 
	SetDParam(0, company);
 
	GetString(company_name, STR_COMPANY_NAME, company_name + MAX_LENGTH_COMPANY_NAME_BYTES - 1);
 

	
 
	/* Add a news item */
 
@@ -189,16 +189,19 @@ static void FindSubsidyPassengerRoute(Fo
 
{
 
	Town *from, *to;
 

	
 
	fr->distance = UINT_MAX;
 

	
 
	fr->from = from = Town::GetRandom();
 
	if (from == NULL || from->population < 400 || from->pct_pass_transported > 42) return;
 
	if (from == NULL || from->population < SUBSIDY_PAX_MIN_POPULATION ||
 
			from->pct_pass_transported > SUBSIDY_MAX_PCT_TRANSPORTED) {
 
		return;
 
	}
 

	
 
	fr->to = to = Town::GetRandom();
 
	if (from == to || to == NULL || to->population < 400) return;
 
	if (from == to || to == NULL || to->population < SUBSIDY_PAX_MIN_POPULATION) return;
 

	
 
	fr->distance = DistanceManhattan(from->xy, to->xy);
 
}
 

	
 
static void FindSubsidyCargoRoute(FoundRoute *fr)
 
{
 
@@ -222,25 +225,25 @@ static void FindSubsidyCargoRoute(FoundR
 
		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;
 
	if (total == 0 || trans > SUBSIDY_MAX_PCT_TRANSPORTED || cargo == CT_INVALID) return;
 

	
 
	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;
 
		if (t == NULL || t->population < SUBSIDY_CARGO_MIN_POPULATION) return;
 

	
 
		fr->distance = DistanceManhattan(i->xy, t->xy);
 
		fr->to = t;
 
	} else {
 
		/* The destination is an industry */
 
		Industry *i2 = Industry::GetRandom();
 
@@ -302,21 +305,21 @@ void SubsidyMonthlyLoop()
 
		if (s == NULL) goto no_add;
 

	
 
		uint n = 1000;
 
		do {
 
			FoundRoute fr;
 
			FindSubsidyPassengerRoute(&fr);
 
			if (fr.distance <= 70) {
 
			if (fr.distance <= SUBSIDY_MAX_DISTANCE) {
 
				s->cargo_type = CT_PASSENGERS;
 
				s->src_type = s->dst_type = ST_TOWN;
 
				s->src = ((Town *)fr.from)->index;
 
				s->dst = ((Town *)fr.to)->index;
 
				goto add_subsidy;
 
			}
 
			FindSubsidyCargoRoute(&fr);
 
			if (fr.distance <= 70) {
 
			if (fr.distance <= SUBSIDY_MAX_DISTANCE) {
 
				s->cargo_type = fr.cargo;
 
				s->src_type = ST_INDUSTRY;
 
				s->src = ((Industry *)fr.from)->index;
 
				{
 
					const CargoSpec *cs = CargoSpec::Get(fr.cargo);
 
					if (cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) {
 
@@ -326,13 +329,13 @@ void SubsidyMonthlyLoop()
 
						s->dst_type = ST_INDUSTRY;
 
						s->dst = ((Industry *)fr.to)->index;
 
					}
 
				}
 
	add_subsidy:
 
				if (!CheckSubsidyDuplicate(s)) {
 
					s->remaining = 12;
 
					s->remaining = SUBSIDY_OFFER_MONTHS;
 
					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;
src/subsidy_base.h
Show inline comments
 
@@ -82,11 +82,21 @@ struct Subsidy {
 
	}
 

	
 
	static Subsidy *AllocateItem();
 
	static void Clean();
 
};
 

	
 
/** Constants related to subsidies */
 
enum {
 
	SUBSIDY_OFFER_MONTHS         =  12, ///< Duration of subsidy offer
 
	SUBSIDY_CONTRACT_MONTHS      =  12, ///< Duration of subsidy after awarding
 
	SUBSIDY_PAX_MIN_POPULATION   = 400, ///< Min. population of towns for subsidised pax route
 
	SUBSIDY_CARGO_MIN_POPULATION = 900, ///< Min. population of destination town for cargo route
 
	SUBSIDY_MAX_PCT_TRANSPORTED  =  42, ///< Subsidy will be created only for towns/industries with less % transported
 
	SUBSIDY_MAX_DISTANCE         =  70, ///< Max. length of subsidised route (DistanceManhattan)
 
};
 

	
 
#define FOR_ALL_SUBSIDIES_FROM(var, start) for (size_t subsidy_index = start; var = NULL, subsidy_index < Subsidy::GetArraySize(); subsidy_index++) \
 
		if ((var = Subsidy::Get(subsidy_index))->IsValid())
 
#define FOR_ALL_SUBSIDIES(var) FOR_ALL_SUBSIDIES_FROM(var, 0)
 

	
 
#endif /* SUBSIDY_BASE_H */
0 comments (0 inline, 0 general)