File diff r27271:e0993573a0ba → r27272:bb139906001a
src/newgrf_house.cpp
Show inline comments
 
@@ -107,103 +107,102 @@ void InitializeBuildingCounts()
 
void IncreaseBuildingCount(Town *t, HouseID house_id)
 
{
 
	HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
 

	
 
	t->cache.building_counts.id_count[house_id]++;
 
	_building_counts.id_count[house_id]++;
 

	
 
	if (class_id == HOUSE_NO_CLASS) return;
 

	
 
	t->cache.building_counts.class_count[class_id]++;
 
	_building_counts.class_count[class_id]++;
 
}
 

	
 
/**
 
 * DecreaseBuildingCount()
 
 * Decrease the number of a building when it is deleted.
 
 * @param t The town that the building was built in
 
 * @param house_id The id of the house being removed
 
 */
 
void DecreaseBuildingCount(Town *t, HouseID house_id)
 
{
 
	HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
 

	
 
	if (t->cache.building_counts.id_count[house_id] > 0) t->cache.building_counts.id_count[house_id]--;
 
	if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
 

	
 
	if (class_id == HOUSE_NO_CLASS) return;
 

	
 
	if (t->cache.building_counts.class_count[class_id] > 0) t->cache.building_counts.class_count[class_id]--;
 
	if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
 
}
 

	
 
/* virtual */ uint32 HouseScopeResolver::GetRandomBits() const
 
{
 
	/* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
 
	assert(IsValidTile(this->tile) && (this->not_yet_constructed || IsTileType(this->tile, MP_HOUSE)));
 
	return this->not_yet_constructed ? this->initial_random_bits : GetHouseRandomBits(this->tile);
 
}
 

	
 
/* virtual */ uint32 HouseScopeResolver::GetTriggers() const
 
{
 
	/* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
 
	assert(IsValidTile(this->tile) && (this->not_yet_constructed || IsTileType(this->tile, MP_HOUSE)));
 
	return this->not_yet_constructed ? 0 : GetHouseTriggers(this->tile);
 
}
 

	
 
static uint32 GetNumHouses(HouseID house_id, const Town *town)
 
{
 
	uint8 map_id_count, town_id_count, map_class_count, town_class_count;
 
	HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
 

	
 
	map_id_count     = ClampU(_building_counts.id_count[house_id], 0, 255);
 
	map_class_count  = ClampU(_building_counts.class_count[class_id], 0, 255);
 
	town_id_count    = ClampU(town->cache.building_counts.id_count[house_id], 0, 255);
 
	town_class_count = ClampU(town->cache.building_counts.class_count[class_id], 0, 255);
 
	uint8_t map_id_count     = ClampTo<uint8_t>(_building_counts.id_count[house_id]);
 
	uint8_t map_class_count  = ClampTo<uint8_t>(_building_counts.class_count[class_id]);
 
	uint8_t town_id_count    = ClampTo<uint8_t>(town->cache.building_counts.id_count[house_id]);
 
	uint8_t town_class_count = ClampTo<uint8_t>(town->cache.building_counts.class_count[class_id]);
 

	
 
	return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
 
}
 

	
 
/**
 
 * Get information about a nearby tile.
 
 * @param parameter from callback. It's in fact a pair of coordinates
 
 * @param tile TileIndex from which the callback was initiated
 
 * @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
 
 * @return a construction of bits obeying the newgrf format
 
 */
 
static uint32 GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8)
 
{
 
	tile = GetNearbyTile(parameter, tile);
 
	return GetNearbyTileInformation(tile, grf_version8);
 
}
 

	
 
/** Structure with user-data for SearchNearbyHouseXXX - functions */
 
struct SearchNearbyHouseData {
 
	const HouseSpec *hs;  ///< Specs of the house that started the search.
 
	TileIndex north_tile; ///< Northern tile of the house.
 
};
 

	
 
/**
 
 * Callback function to search a house by its HouseID
 
 * @param tile TileIndex to be examined
 
 * @param user_data SearchNearbyHouseData
 
 * @return true or false, if found or not
 
 */
 
static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
 
{
 
	if (IsTileType(tile, MP_HOUSE)) {
 
		HouseID house = GetHouseType(tile); // tile been examined
 
		const HouseSpec *hs = HouseSpec::Get(house);
 
		if (hs->grf_prop.grffile != nullptr) { // must be one from a grf file
 
			SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
 

	
 
			TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
 
			if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
 

	
 
			return hs->grf_prop.local_id == nbhd->hs->grf_prop.local_id &&  // same local id as the one requested
 
				hs->grf_prop.grffile->grfid == nbhd->hs->grf_prop.grffile->grfid;  // from the same grf
 
		}
 
	}
 
	return false;
 
}
 

	
 
/**