summaryrefslogtreecommitdiff
path: root/src/newgrf_house.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-03-17 19:40:10 +0000
committerfrosch <frosch@openttd.org>2009-03-17 19:40:10 +0000
commitc7345c6db077abd490011df9a8241509ba8064e2 (patch)
tree48fa63e7eb4c788b98a17eba405e6c2f076110ac /src/newgrf_house.cpp
parentef28042bf1f06d7410c1dd7e3c60d4ed5820e5b4 (diff)
downloadopenttd-c7345c6db077abd490011df9a8241509ba8064e2.tar.xz
(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.
Diffstat (limited to 'src/newgrf_house.cpp')
-rw-r--r--src/newgrf_house.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index e5897c92c..816ea513b 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -22,7 +22,7 @@
#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);
@@ -61,20 +61,13 @@ void IncreaseBuildingCount(Town *t, HouseID house_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]++;
- if (_building_counts.id_count[house_id] < 255) _building_counts.id_count[house_id]++;
+ _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]++;
}
/**
@@ -121,10 +114,10 @@ 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;
}