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