summaryrefslogtreecommitdiff
path: root/town.h
blob: a8757d5961a979926679bb81dcc151439b37e05b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef TOWN_H
#define TOWN_H

#include "player.h"

struct Town {
	TileIndex xy;

	// Current population of people and amount of houses.
	uint16 num_houses;
	uint32 population;

	// Town name
	uint16 townnametype;
	uint32 townnameparts;

	// NOSAVE: Location of name sign, UpdateTownVirtCoord updates this.
	ViewportSign sign;

	// Makes sure we don't build certain house types twice.
	byte flags12;

	// Which players have a statue?
	byte statues;

	// Sort index in listings
	byte sort_index_obsolete;

	// Player ratings as well as a mask that determines which players have a rating.
	byte have_ratings;
	uint8 unwanted[MAX_PLAYERS]; // how many months companies aren't wanted by towns (bribe)
	uint8 exclusivity;	     // which player has exslusivity
	uint8 exclusive_counter;     // months till the exclusivity expires
	int16 ratings[MAX_PLAYERS];

	// Maximum amount of passengers and mail that can be transported.
	uint16 max_pass;
	uint16 max_mail;
	uint16 new_max_pass;
	uint16 new_max_mail;
	uint16 act_pass;
	uint16 act_mail;
	uint16 new_act_pass;
	uint16 new_act_mail;

	// Amount of passengers that were transported.
	byte pct_pass_transported;
	byte pct_mail_transported;

	// Amount of food and paper that was transported. Actually a bit mask would be enough.
	uint16 act_food;
	uint16 act_water;
	uint16 new_act_food;
	uint16 new_act_water;

	// Time until we rebuild a house.
	byte time_until_rebuild;

	// When to grow town next time.
	byte grow_counter;
	byte growth_rate;

	// Fund buildings program in action?
	byte fund_buildings_months;

	// Fund road reconstruction in action?
	byte road_build_months;

	// Index in town array
	uint16 index;

	// NOSAVE: UpdateTownRadius updates this given the house count.
	uint16 radius[5];
};

uint32 GetWorldPopulation(void);

void UpdateTownVirtCoord(Town *t);
void InitializeTown(void);
void ShowTownViewWindow(uint town);
void DeleteTown(Town *t);
void ExpandTown(Town *t);
bool GrowTown(Town *t);
Town *CreateRandomTown(void);

enum {
	ROAD_REMOVE = 0,
	UNMOVEABLE_REMOVE = 1,
	TUNNELBRIDGE_REMOVE = 1,
	INDUSTRY_REMOVE = 2
};

enum {
	// These refer to the maximums, so Appalling is -1000 to -400
	// MAXIMUM RATINGS BOUNDARIES
	RATING_MINIMUM 		= -1000,
	RATING_APPALLING 	= -400,
	RATING_VERYPOOR 	= -200,
	RATING_POOR 			= 0,
	RATING_MEDIOCRE		= 200,
	RATING_GOOD				= 400,
	RATING_VERYGOOD		= 600,
	RATING_EXCELLENT	= 800,
	RATING_OUTSTANDING= 1000, 	// OUTSTANDING

	RATING_MAXIMUM = RATING_OUTSTANDING,

	// RATINGS AFFECTING NUMBERS
	RATING_TREE_DOWN_STEP = -35,
	RATING_TREE_MINIMUM = RATING_MINIMUM,
	RATING_TREE_UP_STEP = 7,
	RATING_TREE_MAXIMUM = 220,

	RATING_TUNNEL_BRIDGE_DOWN_STEP = -250,
	RATING_TUNNEL_BRIDGE_MINIMUM = 0,

	RATING_INDUSTRY_DOWN_STEP = -1500,
	RATING_INDUSTRY_MINIMUM = RATING_MINIMUM,

	RATING_ROAD_DOWN_STEP = -50,
	RATING_ROAD_MINIMUM = -100,
	RATING_HOUSE_MINIMUM = RATING_MINIMUM,

	RATING_BRIBE_UP_STEP = 200,
	RATING_BRIBE_MAXIMUM = 800,
	RATING_BRIBE_DOWN_TO = -50 					// XXX SHOULD BE SOMETHING LOWER?
};

bool CheckforTownRating(uint tile, uint32 flags, Town *t, byte type);

VARDEF Town _towns[250];
VARDEF uint _towns_size;

VARDEF uint16 *_town_sort;

static inline Town *GetTown(uint index)
{
	assert(index < _towns_size);
	return &_towns[index];
}

#define FOR_ALL_TOWNS(t) for(t = _towns; t != &_towns[_towns_size]; t++)

VARDEF int _total_towns; // For the AI: the amount of towns active

VARDEF bool _town_sort_dirty;
VARDEF byte _town_sort_order;

VARDEF Town *_cleared_town;
VARDEF int _cleared_town_rating;

#endif /* TOWN_H */