File diff r19275:0c394e0a1f14 → r19276:ad854f3053cd
src/subsidy.cpp
Show inline comments
 
@@ -118,22 +118,22 @@ Pair SetupSubsidyDecodeParam(const Subsi
 
 * @param flag flag to set
 
 */
 
static inline void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfSubsidy flag)
 
{
 
	switch (type) {
 
		case ST_INDUSTRY: Industry::Get(index)->part_of_subsidy |= flag; return;
 
		case ST_TOWN:         Town::Get(index)->part_of_subsidy |= flag; return;
 
		case ST_TOWN:   Town::Get(index)->cache.part_of_subsidy |= flag; return;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/** Perform a full rebuild of the subsidies cache. */
 
void RebuildSubsidisedSourceAndDestinationCache()
 
{
 
	Town *t;
 
	FOR_ALL_TOWNS(t) t->part_of_subsidy = POS_NONE;
 
	FOR_ALL_TOWNS(t) t->cache.part_of_subsidy = POS_NONE;
 

	
 
	Industry *i;
 
	FOR_ALL_INDUSTRIES(i) i->part_of_subsidy = POS_NONE;
 

	
 
	const Subsidy *s;
 
	FOR_ALL_SUBSIDIES(s) {
 
@@ -294,19 +294,19 @@ CommandCost CmdCreateSubsidy(TileIndex t
 
 */
 
bool FindSubsidyPassengerRoute()
 
{
 
	if (!Subsidy::CanAllocateItem()) return false;
 

	
 
	const Town *src = Town::GetRandom();
 
	if (src->population < SUBSIDY_PAX_MIN_POPULATION ||
 
	if (src->cache.population < SUBSIDY_PAX_MIN_POPULATION ||
 
			src->GetPercentTransported(CT_PASSENGERS) > SUBSIDY_MAX_PCT_TRANSPORTED) {
 
		return false;
 
	}
 

	
 
	const Town *dst = Town::GetRandom();
 
	if (dst->population < SUBSIDY_PAX_MIN_POPULATION || src == dst) {
 
	if (dst->cache.population < SUBSIDY_PAX_MIN_POPULATION || src == dst) {
 
		return false;
 
	}
 

	
 
	if (DistanceManhattan(src->xy, dst->xy) > SUBSIDY_MAX_DISTANCE) return false;
 
	if (CheckSubsidyDuplicate(CT_PASSENGERS, ST_TOWN, src->index, ST_TOWN, dst->index)) return false;
 

	
 
@@ -531,13 +531,13 @@ bool CheckSubsidised(CargoID cargo_type,
 
	if (src == INVALID_SOURCE) return false;
 
	switch (src_type) {
 
		case ST_INDUSTRY:
 
			if (!(Industry::Get(src)->part_of_subsidy & POS_SRC)) return false;
 
			break;
 
		case ST_TOWN:
 
			if (!(    Town::Get(src)->part_of_subsidy & POS_SRC)) return false;
 
			if (!(Town::Get(src)->cache.part_of_subsidy & POS_SRC)) return false;
 
			break;
 
		default: return false;
 
	}
 

	
 
	/* Remember all towns near this station (at least one house in its catchment radius)
 
	 * which are destination of subsidised path. Do that only if needed */
 
@@ -554,13 +554,13 @@ bool CheckSubsidised(CargoID cargo_type,
 

	
 
			for (int y = rect.top; y <= rect.bottom; y++) {
 
				for (int x = rect.left; x <= rect.right; x++) {
 
					TileIndex tile = TileXY(x, y);
 
					if (!IsTileType(tile, MP_HOUSE)) continue;
 
					const Town *t = Town::GetByTile(tile);
 
					if (t->part_of_subsidy & POS_DST) towns_near.Include(t);
 
					if (t->cache.part_of_subsidy & POS_DST) towns_near.Include(t);
 
				}
 
			}
 
			break;
 
		}
 
	}
 

	
 
@@ -581,13 +581,13 @@ bool CheckSubsidised(CargoID cargo_type,
 
						}
 
					}
 
					break;
 
				case ST_TOWN:
 
					for (const Town * const *tp = towns_near.Begin(); tp != towns_near.End(); tp++) {
 
						if (s->dst == (*tp)->index) {
 
							assert((*tp)->part_of_subsidy & POS_DST);
 
							assert((*tp)->cache.part_of_subsidy & POS_DST);
 
							subsidised = true;
 
							if (!s->IsAwarded()) s->AwardTo(company);
 
						}
 
					}
 
					break;
 
				default: