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