town.h
author celestar
Mon, 01 Jan 2007 16:07:21 +0000
branchcustombridgeheads
changeset 5621 6ce400c0a2f4
parent 5299 5d613241ee5e
permissions -rw-r--r--
(svn r7719) [cbh] - Codechange: KUDr and I have decided that our developemnt efforts went in the wrong direction, so revert all changes from 7686 onwards
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 1977
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 1977
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#ifndef TOWN_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
#define TOWN_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
5216
d581e4db95b6 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4983
diff changeset
     6
#include "oldpool.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
     9
enum {
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
    10
	INVALID_TOWN = 0xFFFF,
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
    11
};
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
    12
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
struct Town {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
	TileIndex xy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
	// Current population of people and amount of houses.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
	uint16 num_houses;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
	uint32 population;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    19
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
	// Town name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	uint16 townnametype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
	uint32 townnameparts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    23
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    24
	// NOSAVE: Location of name sign, UpdateTownVirtCoord updates this.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	ViewportSign sign;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	// Makes sure we don't build certain house types twice.
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
    28
	// bit 0 = Building funds received
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
    29
	// bit 1 = CHURCH
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
    30
	// bit 2 = STADIUM
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	byte flags12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	// Which players have a statue?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	byte statues;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	// Player ratings as well as a mask that determines which players have a rating.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	byte have_ratings;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	uint8 unwanted[MAX_PLAYERS]; // how many months companies aren't wanted by towns (bribe)
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2436
diff changeset
    39
	PlayerID exclusivity;        // which player has exslusivity
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 4
diff changeset
    40
	uint8 exclusive_counter;     // months till the exclusivity expires
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	int16 ratings[MAX_PLAYERS];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    42
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	// Maximum amount of passengers and mail that can be transported.
1377
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    44
	uint32 max_pass;
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    45
	uint32 max_mail;
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    46
	uint32 new_max_pass;
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    47
	uint32 new_max_mail;
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    48
	uint32 act_pass;
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    49
	uint32 act_mail;
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    50
	uint32 new_act_pass;
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
    51
	uint32 new_act_mail;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	// Amount of passengers that were transported.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	byte pct_pass_transported;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	byte pct_mail_transported;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	// Amount of food and paper that was transported. Actually a bit mask would be enough.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	uint16 act_food;
4
cad62d5f9708 (svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents: 0
diff changeset
    59
	uint16 act_water;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	uint16 new_act_food;
4
cad62d5f9708 (svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents: 0
diff changeset
    61
	uint16 new_act_water;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    62
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	// Time until we rebuild a house.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	byte time_until_rebuild;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	// When to grow town next time.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
	byte grow_counter;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    68
	byte growth_rate;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	// Fund buildings program in action?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	byte fund_buildings_months;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 121
diff changeset
    72
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	// Fund road reconstruction in action?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	byte road_build_months;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
	// Index in town array
3346
96c5db77aa83 (svn r4130) - CodeChange: Add proper semantics for TownID for such variables instead of using the general uint16-type. We probably need to change GetTown() and IsTownIndex() as well to use TownID.
Darkvater
parents: 2958
diff changeset
    77
	TownID index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	// NOSAVE: UpdateTownRadius updates this given the house count.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	uint16 radius[5];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
    83
uint32 GetWorldPopulation(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 820
diff changeset
    85
void UpdateTownVirtCoord(Town *t);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
    86
void InitializeTown(void);
3346
96c5db77aa83 (svn r4130) - CodeChange: Add proper semantics for TownID for such variables instead of using the general uint16-type. We probably need to change GetTown() and IsTownIndex() as well to use TownID.
Darkvater
parents: 2958
diff changeset
    87
void ShowTownViewWindow(TownID town);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
void ExpandTown(Town *t);
3674
e55478cff17e (svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents: 3432
diff changeset
    89
Town *CreateRandomTown(uint attempts, uint size_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
enum {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	ROAD_REMOVE = 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	UNMOVEABLE_REMOVE = 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	TUNNELBRIDGE_REMOVE = 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	INDUSTRY_REMOVE = 2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
    98
enum {
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
    99
	// These refer to the maximums, so Appalling is -1000 to -400
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   100
	// MAXIMUM RATINGS BOUNDARIES
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   101
	RATING_MINIMUM     = -1000,
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   102
	RATING_APPALLING   =  -400,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   103
	RATING_VERYPOOR    =  -200,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   104
	RATING_POOR        =     0,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   105
	RATING_MEDIOCRE    =   200,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   106
	RATING_GOOD        =   400,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   107
	RATING_VERYGOOD    =   600,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   108
	RATING_EXCELLENT   =   800,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   109
	RATING_OUTSTANDING =  1000,         // OUTSTANDING
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   110
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   111
	RATING_MAXIMUM = RATING_OUTSTANDING,
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   112
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   113
	// RATINGS AFFECTING NUMBERS
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   114
	RATING_TREE_DOWN_STEP = -35,
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   115
	RATING_TREE_MINIMUM   = RATING_MINIMUM,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   116
	RATING_TREE_UP_STEP   = 7,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   117
	RATING_TREE_MAXIMUM   = 220,
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   118
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   119
	RATING_TUNNEL_BRIDGE_DOWN_STEP = -250,
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   120
	RATING_TUNNEL_BRIDGE_MINIMUM   = 0,
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   121
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   122
	RATING_INDUSTRY_DOWN_STEP = -1500,
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   123
	RATING_INDUSTRY_MINIMUM   = RATING_MINIMUM,
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   124
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   125
	RATING_ROAD_DOWN_STEP = -50,
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   126
	RATING_ROAD_MINIMUM   = -100,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   127
	RATING_HOUSE_MINIMUM  = RATING_MINIMUM,
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   128
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   129
	RATING_BRIBE_UP_STEP = 200,
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   130
	RATING_BRIBE_MAXIMUM = 800,
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   131
	RATING_BRIBE_DOWN_TO = -50        // XXX SHOULD BE SOMETHING LOWER?
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   132
};
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   133
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   134
enum {
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   135
/* This is the base "normal" number of towns on the 8x8 map, when
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   136
 * one town should get grown per tick. The other numbers of towns
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   137
 * are then scaled based on that. */
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   138
	TOWN_GROWTH_FREQUENCY = 23,
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   139
/* Simple value that indicates the house has reached final stage of construction*/
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4277
diff changeset
   140
	TOWN_HOUSE_COMPLETED  =  3,
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   141
};
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   142
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   143
/* This enum is used in conjonction with town->flags12.
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   144
 * IT simply states what bit is used for.
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   145
 * It is pretty unrealistic (IMHO) to only have one church/stadium
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   146
 * per town, NO MATTER the population of it.
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   147
 * And there are 5 more bits available on flags12...
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   148
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   149
enum {
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   150
	TOWN_IS_FUNDED      = 0,   // Town has received some funds for
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   151
	TOWN_HAS_CHURCH     = 1,   // There can be only one church by town.
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3349
diff changeset
   152
	TOWN_HAS_STADIUM    = 2    // There can be only one stadium by town.
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   153
};
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 919
diff changeset
   154
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2817
diff changeset
   155
bool CheckforTownRating(uint32 flags, Town *t, byte type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 3674
diff changeset
   157
VARDEF const Town** _town_sort;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 835
diff changeset
   158
5216
d581e4db95b6 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4983
diff changeset
   159
DECLARE_OLD_POOL(Town, Town, 3, 8000)
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1220
diff changeset
   160
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1220
diff changeset
   161
/**
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1260
diff changeset
   162
 * Check if a Town really exists.
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1260
diff changeset
   163
 */
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2186
diff changeset
   164
static inline bool IsValidTown(const Town* town)
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1260
diff changeset
   165
{
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   166
	return town->xy != 0;
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1260
diff changeset
   167
}
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1260
diff changeset
   168
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   169
static inline bool IsValidTownID(TownID index)
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   170
{
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   171
	return index < GetTownPoolSize() && IsValidTown(GetTown(index));
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   172
}
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   173
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   174
VARDEF uint _total_towns;
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   175
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   176
static inline TownID GetMaxTownIndex(void)
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   177
{
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   178
	/* TODO - This isn't the real content of the function, but
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   179
	 *  with the new pool-system this will be replaced with one that
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   180
	 *  _really_ returns the highest index. Now it just returns
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   181
	 *  the next safe value we are sure about everything is below.
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   182
	 */
5298
6d4c150bdd94 (svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents: 5247
diff changeset
   183
	return GetTownPoolSize() - 1;
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   184
}
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   185
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   186
static inline uint GetNumTowns(void)
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   187
{
4357
3d72606e9192 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4356
diff changeset
   188
	return _total_towns;
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   189
}
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   190
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   191
/**
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   192
 * Return a random valid town.
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   193
 */
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   194
static inline Town *GetRandomTown(void)
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   195
{
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   196
	int num = RandomRange(GetNumTowns());
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   197
	TownID index = INVALID_TOWN;
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   198
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   199
	while (num >= 0) {
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   200
		num--;
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   201
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   202
		index++;
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   203
		/* Make sure we have a valid industry */
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   204
		while (!IsValidTownID(index)) {
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   205
			index++;
5299
5d613241ee5e (svn r7452) -Fix: GetRandom(Industry|Town) must return a valid industry/town and should not need to loop over the pool for a second time.
rubidium
parents: 5298
diff changeset
   206
			assert(index <= GetMaxTownIndex());
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   207
		}
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   208
	}
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   209
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   210
	return GetTown(index);
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   211
}
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   212
4396
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   213
void DestroyTown(Town *t);
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   214
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   215
static inline void DeleteTown(Town *t)
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   216
{
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   217
	DestroyTown(t);
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   218
	t->xy = 0;
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   219
}
549f28155809 (svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents: 4357
diff changeset
   220
4983
16a0ede2f7fb (svn r6986) Use the pool macros for the Town pool
tron
parents: 4396
diff changeset
   221
#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))
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1220
diff changeset
   222
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1220
diff changeset
   223
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
VARDEF bool _town_sort_dirty;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
VARDEF byte _town_sort_order;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
VARDEF Town *_cleared_town;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
VARDEF int _cleared_town_rating;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
#endif /* TOWN_H */