tron@2186: /* $Id$ */ tron@2186: truelight@0: #ifndef TOWN_H truelight@0: #define TOWN_H truelight@0: matthijs@5216: #include "oldpool.h" truelight@0: #include "player.h" truelight@0: rubidium@5299: enum { rubidium@5299: INVALID_TOWN = 0xFFFF, rubidium@5299: }; rubidium@5299: truelight@0: struct Town { truelight@0: TileIndex xy; truelight@0: truelight@0: // Current population of people and amount of houses. truelight@0: uint16 num_houses; truelight@0: uint32 population; truelight@193: truelight@0: // Town name truelight@0: uint16 townnametype; truelight@0: uint32 townnameparts; truelight@193: truelight@193: // NOSAVE: Location of name sign, UpdateTownVirtCoord updates this. truelight@0: ViewportSign sign; truelight@193: truelight@0: // Makes sure we don't build certain house types twice. belugas@3432: // bit 0 = Building funds received belugas@3432: // bit 1 = CHURCH belugas@3432: // bit 2 = STADIUM truelight@0: byte flags12; truelight@0: truelight@0: // Which players have a statue? truelight@0: byte statues; truelight@0: truelight@0: // Player ratings as well as a mask that determines which players have a rating. truelight@0: byte have_ratings; truelight@0: uint8 unwanted[MAX_PLAYERS]; // how many months companies aren't wanted by towns (bribe) tron@2498: PlayerID exclusivity; // which player has exslusivity dominik@121: uint8 exclusive_counter; // months till the exclusivity expires truelight@0: int16 ratings[MAX_PLAYERS]; truelight@193: truelight@0: // Maximum amount of passengers and mail that can be transported. celestar@1377: uint32 max_pass; celestar@1377: uint32 max_mail; celestar@1377: uint32 new_max_pass; celestar@1377: uint32 new_max_mail; celestar@1377: uint32 act_pass; celestar@1377: uint32 act_mail; celestar@1377: uint32 new_act_pass; celestar@1377: uint32 new_act_mail; truelight@0: truelight@0: // Amount of passengers that were transported. truelight@0: byte pct_pass_transported; truelight@0: byte pct_mail_transported; truelight@0: truelight@0: // Amount of food and paper that was transported. Actually a bit mask would be enough. truelight@0: uint16 act_food; darkvater@4: uint16 act_water; truelight@0: uint16 new_act_food; darkvater@4: uint16 new_act_water; truelight@193: truelight@0: // Time until we rebuild a house. truelight@0: byte time_until_rebuild; truelight@0: truelight@0: // When to grow town next time. truelight@0: byte grow_counter; truelight@193: byte growth_rate; truelight@0: truelight@0: // Fund buildings program in action? truelight@0: byte fund_buildings_months; truelight@193: truelight@0: // Fund road reconstruction in action? truelight@0: byte road_build_months; truelight@0: truelight@0: // Index in town array Darkvater@3346: TownID index; truelight@0: truelight@0: // NOSAVE: UpdateTownRadius updates this given the house count. truelight@0: uint16 radius[5]; truelight@0: }; truelight@0: tron@1093: uint32 GetWorldPopulation(void); truelight@0: truelight@835: void UpdateTownVirtCoord(Town *t); tron@1093: void InitializeTown(void); Darkvater@3346: void ShowTownViewWindow(TownID town); truelight@0: void ExpandTown(Town *t); celestar@3674: Town *CreateRandomTown(uint attempts, uint size_mode); truelight@0: truelight@0: enum { truelight@0: ROAD_REMOVE = 0, truelight@0: UNMOVEABLE_REMOVE = 1, truelight@0: TUNNELBRIDGE_REMOVE = 1, truelight@0: INDUSTRY_REMOVE = 2 truelight@0: }; truelight@0: celestar@1005: enum { celestar@1005: // These refer to the maximums, so Appalling is -1000 to -400 celestar@1005: // MAXIMUM RATINGS BOUNDARIES belugas@3432: RATING_MINIMUM = -1000, rubidium@4344: RATING_APPALLING = -400, rubidium@4344: RATING_VERYPOOR = -200, rubidium@4344: RATING_POOR = 0, rubidium@4344: RATING_MEDIOCRE = 200, rubidium@4344: RATING_GOOD = 400, rubidium@4344: RATING_VERYGOOD = 600, rubidium@4344: RATING_EXCELLENT = 800, rubidium@4344: RATING_OUTSTANDING = 1000, // OUTSTANDING celestar@1005: celestar@1005: RATING_MAXIMUM = RATING_OUTSTANDING, celestar@1005: celestar@1005: // RATINGS AFFECTING NUMBERS celestar@1005: RATING_TREE_DOWN_STEP = -35, rubidium@4344: RATING_TREE_MINIMUM = RATING_MINIMUM, rubidium@4344: RATING_TREE_UP_STEP = 7, rubidium@4344: RATING_TREE_MAXIMUM = 220, celestar@1005: celestar@1005: RATING_TUNNEL_BRIDGE_DOWN_STEP = -250, rubidium@4344: RATING_TUNNEL_BRIDGE_MINIMUM = 0, celestar@1005: celestar@1005: RATING_INDUSTRY_DOWN_STEP = -1500, rubidium@4344: RATING_INDUSTRY_MINIMUM = RATING_MINIMUM, celestar@1005: celestar@1005: RATING_ROAD_DOWN_STEP = -50, rubidium@4344: RATING_ROAD_MINIMUM = -100, rubidium@4344: RATING_HOUSE_MINIMUM = RATING_MINIMUM, celestar@1005: celestar@1005: RATING_BRIBE_UP_STEP = 200, celestar@1005: RATING_BRIBE_MAXIMUM = 800, belugas@3432: RATING_BRIBE_DOWN_TO = -50 // XXX SHOULD BE SOMETHING LOWER? belugas@3432: }; belugas@3432: belugas@3432: enum { belugas@3432: /* This is the base "normal" number of towns on the 8x8 map, when belugas@3432: * one town should get grown per tick. The other numbers of towns belugas@3432: * are then scaled based on that. */ rubidium@4344: TOWN_GROWTH_FREQUENCY = 23, belugas@3432: /* Simple value that indicates the house has reached final stage of construction*/ rubidium@4344: TOWN_HOUSE_COMPLETED = 3, belugas@3432: }; belugas@3432: belugas@3432: /* This enum is used in conjonction with town->flags12. belugas@3432: * IT simply states what bit is used for. belugas@3432: * It is pretty unrealistic (IMHO) to only have one church/stadium belugas@3432: * per town, NO MATTER the population of it. belugas@3432: * And there are 5 more bits available on flags12... belugas@3432: */ belugas@3432: enum { belugas@3432: TOWN_IS_FUNDED = 0, // Town has received some funds for belugas@3432: TOWN_HAS_CHURCH = 1, // There can be only one church by town. belugas@3432: TOWN_HAS_STADIUM = 2 // There can be only one stadium by town. celestar@1005: }; celestar@1005: tron@2958: bool CheckforTownRating(uint32 flags, Town *t, byte type); truelight@0: tron@4277: VARDEF const Town** _town_sort; truelight@919: matthijs@5216: DECLARE_OLD_POOL(Town, Town, 3, 8000) truelight@1260: truelight@1260: /** matthijs@1330: * Check if a Town really exists. matthijs@1330: */ Darkvater@2436: static inline bool IsValidTown(const Town* town) matthijs@1330: { truelight@4346: return town->xy != 0; matthijs@1330: } matthijs@1330: rubidium@5299: static inline bool IsValidTownID(TownID index) rubidium@5299: { rubidium@5299: return index < GetTownPoolSize() && IsValidTown(GetTown(index)); rubidium@5299: } rubidium@5299: truelight@4354: VARDEF uint _total_towns; truelight@4354: matthijs@5247: static inline TownID GetMaxTownIndex(void) truelight@4354: { truelight@4354: /* TODO - This isn't the real content of the function, but truelight@4354: * with the new pool-system this will be replaced with one that matthijs@5247: * _really_ returns the highest index. Now it just returns truelight@4354: * the next safe value we are sure about everything is below. truelight@4354: */ rubidium@5298: return GetTownPoolSize() - 1; matthijs@5247: } matthijs@5247: matthijs@5247: static inline uint GetNumTowns(void) matthijs@5247: { truelight@4357: return _total_towns; truelight@4354: } truelight@4354: truelight@4356: /** truelight@4356: * Return a random valid town. truelight@4356: */ truelight@4356: static inline Town *GetRandomTown(void) truelight@4356: { rubidium@5299: int num = RandomRange(GetNumTowns()); rubidium@5299: TownID index = INVALID_TOWN; truelight@4356: rubidium@5299: while (num >= 0) { truelight@4356: num--; truelight@4356: truelight@4356: index++; truelight@4356: /* Make sure we have a valid industry */ rubidium@5299: while (!IsValidTownID(index)) { truelight@4356: index++; rubidium@5299: assert(index <= GetMaxTownIndex()); truelight@4356: } truelight@4356: } truelight@4356: truelight@4356: return GetTown(index); truelight@4356: } truelight@4356: truelight@4396: void DestroyTown(Town *t); truelight@4396: truelight@4396: static inline void DeleteTown(Town *t) truelight@4396: { truelight@4396: DestroyTown(t); truelight@4396: t->xy = 0; truelight@4396: } truelight@4396: tron@4983: #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)) truelight@1260: #define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0) truelight@1260: truelight@0: VARDEF bool _town_sort_dirty; truelight@0: VARDEF byte _town_sort_order; truelight@0: truelight@0: VARDEF Town *_cleared_town; truelight@0: VARDEF int _cleared_town_rating; truelight@0: truelight@0: #endif /* TOWN_H */