author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1373 | 4f5722822810 |
child 1586 | d179623e13c9 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
552
diff
changeset
|
4 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
5 |
#include "tile.h" |
0 | 6 |
#include "viewport.h" |
7 |
#include "command.h" |
|
8 |
#include "industry.h" |
|
9 |
#include "town.h" |
|
10 |
#include "vehicle.h" |
|
11 |
#include "news.h" |
|
12 |
#include "saveload.h" |
|
13 |
#include "economy.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
314
diff
changeset
|
14 |
#include "sound.h" |
0 | 15 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
16 |
enum { |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
17 |
/* Max industries: 64000 (8 * 8000) */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
18 |
INDUSTRY_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
19 |
INDUSTRY_POOL_MAX_BLOCKS = 8000, |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
20 |
}; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
21 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
22 |
/** |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
23 |
* Called if a new block is added to the industry-pool |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
24 |
*/ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
25 |
void IndustryPoolNewBlock(uint start_item) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
26 |
{ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
27 |
Industry *i; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
28 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
29 |
FOR_ALL_INDUSTRIES_FROM(i, start_item) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
30 |
i->index = start_item++; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
31 |
} |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
32 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
33 |
/* Initialize the industry-pool */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
34 |
MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, 0, 0, NULL }; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
35 |
|
0 | 36 |
byte _industry_sound_ctr; |
37 |
TileIndex _industry_sound_tile; |
|
38 |
||
39 |
void ShowIndustryViewWindow(int industry); |
|
40 |
void BuildOilRig(uint tile); |
|
41 |
void DeleteOilRig(uint tile); |
|
42 |
||
43 |
typedef struct DrawIndustryTileStruct { |
|
44 |
uint32 sprite_1; |
|
45 |
uint32 sprite_2; |
|
46 |
||
47 |
byte subtile_xy; |
|
48 |
byte width_height; |
|
49 |
byte dz; |
|
50 |
byte proc; |
|
51 |
} DrawIndustryTileStruct; |
|
52 |
||
53 |
||
54 |
typedef struct DrawIndustrySpec1Struct { |
|
55 |
byte x; |
|
56 |
byte image_1; |
|
57 |
byte image_2; |
|
58 |
byte image_3; |
|
59 |
} DrawIndustrySpec1Struct; |
|
60 |
||
61 |
typedef struct DrawIndustrySpec4Struct { |
|
62 |
byte image_1; |
|
63 |
byte image_2; |
|
64 |
byte image_3; |
|
65 |
} DrawIndustrySpec4Struct; |
|
66 |
||
67 |
||
68 |
||
69 |
#include "table/industry_land.h" |
|
70 |
||
71 |
||
72 |
typedef struct IndustryTileTable { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
73 |
TileIndexDiffC ti; |
0 | 74 |
byte map5; |
75 |
} IndustryTileTable; |
|
76 |
||
77 |
typedef struct IndustrySpec { |
|
78 |
const IndustryTileTable * const * table; |
|
79 |
byte num_table; |
|
80 |
byte a,b,c; |
|
81 |
byte produced_cargo[2]; |
|
82 |
byte production_rate[2]; |
|
83 |
byte accepts_cargo[3]; |
|
84 |
byte check_proc; |
|
85 |
} IndustrySpec; |
|
86 |
||
87 |
#include "table/build_industry.h" |
|
88 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
89 |
typedef enum IndustryType { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
90 |
INDUSTRY_NOT_CLOSABLE, //! Industry can never close |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
91 |
INDUSTRY_PRODUCTION, //! Industry can close and change of production |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
92 |
INDUSTRY_CLOSABLE, //! Industry can only close (no production change) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
93 |
} IndustryType; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
94 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
95 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
96 |
static const IndustryType _industry_close_mode[37] = { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
97 |
/* COAL_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
98 |
/* POWER_STATION */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
99 |
/* SAWMILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
100 |
/* FOREST */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
101 |
/* OIL_REFINERY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
102 |
/* OIL_RIG */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
103 |
/* FACTORY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
104 |
/* PRINTING_WORKS */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
105 |
/* STEEL_MILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
106 |
/* FARM */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
107 |
/* COPPER_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
108 |
/* OIL_WELL */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
109 |
/* BANK */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
110 |
/* FOOD_PROCESS */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
111 |
/* PAPER_MILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
112 |
/* GOLD_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
113 |
/* BANK_2, */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
114 |
/* DIAMOND_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
115 |
/* IRON_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
116 |
/* FRUIT_PLANTATION */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
117 |
/* RUBBER_PLANTATION */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
118 |
/* WATER_SUPPLY */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
119 |
/* WATER_TOWER */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
120 |
/* FACTORY_2 */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
121 |
/* FARM_2 */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
122 |
/* LUMBER_MILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
123 |
/* COTTON_CANDY */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
124 |
/* CANDY_FACTORY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
125 |
/* BATTERY_FARM */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
126 |
/* COLA_WELLS */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
127 |
/* TOY_SHOP */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
128 |
/* TOY_FACTORY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
129 |
/* PLASTIC_FOUNTAINS */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
130 |
/* FIZZY_DRINK_FACTORY */INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
131 |
/* BUBBLE_GENERATOR */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
132 |
/* TOFFEE_QUARRY */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
133 |
/* SUGAR_MINE */ INDUSTRY_PRODUCTION |
0 | 134 |
}; |
135 |
||
136 |
static const StringID _industry_prod_up_strings[] = { |
|
137 |
STR_4836_NEW_COAL_SEAM_FOUND_AT, |
|
138 |
STR_4835_INCREASES_PRODUCTION, |
|
139 |
STR_4835_INCREASES_PRODUCTION, |
|
140 |
STR_4835_INCREASES_PRODUCTION, |
|
141 |
STR_4835_INCREASES_PRODUCTION, |
|
142 |
STR_4837_NEW_OIL_RESERVES_FOUND, |
|
143 |
STR_4835_INCREASES_PRODUCTION, |
|
144 |
STR_4835_INCREASES_PRODUCTION, |
|
145 |
STR_4835_INCREASES_PRODUCTION, |
|
146 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
147 |
STR_4835_INCREASES_PRODUCTION, |
|
148 |
STR_4837_NEW_OIL_RESERVES_FOUND, |
|
149 |
STR_4835_INCREASES_PRODUCTION, |
|
150 |
STR_4835_INCREASES_PRODUCTION, |
|
151 |
STR_4835_INCREASES_PRODUCTION, |
|
152 |
STR_4835_INCREASES_PRODUCTION, |
|
153 |
STR_4835_INCREASES_PRODUCTION, |
|
154 |
STR_4835_INCREASES_PRODUCTION, |
|
155 |
STR_4835_INCREASES_PRODUCTION, |
|
156 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
157 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
158 |
STR_4835_INCREASES_PRODUCTION, |
|
159 |
STR_4835_INCREASES_PRODUCTION, |
|
160 |
STR_4835_INCREASES_PRODUCTION, |
|
161 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
162 |
STR_4835_INCREASES_PRODUCTION, |
|
163 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
164 |
STR_4835_INCREASES_PRODUCTION, |
|
165 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
166 |
STR_4835_INCREASES_PRODUCTION, |
|
167 |
STR_4835_INCREASES_PRODUCTION, |
|
168 |
STR_4835_INCREASES_PRODUCTION, |
|
169 |
STR_4835_INCREASES_PRODUCTION, |
|
170 |
STR_4835_INCREASES_PRODUCTION, |
|
171 |
STR_4835_INCREASES_PRODUCTION, |
|
172 |
STR_4835_INCREASES_PRODUCTION, |
|
173 |
STR_4835_INCREASES_PRODUCTION, |
|
174 |
}; |
|
175 |
||
176 |
static const StringID _industry_prod_down_strings[] = { |
|
177 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
178 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
179 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
180 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
181 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
182 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
183 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
184 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
185 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
186 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
187 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
188 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
189 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
190 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
191 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
192 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
193 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
194 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
195 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
196 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
197 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
198 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
199 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
200 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
201 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
202 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
203 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
204 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
205 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
206 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
207 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
208 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
209 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
210 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
211 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
212 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
213 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
214 |
}; |
|
215 |
||
216 |
static const StringID _industry_close_strings[] = { |
|
217 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
218 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
219 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
220 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
221 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
222 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
223 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
224 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
225 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
226 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
227 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
228 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
229 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
230 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
231 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
232 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
233 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
234 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
235 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
236 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
237 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
238 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
239 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
240 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
241 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
242 |
STR_4834_LACK_OF_NEARBY_TREES_CAUSES, |
|
243 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
244 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
245 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
246 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
247 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
248 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
249 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
250 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
251 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
252 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
253 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE , |
|
254 |
}; |
|
255 |
||
256 |
||
257 |
static void IndustryDrawTileProc1(TileInfo *ti) |
|
258 |
{ |
|
259 |
const DrawIndustrySpec1Struct *d; |
|
260 |
uint32 image; |
|
261 |
||
262 |
if (!(_map_owner[ti->tile] & 0x80)) |
|
263 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
264 |
|
0 | 265 |
d = &_draw_industry_spec1[_map3_lo[ti->tile]]; |
266 |
||
267 |
AddChildSpriteScreen(0x12A7 + d->image_1, d->x, 0); |
|
268 |
||
269 |
if ( (image = d->image_2) != 0) |
|
270 |
AddChildSpriteScreen(0x12B0 + image - 1, 8, 41); |
|
271 |
||
272 |
if ( (image = d->image_3) != 0) |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
273 |
AddChildSpriteScreen(0x12AC + image - 1, |
0 | 274 |
_drawtile_proc1_x[image-1], _drawtile_proc1_y[image-1]); |
275 |
} |
|
276 |
||
277 |
static void IndustryDrawTileProc2(TileInfo *ti) |
|
278 |
{ |
|
279 |
int x = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
280 |
|
0 | 281 |
if (_map_owner[ti->tile] & 0x80) { |
282 |
x = _industry_anim_offs[_map3_lo[ti->tile]]; |
|
283 |
if ( (byte)x == 0xFF) |
|
284 |
x = 0; |
|
285 |
} |
|
286 |
||
287 |
AddChildSpriteScreen(0x129F, 22-x, x+24); |
|
288 |
AddChildSpriteScreen(0x129E, 6, 0xE); |
|
289 |
} |
|
290 |
||
291 |
static void IndustryDrawTileProc3(TileInfo *ti) |
|
292 |
{ |
|
293 |
if (_map_owner[ti->tile] & 0x80) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
294 |
AddChildSpriteScreen(0x128B, 5, |
0 | 295 |
_industry_anim_offs_2[_map3_lo[ti->tile]]); |
296 |
} |
|
552
698b1118e41f
(svn r952) -A tiny insignificant fix for a toyland industry gfx
darkvater
parents:
543
diff
changeset
|
297 |
AddChildSpriteScreen(4746, 3, 67); |
0 | 298 |
} |
299 |
||
300 |
static void IndustryDrawTileProc4(TileInfo *ti) |
|
301 |
{ |
|
302 |
const DrawIndustrySpec4Struct *d; |
|
303 |
||
304 |
d = &_industry_anim_offs_3[_map3_lo[ti->tile]]; |
|
305 |
||
306 |
if (d->image_1 != 0xFF) { |
|
307 |
AddChildSpriteScreen(0x126F, 0x32 - d->image_1 * 2, 0x60 + d->image_1); |
|
308 |
} |
|
309 |
||
310 |
if (d->image_2 != 0xFF) { |
|
311 |
AddChildSpriteScreen(0x1270, 0x10 - d->image_2*2, 100 + d->image_2); |
|
312 |
} |
|
313 |
||
314 |
AddChildSpriteScreen(0x126E, 7, d->image_3); |
|
315 |
AddChildSpriteScreen(0x126D, 0, 42); |
|
316 |
} |
|
317 |
||
318 |
static void DrawCoalPlantSparkles(TileInfo *ti) |
|
319 |
{ |
|
320 |
int image = _map_owner[ti->tile]; |
|
321 |
if (image & 0x80) { |
|
322 |
image = (image >> 2) & 0x1F; |
|
323 |
if (image != 0 && image < 7) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
324 |
AddChildSpriteScreen(image + 0x806, |
0 | 325 |
_coal_plant_sparkles_x[image-1], |
326 |
_coal_plant_sparkles_y[image-1] |
|
327 |
); |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
typedef void IndustryDrawTileProc(TileInfo *ti); |
|
333 |
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = { |
|
334 |
IndustryDrawTileProc1, |
|
335 |
IndustryDrawTileProc2, |
|
336 |
IndustryDrawTileProc3, |
|
337 |
IndustryDrawTileProc4, |
|
338 |
DrawCoalPlantSparkles, |
|
339 |
}; |
|
340 |
||
341 |
static void DrawTile_Industry(TileInfo *ti) |
|
342 |
{ |
|
343 |
Industry *ind; |
|
344 |
const DrawIndustryTileStruct *dits; |
|
345 |
byte z; |
|
346 |
uint32 image, ormod; |
|
347 |
||
348 |
/* Pointer to industry */ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
349 |
ind = GetIndustry(_map2[ti->tile]); |
0 | 350 |
ormod = (ind->color_map+0x307)<<16; |
351 |
||
352 |
/* Retrieve pointer to the draw industry tile struct */ |
|
353 |
dits = &_industry_draw_tile_data[(ti->map5<<2) | (_map_owner[ti->tile]&3)]; |
|
354 |
||
355 |
image = dits->sprite_1; |
|
356 |
if (image&0x8000 && (image & 0xFFFF0000) == 0) |
|
357 |
image |= ormod; |
|
358 |
||
359 |
z = ti->z; |
|
360 |
/* Add bricks below the industry? */ |
|
361 |
if (ti->tileh & 0xF) { |
|
362 |
AddSortableSpriteToDraw((ti->tileh & 0xF) + 0x3DD, ti->x, ti->y, 16, 16, 7, z); |
|
363 |
AddChildSpriteScreen(image, 0x1F, 1); |
|
364 |
z += 8; |
|
365 |
} else { |
|
366 |
/* Else draw regular ground */ |
|
367 |
DrawGroundSprite(image); |
|
368 |
} |
|
369 |
||
370 |
/* Add industry on top of the ground? */ |
|
371 |
if ((image = dits->sprite_2) != 0) { |
|
372 |
||
373 |
if (image&0x8000 && (image & 0xFFFF0000) == 0) |
|
374 |
image |= ormod; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
375 |
|
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
376 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 377 |
image = (image & 0x3FFF) | 0x3224000; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
378 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
379 |
AddSortableSpriteToDraw(image, |
0 | 380 |
ti->x | (dits->subtile_xy>>4), |
381 |
ti->y | (dits->subtile_xy&0xF), |
|
382 |
(dits->width_height>>4)+1, |
|
383 |
(dits->width_height&0xF)+1, |
|
384 |
dits->dz, |
|
385 |
z); |
|
386 |
||
497
4d1c889526ee
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
387 |
if (_display_opt & DO_TRANS_BUILDINGS) |
0 | 388 |
return; |
389 |
} |
|
390 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
391 |
/* TTDBUG: strange code here, return if AddSortableSpriteToDraw failed? */ |
0 | 392 |
{ |
393 |
int proc; |
|
394 |
if ((proc=dits->proc-1) >= 0 ) |
|
395 |
_industry_draw_tile_procs[proc](ti); |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
||
400 |
static uint GetSlopeZ_Industry(TileInfo *ti) { |
|
401 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; |
|
402 |
} |
|
403 |
||
39 | 404 |
static uint GetSlopeTileh_Industry(TileInfo *ti) { |
405 |
return 0; |
|
406 |
} |
|
407 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
408 |
static void GetAcceptedCargo_Industry(uint tile, AcceptedCargo ac) |
0 | 409 |
{ |
410 |
int m5 = _map5[tile]; |
|
411 |
int a; |
|
412 |
||
413 |
a = _industry_map5_accepts_1[m5]; |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
414 |
if (a >= 0) ac[a] = (a == 0) ? 1 : 8; |
0 | 415 |
|
416 |
a = _industry_map5_accepts_2[m5]; |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
417 |
if (a >= 0) ac[a] = 8; |
0 | 418 |
|
419 |
a = _industry_map5_accepts_3[m5]; |
|
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
420 |
if (a >= 0) ac[a] = 8; |
0 | 421 |
} |
422 |
||
423 |
static void GetTileDesc_Industry(uint tile, TileDesc *td) |
|
424 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
425 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 426 |
|
427 |
td->owner = i->owner; |
|
428 |
td->str = STR_4802_COAL_MINE + i->type; |
|
429 |
if ((_map_owner[tile] & 0x80) == 0) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
430 |
SetDParamX(td->dparam, 0, td->str); |
0 | 431 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
432 |
} |
|
433 |
} |
|
434 |
||
435 |
static int32 ClearTile_Industry(uint tile, byte flags) |
|
436 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
437 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 438 |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
439 |
/* * water can destroy industries |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
440 |
* in editor you can bulldoze industries |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
441 |
* with magic_bulldozer cheat you can destroy industries |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
442 |
* (area around OILRIG is water, so water shouldn't flood it |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
443 |
*/ |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
444 |
if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR && |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
445 |
!_cheats.magic_bulldozer.value) || |
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
446 |
(_current_player == OWNER_WATER && i->type == IT_OIL_RIG) ) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
447 |
SetDParam(0, STR_4802_COAL_MINE + i->type); |
0 | 448 |
return_cmd_error(STR_4800_IN_THE_WAY); |
449 |
} |
|
450 |
||
451 |
if (flags & DC_EXEC) { |
|
452 |
DeleteIndustry(i); |
|
453 |
} |
|
454 |
return 0; |
|
455 |
} |
|
456 |
||
457 |
||
458 |
static const byte _industry_min_cargo[] = { |
|
459 |
5, 5, 5, 30, 5, 5, 5, 5, |
|
460 |
5, 5, 5, 5, 2, 5, 5, 5, |
|
461 |
5, 5, 5, 15, 15, 5, 5, 5, |
|
462 |
5, 5, 30, 5, 30, 5, 5, 5, |
|
463 |
5, 5, 5, 5, 5, |
|
464 |
}; |
|
465 |
||
410 | 466 |
static void TransportIndustryGoods(uint tile) |
0 | 467 |
{ |
468 |
Industry *i; |
|
469 |
int type; |
|
470 |
uint cw, am; |
|
471 |
byte m5; |
|
472 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
473 |
i = GetIndustry(_map2[tile]); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
474 |
|
0 | 475 |
type = i->type; |
476 |
cw = min(i->cargo_waiting[0], 255); |
|
477 |
if (cw > _industry_min_cargo[type]/* && i->produced_cargo[0] != 0xFF*/) { |
|
478 |
i->cargo_waiting[0] -= cw; |
|
479 |
||
480 |
/* fluctuating economy? */ |
|
481 |
if (_economy.fluct <= 0) cw = (cw + 1) >> 1; |
|
482 |
||
483 |
i->last_mo_production[0] += cw; |
|
484 |
||
485 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw); |
|
486 |
i->last_mo_transported[0] += am; |
|
487 |
if (am != 0 && (m5 = _industry_produce_map5[_map5[tile]]) != 0xFF) { |
|
488 |
_map5[tile] = m5; |
|
489 |
_map_owner[tile] = 0x80; |
|
490 |
MarkTileDirtyByTile(tile); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
type = i->type; |
|
495 |
cw = min(i->cargo_waiting[1], 255); |
|
496 |
if (cw > _industry_min_cargo[type]) { |
|
497 |
i->cargo_waiting[1] -= cw; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
498 |
|
0 | 499 |
if (_economy.fluct <= 0) cw = (cw + 1) >> 1; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
500 |
|
0 | 501 |
i->last_mo_production[1] += cw; |
502 |
||
503 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw); |
|
504 |
i->last_mo_transported[1] += am; |
|
505 |
} |
|
506 |
} |
|
507 |
||
508 |
||
509 |
static void AnimateTile_Industry(uint tile) |
|
510 |
{ |
|
511 |
byte m,n; |
|
512 |
||
513 |
switch(_map5[tile]) { |
|
514 |
case 174: |
|
515 |
if ((_tick_counter & 1) == 0) { |
|
516 |
m = _map3_lo[tile] + 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
517 |
|
0 | 518 |
switch(m & 7) { |
541 | 519 |
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; |
520 |
case 6: SndPlayTileFx(SND_29_RIP, tile); break; |
|
0 | 521 |
} |
522 |
||
523 |
if (m >= 96) { |
|
524 |
m = 0; |
|
525 |
DeleteAnimatedTile(tile); |
|
526 |
} |
|
527 |
_map3_lo[tile] = m; |
|
528 |
||
529 |
MarkTileDirtyByTile(tile); |
|
530 |
} |
|
531 |
break; |
|
532 |
||
533 |
case 165: |
|
534 |
if ((_tick_counter & 3) == 0) { |
|
535 |
m = _map3_lo[tile]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
536 |
|
0 | 537 |
if (_industry_anim_offs[m] == 0xFF) { |
541 | 538 |
SndPlayTileFx(SND_30_CARTOON_SOUND, tile); |
0 | 539 |
} |
540 |
||
541 |
if (++m >= 70) { |
|
542 |
m = 0; |
|
543 |
DeleteAnimatedTile(tile); |
|
544 |
} |
|
545 |
_map3_lo[tile] = m; |
|
546 |
||
547 |
MarkTileDirtyByTile(tile); |
|
548 |
} |
|
549 |
break; |
|
550 |
||
551 |
case 162: |
|
552 |
if ((_tick_counter&1) == 0) { |
|
553 |
m = _map3_lo[tile]; |
|
554 |
||
555 |
if (++m >= 40) { |
|
556 |
m = 0; |
|
557 |
DeleteAnimatedTile(tile); |
|
558 |
} |
|
559 |
_map3_lo[tile] = m; |
|
560 |
||
561 |
MarkTileDirtyByTile(tile); |
|
562 |
} |
|
563 |
break; |
|
564 |
||
565 |
// Sparks on a coal plant |
|
566 |
case 10: |
|
567 |
if ((_tick_counter & 3) == 0) { |
|
568 |
m = _map_owner[tile]; |
|
569 |
if ((m & (31<<2)) == (6 << 2)) { |
|
570 |
_map_owner[tile] = m&~(31<<2); |
|
571 |
DeleteAnimatedTile(tile); |
|
572 |
} else { |
|
573 |
_map_owner[tile] = m + (1<<2); |
|
574 |
MarkTileDirtyByTile(tile); |
|
575 |
} |
|
576 |
} |
|
577 |
break; |
|
578 |
||
579 |
case 143: |
|
580 |
if ((_tick_counter & 1) == 0) { |
|
581 |
m = _map3_lo[tile] + 1; |
|
582 |
||
583 |
if (m == 1) { |
|
541 | 584 |
SndPlayTileFx(SND_2C_MACHINERY, tile); |
0 | 585 |
} else if (m == 23) { |
541 | 586 |
SndPlayTileFx(SND_2B_COMEDY_HIT, tile); |
0 | 587 |
} else if (m == 28) { |
541 | 588 |
SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); |
0 | 589 |
} |
590 |
||
591 |
if (m >= 50 && (m=0,++_map3_hi[tile] >= 8)) { |
|
592 |
_map3_hi[tile] = 0; |
|
593 |
DeleteAnimatedTile(tile); |
|
594 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
595 |
_map3_lo[tile] = m; |
0 | 596 |
MarkTileDirtyByTile(tile); |
597 |
} |
|
598 |
break; |
|
599 |
||
600 |
case 148: case 149: case 150: case 151: |
|
601 |
case 152: case 153: case 154: case 155: |
|
602 |
if ((_tick_counter & 3) == 0) { |
|
603 |
m = _map5[tile] + 1; |
|
604 |
if (m == 155+1) m = 148; |
|
605 |
_map5[tile] = m; |
|
606 |
||
607 |
MarkTileDirtyByTile(tile); |
|
608 |
} |
|
609 |
break; |
|
610 |
||
611 |
case 30: case 31: case 32: |
|
612 |
if ((_tick_counter & 7) == 0) { |
|
613 |
bool b = CHANCE16(1,7); |
|
614 |
m = _map_owner[tile]; |
|
615 |
m = (m & 3) + 1; |
|
616 |
n = _map5[tile]; |
|
617 |
if (m == 4 && (m=0,++n) == 32+1 && (n=30,b)) { |
|
618 |
_map_owner[tile] = 0x83; |
|
619 |
_map5[tile] = 29; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
620 |
DeleteAnimatedTile(tile); |
0 | 621 |
} else { |
622 |
_map5[tile] = n; |
|
623 |
_map_owner[tile] = (_map_owner[tile] & ~3) | m; |
|
624 |
MarkTileDirtyByTile(tile); |
|
625 |
} |
|
626 |
} |
|
627 |
break; |
|
628 |
||
629 |
case 88: |
|
630 |
case 48: |
|
631 |
case 1: { |
|
632 |
int state = _tick_counter & 0x7FF; |
|
633 |
||
634 |
if ((state -= 0x400) < 0) |
|
635 |
return; |
|
636 |
||
637 |
if (state < 0x1A0) { |
|
638 |
if (state < 0x20 || state >= 0x180) { |
|
639 |
if (! (_map_owner[tile] & 0x40)) { |
|
640 |
_map_owner[tile] |= 0x40; |
|
541 | 641 |
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); |
0 | 642 |
} |
643 |
if (state & 7) |
|
644 |
return; |
|
645 |
} else { |
|
646 |
if (state & 3) |
|
647 |
return; |
|
648 |
} |
|
649 |
m = (_map_owner[tile] + 1) | 0x40; |
|
650 |
if (m > 0xC2) m = 0xC0; |
|
651 |
_map_owner[tile] = m; |
|
652 |
MarkTileDirtyByTile(tile); |
|
653 |
} else if (state >= 0x200 && state < 0x3A0) { |
|
654 |
int i; |
|
655 |
i = (state < 0x220 || state >= 0x380) ? 7 : 3; |
|
656 |
if (state & i) |
|
657 |
return; |
|
658 |
||
659 |
m = (_map_owner[tile] & 0xBF) - 1; |
|
660 |
if (m < 0x80) m = 0x82; |
|
661 |
_map_owner[tile] = m; |
|
662 |
MarkTileDirtyByTile(tile); |
|
663 |
} |
|
664 |
} break; |
|
665 |
} |
|
666 |
} |
|
667 |
||
668 |
static void MakeIndustryTileBiggerCase8(uint tile) |
|
669 |
{ |
|
670 |
TileInfo ti; |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
671 |
FindLandscapeHeight(&ti, TileX(tile) * 16, TileY(tile) * 16); |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1335
diff
changeset
|
672 |
CreateEffectVehicle(ti.x + 15, ti.y + 14, ti.z + 59 + (ti.tileh != 0 ? 8 : 0), EV_CHIMNEY_SMOKE); |
0 | 673 |
} |
674 |
||
675 |
static void MakeIndustryTileBigger(uint tile, byte size) |
|
676 |
{ |
|
677 |
byte b = (byte)((size + (1<<2)) & (3<<2)); |
|
678 |
||
679 |
if (b != 0) { |
|
680 |
_map_owner[tile] = b | (size & 3); |
|
681 |
return; |
|
682 |
} |
|
683 |
||
684 |
size = (size + 1) & 3; |
|
685 |
if (size == 3) size |= 0x80; |
|
686 |
_map_owner[tile] = size | b; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
687 |
|
0 | 688 |
MarkTileDirtyByTile(tile); |
689 |
||
690 |
if (!(_map_owner[tile] & 0x80)) |
|
691 |
return; |
|
692 |
||
693 |
switch(_map5[tile]) { |
|
694 |
case 8: |
|
695 |
MakeIndustryTileBiggerCase8(tile); |
|
696 |
break; |
|
697 |
||
698 |
case 24: |
|
699 |
if (_map5[tile + TILE_XY(0,1)] == 24) { |
|
700 |
BuildOilRig(tile); |
|
701 |
} |
|
702 |
break; |
|
703 |
||
704 |
case 143: |
|
705 |
case 162: |
|
706 |
case 165: |
|
707 |
_map3_lo[tile] = 0; |
|
708 |
_map3_hi[tile] = 0; |
|
709 |
break; |
|
710 |
||
711 |
case 148: case 149: case 150: case 151: |
|
712 |
case 152: case 153: case 154: case 155: |
|
713 |
AddAnimatedTile(tile); |
|
714 |
break; |
|
715 |
} |
|
716 |
} |
|
717 |
||
718 |
||
719 |
||
720 |
static void TileLoopIndustryCase161(uint tile) |
|
721 |
{ |
|
722 |
int dir; |
|
723 |
Vehicle *v; |
|
724 |
static const int8 _tileloop_ind_case_161[12] = { |
|
725 |
11, 0, -4, -14, |
|
726 |
-4, -10, -4, 1, |
|
727 |
49, 59, 60, 65, |
|
728 |
}; |
|
729 |
||
541 | 730 |
SndPlayTileFx(SND_2E_EXTRACT_AND_POP, tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
731 |
|
0 | 732 |
dir = Random() & 3; |
733 |
||
734 |
v = CreateEffectVehicleAbove( |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
735 |
TileX(tile) * 16 + _tileloop_ind_case_161[dir + 0], |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
736 |
TileY(tile) * 16 + _tileloop_ind_case_161[dir + 4], |
0 | 737 |
_tileloop_ind_case_161[dir + 8], |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1335
diff
changeset
|
738 |
EV_BUBBLE |
0 | 739 |
); |
740 |
||
741 |
if (v != NULL) |
|
742 |
v->u.special.unk2 = dir; |
|
743 |
} |
|
744 |
||
745 |
static void TileLoop_Industry(uint tile) |
|
746 |
{ |
|
747 |
byte n; |
|
748 |
||
749 |
if (!(_map_owner[tile] & 0x80)) { |
|
750 |
MakeIndustryTileBigger(tile, _map_owner[tile]); |
|
751 |
return; |
|
752 |
} |
|
753 |
||
754 |
if (_game_mode == GM_EDITOR) |
|
755 |
return; |
|
756 |
||
757 |
TransportIndustryGoods(tile); |
|
758 |
||
759 |
n = _industry_map5_animation_next[_map5[tile]]; |
|
760 |
if (n != 255) { |
|
761 |
_map5[tile] = n; |
|
762 |
_map_owner[tile] = 0; |
|
763 |
MarkTileDirtyByTile(tile); |
|
764 |
return; |
|
765 |
} |
|
766 |
||
767 |
#define SET_AND_ANIMATE(tile,a,b) { _map5[tile]=a; _map_owner[tile]=b; AddAnimatedTile(tile); } |
|
768 |
#define SET_AND_UNANIMATE(tile,a,b) { _map5[tile]=a; _map_owner[tile]=b; DeleteAnimatedTile(tile); } |
|
769 |
||
770 |
switch(_map5[tile]) { |
|
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
771 |
case 0x18: // coast line at oilrigs |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
772 |
case 0x19: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
773 |
case 0x1A: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
774 |
case 0x1B: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
775 |
case 0x1C: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
776 |
TileLoop_Water(tile); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
777 |
break; |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
778 |
|
0 | 779 |
case 0: |
780 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
781 |
SET_AND_ANIMATE(tile,1,0x80); |
|
782 |
break; |
|
783 |
||
784 |
case 47: |
|
785 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
786 |
SET_AND_ANIMATE(tile,0x30,0x80); |
|
787 |
break; |
|
788 |
||
789 |
case 79: |
|
790 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
791 |
SET_AND_ANIMATE(tile,0x58,0x80); |
|
792 |
break; |
|
793 |
||
794 |
case 29: |
|
795 |
if (CHANCE16(1,6)) |
|
796 |
SET_AND_ANIMATE(tile,0x1E,0x80); |
|
797 |
break; |
|
798 |
||
799 |
case 1: |
|
800 |
if (!(_tick_counter & 0x400)) |
|
801 |
SET_AND_UNANIMATE(tile, 0, 0x83); |
|
802 |
break; |
|
803 |
||
804 |
case 48: |
|
805 |
if (!(_tick_counter & 0x400)) |
|
806 |
SET_AND_UNANIMATE(tile, 0x2F, 0x83); |
|
807 |
break; |
|
808 |
||
809 |
case 88: |
|
810 |
if (!(_tick_counter & 0x400)) |
|
811 |
SET_AND_UNANIMATE(tile, 0x4F, 0x83); |
|
812 |
break; |
|
813 |
||
814 |
case 10: |
|
815 |
if (CHANCE16(1,3)) { |
|
541 | 816 |
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile); |
0 | 817 |
AddAnimatedTile(tile); |
818 |
} |
|
819 |
break; |
|
820 |
||
821 |
case 49: { |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1335
diff
changeset
|
822 |
CreateEffectVehicleAbove(TileX(tile) * 16 + 6, TileY(tile) * 16 + 6, 43, EV_SMOKE); |
0 | 823 |
} break; |
824 |
||
825 |
||
826 |
case 143: { |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
827 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 828 |
if (i->was_cargo_delivered) { |
829 |
i->was_cargo_delivered = false; |
|
830 |
if ((_map3_hi[tile]|_map3_lo[tile]) != 0) |
|
831 |
_map3_hi[tile] = 0; |
|
832 |
AddAnimatedTile(tile); |
|
833 |
} |
|
834 |
} |
|
835 |
break; |
|
836 |
||
837 |
case 161: |
|
838 |
TileLoopIndustryCase161(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
839 |
break; |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
840 |
|
0 | 841 |
case 165: |
842 |
AddAnimatedTile(tile); |
|
843 |
break; |
|
844 |
||
845 |
case 174: |
|
846 |
if (CHANCE16(1,3)) { |
|
847 |
AddAnimatedTile(tile); |
|
848 |
} |
|
849 |
break; |
|
850 |
} |
|
851 |
} |
|
852 |
||
853 |
||
854 |
static void ClickTile_Industry(uint tile) |
|
855 |
{ |
|
856 |
ShowIndustryViewWindow(_map2[tile]); |
|
857 |
} |
|
858 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
859 |
static uint32 GetTileTrackStatus_Industry(uint tile, TransportType mode) |
0 | 860 |
{ |
861 |
return 0; |
|
862 |
} |
|
863 |
||
864 |
static void GetProducedCargo_Industry(uint tile, byte *b) |
|
865 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
866 |
Industry *i = GetIndustry(_map2[tile]); |
0 | 867 |
b[0] = i->produced_cargo[0]; |
868 |
b[1] = i->produced_cargo[1]; |
|
869 |
} |
|
870 |
||
871 |
static void ChangeTileOwner_Industry(uint tile, byte old_player, byte new_player) |
|
872 |
{ |
|
873 |
/* not used */ |
|
874 |
} |
|
875 |
||
876 |
void DeleteIndustry(Industry *i) |
|
877 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
878 |
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
879 |
if (IsTileType(tile_cur, MP_INDUSTRY)) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
880 |
if (_map2[tile_cur] == i->index) { |
0 | 881 |
DoClearSquare(tile_cur); |
882 |
} |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
883 |
} else if (IsTileType(tile_cur, MP_STATION) && _map5[tile_cur] == 0x4B) { |
0 | 884 |
DeleteOilRig(tile_cur); |
885 |
} |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
886 |
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
887 |
|
0 | 888 |
i->xy = 0; |
889 |
_industry_sort_dirty = true; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
890 |
DeleteSubsidyWithIndustry(i->index); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
891 |
DeleteWindowById(WC_INDUSTRY_VIEW, i->index); |
0 | 892 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
893 |
} |
|
894 |
||
895 |
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; |
|
896 |
||
1048 | 897 |
static bool IsBadFarmFieldTile(TileIndex tile) |
0 | 898 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
899 |
switch (GetTileType(tile)) { |
1048 | 900 |
case MP_CLEAR: { |
901 |
byte m5 = _map5[tile] & 0x1C; |
|
902 |
return m5 == 0xC || m5 == 0x10; |
|
903 |
} |
|
904 |
||
905 |
case MP_TREES: |
|
906 |
return false; |
|
907 |
||
908 |
default: |
|
0 | 909 |
return true; |
910 |
} |
|
911 |
} |
|
912 |
||
1048 | 913 |
static bool IsBadFarmFieldTile2(TileIndex tile) |
0 | 914 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
915 |
switch (GetTileType(tile)) { |
1048 | 916 |
case MP_CLEAR: { |
917 |
byte m5 = _map5[tile] & 0x1C; |
|
918 |
return m5 == 0x10; |
|
919 |
} |
|
920 |
||
921 |
case MP_TREES: |
|
922 |
return false; |
|
923 |
||
924 |
default: |
|
0 | 925 |
return true; |
926 |
} |
|
927 |
} |
|
928 |
||
929 |
static void SetupFarmFieldFence(uint tile, int size, byte type, int direction) |
|
930 |
{ |
|
931 |
byte or, and; |
|
932 |
||
933 |
do { |
|
934 |
tile = TILE_MASK(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
935 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
936 |
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
937 |
|
0 | 938 |
or = type; |
939 |
if (or == 1 && (uint16)Random() <= 9362) or = 2; |
|
940 |
||
941 |
or <<= 2; |
|
942 |
and = (byte)~0x1C; |
|
943 |
if (direction) { |
|
944 |
or <<= 3; |
|
945 |
and = (byte)~0xE0; |
|
946 |
} |
|
947 |
_map3_hi[tile] = (_map3_hi[tile] & and) | or; |
|
948 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
949 |
|
0 | 950 |
tile += direction ? TILE_XY(0,1) : TILE_XY(1,0); |
951 |
} while (--size); |
|
952 |
} |
|
953 |
||
954 |
static void PlantFarmField(uint tile) |
|
955 |
{ |
|
956 |
uint size_x, size_y; |
|
957 |
uint32 r; |
|
958 |
int count; |
|
959 |
int type, type2; |
|
960 |
||
961 |
if (_opt.landscape == LT_HILLY) { |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1320
diff
changeset
|
962 |
if (GetTileZ(tile) + 16 >= _opt.snow_line) |
0 | 963 |
return; |
964 |
} |
|
965 |
||
966 |
/* determine field size */ |
|
967 |
r = (Random() & 0x303) + 0x404; |
|
968 |
if (_opt.landscape == LT_HILLY) r += 0x404; |
|
969 |
size_x = (byte)r; |
|
970 |
size_y = r >> 8; |
|
971 |
||
972 |
/* offset tile to match size */ |
|
973 |
tile = tile - TILE_XY(size_x>>1, size_y>>1); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
974 |
|
0 | 975 |
/* check the amount of bad tiles */ |
976 |
count = 0; |
|
977 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
978 |
cur_tile = TILE_MASK(cur_tile); |
|
979 |
count += IsBadFarmFieldTile(cur_tile); |
|
980 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
981 |
if ((uint)(count * 2) >= size_x * size_y) |
|
982 |
return; |
|
983 |
||
984 |
/* determine type of field */ |
|
985 |
r = Random(); |
|
986 |
type = ((r & 0xE0) | 0xF); |
|
987 |
type2 = ((byte)(r >> 8) * 9) >> 8; |
|
988 |
||
989 |
/* make field */ |
|
990 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
991 |
cur_tile = TILE_MASK(cur_tile); |
|
992 |
if (!IsBadFarmFieldTile2(cur_tile)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
993 |
ModifyTile(cur_tile, |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
994 |
MP_SETTYPE(MP_CLEAR) | |
0 | 995 |
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5, |
996 |
type2, /* map3_lo */ |
|
997 |
OWNER_NONE, /* map_owner */ |
|
998 |
type); /* map5 */ |
|
999 |
} |
|
1000 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1001 |
|
0 | 1002 |
type = 3; |
1003 |
if (_opt.landscape != LT_HILLY && _opt.landscape != LT_DESERT) { |
|
1004 |
type = _plantfarmfield_type[Random() & 0xF]; |
|
1005 |
} |
|
1006 |
||
1007 |
SetupFarmFieldFence(tile-TILE_XY(1,0), size_y, type, 1); |
|
1008 |
SetupFarmFieldFence(tile-TILE_XY(0,1), size_x, type, 0); |
|
1009 |
SetupFarmFieldFence(tile+TILE_XY(1,0) * (size_x-1), size_y, type, 1); |
|
1010 |
SetupFarmFieldFence(tile+TILE_XY(0,1) * (size_y-1), size_x, type, 0); |
|
1011 |
} |
|
1012 |
||
1013 |
static void MaybePlantFarmField(Industry *i) |
|
1014 |
{ |
|
1015 |
uint tile; |
|
1016 |
if (CHANCE16(1,8)) { |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1017 |
int x = (i->width>>1) + Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1018 |
int y = (i->height>>1) + Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1019 |
tile = TileAddWrap(i->xy, x, y); |
1247 | 1020 |
if (tile != INVALID_TILE) |
0 | 1021 |
PlantFarmField(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1022 |
} |
0 | 1023 |
} |
1024 |
||
1025 |
static void ChopLumberMillTrees(Industry *i) |
|
1026 |
{ |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1027 |
static const TileIndexDiffC _chop_dir[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1028 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1029 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1030 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1031 |
{-1, 0} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1032 |
}; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1033 |
|
0 | 1034 |
uint tile = i->xy; |
1035 |
int dir, a, j; |
|
1036 |
||
1037 |
if ((_map_owner[tile] & 0x80) == 0) |
|
1038 |
return; |
|
1039 |
||
1040 |
/* search outwards as a rectangular spiral */ |
|
1041 |
for(a=1; a!=41; a+=2) { |
|
1042 |
for(dir=0; dir!=4; dir++) { |
|
1043 |
j = a; |
|
1044 |
do { |
|
1045 |
tile = TILE_MASK(tile); |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
1046 |
if (IsTileType(tile, MP_TREES)) { |
314 | 1047 |
uint old_player = _current_player; |
0 | 1048 |
/* found a tree */ |
1049 |
||
1050 |
_current_player = OWNER_NONE; |
|
1051 |
_industry_sound_ctr = 1; |
|
1052 |
_industry_sound_tile = tile; |
|
541 | 1053 |
SndPlayTileFx(SND_38_CHAINSAW, tile); |
0 | 1054 |
|
1055 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1056 |
SetMapExtraBits(tile, 0); |
|
1057 |
||
1058 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45); |
|
314 | 1059 |
|
1060 |
_current_player = old_player; |
|
0 | 1061 |
return; |
1062 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1063 |
tile += ToTileIndexDiff(_chop_dir[dir]); |
0 | 1064 |
} while (--j); |
1065 |
} |
|
1066 |
tile -= TILE_XY(1,1); |
|
1067 |
} |
|
1068 |
} |
|
1069 |
||
1070 |
static const byte _industry_sounds[37][2] = { |
|
1071 |
{0}, |
|
1072 |
{0}, |
|
541 | 1073 |
{1, SND_28_SAWMILL}, |
0 | 1074 |
{0}, |
1075 |
{0}, |
|
1076 |
{0}, |
|
541 | 1077 |
{1, SND_03_FACTORY_WHISTLE}, |
1078 |
{1, SND_03_FACTORY_WHISTLE}, |
|
0 | 1079 |
{0}, |
541 | 1080 |
{3, SND_24_SHEEP}, |
0 | 1081 |
{0}, |
1082 |
{0}, |
|
1083 |
{0}, |
|
1084 |
{0}, |
|
541 | 1085 |
{1, SND_28_SAWMILL}, |
0 | 1086 |
{0}, |
1087 |
{0}, |
|
1088 |
{0}, |
|
1089 |
{0}, |
|
1090 |
{0}, |
|
1091 |
{0}, |
|
1092 |
{0}, |
|
1093 |
{0}, |
|
541 | 1094 |
{1, SND_03_FACTORY_WHISTLE}, |
0 | 1095 |
{0}, |
1096 |
{0}, |
|
1097 |
{0}, |
|
1098 |
{0}, |
|
1099 |
{0}, |
|
1100 |
{0}, |
|
1101 |
{0}, |
|
1102 |
{0}, |
|
541 | 1103 |
{1, SND_33_PLASTIC_MINE}, |
0 | 1104 |
{0}, |
1105 |
{0}, |
|
1106 |
{0}, |
|
1107 |
{0}, |
|
1108 |
}; |
|
1109 |
||
1110 |
||
1111 |
static void ProduceIndustryGoods(Industry *i) |
|
1112 |
{ |
|
1113 |
uint32 r; |
|
1114 |
uint num; |
|
1115 |
||
1116 |
/* play a sound? */ |
|
1117 |
if ((i->counter & 0x3F) == 0) { |
|
1118 |
if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) { |
|
1119 |
SndPlayTileFx( |
|
1120 |
_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16), |
|
1121 |
i->xy); |
|
1122 |
} |
|
1123 |
} |
|
1124 |
||
1125 |
i->counter--; |
|
1126 |
||
1127 |
/* produce some cargo */ |
|
1128 |
if ((i->counter & 0xFF) == 0) { |
|
1129 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]); |
|
1130 |
i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]); |
|
1131 |
||
1132 |
if (i->type == IT_FARM) |
|
1133 |
MaybePlantFarmField(i); |
|
1134 |
else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) |
|
1135 |
ChopLumberMillTrees(i); |
|
1136 |
} |
|
1137 |
} |
|
1138 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1139 |
void OnTick_Industry(void) |
0 | 1140 |
{ |
1141 |
Industry *i; |
|
1142 |
||
1143 |
if (_industry_sound_ctr != 0) { |
|
1144 |
_industry_sound_ctr++; |
|
1145 |
||
1146 |
if (_industry_sound_ctr == 75) { |
|
541 | 1147 |
SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile); |
0 | 1148 |
} else if (_industry_sound_ctr == 160) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1149 |
_industry_sound_ctr = 0; |
541 | 1150 |
SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile); |
0 | 1151 |
} |
1152 |
} |
|
1153 |
||
1154 |
if (_game_mode == GM_EDITOR) |
|
1155 |
return; |
|
1156 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1157 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1158 |
if (i->xy != 0) |
1159 |
ProduceIndustryGoods(i); |
|
1160 |
} |
|
1161 |
} |
|
1162 |
||
1163 |
||
1164 |
static bool CheckNewIndustry_NULL(uint tile, int type) |
|
1165 |
{ |
|
1166 |
return true; |
|
1167 |
} |
|
1168 |
||
1169 |
static bool CheckNewIndustry_Forest(uint tile, int type) |
|
1170 |
{ |
|
1171 |
if (_opt.landscape == LT_HILLY) { |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1320
diff
changeset
|
1172 |
if (GetTileZ(tile) < _opt.snow_line + 16U) { |
0 | 1173 |
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED; |
1174 |
return false; |
|
1175 |
} |
|
1176 |
} |
|
1177 |
return true; |
|
1178 |
} |
|
1179 |
||
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1180 |
extern bool _ignore_restrictions; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1181 |
|
0 | 1182 |
static bool CheckNewIndustry_Oilwell(uint tile, int type) |
1183 |
{ |
|
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1184 |
if(_ignore_restrictions && _game_mode == GM_EDITOR) |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1185 |
return true; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1186 |
|
0 | 1187 |
if (type != IT_OIL_RIG && _game_mode == GM_EDITOR) |
1188 |
return true; |
|
1189 |
||
1372
b086d32562e6
(svn r1876) Make placement of oil rigs and refineries map size agnostic
tron
parents:
1359
diff
changeset
|
1190 |
if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < 16) |
0 | 1191 |
return true; |
1192 |
||
1193 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
|
1194 |
return false; |
|
1195 |
} |
|
1196 |
||
1197 |
static bool CheckNewIndustry_Farm(uint tile, int type) |
|
1198 |
{ |
|
1199 |
if (_opt.landscape == LT_HILLY) { |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1320
diff
changeset
|
1200 |
if (GetTileZ(tile) + 16 >= _opt.snow_line) { |
0 | 1201 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1202 |
return false; |
|
1203 |
} |
|
1204 |
} |
|
1205 |
return true; |
|
1206 |
} |
|
1207 |
||
1208 |
static bool CheckNewIndustry_Plantation(uint tile, int type) |
|
1209 |
{ |
|
1210 |
if (GetMapExtraBits(tile) == 1) { |
|
1211 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1212 |
return false; |
|
1213 |
} |
|
1214 |
||
1215 |
return true; |
|
1216 |
} |
|
1217 |
||
1218 |
static bool CheckNewIndustry_Water(uint tile, int type) |
|
1219 |
{ |
|
1220 |
if (GetMapExtraBits(tile) != 1) { |
|
1221 |
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; |
|
1222 |
return false; |
|
1223 |
} |
|
1224 |
||
1225 |
return true; |
|
1226 |
} |
|
1227 |
||
1228 |
static bool CheckNewIndustry_Lumbermill(uint tile, int type) |
|
1229 |
{ |
|
1230 |
if (GetMapExtraBits(tile) != 2) { |
|
1231 |
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; |
|
1232 |
return false; |
|
1233 |
} |
|
1234 |
return true; |
|
1235 |
} |
|
1236 |
||
1237 |
static bool CheckNewIndustry_BubbleGen(uint tile, int type) |
|
1238 |
{ |
|
1239 |
if (GetTileZ(tile) > 32) { |
|
1240 |
return false; |
|
1241 |
} |
|
1242 |
return true; |
|
1243 |
} |
|
1244 |
||
1245 |
typedef bool CheckNewIndustryProc(uint tile, int type); |
|
1246 |
static CheckNewIndustryProc * const _check_new_industry_procs[] = { |
|
1247 |
CheckNewIndustry_NULL, |
|
1248 |
CheckNewIndustry_Forest, |
|
1249 |
CheckNewIndustry_Oilwell, |
|
1250 |
CheckNewIndustry_Farm, |
|
1251 |
CheckNewIndustry_Plantation, |
|
1252 |
CheckNewIndustry_Water, |
|
1253 |
CheckNewIndustry_Lumbermill, |
|
1254 |
CheckNewIndustry_BubbleGen, |
|
1255 |
}; |
|
1256 |
||
1257 |
static bool CheckSuitableIndustryPos(uint tile) |
|
1258 |
{ |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1259 |
uint x = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1260 |
uint y = TileY(tile); |
0 | 1261 |
|
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
838
diff
changeset
|
1262 |
if ( x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { |
0 | 1263 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1264 |
return false; |
|
1265 |
} |
|
1266 |
||
1267 |
return true; |
|
1268 |
} |
|
1269 |
||
1270 |
static Town *CheckMultipleIndustryInTown(uint tile, int type) |
|
1271 |
{ |
|
1272 |
Town *t; |
|
1273 |
Industry *i; |
|
1274 |
||
1275 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1276 |
|
0 | 1277 |
if (_patches.multiple_industry_per_town) |
1278 |
return t; |
|
1279 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1280 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1281 |
if (i->xy != 0 && |
1282 |
i->type == (byte)type && |
|
1283 |
i->town == t) { |
|
1284 |
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; |
|
1285 |
return NULL; |
|
1286 |
} |
|
1287 |
} |
|
1288 |
||
1289 |
return t; |
|
1290 |
} |
|
1291 |
||
1292 |
static const byte _industry_map5_bits[] = { |
|
1293 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1294 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1295 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1296 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1297 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1298 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1299 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1300 |
16, 16, 4, 2, 16, 16, 16, 16, |
|
1301 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1302 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1303 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1304 |
16, 4, 2, 16, 16, 16, 16, 16, |
|
1305 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1306 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1307 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1308 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1309 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1310 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1311 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1312 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1313 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1314 |
16, 16, 16, 16, 16, 16, 16, |
|
1315 |
}; |
|
1316 |
||
1317 |
static bool CheckIfIndustryTilesAreFree(uint tile, const IndustryTileTable *it, int type, Town *t) |
|
1318 |
{ |
|
1319 |
TileInfo ti; |
|
1320 |
uint cur_tile; |
|
1321 |
||
1322 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1323 |
||
1324 |
do { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1325 |
cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1326 |
if (!IsValidTile(cur_tile)) { |
1327 |
if (it->map5 == 0xff) |
|
1328 |
continue; |
|
1329 |
return false; |
|
1330 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1331 |
|
0 | 1332 |
FindLandscapeHeightByTile(&ti, cur_tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1333 |
|
0 | 1334 |
if (it->map5 == 0xFF) { |
1335 |
if (ti.type != MP_WATER || ti.tileh != 0) |
|
1336 |
return false; |
|
1337 |
} else { |
|
1338 |
if (!EnsureNoVehicle(cur_tile)) |
|
1339 |
return false; |
|
1340 |
||
1341 |
if (type == IT_OIL_RIG) { |
|
1342 |
if (ti.type != MP_WATER || ti.map5 != 0) |
|
1343 |
return false; |
|
1344 |
} else { |
|
1345 |
if (ti.type == MP_WATER && ti.map5 == 0) |
|
1346 |
return false; |
|
1347 |
if (ti.tileh & 0x10) |
|
1348 |
return false; |
|
1349 |
||
1350 |
if (ti.tileh != 0) { |
|
1351 |
int t; |
|
1352 |
byte bits = _industry_map5_bits[it->map5]; |
|
1353 |
||
1354 |
if (bits & 0x10) |
|
1355 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1356 |
|
0 | 1357 |
t = ~ti.tileh; |
1358 |
||
1359 |
if (bits & 1 && (t & (1+8))) |
|
1360 |
return false; |
|
1361 |
||
1362 |
if (bits & 2 && (t & (4+8))) |
|
1363 |
return false; |
|
1364 |
||
1365 |
if (bits & 4 && (t & (1+2))) |
|
1366 |
return false; |
|
1367 |
||
1368 |
if (bits & 8 && (t & (2+4))) |
|
1369 |
return false; |
|
1370 |
} |
|
1371 |
||
1372 |
if (type == IT_BANK) { |
|
1373 |
if (ti.type != MP_HOUSE || t->population < 1200) { |
|
1374 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1375 |
return false; |
|
1376 |
} |
|
1377 |
} else if (type == IT_BANK_2) { |
|
1378 |
if (ti.type != MP_HOUSE) { |
|
1379 |
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1380 |
return false; |
|
1381 |
} |
|
1382 |
} else if (type == IT_TOY_SHOP) { |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
1383 |
if (DistanceMax(t->xy, cur_tile) > 9) |
0 | 1384 |
return false; |
1385 |
if (ti.type != MP_HOUSE) goto do_clear; |
|
1386 |
} else if (type == IT_WATER_TOWER) { |
|
1387 |
if (ti.type != MP_HOUSE) { |
|
1388 |
_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1389 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1390 |
} |
0 | 1391 |
} else { |
1392 |
do_clear: |
|
1393 |
if (DoCommandByTile(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) == CMD_ERROR) |
|
1394 |
return false; |
|
1395 |
} |
|
1396 |
} |
|
1397 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1398 |
} while ((++it)->ti.x != -0x80); |
0 | 1399 |
|
1400 |
return true; |
|
1401 |
} |
|
1402 |
||
1403 |
static bool CheckIfTooCloseToIndustry(uint tile, int type) |
|
1404 |
{ |
|
1405 |
Industry *i; |
|
1406 |
const IndustrySpec *spec; |
|
1407 |
spec = &_industry_spec[type]; |
|
1408 |
||
1409 |
// accepting industries won't be close, not even with patch |
|
1410 |
if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) ) |
|
1411 |
return true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1412 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1413 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1414 |
// check if an industry that accepts the same goods is nearby |
1415 |
if (i->xy != 0 && |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
1416 |
(DistanceMax(tile, i->xy) <= 14) && |
0 | 1417 |
spec->accepts_cargo[0] != 0xFF && |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1005
diff
changeset
|
1418 |
spec->accepts_cargo[0] == i->accepts_cargo[0] && |
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1005
diff
changeset
|
1419 |
!(_game_mode == GM_EDITOR && |
952
48dbeb24b216
(svn r1443) Added feature that users are able to place multiple accepting industies nearby in the editor mode if the appropriate patches are set
miham
parents:
926
diff
changeset
|
1420 |
_patches.same_industry_close && |
48dbeb24b216
(svn r1443) Added feature that users are able to place multiple accepting industies nearby in the editor mode if the appropriate patches are set
miham
parents:
926
diff
changeset
|
1421 |
_patches.multiple_industry_per_town)) { |
0 | 1422 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1423 |
return false; |
|
1424 |
} |
|
1425 |
||
1426 |
// check "not close to" field. |
|
1427 |
if (i->xy != 0 && |
|
1428 |
(i->type == spec->a || i->type == spec->b || i->type == spec->c) && |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
1429 |
DistanceMax(tile, i->xy) <= 14) { |
0 | 1430 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1431 |
return false; |
|
1432 |
} |
|
1433 |
} |
|
1434 |
return true; |
|
1435 |
} |
|
1436 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1437 |
static Industry *AllocateIndustry(void) |
0 | 1438 |
{ |
1439 |
Industry *i; |
|
1440 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1441 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1442 |
if (i->xy == 0) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1443 |
uint index = i->index; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1444 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1445 |
if (i->index > _total_industries) |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1446 |
_total_industries = i->index; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1447 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1448 |
memset(i, 0, sizeof(Industry)); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1449 |
i->index = index; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1450 |
|
0 | 1451 |
return i; |
1452 |
} |
|
1453 |
} |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1454 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1455 |
/* Check if we can add a block to the pool */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1456 |
if (AddBlockToPool(&_industry_pool)) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1457 |
return AllocateIndustry(); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1458 |
|
0 | 1459 |
return NULL; |
1460 |
} |
|
1461 |
||
1462 |
static void DoCreateNewIndustry(Industry *i, uint tile, int type, const IndustryTileTable *it, Town *t, byte owner) |
|
1463 |
{ |
|
1464 |
const IndustrySpec *spec; |
|
1465 |
uint32 r; |
|
1466 |
uint cur_tile; |
|
1467 |
int j; |
|
1468 |
||
1469 |
i->xy = tile; |
|
1470 |
i->width = i->height = 0; |
|
1471 |
i->type = type; |
|
1472 |
||
1473 |
spec = &_industry_spec[type]; |
|
1474 |
||
1475 |
i->produced_cargo[0] = spec->produced_cargo[0]; |
|
1476 |
i->produced_cargo[1] = spec->produced_cargo[1]; |
|
1477 |
i->accepts_cargo[0] = spec->accepts_cargo[0]; |
|
1478 |
i->accepts_cargo[1] = spec->accepts_cargo[1]; |
|
1479 |
i->accepts_cargo[2] = spec->accepts_cargo[2]; |
|
1480 |
i->production_rate[0] = spec->production_rate[0]; |
|
1481 |
i->production_rate[1] = spec->production_rate[1]; |
|
1482 |
||
1483 |
if (_patches.smooth_economy) { |
|
1484 |
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); |
|
1485 |
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); |
|
1486 |
} |
|
1487 |
||
1488 |
i->town = t; |
|
1489 |
i->owner = owner; |
|
1490 |
||
1491 |
r = Random() & 0xFFF; |
|
1492 |
i->color_map = (byte)(r >> 8); |
|
1493 |
i->counter = (uint16)r; |
|
1494 |
i->cargo_waiting[0] = 0; |
|
1495 |
i->cargo_waiting[1] = 0; |
|
1496 |
i->last_mo_production[0] = 0; |
|
1497 |
i->last_mo_production[1] = 0; |
|
1498 |
i->last_mo_transported[0] = 0; |
|
1499 |
i->last_mo_transported[1] = 0; |
|
1500 |
i->pct_transported[0] = 0; |
|
1501 |
i->pct_transported[1] = 0; |
|
1502 |
i->total_transported[0] = 0; |
|
1503 |
i->total_transported[1] = 0; |
|
1504 |
i->was_cargo_delivered = false; |
|
1505 |
i->last_prod_year = _cur_year; |
|
1506 |
i->total_production[0] = i->production_rate[0] * 8; |
|
1507 |
i->total_production[1] = i->production_rate[1] * 8; |
|
1508 |
||
1509 |
if (_generating_world == 0) |
|
1510 |
i->total_production[0] = i->total_production[1] = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1511 |
|
0 | 1512 |
i->prod_level = 0x10; |
1513 |
||
1514 |
do { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1515 |
cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1516 |
|
1517 |
if (it->map5 != 0xFF) { |
|
1518 |
byte size; |
|
1519 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1520 |
size = it->ti.x; |
0 | 1521 |
if (size > i->width) i->width = size; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1522 |
size = it->ti.y; |
0 | 1523 |
if (size > i->height)i->height = size; |
1524 |
||
1525 |
DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1526 |
||
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1048
diff
changeset
|
1527 |
SetTileType(cur_tile, MP_INDUSTRY); |
0 | 1528 |
_map5[cur_tile] = it->map5; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1529 |
_map2[cur_tile] = i->index; |
0 | 1530 |
_map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */ |
1531 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1532 |
} while ((++it)->ti.x != -0x80); |
0 | 1533 |
|
1534 |
i->width++; |
|
1535 |
i->height++; |
|
1536 |
||
1537 |
if (i->type == IT_FARM || i->type == IT_FARM_2) { |
|
1538 |
tile = i->xy + TILE_XY((i->width >> 1), (i->height >> 1)); |
|
1539 |
for(j=0; j!=50; j++) { |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1540 |
int x = Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1541 |
int y = Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1542 |
uint new_tile = TileAddWrap(tile, x, y); |
1247 | 1543 |
if (new_tile != INVALID_TILE) |
0 | 1544 |
PlantFarmField(new_tile); |
131
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
110
diff
changeset
|
1545 |
} |
0 | 1546 |
} |
1547 |
_industry_sort_dirty = true; |
|
1548 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1549 |
} |
|
1550 |
||
1551 |
/* p1 = industry type 0-36 */ |
|
1552 |
int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1553 |
{ |
|
1554 |
uint tile = TILE_FROM_XY(x,y); |
|
1555 |
Town *t; |
|
1556 |
int num; |
|
1557 |
const IndustryTileTable * const *itt; |
|
1558 |
const IndustryTileTable *it; |
|
1559 |
Industry *i; |
|
1560 |
const IndustrySpec *spec; |
|
1561 |
||
1562 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1563 |
||
1564 |
if (!CheckSuitableIndustryPos(tile)) |
|
1565 |
return CMD_ERROR; |
|
1566 |
||
1567 |
spec = &_industry_spec[p1]; |
|
1568 |
||
1569 |
if (!_check_new_industry_procs[spec->check_proc](tile, p1)) |
|
1570 |
return CMD_ERROR; |
|
1571 |
||
1572 |
if ((t=CheckMultipleIndustryInTown(tile, p1)) == NULL) |
|
1573 |
return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1574 |
|
0 | 1575 |
num = spec->num_table; |
1576 |
itt = spec->table; |
|
1577 |
||
1578 |
do { |
|
1579 |
if (--num < 0) |
|
1580 |
return_cmd_error(STR_0239_SITE_UNSUITABLE); |
|
1581 |
} while (!CheckIfIndustryTilesAreFree(tile, it=itt[num], p1, t)); |
|
1582 |
||
1583 |
||
1584 |
if (!CheckIfTooCloseToIndustry(tile, p1)) |
|
1585 |
return CMD_ERROR; |
|
1586 |
||
1587 |
if ( (i = AllocateIndustry()) == NULL) |
|
1588 |
return CMD_ERROR; |
|
1589 |
||
1590 |
if (flags & DC_EXEC) |
|
1591 |
DoCreateNewIndustry(i, tile, p1, it, t, 0x10); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1592 |
|
0 | 1593 |
return (_price.build_industry >> 5) * _industry_type_costs[p1]; |
1594 |
} |
|
1595 |
||
1596 |
||
1597 |
Industry *CreateNewIndustry(uint tile, int type) |
|
1598 |
{ |
|
1599 |
Town *t; |
|
1600 |
const IndustryTileTable *it; |
|
1601 |
Industry *i; |
|
1602 |
||
1603 |
const IndustrySpec *spec; |
|
1604 |
||
1605 |
if (!CheckSuitableIndustryPos(tile)) |
|
1606 |
return NULL; |
|
1607 |
||
1608 |
spec = &_industry_spec[type]; |
|
1609 |
||
1610 |
if (!_check_new_industry_procs[spec->check_proc](tile, type)) |
|
1611 |
return NULL; |
|
1612 |
||
1613 |
if (!(t=CheckMultipleIndustryInTown(tile, type))) |
|
1614 |
return NULL; |
|
1615 |
||
1616 |
/* pick a random layout */ |
|
1617 |
it = spec->table[(spec->num_table * (uint16)Random()) >> 16]; |
|
1618 |
||
1619 |
if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) |
|
1620 |
return NULL; |
|
1621 |
||
1622 |
if (!CheckIfTooCloseToIndustry(tile, type)) |
|
1623 |
return NULL; |
|
1624 |
||
1625 |
if ( (i = AllocateIndustry()) == NULL) |
|
1626 |
return NULL; |
|
1627 |
||
1628 |
DoCreateNewIndustry(i, tile, type, it, t, 0x10); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1629 |
|
0 | 1630 |
return i; |
1631 |
} |
|
1632 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1633 |
static const byte _numof_industry_table[4][12] = { |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1634 |
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
0 | 1635 |
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, |
1636 |
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
|
1637 |
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, |
|
1638 |
}; |
|
1639 |
||
1640 |
static void PlaceInitialIndustry(byte type, int amount) |
|
1641 |
{ |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1642 |
int num = |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1643 |
ScaleByMapSize(_numof_industry_table[_opt.diff.number_industries][amount]); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1644 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1645 |
if (_opt.diff.number_industries != 0) |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1646 |
{ |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1647 |
byte old_player = _current_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1648 |
_current_player = OWNER_NONE; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1649 |
assert(num > 0); |
0 | 1650 |
|
1651 |
do { |
|
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1652 |
int i = 2000; |
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1653 |
do { |
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1654 |
if (CreateNewIndustry(TILE_MASK(Random()), type) != NULL) |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1655 |
break; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1656 |
} while (--i != 0); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1657 |
} while (--num); |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1658 |
|
267 | 1659 |
_current_player = old_player; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1660 |
} |
0 | 1661 |
} |
1662 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1663 |
void GenerateIndustries(void) |
0 | 1664 |
{ |
1665 |
const byte *b; |
|
1666 |
||
1667 |
b = _industry_create_table[_opt.landscape]; |
|
1668 |
do { |
|
1669 |
PlaceInitialIndustry(b[1], b[0]); |
|
1670 |
} while ( (b+=2)[0] != 0); |
|
1671 |
} |
|
1672 |
||
1673 |
static void ExtChangeIndustryProduction(Industry *i) |
|
1674 |
{ |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1675 |
bool closeit = true; |
0 | 1676 |
int j; |
1677 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1678 |
switch (_industry_close_mode[i->type]) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1679 |
case INDUSTRY_NOT_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1680 |
return; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1681 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1682 |
case INDUSTRY_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1683 |
if ( (byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1,180)) |
0 | 1684 |
closeit = false; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1685 |
break; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1686 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1687 |
default: /* INDUSTRY_PRODUCTION */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1688 |
for (j=0; j != 2 && i->produced_cargo[j]!=255; j++){ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1689 |
uint32 r; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1690 |
int change,percent,old; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1691 |
int mag; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1692 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1693 |
change = old = i->production_rate[j]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1694 |
if (CHANCE16R(20,1024,r))change -= ((RandomRange(50) + 10)*old) >> 8; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1695 |
if (CHANCE16I(20+(i->pct_transported[j]*20>>8),1024,r>>16)) change += ((RandomRange(50) + 10)*old) >> 8; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1696 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1697 |
// make sure it doesn't exceed 255 or goes below 0 |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1698 |
change = clamp(change, 0, 255); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1699 |
if (change == old) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1700 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1701 |
continue; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1702 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1703 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1704 |
percent = change*100/old - 100; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1705 |
i->production_rate[j] = change; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1706 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1707 |
if (change >= _industry_spec[i->type].production_rate[j]/4) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1708 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1709 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1710 |
mag = abs(percent); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1711 |
if (mag >= 10) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1712 |
SetDParam(3, mag); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1713 |
SetDParam(0,_cargoc.names_s[i->produced_cargo[j]]); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1714 |
SetDParam(1, i->town->index); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1715 |
SetDParam(2, i->type + STR_4802_COAL_MINE); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1716 |
AddNewsItem(percent>=0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1717 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1718 |
i->xy + TILE_XY(1,1), 0); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1719 |
} |
0 | 1720 |
} |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1721 |
break; |
0 | 1722 |
} |
1723 |
||
1724 |
if (closeit) { |
|
1725 |
i->prod_level = 0; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1726 |
SetDParam(1, i->type + STR_4802_COAL_MINE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1727 |
SetDParam(0, i->town->index); |
0 | 1728 |
AddNewsItem(_industry_close_strings[i->type], NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0); |
1729 |
} |
|
1730 |
} |
|
1731 |
||
1732 |
||
1733 |
static void UpdateIndustryStatistics(Industry *i) |
|
1734 |
{ |
|
1735 |
byte pct; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1736 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1737 |
if (i->produced_cargo[0] != 0xFF) { |
0 | 1738 |
pct = 0; |
1739 |
if (i->last_mo_production[0] != 0) { |
|
1740 |
i->last_prod_year = _cur_year; |
|
1741 |
pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0],255); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1742 |
} |
0 | 1743 |
i->pct_transported[0] = pct; |
1744 |
||
1745 |
i->total_production[0] = i->last_mo_production[0]; |
|
1746 |
i->last_mo_production[0] = 0; |
|
1747 |
||
1748 |
i->total_transported[0] = i->last_mo_transported[0]; |
|
1749 |
i->last_mo_transported[0] = 0; |
|
1750 |
} |
|
1751 |
||
1752 |
if (i->produced_cargo[1] != 0xFF) { |
|
1753 |
pct = 0; |
|
1754 |
if (i->last_mo_production[1] != 0) { |
|
1755 |
i->last_prod_year = _cur_year; |
|
1756 |
pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1],255); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1757 |
} |
0 | 1758 |
i->pct_transported[1] = pct; |
1759 |
||
1760 |
i->total_production[1] = i->last_mo_production[1]; |
|
1761 |
i->last_mo_production[1] = 0; |
|
1762 |
||
1763 |
i->total_transported[1] = i->last_mo_transported[1]; |
|
1764 |
i->last_mo_transported[1] = 0; |
|
1765 |
} |
|
1766 |
||
1767 |
||
1768 |
if ( i->produced_cargo[0] != 0xFF || i->produced_cargo[1] != 0xFF ) |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1769 |
InvalidateWindow(WC_INDUSTRY_VIEW, i->index); |
0 | 1770 |
|
1771 |
if (i->prod_level == 0) |
|
1772 |
DeleteIndustry(i); |
|
1773 |
else if (_patches.smooth_economy) |
|
1774 |
ExtChangeIndustryProduction(i); |
|
1775 |
} |
|
1776 |
||
1777 |
static const byte _new_industry_rand[4][32] = { |
|
1778 |
{12,12,12,12,12,12,12, 0, 0, 6, 6, 9, 9, 3, 3, 3,18,18, 4, 4, 2, 2, 5, 5, 5, 5, 5, 5, 1, 1, 8, 8}, |
|
1779 |
{16,16,16, 0, 0, 0, 9, 9, 9, 9,13,13, 3, 3, 3, 3,15,15,15, 4, 4,11,11,11,11,11,14,14, 1, 1, 7, 7}, |
|
1780 |
{21,21,21,24,22,22,22,22,23,23,12,12,12, 4, 4,19,19,19,13,13,20,20,20,11,11,11,17,17,17,10,10,10}, |
|
1781 |
{30,30,30,36,36,31,31,31,27,27,27,28,28,28,26,26,26,34,34,34,35,35,35,29,29,29,32,32,32,33,33,33}, |
|
1782 |
}; |
|
1783 |
||
1784 |
static void MaybeNewIndustry(uint32 r) |
|
1785 |
{ |
|
1786 |
int type; |
|
1787 |
int j; |
|
1788 |
Industry *i; |
|
1789 |
||
1790 |
type = _new_industry_rand[_opt.landscape][(r >> 16) & 0x1F]; |
|
1791 |
if (type == IT_OIL_WELL && _date > 10958) |
|
1792 |
return; |
|
1793 |
||
1794 |
if (type == IT_OIL_RIG && _date < 14610) |
|
1795 |
return; |
|
1796 |
||
1797 |
j = 2000; |
|
1798 |
for(;;) { |
|
1799 |
i = CreateNewIndustry(TILE_MASK(Random()), type); |
|
1800 |
if (i != NULL) |
|
1801 |
break; |
|
1802 |
if (--j == 0) |
|
1803 |
return; |
|
1804 |
} |
|
1805 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1806 |
SetDParam(0, type + STR_4802_COAL_MINE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1807 |
SetDParam(1, i->town->index); |
0 | 1808 |
AddNewsItem( STR_482D_NEW_UNDER_CONSTRUCTION + (type == IT_FOREST), NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ECONOMY,0), i->xy, 0); |
1809 |
} |
|
1810 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1811 |
static void ChangeIndustryProduction(Industry *i) |
0 | 1812 |
{ |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1813 |
bool only_decrease = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1814 |
StringID str = STR_NULL; |
0 | 1815 |
int type = i->type; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1816 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1817 |
switch (_industry_close_mode[type]) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1818 |
case INDUSTRY_NOT_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1819 |
return; |
0 | 1820 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1821 |
case INDUSTRY_PRODUCTION: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1822 |
/* decrease or increase */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1823 |
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1824 |
only_decrease = true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1825 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1826 |
if (only_decrease || CHANCE16(1,3)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1827 |
/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1828 |
if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1829 |
/* Increase production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1830 |
if (i->prod_level != 0x80) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1831 |
byte b; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1832 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1833 |
i->prod_level <<= 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1834 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1835 |
b = i->production_rate[0] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1836 |
if (i->production_rate[0] >= 128) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1837 |
b = 0xFF; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1838 |
i->production_rate[0] = b; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1839 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1840 |
b = i->production_rate[1] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1841 |
if (i->production_rate[1] >= 128) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1842 |
b = 0xFF; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1843 |
i->production_rate[1] = b; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1844 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1845 |
str = _industry_prod_up_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1846 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1847 |
} else { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1848 |
/* Decrease production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1849 |
if (i->prod_level == 4) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1850 |
i->prod_level = 0; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1851 |
str = _industry_close_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1852 |
} else { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1853 |
i->prod_level >>= 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1854 |
i->production_rate[0] = (i->production_rate[0] + 1) >> 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1855 |
i->production_rate[1] = (i->production_rate[1] + 1) >> 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1856 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1857 |
str = _industry_prod_down_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1858 |
} |
0 | 1859 |
} |
1860 |
} |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1861 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1862 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1863 |
case INDUSTRY_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1864 |
/* maybe close */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1865 |
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1866 |
i->prod_level = 0; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1867 |
str = _industry_close_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1868 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1869 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1870 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1871 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1872 |
if (str != STR_NULL) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1873 |
SetDParam(1, type + STR_4802_COAL_MINE); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1874 |
SetDParam(0, i->town->index); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1875 |
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0); |
0 | 1876 |
} |
1877 |
} |
|
1878 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1879 |
void IndustryMonthlyLoop(void) |
0 | 1880 |
{ |
1881 |
Industry *i; |
|
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1882 |
byte old_player = _current_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1883 |
_current_player = OWNER_NONE; |
0 | 1884 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1885 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1886 |
if (i->xy != 0) |
1887 |
UpdateIndustryStatistics(i); |
|
1888 |
} |
|
1889 |
||
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1890 |
/* 3% chance that we start a new industry */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1891 |
if (CHANCE16(3, 100)) { |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1892 |
MaybeNewIndustry(Random()); |
1269
0c8818a1c07a
(svn r1773) -Fix: [ 1114950 ] Game crashed sometimes when there were no industries
truelight
parents:
1267
diff
changeset
|
1893 |
} else if (!_patches.smooth_economy && _total_industries > 0) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1894 |
i = GetIndustry(RandomRange(_total_industries)); |
1270
a084b84eb971
(svn r1774) -Fix: fixed an other possible crash related to previous commit
truelight
parents:
1269
diff
changeset
|
1895 |
if (i->xy != 0) |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1896 |
ChangeIndustryProduction(i); |
0 | 1897 |
} |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1898 |
|
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1899 |
_current_player = old_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1900 |
|
0 | 1901 |
// production-change |
1902 |
_industry_sort_dirty = true; |
|
1903 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1904 |
} |
|
1905 |
||
1906 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1907 |
void InitializeIndustries(void) |
0 | 1908 |
{ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1909 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1910 |
CleanPool(&_industry_pool); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1911 |
AddBlockToPool(&_industry_pool); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1912 |
|
0 | 1913 |
_total_industries = 0; |
1914 |
_industry_sort_dirty = true; |
|
1915 |
} |
|
1916 |
||
1917 |
const TileTypeProcs _tile_type_industry_procs = { |
|
1918 |
DrawTile_Industry, /* draw_tile_proc */ |
|
1919 |
GetSlopeZ_Industry, /* get_slope_z_proc */ |
|
1920 |
ClearTile_Industry, /* clear_tile_proc */ |
|
1921 |
GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
|
1922 |
GetTileDesc_Industry, /* get_tile_desc_proc */ |
|
1923 |
GetTileTrackStatus_Industry,/* get_tile_track_status_proc */ |
|
1924 |
ClickTile_Industry, /* click_tile_proc */ |
|
1925 |
AnimateTile_Industry, /* animate_tile_proc */ |
|
1926 |
TileLoop_Industry, /* tile_loop_proc */ |
|
1927 |
ChangeTileOwner_Industry, /* change_tile_owner_proc */ |
|
1928 |
GetProducedCargo_Industry, /* get_produced_cargo_proc */ |
|
1929 |
NULL, /* vehicle_enter_tile_proc */ |
|
1930 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1931 |
GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
0 | 1932 |
}; |
1933 |
||
1934 |
static const byte _industry_desc[] = { |
|
1174
6a5e747f3ba6
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
1935 |
SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
6a5e747f3ba6
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
1936 |
SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, 255), |
0 | 1937 |
SLE_VAR(Industry,width, SLE_UINT8), |
1938 |
SLE_VAR(Industry,height, SLE_UINT8), |
|
1939 |
SLE_REF(Industry,town, REF_TOWN), |
|
1940 |
SLE_ARR(Industry,produced_cargo, SLE_UINT8, 2), |
|
1941 |
SLE_ARR(Industry,cargo_waiting, SLE_UINT16, 2), |
|
1942 |
SLE_ARR(Industry,production_rate, SLE_UINT8, 2), |
|
1943 |
SLE_ARR(Industry,accepts_cargo, SLE_UINT8, 3), |
|
1944 |
SLE_VAR(Industry,prod_level, SLE_UINT8), |
|
1945 |
SLE_ARR(Industry,last_mo_production,SLE_UINT16, 2), |
|
1946 |
SLE_ARR(Industry,last_mo_transported,SLE_UINT16, 2), |
|
1947 |
SLE_ARR(Industry,pct_transported,SLE_UINT8, 2), |
|
1948 |
SLE_ARR(Industry,total_production,SLE_UINT16, 2), |
|
1949 |
SLE_ARR(Industry,total_transported,SLE_UINT16, 2), |
|
1950 |
||
1951 |
SLE_VAR(Industry,counter, SLE_UINT16), |
|
1952 |
||
1953 |
SLE_VAR(Industry,type, SLE_UINT8), |
|
1954 |
SLE_VAR(Industry,owner, SLE_UINT8), |
|
1955 |
SLE_VAR(Industry,color_map, SLE_UINT8), |
|
1956 |
SLE_VAR(Industry,last_prod_year, SLE_UINT8), |
|
1957 |
SLE_VAR(Industry,was_cargo_delivered,SLE_UINT8), |
|
1958 |
||
1959 |
// reserve extra space in savegame here. (currently 32 bytes) |
|
1960 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 4, 2, 255), |
|
1961 |
||
1962 |
SLE_END() |
|
1963 |
}; |
|
1964 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1965 |
static void Save_INDY(void) |
0 | 1966 |
{ |
1967 |
Industry *ind; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1968 |
|
0 | 1969 |
// Write the vehicles |
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1970 |
FOR_ALL_INDUSTRIES(ind) { |
0 | 1971 |
if (ind->xy != 0) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1972 |
SlSetArrayIndex(ind->index); |
0 | 1973 |
SlObject(ind, _industry_desc); |
1974 |
} |
|
1975 |
} |
|
1976 |
} |
|
1977 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1978 |
static void Load_INDY(void) |
0 | 1979 |
{ |
1980 |
int index; |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1981 |
|
0 | 1982 |
_total_industries = 0; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1983 |
|
0 | 1984 |
while ((index = SlIterateArray()) != -1) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1985 |
Industry *i; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1986 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1987 |
if (!AddBlockIfNeeded(&_industry_pool, index)) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1988 |
error("Industries: failed loading savegame: too many industries"); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1989 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1990 |
i = GetIndustry(index); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1991 |
SlObject(i, _industry_desc); |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1992 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1993 |
if (index > _total_industries) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1994 |
_total_industries = index; |
0 | 1995 |
} |
1996 |
} |
|
1997 |
||
1998 |
const ChunkHandler _industry_chunk_handlers[] = { |
|
1999 |
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |
|
2000 |
}; |
|
2001 |