src/town.h
branchnoai
changeset 9694 e72987579514
parent 9629 66dde6412125
child 9701 d1ac22c62f64
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
    73 struct BuildingCounts {
    73 struct BuildingCounts {
    74 	uint8 id_count[HOUSE_MAX];
    74 	uint8 id_count[HOUSE_MAX];
    75 	uint8 class_count[HOUSE_CLASS_MAX];
    75 	uint8 class_count[HOUSE_CLASS_MAX];
    76 };
    76 };
    77 
    77 
    78 struct Town {
    78 struct Town;
       
    79 DECLARE_OLD_POOL(Town, Town, 3, 8000)
       
    80 
       
    81 struct Town : PoolItem<Town, TownID, &_Town_pool> {
    79 	TileIndex xy;
    82 	TileIndex xy;
    80 
    83 
    81 	/* Current population of people and amount of houses. */
    84 	/* Current population of people and amount of houses. */
    82 	uint16 num_houses;
    85 	uint16 num_houses;
    83 	uint32 population;
    86 	uint32 population;
   137 	byte fund_buildings_months;
   140 	byte fund_buildings_months;
   138 
   141 
   139 	/* Fund road reconstruction in action? */
   142 	/* Fund road reconstruction in action? */
   140 	byte road_build_months;
   143 	byte road_build_months;
   141 
   144 
   142 	/* Index in town array */
       
   143 	TownID index;
       
   144 
       
   145 	/* If this is a larger town, and should grow more quickly. */
   145 	/* If this is a larger town, and should grow more quickly. */
   146 	bool larger_town;
   146 	bool larger_town;
   147 
   147 
   148 	/* NOSAVE: UpdateTownRadius updates this given the house count. */
   148 	/* NOSAVE: UpdateTownRadius updates this given the house count. */
   149 	uint16 radius[5];
   149 	uint16 radius[5];
   150 
   150 
   151 	/* NOSAVE: The number of each type of building in the town. */
   151 	/* NOSAVE: The number of each type of building in the town. */
   152 	BuildingCounts building_counts;
   152 	BuildingCounts building_counts;
       
   153 
       
   154 	/**
       
   155 	 * Creates a new town
       
   156 	 */
       
   157 	Town(TileIndex tile = 0);
       
   158 
       
   159 	/** Destroy the town */
       
   160 	~Town();
       
   161 
       
   162 	bool IsValid() const { return this->xy != 0; }
       
   163 
       
   164 	void QuickFree();
   153 };
   165 };
   154 
   166 
   155 struct HouseSpec {
   167 struct HouseSpec {
   156 	/* Standard properties */
   168 	/* Standard properties */
   157 	Year min_date;                     ///< introduction year of the house
   169 	Year min_date;                     ///< introduction year of the house
   268 
   280 
   269 bool CheckforTownRating(uint32 flags, Town *t, byte type);
   281 bool CheckforTownRating(uint32 flags, Town *t, byte type);
   270 
   282 
   271 VARDEF const Town** _town_sort;
   283 VARDEF const Town** _town_sort;
   272 
   284 
   273 DECLARE_OLD_POOL(Town, Town, 3, 8000)
       
   274 
       
   275 static inline HouseSpec *GetHouseSpecs(HouseID house_id)
   285 static inline HouseSpec *GetHouseSpecs(HouseID house_id)
   276 {
   286 {
   277 	assert(house_id < HOUSE_MAX);
   287 	assert(house_id < HOUSE_MAX);
   278 	return &_house_specs[house_id];
   288 	return &_house_specs[house_id];
   279 }
       
   280 
       
   281 /**
       
   282  * Check if a Town really exists.
       
   283  * @param town to inquiry
       
   284  * @return true if it exists
       
   285  */
       
   286 static inline bool IsValidTown(const Town* town)
       
   287 {
       
   288 	return town->xy != 0;
       
   289 }
   289 }
   290 
   290 
   291 /**
   291 /**
   292  * Check if a TownID is valid.
   292  * Check if a TownID is valid.
   293  * @param index to inquiry in the pool of town
   293  * @param index to inquiry in the pool of town
   294  * @return true if it exists
   294  * @return true if it exists
   295  */
   295  */
   296 static inline bool IsValidTownID(TownID index)
   296 static inline bool IsValidTownID(TownID index)
   297 {
   297 {
   298 	return index < GetTownPoolSize() && IsValidTown(GetTown(index));
   298 	return index < GetTownPoolSize() && GetTown(index)->IsValid();
   299 }
   299 }
   300 
   300 
   301 VARDEF uint _total_towns;
   301 VARDEF uint _total_towns;
   302 
   302 
   303 static inline TownID GetMaxTownIndex()
   303 static inline TownID GetMaxTownIndex()
   335 	}
   335 	}
   336 
   336 
   337 	return GetTown(index);
   337 	return GetTown(index);
   338 }
   338 }
   339 
   339 
   340 void DestroyTown(Town *t);
       
   341 
       
   342 static inline void DeleteTown(Town *t)
       
   343 {
       
   344 	DestroyTown(t);
       
   345 	t->xy = 0;
       
   346 }
       
   347 
       
   348 Town* CalcClosestTownFromTile(TileIndex tile, uint threshold);
   340 Town* CalcClosestTownFromTile(TileIndex tile, uint threshold);
   349 
   341 
   350 #define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) if (IsValidTown(t))
   342 #define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) if (t->IsValid())
   351 #define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
   343 #define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
   352 
   344 
   353 VARDEF bool _town_sort_dirty;
   345 VARDEF bool _town_sort_dirty;
   354 VARDEF byte _town_sort_order;
   346 VARDEF byte _town_sort_order;
   355 
   347