Changeset - r27889:87ac6e837ad9
[Not reviewed]
master
0 3 0
PeterN - 9 months ago 2023-09-10 17:55:37
peter1138@openttd.org
Fix: NewGRF house class mappings were not reset between games. (#11279)
3 files changed with 9 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/newgrf_house.cpp
Show inline comments
 
@@ -22,13 +22,13 @@
 
#include "newgrf_cargo.h"
 
#include "station_base.h"
 

	
 
#include "safeguards.h"
 

	
 
static BuildingCounts<uint32_t> _building_counts;
 
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
 
static std::array<HouseClassMapping, HOUSE_CLASS_MAX> _class_mapping;
 

	
 
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, NUM_HOUSES, INVALID_HOUSE_ID);
 

	
 
/**
 
 * Retrieve the grf file associated with a house.
 
 * @param house_id House to query.
 
@@ -69,12 +69,17 @@ GrfSpecFeature HouseResolverObject::GetF
 

	
 
uint32_t HouseResolverObject::GetDebugID() const
 
{
 
	return HouseSpec::Get(this->house_scope.house_id)->grf_prop.local_id;
 
}
 

	
 
void ResetHouseClassIDs()
 
{
 
	_class_mapping = {};
 
}
 

	
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32_t grfid)
 
{
 
	/* Start from 1 because 0 means that no class has been assigned. */
 
	for (int i = 1; i != lengthof(_class_mapping); i++) {
 
		HouseClassMapping *map = &_class_mapping[i];
 

	
src/newgrf_house.h
Show inline comments
 
@@ -84,12 +84,13 @@ struct HouseResolverObject : public Reso
 
 */
 
struct HouseClassMapping {
 
	uint32_t grfid;     ///< The GRF ID of the file this class belongs to
 
	uint8_t  class_id;  ///< The class id within the grf file
 
};
 

	
 
void ResetHouseClassIDs();
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32_t grfid);
 

	
 
void InitializeBuildingCounts();
 
void IncreaseBuildingCount(Town *t, HouseID house_id);
 
void DecreaseBuildingCount(Town *t, HouseID house_id);
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -3839,12 +3839,14 @@ extern const TileTypeProcs _tile_type_to
 

	
 

	
 
HouseSpec _house_specs[NUM_HOUSES];
 

	
 
void ResetHouses()
 
{
 
	ResetHouseClassIDs();
 

	
 
	auto insert = std::copy(std::begin(_original_house_specs), std::end(_original_house_specs), std::begin(_house_specs));
 
	std::fill(insert, std::end(_house_specs), HouseSpec{});
 

	
 
	/* Reset any overrides that have been set. */
 
	_house_mngr.ResetOverride();
 
}
0 comments (0 inline, 0 general)