author | tron |
Sun, 06 Feb 2005 20:53:31 +0000 | |
changeset 1328 | eacd8225ed42 |
parent 1320 | 44a8658d88c0 |
child 1335 | a5f223b9f549 |
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); |
0 | 672 |
CreateEffectVehicle(ti.x + 15, ti.y + 14, ti.z + 59 + (ti.tileh != 0 ? 8 : 0), EV_INDUSTRYSMOKE); |
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], |
738 |
EV_INDUSTRY_SMOKE |
|
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: { |
|
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
|
822 |
CreateEffectVehicleAbove(TileX(tile) * 16 + 6, TileY(tile) * 16 + 6, 43, EV_SMOKE_3); |
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) { |
|
962 |
if (GetTileZ(tile) >= (_opt.snow_line - 16)) |
|
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) { |
|
1172 |
if (GetTileZ(tile) < (_opt.snow_line + 16) ) { |
|
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 |
{ |
|
1184 |
int x,y; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1185 |
|
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1186 |
if(_ignore_restrictions && _game_mode == GM_EDITOR) |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1187 |
return true; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1188 |
|
0 | 1189 |
if (type != IT_OIL_RIG && _game_mode == GM_EDITOR) |
1190 |
return true; |
|
1191 |
||
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
|
1192 |
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
|
1193 |
y = TileY(tile); |
0 | 1194 |
|
1195 |
if ( x < 15 || y < 15 || x > 238 || y > 238) |
|
1196 |
return true; |
|
1197 |
||
1198 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
|
1199 |
return false; |
|
1200 |
} |
|
1201 |
||
1202 |
static bool CheckNewIndustry_Farm(uint tile, int type) |
|
1203 |
{ |
|
1204 |
if (_opt.landscape == LT_HILLY) { |
|
1205 |
if (GetTileZ(tile) >= (_opt.snow_line - 16)) { |
|
1206 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1207 |
return false; |
|
1208 |
} |
|
1209 |
} |
|
1210 |
return true; |
|
1211 |
} |
|
1212 |
||
1213 |
static bool CheckNewIndustry_Plantation(uint tile, int type) |
|
1214 |
{ |
|
1215 |
if (GetMapExtraBits(tile) == 1) { |
|
1216 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1217 |
return false; |
|
1218 |
} |
|
1219 |
||
1220 |
return true; |
|
1221 |
} |
|
1222 |
||
1223 |
static bool CheckNewIndustry_Water(uint tile, int type) |
|
1224 |
{ |
|
1225 |
if (GetMapExtraBits(tile) != 1) { |
|
1226 |
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; |
|
1227 |
return false; |
|
1228 |
} |
|
1229 |
||
1230 |
return true; |
|
1231 |
} |
|
1232 |
||
1233 |
static bool CheckNewIndustry_Lumbermill(uint tile, int type) |
|
1234 |
{ |
|
1235 |
if (GetMapExtraBits(tile) != 2) { |
|
1236 |
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; |
|
1237 |
return false; |
|
1238 |
} |
|
1239 |
return true; |
|
1240 |
} |
|
1241 |
||
1242 |
static bool CheckNewIndustry_BubbleGen(uint tile, int type) |
|
1243 |
{ |
|
1244 |
if (GetTileZ(tile) > 32) { |
|
1245 |
return false; |
|
1246 |
} |
|
1247 |
return true; |
|
1248 |
} |
|
1249 |
||
1250 |
typedef bool CheckNewIndustryProc(uint tile, int type); |
|
1251 |
static CheckNewIndustryProc * const _check_new_industry_procs[] = { |
|
1252 |
CheckNewIndustry_NULL, |
|
1253 |
CheckNewIndustry_Forest, |
|
1254 |
CheckNewIndustry_Oilwell, |
|
1255 |
CheckNewIndustry_Farm, |
|
1256 |
CheckNewIndustry_Plantation, |
|
1257 |
CheckNewIndustry_Water, |
|
1258 |
CheckNewIndustry_Lumbermill, |
|
1259 |
CheckNewIndustry_BubbleGen, |
|
1260 |
}; |
|
1261 |
||
1262 |
static bool CheckSuitableIndustryPos(uint tile) |
|
1263 |
{ |
|
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
|
1264 |
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
|
1265 |
uint y = TileY(tile); |
0 | 1266 |
|
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
838
diff
changeset
|
1267 |
if ( x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { |
0 | 1268 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1269 |
return false; |
|
1270 |
} |
|
1271 |
||
1272 |
return true; |
|
1273 |
} |
|
1274 |
||
1275 |
static Town *CheckMultipleIndustryInTown(uint tile, int type) |
|
1276 |
{ |
|
1277 |
Town *t; |
|
1278 |
Industry *i; |
|
1279 |
||
1280 |
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
|
1281 |
|
0 | 1282 |
if (_patches.multiple_industry_per_town) |
1283 |
return t; |
|
1284 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1285 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1286 |
if (i->xy != 0 && |
1287 |
i->type == (byte)type && |
|
1288 |
i->town == t) { |
|
1289 |
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; |
|
1290 |
return NULL; |
|
1291 |
} |
|
1292 |
} |
|
1293 |
||
1294 |
return t; |
|
1295 |
} |
|
1296 |
||
1297 |
static const byte _industry_map5_bits[] = { |
|
1298 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1299 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1300 |
16, 16, 16, 16, 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, 16, 16, 16, 16, 16, 16, 16, |
|
1305 |
16, 16, 4, 2, 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, 4, 2, 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, 16, |
|
1315 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1316 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1317 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1318 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1319 |
16, 16, 16, 16, 16, 16, 16, |
|
1320 |
}; |
|
1321 |
||
1322 |
static bool CheckIfIndustryTilesAreFree(uint tile, const IndustryTileTable *it, int type, Town *t) |
|
1323 |
{ |
|
1324 |
TileInfo ti; |
|
1325 |
uint cur_tile; |
|
1326 |
||
1327 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1328 |
||
1329 |
do { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1330 |
cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1331 |
if (!IsValidTile(cur_tile)) { |
1332 |
if (it->map5 == 0xff) |
|
1333 |
continue; |
|
1334 |
return false; |
|
1335 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1336 |
|
0 | 1337 |
FindLandscapeHeightByTile(&ti, cur_tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1338 |
|
0 | 1339 |
if (it->map5 == 0xFF) { |
1340 |
if (ti.type != MP_WATER || ti.tileh != 0) |
|
1341 |
return false; |
|
1342 |
} else { |
|
1343 |
if (!EnsureNoVehicle(cur_tile)) |
|
1344 |
return false; |
|
1345 |
||
1346 |
if (type == IT_OIL_RIG) { |
|
1347 |
if (ti.type != MP_WATER || ti.map5 != 0) |
|
1348 |
return false; |
|
1349 |
} else { |
|
1350 |
if (ti.type == MP_WATER && ti.map5 == 0) |
|
1351 |
return false; |
|
1352 |
if (ti.tileh & 0x10) |
|
1353 |
return false; |
|
1354 |
||
1355 |
if (ti.tileh != 0) { |
|
1356 |
int t; |
|
1357 |
byte bits = _industry_map5_bits[it->map5]; |
|
1358 |
||
1359 |
if (bits & 0x10) |
|
1360 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1361 |
|
0 | 1362 |
t = ~ti.tileh; |
1363 |
||
1364 |
if (bits & 1 && (t & (1+8))) |
|
1365 |
return false; |
|
1366 |
||
1367 |
if (bits & 2 && (t & (4+8))) |
|
1368 |
return false; |
|
1369 |
||
1370 |
if (bits & 4 && (t & (1+2))) |
|
1371 |
return false; |
|
1372 |
||
1373 |
if (bits & 8 && (t & (2+4))) |
|
1374 |
return false; |
|
1375 |
} |
|
1376 |
||
1377 |
if (type == IT_BANK) { |
|
1378 |
if (ti.type != MP_HOUSE || t->population < 1200) { |
|
1379 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1380 |
return false; |
|
1381 |
} |
|
1382 |
} else if (type == IT_BANK_2) { |
|
1383 |
if (ti.type != MP_HOUSE) { |
|
1384 |
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1385 |
return false; |
|
1386 |
} |
|
1387 |
} 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
|
1388 |
if (DistanceMax(t->xy, cur_tile) > 9) |
0 | 1389 |
return false; |
1390 |
if (ti.type != MP_HOUSE) goto do_clear; |
|
1391 |
} else if (type == IT_WATER_TOWER) { |
|
1392 |
if (ti.type != MP_HOUSE) { |
|
1393 |
_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS; |
|
1394 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1395 |
} |
0 | 1396 |
} else { |
1397 |
do_clear: |
|
1398 |
if (DoCommandByTile(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) == CMD_ERROR) |
|
1399 |
return false; |
|
1400 |
} |
|
1401 |
} |
|
1402 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1403 |
} while ((++it)->ti.x != -0x80); |
0 | 1404 |
|
1405 |
return true; |
|
1406 |
} |
|
1407 |
||
1408 |
static bool CheckIfTooCloseToIndustry(uint tile, int type) |
|
1409 |
{ |
|
1410 |
Industry *i; |
|
1411 |
const IndustrySpec *spec; |
|
1412 |
spec = &_industry_spec[type]; |
|
1413 |
||
1414 |
// accepting industries won't be close, not even with patch |
|
1415 |
if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) ) |
|
1416 |
return true; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1417 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1418 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1419 |
// check if an industry that accepts the same goods is nearby |
1420 |
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
|
1421 |
(DistanceMax(tile, i->xy) <= 14) && |
0 | 1422 |
spec->accepts_cargo[0] != 0xFF && |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1005
diff
changeset
|
1423 |
spec->accepts_cargo[0] == i->accepts_cargo[0] && |
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1005
diff
changeset
|
1424 |
!(_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
|
1425 |
_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
|
1426 |
_patches.multiple_industry_per_town)) { |
0 | 1427 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1428 |
return false; |
|
1429 |
} |
|
1430 |
||
1431 |
// check "not close to" field. |
|
1432 |
if (i->xy != 0 && |
|
1433 |
(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
|
1434 |
DistanceMax(tile, i->xy) <= 14) { |
0 | 1435 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1436 |
return false; |
|
1437 |
} |
|
1438 |
} |
|
1439 |
return true; |
|
1440 |
} |
|
1441 |
||
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
|
1442 |
static Industry *AllocateIndustry(void) |
0 | 1443 |
{ |
1444 |
Industry *i; |
|
1445 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1446 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1447 |
if (i->xy == 0) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1448 |
uint index = i->index; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1449 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1450 |
if (i->index > _total_industries) |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1451 |
_total_industries = i->index; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1452 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1453 |
memset(i, 0, sizeof(Industry)); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1454 |
i->index = index; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1455 |
|
0 | 1456 |
return i; |
1457 |
} |
|
1458 |
} |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1459 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1460 |
/* 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
|
1461 |
if (AddBlockToPool(&_industry_pool)) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1462 |
return AllocateIndustry(); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1463 |
|
0 | 1464 |
return NULL; |
1465 |
} |
|
1466 |
||
1467 |
static void DoCreateNewIndustry(Industry *i, uint tile, int type, const IndustryTileTable *it, Town *t, byte owner) |
|
1468 |
{ |
|
1469 |
const IndustrySpec *spec; |
|
1470 |
uint32 r; |
|
1471 |
uint cur_tile; |
|
1472 |
int j; |
|
1473 |
||
1474 |
i->xy = tile; |
|
1475 |
i->width = i->height = 0; |
|
1476 |
i->type = type; |
|
1477 |
||
1478 |
spec = &_industry_spec[type]; |
|
1479 |
||
1480 |
i->produced_cargo[0] = spec->produced_cargo[0]; |
|
1481 |
i->produced_cargo[1] = spec->produced_cargo[1]; |
|
1482 |
i->accepts_cargo[0] = spec->accepts_cargo[0]; |
|
1483 |
i->accepts_cargo[1] = spec->accepts_cargo[1]; |
|
1484 |
i->accepts_cargo[2] = spec->accepts_cargo[2]; |
|
1485 |
i->production_rate[0] = spec->production_rate[0]; |
|
1486 |
i->production_rate[1] = spec->production_rate[1]; |
|
1487 |
||
1488 |
if (_patches.smooth_economy) { |
|
1489 |
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); |
|
1490 |
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); |
|
1491 |
} |
|
1492 |
||
1493 |
i->town = t; |
|
1494 |
i->owner = owner; |
|
1495 |
||
1496 |
r = Random() & 0xFFF; |
|
1497 |
i->color_map = (byte)(r >> 8); |
|
1498 |
i->counter = (uint16)r; |
|
1499 |
i->cargo_waiting[0] = 0; |
|
1500 |
i->cargo_waiting[1] = 0; |
|
1501 |
i->last_mo_production[0] = 0; |
|
1502 |
i->last_mo_production[1] = 0; |
|
1503 |
i->last_mo_transported[0] = 0; |
|
1504 |
i->last_mo_transported[1] = 0; |
|
1505 |
i->pct_transported[0] = 0; |
|
1506 |
i->pct_transported[1] = 0; |
|
1507 |
i->total_transported[0] = 0; |
|
1508 |
i->total_transported[1] = 0; |
|
1509 |
i->was_cargo_delivered = false; |
|
1510 |
i->last_prod_year = _cur_year; |
|
1511 |
i->total_production[0] = i->production_rate[0] * 8; |
|
1512 |
i->total_production[1] = i->production_rate[1] * 8; |
|
1513 |
||
1514 |
if (_generating_world == 0) |
|
1515 |
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
|
1516 |
|
0 | 1517 |
i->prod_level = 0x10; |
1518 |
||
1519 |
do { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1520 |
cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1521 |
|
1522 |
if (it->map5 != 0xFF) { |
|
1523 |
byte size; |
|
1524 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1525 |
size = it->ti.x; |
0 | 1526 |
if (size > i->width) i->width = size; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1527 |
size = it->ti.y; |
0 | 1528 |
if (size > i->height)i->height = size; |
1529 |
||
1530 |
DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1531 |
||
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1048
diff
changeset
|
1532 |
SetTileType(cur_tile, MP_INDUSTRY); |
0 | 1533 |
_map5[cur_tile] = it->map5; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1534 |
_map2[cur_tile] = i->index; |
0 | 1535 |
_map_owner[cur_tile] = _generating_world ? 0x1E : 0; /* maturity */ |
1536 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1537 |
} while ((++it)->ti.x != -0x80); |
0 | 1538 |
|
1539 |
i->width++; |
|
1540 |
i->height++; |
|
1541 |
||
1542 |
if (i->type == IT_FARM || i->type == IT_FARM_2) { |
|
1543 |
tile = i->xy + TILE_XY((i->width >> 1), (i->height >> 1)); |
|
1544 |
for(j=0; j!=50; j++) { |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1545 |
int x = Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1546 |
int y = Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1547 |
uint new_tile = TileAddWrap(tile, x, y); |
1247 | 1548 |
if (new_tile != INVALID_TILE) |
0 | 1549 |
PlantFarmField(new_tile); |
131
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
110
diff
changeset
|
1550 |
} |
0 | 1551 |
} |
1552 |
_industry_sort_dirty = true; |
|
1553 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1554 |
} |
|
1555 |
||
1556 |
/* p1 = industry type 0-36 */ |
|
1557 |
int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1558 |
{ |
|
1559 |
uint tile = TILE_FROM_XY(x,y); |
|
1560 |
Town *t; |
|
1561 |
int num; |
|
1562 |
const IndustryTileTable * const *itt; |
|
1563 |
const IndustryTileTable *it; |
|
1564 |
Industry *i; |
|
1565 |
const IndustrySpec *spec; |
|
1566 |
||
1567 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1568 |
||
1569 |
if (!CheckSuitableIndustryPos(tile)) |
|
1570 |
return CMD_ERROR; |
|
1571 |
||
1572 |
spec = &_industry_spec[p1]; |
|
1573 |
||
1574 |
if (!_check_new_industry_procs[spec->check_proc](tile, p1)) |
|
1575 |
return CMD_ERROR; |
|
1576 |
||
1577 |
if ((t=CheckMultipleIndustryInTown(tile, p1)) == NULL) |
|
1578 |
return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1579 |
|
0 | 1580 |
num = spec->num_table; |
1581 |
itt = spec->table; |
|
1582 |
||
1583 |
do { |
|
1584 |
if (--num < 0) |
|
1585 |
return_cmd_error(STR_0239_SITE_UNSUITABLE); |
|
1586 |
} while (!CheckIfIndustryTilesAreFree(tile, it=itt[num], p1, t)); |
|
1587 |
||
1588 |
||
1589 |
if (!CheckIfTooCloseToIndustry(tile, p1)) |
|
1590 |
return CMD_ERROR; |
|
1591 |
||
1592 |
if ( (i = AllocateIndustry()) == NULL) |
|
1593 |
return CMD_ERROR; |
|
1594 |
||
1595 |
if (flags & DC_EXEC) |
|
1596 |
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
|
1597 |
|
0 | 1598 |
return (_price.build_industry >> 5) * _industry_type_costs[p1]; |
1599 |
} |
|
1600 |
||
1601 |
||
1602 |
Industry *CreateNewIndustry(uint tile, int type) |
|
1603 |
{ |
|
1604 |
Town *t; |
|
1605 |
const IndustryTileTable *it; |
|
1606 |
Industry *i; |
|
1607 |
||
1608 |
const IndustrySpec *spec; |
|
1609 |
||
1610 |
if (!CheckSuitableIndustryPos(tile)) |
|
1611 |
return NULL; |
|
1612 |
||
1613 |
spec = &_industry_spec[type]; |
|
1614 |
||
1615 |
if (!_check_new_industry_procs[spec->check_proc](tile, type)) |
|
1616 |
return NULL; |
|
1617 |
||
1618 |
if (!(t=CheckMultipleIndustryInTown(tile, type))) |
|
1619 |
return NULL; |
|
1620 |
||
1621 |
/* pick a random layout */ |
|
1622 |
it = spec->table[(spec->num_table * (uint16)Random()) >> 16]; |
|
1623 |
||
1624 |
if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) |
|
1625 |
return NULL; |
|
1626 |
||
1627 |
if (!CheckIfTooCloseToIndustry(tile, type)) |
|
1628 |
return NULL; |
|
1629 |
||
1630 |
if ( (i = AllocateIndustry()) == NULL) |
|
1631 |
return NULL; |
|
1632 |
||
1633 |
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
|
1634 |
|
0 | 1635 |
return i; |
1636 |
} |
|
1637 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1638 |
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
|
1639 |
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
0 | 1640 |
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, |
1641 |
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
|
1642 |
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, |
|
1643 |
}; |
|
1644 |
||
1645 |
static void PlaceInitialIndustry(byte type, int amount) |
|
1646 |
{ |
|
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1647 |
int num = |
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1648 |
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
|
1649 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1650 |
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
|
1651 |
{ |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1652 |
byte old_player = _current_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1653 |
_current_player = OWNER_NONE; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1654 |
assert(num > 0); |
0 | 1655 |
|
1656 |
do { |
|
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1657 |
int i = 2000; |
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1658 |
do { |
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1659 |
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
|
1660 |
break; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1661 |
} while (--i != 0); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1662 |
} while (--num); |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1663 |
|
267 | 1664 |
_current_player = old_player; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1665 |
} |
0 | 1666 |
} |
1667 |
||
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
|
1668 |
void GenerateIndustries(void) |
0 | 1669 |
{ |
1670 |
const byte *b; |
|
1671 |
||
1672 |
b = _industry_create_table[_opt.landscape]; |
|
1673 |
do { |
|
1674 |
PlaceInitialIndustry(b[1], b[0]); |
|
1675 |
} while ( (b+=2)[0] != 0); |
|
1676 |
} |
|
1677 |
||
1678 |
static void ExtChangeIndustryProduction(Industry *i) |
|
1679 |
{ |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1680 |
bool closeit = true; |
0 | 1681 |
int j; |
1682 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1683 |
switch (_industry_close_mode[i->type]) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1684 |
case INDUSTRY_NOT_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1685 |
return; |
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 |
case INDUSTRY_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1688 |
if ( (byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1,180)) |
0 | 1689 |
closeit = false; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1690 |
break; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1691 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1692 |
default: /* INDUSTRY_PRODUCTION */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1693 |
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
|
1694 |
uint32 r; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1695 |
int change,percent,old; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1696 |
int mag; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1697 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1698 |
change = old = i->production_rate[j]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1699 |
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
|
1700 |
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
|
1701 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1702 |
// 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
|
1703 |
change = clamp(change, 0, 255); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1704 |
if (change == old) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1705 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1706 |
continue; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1707 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1708 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1709 |
percent = change*100/old - 100; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1710 |
i->production_rate[j] = change; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1711 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1712 |
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
|
1713 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1714 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1715 |
mag = abs(percent); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1716 |
if (mag >= 10) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1717 |
SetDParam(3, mag); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1718 |
SetDParam(0,_cargoc.names_s[i->produced_cargo[j]]); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1719 |
SetDParam(1, i->town->index); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1720 |
SetDParam(2, i->type + STR_4802_COAL_MINE); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1721 |
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
|
1722 |
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
|
1723 |
i->xy + TILE_XY(1,1), 0); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1724 |
} |
0 | 1725 |
} |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1726 |
break; |
0 | 1727 |
} |
1728 |
||
1729 |
if (closeit) { |
|
1730 |
i->prod_level = 0; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1731 |
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
|
1732 |
SetDParam(0, i->town->index); |
0 | 1733 |
AddNewsItem(_industry_close_strings[i->type], NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0); |
1734 |
} |
|
1735 |
} |
|
1736 |
||
1737 |
||
1738 |
static void UpdateIndustryStatistics(Industry *i) |
|
1739 |
{ |
|
1740 |
byte pct; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1741 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1742 |
if (i->produced_cargo[0] != 0xFF) { |
0 | 1743 |
pct = 0; |
1744 |
if (i->last_mo_production[0] != 0) { |
|
1745 |
i->last_prod_year = _cur_year; |
|
1746 |
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
|
1747 |
} |
0 | 1748 |
i->pct_transported[0] = pct; |
1749 |
||
1750 |
i->total_production[0] = i->last_mo_production[0]; |
|
1751 |
i->last_mo_production[0] = 0; |
|
1752 |
||
1753 |
i->total_transported[0] = i->last_mo_transported[0]; |
|
1754 |
i->last_mo_transported[0] = 0; |
|
1755 |
} |
|
1756 |
||
1757 |
if (i->produced_cargo[1] != 0xFF) { |
|
1758 |
pct = 0; |
|
1759 |
if (i->last_mo_production[1] != 0) { |
|
1760 |
i->last_prod_year = _cur_year; |
|
1761 |
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
|
1762 |
} |
0 | 1763 |
i->pct_transported[1] = pct; |
1764 |
||
1765 |
i->total_production[1] = i->last_mo_production[1]; |
|
1766 |
i->last_mo_production[1] = 0; |
|
1767 |
||
1768 |
i->total_transported[1] = i->last_mo_transported[1]; |
|
1769 |
i->last_mo_transported[1] = 0; |
|
1770 |
} |
|
1771 |
||
1772 |
||
1773 |
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
|
1774 |
InvalidateWindow(WC_INDUSTRY_VIEW, i->index); |
0 | 1775 |
|
1776 |
if (i->prod_level == 0) |
|
1777 |
DeleteIndustry(i); |
|
1778 |
else if (_patches.smooth_economy) |
|
1779 |
ExtChangeIndustryProduction(i); |
|
1780 |
} |
|
1781 |
||
1782 |
static const byte _new_industry_rand[4][32] = { |
|
1783 |
{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}, |
|
1784 |
{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}, |
|
1785 |
{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}, |
|
1786 |
{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}, |
|
1787 |
}; |
|
1788 |
||
1789 |
static void MaybeNewIndustry(uint32 r) |
|
1790 |
{ |
|
1791 |
int type; |
|
1792 |
int j; |
|
1793 |
Industry *i; |
|
1794 |
||
1795 |
type = _new_industry_rand[_opt.landscape][(r >> 16) & 0x1F]; |
|
1796 |
if (type == IT_OIL_WELL && _date > 10958) |
|
1797 |
return; |
|
1798 |
||
1799 |
if (type == IT_OIL_RIG && _date < 14610) |
|
1800 |
return; |
|
1801 |
||
1802 |
j = 2000; |
|
1803 |
for(;;) { |
|
1804 |
i = CreateNewIndustry(TILE_MASK(Random()), type); |
|
1805 |
if (i != NULL) |
|
1806 |
break; |
|
1807 |
if (--j == 0) |
|
1808 |
return; |
|
1809 |
} |
|
1810 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1811 |
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
|
1812 |
SetDParam(1, i->town->index); |
0 | 1813 |
AddNewsItem( STR_482D_NEW_UNDER_CONSTRUCTION + (type == IT_FOREST), NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ECONOMY,0), i->xy, 0); |
1814 |
} |
|
1815 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1816 |
static void ChangeIndustryProduction(Industry *i) |
0 | 1817 |
{ |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1818 |
bool only_decrease = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1819 |
StringID str = STR_NULL; |
0 | 1820 |
int type = i->type; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1821 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1822 |
switch (_industry_close_mode[type]) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1823 |
case INDUSTRY_NOT_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1824 |
return; |
0 | 1825 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1826 |
case INDUSTRY_PRODUCTION: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1827 |
/* decrease or increase */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1828 |
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1829 |
only_decrease = true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1830 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1831 |
if (only_decrease || CHANCE16(1,3)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1832 |
/* 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
|
1833 |
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
|
1834 |
/* Increase production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1835 |
if (i->prod_level != 0x80) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1836 |
byte b; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1837 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1838 |
i->prod_level <<= 1; |
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[0] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1841 |
if (i->production_rate[0] >= 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[0] = 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 |
b = i->production_rate[1] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1846 |
if (i->production_rate[1] >= 128) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1847 |
b = 0xFF; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1848 |
i->production_rate[1] = b; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1849 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1850 |
str = _industry_prod_up_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1851 |
} |
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 |
/* Decrease production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1854 |
if (i->prod_level == 4) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1855 |
i->prod_level = 0; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1856 |
str = _industry_close_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1857 |
} else { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1858 |
i->prod_level >>= 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1859 |
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
|
1860 |
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
|
1861 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1862 |
str = _industry_prod_down_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1863 |
} |
0 | 1864 |
} |
1865 |
} |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1866 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1867 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1868 |
case INDUSTRY_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1869 |
/* maybe close */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1870 |
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
|
1871 |
i->prod_level = 0; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1872 |
str = _industry_close_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1873 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1874 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1875 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1876 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1877 |
if (str != STR_NULL) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1878 |
SetDParam(1, type + STR_4802_COAL_MINE); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1879 |
SetDParam(0, i->town->index); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1880 |
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0); |
0 | 1881 |
} |
1882 |
} |
|
1883 |
||
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
|
1884 |
void IndustryMonthlyLoop(void) |
0 | 1885 |
{ |
1886 |
Industry *i; |
|
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1887 |
byte old_player = _current_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1888 |
_current_player = OWNER_NONE; |
0 | 1889 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1890 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1891 |
if (i->xy != 0) |
1892 |
UpdateIndustryStatistics(i); |
|
1893 |
} |
|
1894 |
||
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1895 |
/* 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
|
1896 |
if (CHANCE16(3, 100)) { |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1897 |
MaybeNewIndustry(Random()); |
1269
0c8818a1c07a
(svn r1773) -Fix: [ 1114950 ] Game crashed sometimes when there were no industries
truelight
parents:
1267
diff
changeset
|
1898 |
} 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
|
1899 |
i = GetIndustry(RandomRange(_total_industries)); |
1270
a084b84eb971
(svn r1774) -Fix: fixed an other possible crash related to previous commit
truelight
parents:
1269
diff
changeset
|
1900 |
if (i->xy != 0) |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1901 |
ChangeIndustryProduction(i); |
0 | 1902 |
} |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1903 |
|
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1904 |
_current_player = old_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1905 |
|
0 | 1906 |
// production-change |
1907 |
_industry_sort_dirty = true; |
|
1908 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1909 |
} |
|
1910 |
||
1911 |
||
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
|
1912 |
void InitializeIndustries(void) |
0 | 1913 |
{ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1914 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1915 |
CleanPool(&_industry_pool); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1916 |
AddBlockToPool(&_industry_pool); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1917 |
|
0 | 1918 |
_total_industries = 0; |
1919 |
_industry_sort_dirty = true; |
|
1920 |
} |
|
1921 |
||
1922 |
const TileTypeProcs _tile_type_industry_procs = { |
|
1923 |
DrawTile_Industry, /* draw_tile_proc */ |
|
1924 |
GetSlopeZ_Industry, /* get_slope_z_proc */ |
|
1925 |
ClearTile_Industry, /* clear_tile_proc */ |
|
1926 |
GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
|
1927 |
GetTileDesc_Industry, /* get_tile_desc_proc */ |
|
1928 |
GetTileTrackStatus_Industry,/* get_tile_track_status_proc */ |
|
1929 |
ClickTile_Industry, /* click_tile_proc */ |
|
1930 |
AnimateTile_Industry, /* animate_tile_proc */ |
|
1931 |
TileLoop_Industry, /* tile_loop_proc */ |
|
1932 |
ChangeTileOwner_Industry, /* change_tile_owner_proc */ |
|
1933 |
GetProducedCargo_Industry, /* get_produced_cargo_proc */ |
|
1934 |
NULL, /* vehicle_enter_tile_proc */ |
|
1935 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1936 |
GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
0 | 1937 |
}; |
1938 |
||
1939 |
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
|
1940 |
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
|
1941 |
SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, 255), |
0 | 1942 |
SLE_VAR(Industry,width, SLE_UINT8), |
1943 |
SLE_VAR(Industry,height, SLE_UINT8), |
|
1944 |
SLE_REF(Industry,town, REF_TOWN), |
|
1945 |
SLE_ARR(Industry,produced_cargo, SLE_UINT8, 2), |
|
1946 |
SLE_ARR(Industry,cargo_waiting, SLE_UINT16, 2), |
|
1947 |
SLE_ARR(Industry,production_rate, SLE_UINT8, 2), |
|
1948 |
SLE_ARR(Industry,accepts_cargo, SLE_UINT8, 3), |
|
1949 |
SLE_VAR(Industry,prod_level, SLE_UINT8), |
|
1950 |
SLE_ARR(Industry,last_mo_production,SLE_UINT16, 2), |
|
1951 |
SLE_ARR(Industry,last_mo_transported,SLE_UINT16, 2), |
|
1952 |
SLE_ARR(Industry,pct_transported,SLE_UINT8, 2), |
|
1953 |
SLE_ARR(Industry,total_production,SLE_UINT16, 2), |
|
1954 |
SLE_ARR(Industry,total_transported,SLE_UINT16, 2), |
|
1955 |
||
1956 |
SLE_VAR(Industry,counter, SLE_UINT16), |
|
1957 |
||
1958 |
SLE_VAR(Industry,type, SLE_UINT8), |
|
1959 |
SLE_VAR(Industry,owner, SLE_UINT8), |
|
1960 |
SLE_VAR(Industry,color_map, SLE_UINT8), |
|
1961 |
SLE_VAR(Industry,last_prod_year, SLE_UINT8), |
|
1962 |
SLE_VAR(Industry,was_cargo_delivered,SLE_UINT8), |
|
1963 |
||
1964 |
// reserve extra space in savegame here. (currently 32 bytes) |
|
1965 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 4, 2, 255), |
|
1966 |
||
1967 |
SLE_END() |
|
1968 |
}; |
|
1969 |
||
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
|
1970 |
static void Save_INDY(void) |
0 | 1971 |
{ |
1972 |
Industry *ind; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1973 |
|
0 | 1974 |
// Write the vehicles |
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1975 |
FOR_ALL_INDUSTRIES(ind) { |
0 | 1976 |
if (ind->xy != 0) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1977 |
SlSetArrayIndex(ind->index); |
0 | 1978 |
SlObject(ind, _industry_desc); |
1979 |
} |
|
1980 |
} |
|
1981 |
} |
|
1982 |
||
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
|
1983 |
static void Load_INDY(void) |
0 | 1984 |
{ |
1985 |
int index; |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1986 |
|
0 | 1987 |
_total_industries = 0; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1988 |
|
0 | 1989 |
while ((index = SlIterateArray()) != -1) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1990 |
Industry *i; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1991 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1992 |
if (!AddBlockIfNeeded(&_industry_pool, index)) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1993 |
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
|
1994 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1995 |
i = GetIndustry(index); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1996 |
SlObject(i, _industry_desc); |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1997 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1998 |
if (index > _total_industries) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1999 |
_total_industries = index; |
0 | 2000 |
} |
2001 |
} |
|
2002 |
||
2003 |
const ChunkHandler _industry_chunk_handlers[] = { |
|
2004 |
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |
|
2005 |
}; |
|
2006 |