src/town.h
changeset 6658 59048224be55
parent 6573 7624f942237f
child 6667 437af4c23305
equal deleted inserted replaced
6657:3bf9d9badb6b 6658:59048224be55
     3 #ifndef TOWN_H
     3 #ifndef TOWN_H
     4 #define TOWN_H
     4 #define TOWN_H
     5 
     5 
     6 #include "oldpool.h"
     6 #include "oldpool.h"
     7 #include "player.h"
     7 #include "player.h"
     8 
     8 #include "functions.h"
     9 enum {
     9 #include "helpers.hpp"
    10 	INVALID_TOWN = 0xFFFF,
    10 
       
    11 enum {
       
    12 	HOUSE_NO_CLASS   = 0,
       
    13 	NEW_HOUSE_OFFSET = 110,
       
    14 	HOUSE_MAX        = 512,
       
    15 	INVALID_TOWN     = 0xFFFF,
       
    16 	INVALID_HOUSE_ID = 0xFFFF,
       
    17 
       
    18 	/* There can only be as many classes as there are new houses, plus one for
       
    19 	 * NO_CLASS, as the original houses don't have classes. */
       
    20 	HOUSE_CLASS_MAX  = HOUSE_MAX - NEW_HOUSE_OFFSET + 1,
       
    21 };
       
    22 
       
    23 enum BuildingFlags {
       
    24 	TILE_NO_FLAG         =       0,
       
    25 	TILE_SIZE_1x1        = 1U << 0,
       
    26 	TILE_NOT_SLOPED      = 1U << 1,
       
    27 	TILE_SIZE_2x1        = 1U << 2,
       
    28 	TILE_SIZE_1x2        = 1U << 3,
       
    29 	TILE_SIZE_2x2        = 1U << 4,
       
    30 	BUILDING_IS_ANIMATED = 1U << 5,
       
    31 	BUILDING_IS_CHURCH   = 1U << 6,
       
    32 	BUILDING_IS_STADIUM  = 1U << 7,
       
    33 	BUILDING_HAS_1_TILE  = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
       
    34 	BUILDING_2_TILES_X   = TILE_SIZE_2x1 | TILE_SIZE_2x2,
       
    35 	BUILDING_2_TILES_Y   = TILE_SIZE_1x2 | TILE_SIZE_2x2,
       
    36 	BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
       
    37 };
       
    38 
       
    39 DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
       
    40 
       
    41 enum HouseZones {                  ///< Bit  Value       Meaning
       
    42 	HZ_NOZNS             = 0x0000,  ///<       0          This is just to get rid of zeros, meaning none
       
    43 	HZ_ZON1              = 0x0001,  ///< 0..4 1,2,4,8,10  which town zones the building can be built in, Zone1 been the further suburb
       
    44 	HZ_ZON2              = 0x0002,
       
    45 	HZ_ZON3              = 0x0004,
       
    46 	HZ_ZON4              = 0x0008,
       
    47 	HZ_ZON5              = 0x0010,  ///<                  center of town
       
    48 	HZ_ZONALL            = 0x001F,  ///<       1F         This is just to englobe all above types at once
       
    49 	HZ_SUBARTC_ABOVE     = 0x0800,  ///< 11    800        can appear in sub-arctic climate above the snow line
       
    50 	HZ_TEMP              = 0x1000,  ///< 12   1000        can appear in temperate climate
       
    51 	HZ_SUBARTC_BELOW     = 0x2000,  ///< 13   2000        can appear in sub-arctic climate below the snow line
       
    52 	HZ_SUBTROPIC         = 0x4000,  ///< 14   4000        can appear in subtropical climate
       
    53 	HZ_TOYLND            = 0x8000   ///< 15   8000        can appear in toyland climate
       
    54 };
       
    55 
       
    56 DECLARE_ENUM_AS_BIT_SET(HouseZones)
       
    57 
       
    58 enum HouseExtraFlags {
       
    59 	NO_EXTRA_FLAG            =       0,
       
    60 	BUILDING_IS_HISTORICAL   = 1U << 0,  ///< this house will only appear during town generation in random games, thus the historical
       
    61 	BUILDING_IS_PROTECTED    = 1U << 1,  ///< towns and AI will not remove this house, while human players will be able tp
       
    62 	SYNCHRONISED_CALLBACK_1B = 1U << 2,  ///< synchronized callback 1B will be performed, on multi tile houses
       
    63 	CALLBACK_1A_RANDOM_BITS  = 1U << 3,  ///< callback 1A needs random bits
       
    64 };
       
    65 
       
    66 DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
       
    67 
       
    68 typedef uint16 HouseID;
       
    69 typedef uint16 HouseClassID;
       
    70 
       
    71 struct BuildingCounts {
       
    72 	uint8 id_count[HOUSE_MAX];
       
    73 	uint8 class_count[HOUSE_CLASS_MAX];
    11 };
    74 };
    12 
    75 
    13 struct Town {
    76 struct Town {
    14 	TileIndex xy;
    77 	TileIndex xy;
    15 
    78 
    76 	// Index in town array
   139 	// Index in town array
    77 	TownID index;
   140 	TownID index;
    78 
   141 
    79 	// NOSAVE: UpdateTownRadius updates this given the house count.
   142 	// NOSAVE: UpdateTownRadius updates this given the house count.
    80 	uint16 radius[5];
   143 	uint16 radius[5];
    81 };
   144 
       
   145 	// NOSAVE: The number of each type of building in the town.
       
   146 	BuildingCounts building_counts;
       
   147 };
       
   148 
       
   149 struct HouseSpec {
       
   150 	/* Standard properties */
       
   151 	Year min_date;                     ///< introduction year of the house
       
   152 	Year max_date;                     ///< last year it can be built
       
   153 	byte population;                   ///< population (Zero on other tiles in multi tile house.)
       
   154 	byte removal_cost;                 ///< cost multiplier for removing it
       
   155 	StringID building_name;            ///< building name
       
   156 	uint16 remove_rating_decrease;     ///< rating decrease if removed
       
   157 	byte mail_generation;              ///< mail generation multiplier (tile based, as the acceptances below)
       
   158 	byte passenger_acceptance;         ///< passenger acceptance, given in 1/8th unit, max is 8, as the 3 next properies
       
   159 	byte mail_acceptance;              ///< mail acceptance
       
   160 	byte goods_acceptance;             ///< good acceptance
       
   161 	byte food_acceptance;              ///< food (or fizzy drink) acceptance
       
   162 	BuildingFlags building_flags;      ///< some flags that describe the house (size, stadium etc...)
       
   163 	HouseZones building_availability;  ///< where can it be built (climates, zones)
       
   164 	bool enabled;                      ///< the house is still avaible (by default, true.newgrf can disable it, though)
       
   165 
       
   166 	/* NewHouses properties */
       
   167 	HouseID substitute_id;             ///< which house this one is based on
       
   168 	struct SpriteGroup *spritegroup;   ///< pointer to the different sprites of the house
       
   169 	HouseID override;                  ///< which house this one replaces
       
   170 	uint16 callback_mask;              ///< House callback flags
       
   171 	byte random_colour[4];             ///< 4 "random" colours
       
   172 	byte probability;                  ///< Relative probability of appearing (16 is the standard value)
       
   173 	HouseExtraFlags extra_flags;       ///< some more flags
       
   174 	HouseClassID class_id;             ///< defines the class this house has (grf file based) @See HouseGetVariable, prop 0x44
       
   175 	byte animation_frames;             ///< number of animation frames
       
   176 	byte animation_speed;              ///< amount of time between each of those frames
       
   177 	byte processing_time;              ///< Periodic refresh multiplier
       
   178 
       
   179 	/* grf file related properties*/
       
   180 	uint8 local_id;                    ///< id defined by the grf file for this house
       
   181 	const struct GRFFile *grffile;     ///< grf file that introduced this house
       
   182 };
       
   183 
       
   184 VARDEF HouseSpec _house_specs[HOUSE_MAX];
    82 
   185 
    83 uint32 GetWorldPopulation();
   186 uint32 GetWorldPopulation();
    84 
   187 
    85 void UpdateTownVirtCoord(Town *t);
   188 void UpdateTownVirtCoord(Town *t);
    86 void InitializeTown();
   189 void InitializeTown();
   156 
   259 
   157 VARDEF const Town** _town_sort;
   260 VARDEF const Town** _town_sort;
   158 
   261 
   159 DECLARE_OLD_POOL(Town, Town, 3, 8000)
   262 DECLARE_OLD_POOL(Town, Town, 3, 8000)
   160 
   263 
       
   264 static inline HouseSpec *GetHouseSpecs(HouseID house_id)
       
   265 {
       
   266 	assert(house_id < HOUSE_MAX);
       
   267 	return &_house_specs[house_id];
       
   268 }
       
   269 
   161 /**
   270 /**
   162  * Check if a Town really exists.
   271  * Check if a Town really exists.
   163  */
   272  */
   164 static inline bool IsValidTown(const Town* town)
   273 static inline bool IsValidTown(const Town* town)
   165 {
   274 {
   227 VARDEF byte _town_sort_order;
   336 VARDEF byte _town_sort_order;
   228 
   337 
   229 VARDEF Town *_cleared_town;
   338 VARDEF Town *_cleared_town;
   230 VARDEF int _cleared_town_rating;
   339 VARDEF int _cleared_town_rating;
   231 
   340 
       
   341 uint OriginalTileRandomiser(uint x, uint y);
       
   342 void ResetHouses();
       
   343 
       
   344 void ClearTownHouse(Town *t, TileIndex tile);
       
   345 
   232 #endif /* TOWN_H */
   346 #endif /* TOWN_H */