Changeset - r11396:4adf79ba94c4
[Not reviewed]
master
0 2 0
frosch - 15 years ago 2009-03-17 19:40:10
frosch@openttd.org
(svn r15755) -Fix: Number of houses in house variables 0x44, 0x60 and 0x61 were incorrect after 0xFF had been reached and could desync clients joining afterwards.
2 files changed with 13 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/newgrf_house.cpp
Show inline comments
 
@@ -19,13 +19,13 @@
 
#include "transparency.h"
 
#include "functions.h"
 
#include "company_func.h"
 
#include "animated_tile_func.h"
 
#include "company_base.h"
 

	
 
static BuildingCounts    _building_counts;
 
static BuildingCounts<uint32> _building_counts;
 
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
 

	
 
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID);
 

	
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
 
{
 
@@ -58,26 +58,19 @@ void InitializeBuildingCounts()
 
void IncreaseBuildingCount(Town *t, HouseID house_id)
 
{
 
	HouseClassID class_id = GetHouseSpecs(house_id)->class_id;
 

	
 
	if (!_loaded_newgrf_features.has_newhouses) return;
 

	
 
	/* If there are 255 buildings of this type in this town, there are also
 
	 * at least that many houses of the same class in the town, and
 
	 * therefore on the map as well. */
 
	if (t->building_counts.id_count[house_id] == 255) return;
 
	t->building_counts.id_count[house_id]++;
 
	_building_counts.id_count[house_id]++;
 

	
 
	t->building_counts.id_count[house_id]++;
 
	if (_building_counts.id_count[house_id] < 255) _building_counts.id_count[house_id]++;
 

	
 
	/* Similarly, if there are 255 houses of this class in this town, there
 
	 * must be at least that number on the map too. */
 
	if (class_id == HOUSE_NO_CLASS || t->building_counts.class_count[class_id] == 255) return;
 
	if (class_id == HOUSE_NO_CLASS) return;
 

	
 
	t->building_counts.class_count[class_id]++;
 
	if (_building_counts.class_count[class_id] < 255) _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
 
@@ -118,16 +111,16 @@ static void HouseSetTriggers(const Resol
 

	
 
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 = GetHouseSpecs(house_id)->class_id;
 

	
 
	map_id_count     = _building_counts.id_count[house_id];
 
	map_class_count  = _building_counts.class_count[class_id];
 
	town_id_count    = town->building_counts.id_count[house_id];
 
	town_class_count = town->building_counts.class_count[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->building_counts.id_count[house_id], 0, 255);
 
	town_class_count = ClampU(town->building_counts.class_count[class_id], 0, 255);
 

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

	
 
uint32 GetNearbyTileInformation(byte parameter, TileIndex tile)
 
{
src/town.h
Show inline comments
 
@@ -87,15 +87,16 @@ enum HouseExtraFlags {
 
	SYNCHRONISED_CALLBACK_1B = 1U << 2,  ///< synchronized callback 1B will be performed, on multi tile houses
 
	CALLBACK_1A_RANDOM_BITS  = 1U << 3,  ///< callback 1A needs random bits
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
 

	
 
template <typename T>
 
struct BuildingCounts {
 
	uint8 id_count[HOUSE_MAX];
 
	uint8 class_count[HOUSE_CLASS_MAX];
 
	T id_count[HOUSE_MAX];
 
	T class_count[HOUSE_CLASS_MAX];
 
};
 

	
 
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY  = 4; ///< value for custom town number in difficulty settings
 
static const uint CUSTOM_TOWN_MAX_NUMBER = 5000;  ///< this is the maximum number of towns a user can specify in customisation
 

	
 
DECLARE_OLD_POOL(Town, Town, 3, 8000)
 
@@ -173,13 +174,13 @@ struct Town : PoolItem<Town, TownID, &_T
 
	TownLayoutByte layout; ///< town specific road layout
 

	
 
	/* NOSAVE: UpdateTownRadius updates this given the house count. */
 
	uint32 squared_town_zone_radius[HZB_END];
 

	
 
	/* NOSAVE: The number of each type of building in the town. */
 
	BuildingCounts building_counts;
 
	BuildingCounts<uint16> building_counts;
 

	
 
	/**
 
	 * Creates a new town
 
	 */
 
	Town(TileIndex tile = INVALID_TILE);
 

	
0 comments (0 inline, 0 general)