src/town.h
branchnoai
changeset 9869 6404afe43575
parent 9826 9707ad4c9b60
child 10249 58810805030e
--- a/src/town.h	Sun Apr 06 14:12:19 2008 +0000
+++ b/src/town.h	Sun Apr 06 23:07:42 2008 +0000
@@ -6,6 +6,7 @@
 #define TOWN_H
 
 #include "oldpool.h"
+#include "core/bitmath_func.hpp"
 #include "core/random_func.hpp"
 #include "cargo_type.h"
 #include "tile_type.h"
@@ -13,6 +14,7 @@
 #include "town_type.h"
 #include "player_type.h"
 #include "newgrf_string_type.h"
+#include "settings_type.h"
 
 enum {
 	HOUSE_NO_CLASS   = 0,
@@ -45,12 +47,17 @@
 DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
 
 enum HouseZonesBits {
+	HZB_BEGIN     = 0,
 	HZB_TOWN_EDGE = 0,
 	HZB_TOWN_OUTSKIRT,
 	HZB_TOWN_OUTER_SUBURB,
 	HZB_TOWN_INNER_SUBURB,
 	HZB_TOWN_CENTRE,
+	HZB_END,
 };
+assert_compile(HZB_END == 5);
+
+DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
 
 enum HouseZones {                  ///< Bit  Value       Meaning
 	HZ_NOZNS             = 0x0000,  ///<       0          This is just to get rid of zeros, meaning none
@@ -156,11 +163,14 @@
 	bool larger_town;
 
 	/* NOSAVE: UpdateTownRadius updates this given the house count. */
-	uint16 radius[5];
+	uint16 radius[HZB_END];
 
 	/* NOSAVE: The number of each type of building in the town. */
 	BuildingCounts building_counts;
 
+	/* NOSAVE: The town specific road layout */
+	TownLayout layout;
+
 	/**
 	 * Creates a new town
 	 */
@@ -170,8 +180,21 @@
 	~Town();
 
 	inline bool IsValid() const { return this->xy != 0; }
+
+	void InitializeLayout();
+
+	inline TownLayout GetActiveLayout() const;
 };
 
+/**
+ * Get the current valid layout for the town
+ * @return the active layout for this town
+ */
+inline TownLayout Town::GetActiveLayout() const
+{
+	return (_patches.town_layout == TL_RANDOM) ? this->layout : _patches.town_layout;
+}
+
 struct HouseSpec {
 	/* Standard properties */
 	Year min_date;                     ///< introduction year of the house
@@ -314,7 +337,6 @@
 extern Town *_cleared_town;
 extern int _cleared_town_rating;
 
-uint OriginalTileRandomiser(uint x, uint y);
 void ResetHouses();
 
 void ClearTownHouse(Town *t, TileIndex tile);
@@ -327,4 +349,34 @@
 HouseZonesBits GetTownRadiusGroup(const Town* t, TileIndex tile);
 void SetTownRatingTestMode(bool mode);
 
+/**
+ * Calculate a hash value from a tile position
+ *
+ * @param x The X coordinate
+ * @param y The Y coordinate
+ * @return The hash of the tile
+ */
+static inline uint TileHash(uint x, uint y)
+{
+	uint hash = x >> 4;
+	hash ^= x >> 6;
+	hash ^= y >> 4;
+	hash -= y >> 6;
+	return hash;
+}
+
+/**
+ * Get the last two bits of the TileHash
+ *  from a tile position.
+ *
+ * @see TileHash()
+ * @param x The X coordinate
+ * @param y The Y coordinate
+ * @return The last two bits from hash of the tile
+ */
+static inline uint TileHash2Bit(uint x, uint y)
+{
+	return GB(TileHash(x, y), 0, 2);
+}
+
 #endif /* TOWN_H */