author | tron |
Fri, 24 Mar 2006 08:00:45 +0000 | |
changeset 3314 | 6aaeba4b92e8 |
parent 3296 | 34064bbe27a5 |
child 3320 | e9e284ab853a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3094
diff
changeset
|
5 |
#include "clear_map.h" |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
6 |
#include "industry_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
7 |
#include "table/strings.h" |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
8 |
#include "table/sprites.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
9 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
552
diff
changeset
|
10 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
11 |
#include "tile.h" |
0 | 12 |
#include "viewport.h" |
13 |
#include "command.h" |
|
14 |
#include "industry.h" |
|
15 |
#include "town.h" |
|
16 |
#include "vehicle.h" |
|
17 |
#include "news.h" |
|
18 |
#include "saveload.h" |
|
19 |
#include "economy.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
314
diff
changeset
|
20 |
#include "sound.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
21 |
#include "variables.h" |
0 | 22 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
23 |
enum { |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
24 |
/* Max industries: 64000 (8 * 8000) */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
25 |
INDUSTRY_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
26 |
INDUSTRY_POOL_MAX_BLOCKS = 8000, |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
27 |
}; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
28 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
29 |
/** |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
30 |
* Called if a new block is added to the industry-pool |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
31 |
*/ |
2817 | 32 |
static void IndustryPoolNewBlock(uint start_item) |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
33 |
{ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
34 |
Industry *i; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
35 |
|
2639 | 36 |
FOR_ALL_INDUSTRIES_FROM(i, start_item) i->index = start_item++; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
37 |
} |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
38 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
39 |
/* Initialize the industry-pool */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
40 |
MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, 0, 0, NULL }; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
41 |
|
2630 | 42 |
static byte _industry_sound_ctr; |
43 |
static TileIndex _industry_sound_tile; |
|
0 | 44 |
|
45 |
void ShowIndustryViewWindow(int industry); |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
46 |
void BuildOilRig(TileIndex tile); |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
47 |
void DeleteOilRig(TileIndex tile); |
0 | 48 |
|
49 |
typedef struct DrawIndustryTileStruct { |
|
50 |
uint32 sprite_1; |
|
51 |
uint32 sprite_2; |
|
52 |
||
2653
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
53 |
byte subtile_x:4; |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
54 |
byte subtile_y:4; |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
55 |
byte width:4; |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
56 |
byte height:4; |
0 | 57 |
byte dz; |
58 |
byte proc; |
|
59 |
} DrawIndustryTileStruct; |
|
60 |
||
61 |
||
62 |
typedef struct DrawIndustrySpec1Struct { |
|
63 |
byte x; |
|
64 |
byte image_1; |
|
65 |
byte image_2; |
|
66 |
byte image_3; |
|
67 |
} DrawIndustrySpec1Struct; |
|
68 |
||
69 |
typedef struct DrawIndustrySpec4Struct { |
|
70 |
byte image_1; |
|
71 |
byte image_2; |
|
72 |
byte image_3; |
|
73 |
} DrawIndustrySpec4Struct; |
|
74 |
||
75 |
typedef struct IndustryTileTable { |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
76 |
TileIndexDiffC ti; |
0 | 77 |
byte map5; |
78 |
} IndustryTileTable; |
|
79 |
||
80 |
typedef struct IndustrySpec { |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
81 |
const IndustryTileTable *const *table; |
0 | 82 |
byte num_table; |
83 |
byte a,b,c; |
|
84 |
byte produced_cargo[2]; |
|
85 |
byte production_rate[2]; |
|
86 |
byte accepts_cargo[3]; |
|
87 |
byte check_proc; |
|
88 |
} IndustrySpec; |
|
89 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
90 |
#include "table/industry_land.h" |
0 | 91 |
#include "table/build_industry.h" |
92 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
93 |
typedef enum IndustryType { |
3173
f56ca618721b
(svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents:
3157
diff
changeset
|
94 |
INDUSTRY_NOT_CLOSABLE, ///< Industry can never close |
f56ca618721b
(svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents:
3157
diff
changeset
|
95 |
INDUSTRY_PRODUCTION, ///< Industry can close and change of production |
f56ca618721b
(svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents:
3157
diff
changeset
|
96 |
INDUSTRY_CLOSABLE, ///< Industry can only close (no production change) |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
97 |
} IndustryType; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
98 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
99 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
100 |
static const IndustryType _industry_close_mode[37] = { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
101 |
/* COAL_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
102 |
/* POWER_STATION */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
103 |
/* SAWMILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
104 |
/* FOREST */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
105 |
/* OIL_REFINERY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
106 |
/* OIL_RIG */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
107 |
/* FACTORY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
108 |
/* PRINTING_WORKS */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
109 |
/* STEEL_MILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
110 |
/* FARM */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
111 |
/* COPPER_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
112 |
/* OIL_WELL */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
113 |
/* BANK */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
114 |
/* FOOD_PROCESS */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
115 |
/* PAPER_MILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
116 |
/* GOLD_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
117 |
/* BANK_2, */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
118 |
/* DIAMOND_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
119 |
/* IRON_MINE */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
120 |
/* FRUIT_PLANTATION */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
121 |
/* RUBBER_PLANTATION */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
122 |
/* WATER_SUPPLY */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
123 |
/* WATER_TOWER */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
124 |
/* FACTORY_2 */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
125 |
/* FARM_2 */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
126 |
/* LUMBER_MILL */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
127 |
/* COTTON_CANDY */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
128 |
/* CANDY_FACTORY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
129 |
/* BATTERY_FARM */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
130 |
/* COLA_WELLS */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
131 |
/* TOY_SHOP */ INDUSTRY_NOT_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
132 |
/* TOY_FACTORY */ INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
133 |
/* PLASTIC_FOUNTAINS */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
134 |
/* FIZZY_DRINK_FACTORY */INDUSTRY_CLOSABLE, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
135 |
/* BUBBLE_GENERATOR */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
136 |
/* TOFFEE_QUARRY */ INDUSTRY_PRODUCTION, |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
137 |
/* SUGAR_MINE */ INDUSTRY_PRODUCTION |
0 | 138 |
}; |
139 |
||
140 |
static const StringID _industry_prod_up_strings[] = { |
|
141 |
STR_4836_NEW_COAL_SEAM_FOUND_AT, |
|
142 |
STR_4835_INCREASES_PRODUCTION, |
|
143 |
STR_4835_INCREASES_PRODUCTION, |
|
144 |
STR_4835_INCREASES_PRODUCTION, |
|
145 |
STR_4835_INCREASES_PRODUCTION, |
|
146 |
STR_4837_NEW_OIL_RESERVES_FOUND, |
|
147 |
STR_4835_INCREASES_PRODUCTION, |
|
148 |
STR_4835_INCREASES_PRODUCTION, |
|
149 |
STR_4835_INCREASES_PRODUCTION, |
|
150 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
151 |
STR_4835_INCREASES_PRODUCTION, |
|
152 |
STR_4837_NEW_OIL_RESERVES_FOUND, |
|
153 |
STR_4835_INCREASES_PRODUCTION, |
|
154 |
STR_4835_INCREASES_PRODUCTION, |
|
155 |
STR_4835_INCREASES_PRODUCTION, |
|
156 |
STR_4835_INCREASES_PRODUCTION, |
|
157 |
STR_4835_INCREASES_PRODUCTION, |
|
158 |
STR_4835_INCREASES_PRODUCTION, |
|
159 |
STR_4835_INCREASES_PRODUCTION, |
|
160 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
161 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
162 |
STR_4835_INCREASES_PRODUCTION, |
|
163 |
STR_4835_INCREASES_PRODUCTION, |
|
164 |
STR_4835_INCREASES_PRODUCTION, |
|
165 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
166 |
STR_4835_INCREASES_PRODUCTION, |
|
167 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
168 |
STR_4835_INCREASES_PRODUCTION, |
|
169 |
STR_4838_IMPROVED_FARMING_METHODS, |
|
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 |
STR_4835_INCREASES_PRODUCTION, |
|
176 |
STR_4835_INCREASES_PRODUCTION, |
|
177 |
STR_4835_INCREASES_PRODUCTION, |
|
178 |
}; |
|
179 |
||
180 |
static const StringID _industry_prod_down_strings[] = { |
|
181 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
182 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
183 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
184 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
185 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
186 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
187 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
188 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
189 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
190 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
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_4839_PRODUCTION_DOWN_BY_50, |
|
198 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
199 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
200 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
201 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
202 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
203 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
204 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
205 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
206 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
207 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
208 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
209 |
STR_483A_INSECT_INFESTATION_CAUSES, |
|
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 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
216 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
217 |
STR_4839_PRODUCTION_DOWN_BY_50, |
|
218 |
}; |
|
219 |
||
220 |
static const StringID _industry_close_strings[] = { |
|
221 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
222 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
223 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
224 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
225 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
226 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
227 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
228 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
229 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
230 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
231 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
232 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
233 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
234 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
235 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
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_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
242 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
243 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
244 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
245 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
246 |
STR_4834_LACK_OF_NEARBY_TREES_CAUSES, |
|
247 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
248 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
249 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
250 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
251 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
252 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
253 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
254 |
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, |
|
255 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
256 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE, |
|
2639 | 257 |
STR_4832_ANNOUNCES_IMMINENT_CLOSURE |
0 | 258 |
}; |
259 |
||
260 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
261 |
static void IndustryDrawSugarMine(const TileInfo *ti) |
0 | 262 |
{ |
263 |
const DrawIndustrySpec1Struct *d; |
|
264 |
uint32 image; |
|
265 |
||
2639 | 266 |
if (!(_m[ti->tile].m1 & 0x80)) return; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
267 |
|
2049
538e73c53f54
(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
|
268 |
d = &_draw_industry_spec1[_m[ti->tile].m3]; |
0 | 269 |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
270 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, d->x, 0); |
0 | 271 |
|
2639 | 272 |
image = d->image_2; |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
273 |
if (image != 0) AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + image - 1, 8, 41); |
0 | 274 |
|
2639 | 275 |
image = d->image_3; |
276 |
if (image != 0) { |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
277 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + image - 1, |
2639 | 278 |
_drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]); |
279 |
} |
|
0 | 280 |
} |
281 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
282 |
static void IndustryDrawToffeeQuarry(const TileInfo *ti) |
0 | 283 |
{ |
284 |
int x = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
285 |
|
2360
4e4ebe18e448
(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
|
286 |
if (_m[ti->tile].m1 & 0x80) { |
2049
538e73c53f54
(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
|
287 |
x = _industry_anim_offs[_m[ti->tile].m3]; |
0 | 288 |
if ( (byte)x == 0xFF) |
289 |
x = 0; |
|
290 |
} |
|
291 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
292 |
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, 22 - x, 24 + x); |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
293 |
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, 6, 14); |
0 | 294 |
} |
295 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
296 |
static void IndustryDrawBubbleGenerator( const TileInfo *ti) |
0 | 297 |
{ |
2360
4e4ebe18e448
(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
|
298 |
if (_m[ti->tile].m1 & 0x80) { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
299 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, 5, _industry_anim_offs_2[_m[ti->tile].m3]); |
2639 | 300 |
} else { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
301 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, 3, 67); |
0 | 302 |
} |
303 |
} |
|
304 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
305 |
static void IndustryDrawToyFactory(const TileInfo *ti) |
0 | 306 |
{ |
307 |
const DrawIndustrySpec4Struct *d; |
|
308 |
||
2049
538e73c53f54
(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
|
309 |
d = &_industry_anim_offs_3[_m[ti->tile].m3]; |
0 | 310 |
|
311 |
if (d->image_1 != 0xFF) { |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
312 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, 50 - d->image_1 * 2, 96 + d->image_1); |
0 | 313 |
} |
314 |
||
315 |
if (d->image_2 != 0xFF) { |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
316 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, 16 - d->image_2 * 2, 100 + d->image_2); |
0 | 317 |
} |
318 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
319 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, 7, d->image_3); |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
320 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, 0, 42); |
0 | 321 |
} |
322 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
323 |
static void IndustryDrawCoalPlantSparks(const TileInfo *ti) |
0 | 324 |
{ |
2360
4e4ebe18e448
(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
|
325 |
int image = _m[ti->tile].m1; |
0 | 326 |
if (image & 0x80) { |
2140
a04d0142ad65
(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
|
327 |
image = GB(image, 2, 5); |
0 | 328 |
if (image != 0 && image < 7) { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
329 |
AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
330 |
_coal_plant_sparks_x[image - 1], |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
331 |
_coal_plant_sparks_y[image - 1] |
0 | 332 |
); |
333 |
} |
|
334 |
} |
|
335 |
} |
|
336 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2360
diff
changeset
|
337 |
typedef void IndustryDrawTileProc(const TileInfo *ti); |
0 | 338 |
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
339 |
IndustryDrawSugarMine, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
340 |
IndustryDrawToffeeQuarry, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
341 |
IndustryDrawBubbleGenerator, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
342 |
IndustryDrawToyFactory, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
343 |
IndustryDrawCoalPlantSparks, |
0 | 344 |
}; |
345 |
||
346 |
static void DrawTile_Industry(TileInfo *ti) |
|
347 |
{ |
|
2630 | 348 |
const Industry* ind; |
0 | 349 |
const DrawIndustryTileStruct *dits; |
350 |
byte z; |
|
351 |
uint32 image, ormod; |
|
352 |
||
353 |
/* Pointer to industry */ |
|
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
354 |
ind = GetIndustryByTile(ti->tile); |
2639 | 355 |
ormod = (ind->color_map + 0x307) << PALETTE_SPRITE_START; |
0 | 356 |
|
357 |
/* Retrieve pointer to the draw industry tile struct */ |
|
2493
f6b4300cc2b0
(svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents:
2492
diff
changeset
|
358 |
dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)]; |
0 | 359 |
|
360 |
image = dits->sprite_1; |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
361 |
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0) |
0 | 362 |
image |= ormod; |
363 |
||
364 |
z = ti->z; |
|
365 |
/* Add bricks below the industry? */ |
|
366 |
if (ti->tileh & 0xF) { |
|
2535 | 367 |
AddSortableSpriteToDraw(SPR_FOUNDATION_BASE + (ti->tileh & 0xF), ti->x, ti->y, 16, 16, 7, z); |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
368 |
AddChildSpriteScreen(image, 31, 1); |
0 | 369 |
z += 8; |
370 |
} else { |
|
371 |
/* Else draw regular ground */ |
|
372 |
DrawGroundSprite(image); |
|
373 |
} |
|
374 |
||
375 |
/* Add industry on top of the ground? */ |
|
2639 | 376 |
image = dits->sprite_2; |
377 |
if (image != 0) { |
|
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
378 |
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0) |
0 | 379 |
image |= ormod; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
380 |
|
2639 | 381 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
382 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
383 |
AddSortableSpriteToDraw(image, |
2653
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
384 |
ti->x + dits->subtile_x, |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
385 |
ti->y + dits->subtile_y, |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
386 |
dits->width + 1, |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
387 |
dits->height + 1, |
0 | 388 |
dits->dz, |
389 |
z); |
|
390 |
||
2639 | 391 |
if (_display_opt & DO_TRANS_BUILDINGS) return; |
0 | 392 |
} |
393 |
||
2639 | 394 |
{ |
395 |
int proc = dits->proc - 1; |
|
396 |
if (proc >= 0) _industry_draw_tile_procs[proc](ti); |
|
0 | 397 |
} |
398 |
} |
|
399 |
||
400 |
||
2537 | 401 |
static uint GetSlopeZ_Industry(const TileInfo* ti) |
402 |
{ |
|
3282
d026008a8f7c
(svn r3996) -Fix: Slope and height information returned for some tile types is wrong
tron
parents:
3222
diff
changeset
|
403 |
return ti->z + (ti->tileh == 0 ? 0 : 8); |
0 | 404 |
} |
405 |
||
2548
49c8a096033f
(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) |
49c8a096033f
(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
37bbebf94434
(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
538e73c53f54
(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
d69238b81415
(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
d69238b81415
(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
d69238b81415
(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
d69238b81415
(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
37bbebf94434
(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 |
{ |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
428 |
const Industry* i = GetIndustryByTile(tile); |
0 | 429 |
|
430 |
td->owner = i->owner; |
|
431 |
td->str = STR_4802_COAL_MINE + i->type; |
|
2360
4e4ebe18e448
(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
306bc86eb23e
(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
37bbebf94434
(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 |
{ |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
440 |
Industry* i = GetIndustryByTile(tile); |
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
306bc86eb23e
(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 |
||
2639 | 454 |
if (flags & DC_EXEC) DeleteIndustry(i); |
0 | 455 |
return 0; |
456 |
} |
|
457 |
||
458 |
||
459 |
static const byte _industry_min_cargo[] = { |
|
460 |
5, 5, 5, 30, 5, 5, 5, 5, |
|
461 |
5, 5, 5, 5, 2, 5, 5, 5, |
|
462 |
5, 5, 5, 15, 15, 5, 5, 5, |
|
463 |
5, 5, 30, 5, 30, 5, 5, 5, |
|
464 |
5, 5, 5, 5, 5, |
|
465 |
}; |
|
466 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
467 |
static void TransportIndustryGoods(TileIndex tile) |
0 | 468 |
{ |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
469 |
Industry* i = GetIndustryByTile(tile); |
0 | 470 |
uint cw, am; |
471 |
||
2639 | 472 |
cw = min(i->cargo_waiting[0], 255); |
473 |
if (cw > _industry_min_cargo[i->type]/* && i->produced_cargo[0] != 0xFF*/) { |
|
474 |
byte m5; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
475 |
|
0 | 476 |
i->cargo_waiting[0] -= cw; |
477 |
||
478 |
/* fluctuating economy? */ |
|
2639 | 479 |
if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
0 | 480 |
|
481 |
i->last_mo_production[0] += cw; |
|
482 |
||
483 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw); |
|
484 |
i->last_mo_transported[0] += am; |
|
2049
538e73c53f54
(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
|
485 |
if (am != 0 && (m5 = _industry_produce_map5[_m[tile].m5]) != 0xFF) { |
2360
4e4ebe18e448
(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
|
486 |
_m[tile].m1 = 0x80; |
2049
538e73c53f54
(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
|
487 |
_m[tile].m5 = m5; |
0 | 488 |
MarkTileDirtyByTile(tile); |
489 |
} |
|
490 |
} |
|
491 |
||
492 |
cw = min(i->cargo_waiting[1], 255); |
|
2639 | 493 |
if (cw > _industry_min_cargo[i->type]) { |
0 | 494 |
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
|
495 |
|
2639 | 496 |
if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
497 |
|
0 | 498 |
i->last_mo_production[1] += cw; |
499 |
||
500 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw); |
|
501 |
i->last_mo_transported[1] += am; |
|
502 |
} |
|
503 |
} |
|
504 |
||
505 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
506 |
static void AnimateTile_Industry(TileIndex tile) |
0 | 507 |
{ |
508 |
byte m,n; |
|
509 |
||
2952 | 510 |
switch (_m[tile].m5) { |
0 | 511 |
case 174: |
512 |
if ((_tick_counter & 1) == 0) { |
|
2049
538e73c53f54
(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
|
513 |
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
|
514 |
|
2952 | 515 |
switch (m & 7) { |
541 | 516 |
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; |
517 |
case 6: SndPlayTileFx(SND_29_RIP, tile); break; |
|
0 | 518 |
} |
519 |
||
520 |
if (m >= 96) { |
|
521 |
m = 0; |
|
522 |
DeleteAnimatedTile(tile); |
|
523 |
} |
|
2049
538e73c53f54
(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
|
524 |
_m[tile].m3 = m; |
0 | 525 |
|
526 |
MarkTileDirtyByTile(tile); |
|
527 |
} |
|
528 |
break; |
|
529 |
||
530 |
case 165: |
|
531 |
if ((_tick_counter & 3) == 0) { |
|
2049
538e73c53f54
(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
|
532 |
m = _m[tile].m3; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
533 |
|
0 | 534 |
if (_industry_anim_offs[m] == 0xFF) { |
541 | 535 |
SndPlayTileFx(SND_30_CARTOON_SOUND, tile); |
0 | 536 |
} |
537 |
||
538 |
if (++m >= 70) { |
|
539 |
m = 0; |
|
540 |
DeleteAnimatedTile(tile); |
|
541 |
} |
|
2049
538e73c53f54
(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
|
542 |
_m[tile].m3 = m; |
0 | 543 |
|
544 |
MarkTileDirtyByTile(tile); |
|
545 |
} |
|
546 |
break; |
|
547 |
||
548 |
case 162: |
|
549 |
if ((_tick_counter&1) == 0) { |
|
2049
538e73c53f54
(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
|
550 |
m = _m[tile].m3; |
0 | 551 |
|
552 |
if (++m >= 40) { |
|
553 |
m = 0; |
|
554 |
DeleteAnimatedTile(tile); |
|
555 |
} |
|
2049
538e73c53f54
(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[tile].m3 = m; |
0 | 557 |
|
558 |
MarkTileDirtyByTile(tile); |
|
559 |
} |
|
560 |
break; |
|
561 |
||
562 |
// Sparks on a coal plant |
|
563 |
case 10: |
|
564 |
if ((_tick_counter & 3) == 0) { |
|
2360
4e4ebe18e448
(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
|
565 |
m = _m[tile].m1; |
2663 | 566 |
if (GB(m, 2, 5) == 6) { |
567 |
SB(_m[tile].m1, 2, 5, 0); |
|
0 | 568 |
DeleteAnimatedTile(tile); |
569 |
} else { |
|
2360
4e4ebe18e448
(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
|
570 |
_m[tile].m1 = m + (1<<2); |
0 | 571 |
MarkTileDirtyByTile(tile); |
572 |
} |
|
573 |
} |
|
574 |
break; |
|
575 |
||
576 |
case 143: |
|
577 |
if ((_tick_counter & 1) == 0) { |
|
2049
538e73c53f54
(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
|
578 |
m = _m[tile].m3 + 1; |
0 | 579 |
|
580 |
if (m == 1) { |
|
541 | 581 |
SndPlayTileFx(SND_2C_MACHINERY, tile); |
0 | 582 |
} else if (m == 23) { |
541 | 583 |
SndPlayTileFx(SND_2B_COMEDY_HIT, tile); |
0 | 584 |
} else if (m == 28) { |
541 | 585 |
SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); |
0 | 586 |
} |
587 |
||
2049
538e73c53f54
(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
|
588 |
if (m >= 50 && (m=0,++_m[tile].m4 >= 8)) { |
538e73c53f54
(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
|
589 |
_m[tile].m4 = 0; |
0 | 590 |
DeleteAnimatedTile(tile); |
591 |
} |
|
2049
538e73c53f54
(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
|
592 |
_m[tile].m3 = m; |
0 | 593 |
MarkTileDirtyByTile(tile); |
594 |
} |
|
595 |
break; |
|
596 |
||
597 |
case 148: case 149: case 150: case 151: |
|
598 |
case 152: case 153: case 154: case 155: |
|
599 |
if ((_tick_counter & 3) == 0) { |
|
2049
538e73c53f54
(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
|
600 |
m = _m[tile].m5 + 1; |
0 | 601 |
if (m == 155+1) m = 148; |
2049
538e73c53f54
(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
|
602 |
_m[tile].m5 = m; |
0 | 603 |
|
604 |
MarkTileDirtyByTile(tile); |
|
605 |
} |
|
606 |
break; |
|
607 |
||
608 |
case 30: case 31: case 32: |
|
609 |
if ((_tick_counter & 7) == 0) { |
|
610 |
bool b = CHANCE16(1,7); |
|
2360
4e4ebe18e448
(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
|
611 |
m = _m[tile].m1; |
0 | 612 |
m = (m & 3) + 1; |
2049
538e73c53f54
(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
|
613 |
n = _m[tile].m5; |
0 | 614 |
if (m == 4 && (m=0,++n) == 32+1 && (n=30,b)) { |
2360
4e4ebe18e448
(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
|
615 |
_m[tile].m1 = 0x83; |
2049
538e73c53f54
(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
|
616 |
_m[tile].m5 = 29; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
617 |
DeleteAnimatedTile(tile); |
0 | 618 |
} else { |
2663 | 619 |
SB(_m[tile].m1, 0, 2, m); |
2049
538e73c53f54
(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
|
620 |
_m[tile].m5 = n; |
0 | 621 |
MarkTileDirtyByTile(tile); |
622 |
} |
|
623 |
} |
|
624 |
break; |
|
625 |
||
626 |
case 88: |
|
627 |
case 48: |
|
628 |
case 1: { |
|
629 |
int state = _tick_counter & 0x7FF; |
|
630 |
||
631 |
if ((state -= 0x400) < 0) |
|
632 |
return; |
|
633 |
||
634 |
if (state < 0x1A0) { |
|
635 |
if (state < 0x20 || state >= 0x180) { |
|
2360
4e4ebe18e448
(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
|
636 |
if (!(_m[tile].m1 & 0x40)) { |
4e4ebe18e448
(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
|
637 |
_m[tile].m1 |= 0x40; |
541 | 638 |
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); |
0 | 639 |
} |
640 |
if (state & 7) |
|
641 |
return; |
|
642 |
} else { |
|
643 |
if (state & 3) |
|
644 |
return; |
|
645 |
} |
|
2360
4e4ebe18e448
(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
|
646 |
m = (_m[tile].m1 + 1) | 0x40; |
0 | 647 |
if (m > 0xC2) m = 0xC0; |
2360
4e4ebe18e448
(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
|
648 |
_m[tile].m1 = m; |
0 | 649 |
MarkTileDirtyByTile(tile); |
650 |
} else if (state >= 0x200 && state < 0x3A0) { |
|
651 |
int i; |
|
652 |
i = (state < 0x220 || state >= 0x380) ? 7 : 3; |
|
653 |
if (state & i) |
|
654 |
return; |
|
655 |
||
2360
4e4ebe18e448
(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
|
656 |
m = (_m[tile].m1 & 0xBF) - 1; |
0 | 657 |
if (m < 0x80) m = 0x82; |
2360
4e4ebe18e448
(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
|
658 |
_m[tile].m1 = m; |
0 | 659 |
MarkTileDirtyByTile(tile); |
660 |
} |
|
661 |
} break; |
|
662 |
} |
|
663 |
} |
|
664 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
665 |
static void CreateIndustryEffectSmoke(TileIndex tile) |
0 | 666 |
{ |
3094 | 667 |
uint tileh; |
668 |
uint x; |
|
669 |
uint y; |
|
670 |
uint z; |
|
671 |
||
672 |
tileh = GetTileSlope(tile, &z); |
|
673 |
x = TileX(tile) * TILE_SIZE; |
|
674 |
y = TileY(tile) * TILE_SIZE; |
|
675 |
CreateEffectVehicle(x + 15, y + 14, z + 59 + (tileh != 0 ? 8 : 0), EV_CHIMNEY_SMOKE); |
|
0 | 676 |
} |
677 |
||
1977
37bbebf94434
(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
4e4ebe18e448
(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
4e4ebe18e448
(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
4e4ebe18e448
(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 |
||
2952 | 696 |
switch (_m[tile].m5) { |
0 | 697 |
case 8: |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
698 |
CreateIndustryEffectSmoke(tile); |
0 | 699 |
break; |
700 |
||
701 |
case 24: |
|
2049
538e73c53f54
(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
538e73c53f54
(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; |
538e73c53f54
(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 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
720 |
static void TileLoopIndustry_BubbleGenerator(TileIndex tile) |
0 | 721 |
{ |
722 |
int dir; |
|
723 |
Vehicle *v; |
|
724 |
static const int8 _tileloop_ind_case_161[12] = { |
|
725 |
11, 0, -4, -14, |
|
726 |
-4, -10, -4, 1, |
|
727 |
49, 59, 60, 65, |
|
728 |
}; |
|
729 |
||
541 | 730 |
SndPlayTileFx(SND_2E_EXTRACT_AND_POP, tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
731 |
|
0 | 732 |
dir = Random() & 3; |
733 |
||
734 |
v = CreateEffectVehicleAbove( |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
735 |
TileX(tile) * 16 + _tileloop_ind_case_161[dir + 0], |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
736 |
TileY(tile) * 16 + _tileloop_ind_case_161[dir + 4], |
0 | 737 |
_tileloop_ind_case_161[dir + 8], |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1335
diff
changeset
|
738 |
EV_BUBBLE |
0 | 739 |
); |
740 |
||
2639 | 741 |
if (v != NULL) v->u.special.unk2 = dir; |
0 | 742 |
} |
743 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
744 |
static void TileLoop_Industry(TileIndex tile) |
0 | 745 |
{ |
746 |
byte n; |
|
747 |
||
2360
4e4ebe18e448
(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
|
748 |
if (!(_m[tile].m1 & 0x80)) { |
4e4ebe18e448
(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
|
749 |
MakeIndustryTileBigger(tile, _m[tile].m1); |
0 | 750 |
return; |
751 |
} |
|
752 |
||
2639 | 753 |
if (_game_mode == GM_EDITOR) return; |
0 | 754 |
|
755 |
TransportIndustryGoods(tile); |
|
756 |
||
2049
538e73c53f54
(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
|
757 |
n = _industry_map5_animation_next[_m[tile].m5]; |
0 | 758 |
if (n != 255) { |
2360
4e4ebe18e448
(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
|
759 |
_m[tile].m1 = 0; |
2049
538e73c53f54
(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 |
_m[tile].m5 = n; |
0 | 761 |
MarkTileDirtyByTile(tile); |
762 |
return; |
|
763 |
} |
|
764 |
||
2360
4e4ebe18e448
(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
|
765 |
#define SET_AND_ANIMATE(tile, a, b) { _m[tile].m5 = a; _m[tile].m1 = b; AddAnimatedTile(tile); } |
4e4ebe18e448
(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
|
766 |
#define SET_AND_UNANIMATE(tile, a, b) { _m[tile].m5 = a; _m[tile].m1 = b; DeleteAnimatedTile(tile); } |
0 | 767 |
|
2639 | 768 |
switch (_m[tile].m5) { |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
769 |
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
|
770 |
case 0x19: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
771 |
case 0x1A: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
772 |
case 0x1B: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
773 |
case 0x1C: |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
774 |
TileLoop_Water(tile); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
775 |
break; |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
776 |
|
0 | 777 |
case 0: |
778 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
779 |
SET_AND_ANIMATE(tile,1,0x80); |
|
780 |
break; |
|
781 |
||
782 |
case 47: |
|
783 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
784 |
SET_AND_ANIMATE(tile,0x30,0x80); |
|
785 |
break; |
|
786 |
||
787 |
case 79: |
|
788 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
|
789 |
SET_AND_ANIMATE(tile,0x58,0x80); |
|
790 |
break; |
|
791 |
||
792 |
case 29: |
|
793 |
if (CHANCE16(1,6)) |
|
794 |
SET_AND_ANIMATE(tile,0x1E,0x80); |
|
795 |
break; |
|
796 |
||
797 |
case 1: |
|
798 |
if (!(_tick_counter & 0x400)) |
|
799 |
SET_AND_UNANIMATE(tile, 0, 0x83); |
|
800 |
break; |
|
801 |
||
802 |
case 48: |
|
803 |
if (!(_tick_counter & 0x400)) |
|
804 |
SET_AND_UNANIMATE(tile, 0x2F, 0x83); |
|
805 |
break; |
|
806 |
||
807 |
case 88: |
|
808 |
if (!(_tick_counter & 0x400)) |
|
809 |
SET_AND_UNANIMATE(tile, 0x4F, 0x83); |
|
810 |
break; |
|
811 |
||
812 |
case 10: |
|
813 |
if (CHANCE16(1,3)) { |
|
541 | 814 |
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile); |
0 | 815 |
AddAnimatedTile(tile); |
816 |
} |
|
817 |
break; |
|
818 |
||
2639 | 819 |
case 49: |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1335
diff
changeset
|
820 |
CreateEffectVehicleAbove(TileX(tile) * 16 + 6, TileY(tile) * 16 + 6, 43, EV_SMOKE); |
2639 | 821 |
break; |
0 | 822 |
|
823 |
||
824 |
case 143: { |
|
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
825 |
Industry* i = GetIndustryByTile(tile); |
0 | 826 |
if (i->was_cargo_delivered) { |
827 |
i->was_cargo_delivered = false; |
|
2061
f5bdffb68ae8
(svn r2570) Fix: Removed some code that had no effect.
ludde
parents:
2051
diff
changeset
|
828 |
_m[tile].m4 = 0; |
0 | 829 |
AddAnimatedTile(tile); |
830 |
} |
|
831 |
} |
|
832 |
break; |
|
833 |
||
834 |
case 161: |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
835 |
TileLoopIndustry_BubbleGenerator(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
836 |
break; |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
837 |
|
0 | 838 |
case 165: |
839 |
AddAnimatedTile(tile); |
|
840 |
break; |
|
841 |
||
842 |
case 174: |
|
2639 | 843 |
if (CHANCE16(1, 3)) AddAnimatedTile(tile); |
0 | 844 |
break; |
845 |
} |
|
846 |
} |
|
847 |
||
848 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
849 |
static void ClickTile_Industry(TileIndex tile) |
0 | 850 |
{ |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
851 |
ShowIndustryViewWindow(GetIndustryIndex(tile)); |
0 | 852 |
} |
853 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
854 |
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode) |
0 | 855 |
{ |
856 |
return 0; |
|
857 |
} |
|
858 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
859 |
static void GetProducedCargo_Industry(TileIndex tile, byte *b) |
0 | 860 |
{ |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
861 |
const Industry* i = GetIndustryByTile(tile); |
2630 | 862 |
|
0 | 863 |
b[0] = i->produced_cargo[0]; |
864 |
b[1] = i->produced_cargo[1]; |
|
865 |
} |
|
866 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2360
diff
changeset
|
867 |
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 868 |
{ |
869 |
/* not used */ |
|
870 |
} |
|
871 |
||
872 |
void DeleteIndustry(Industry *i) |
|
873 |
{ |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
874 |
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
875 |
if (IsTileType(tile_cur, MP_INDUSTRY)) { |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
876 |
if (GetIndustryIndex(tile_cur) == i->index) { |
0 | 877 |
DoClearSquare(tile_cur); |
878 |
} |
|
2049
538e73c53f54
(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
|
879 |
} else if (IsTileType(tile_cur, MP_STATION) && _m[tile_cur].m5 == 0x4B) { |
0 | 880 |
DeleteOilRig(tile_cur); |
881 |
} |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
882 |
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
883 |
|
0 | 884 |
i->xy = 0; |
885 |
_industry_sort_dirty = true; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
886 |
DeleteSubsidyWithIndustry(i->index); |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
887 |
DeleteWindowById(WC_INDUSTRY_VIEW, i->index); |
0 | 888 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
889 |
} |
|
890 |
||
891 |
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; |
|
892 |
||
1048 | 893 |
static bool IsBadFarmFieldTile(TileIndex tile) |
0 | 894 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
895 |
switch (GetTileType(tile)) { |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
896 |
case MP_CLEAR: return IsClearGround(tile, CL_FIELDS) || IsClearGround(tile, CL_SNOW); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
897 |
case MP_TREES: return false; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
898 |
default: return true; |
0 | 899 |
} |
900 |
} |
|
901 |
||
1048 | 902 |
static bool IsBadFarmFieldTile2(TileIndex tile) |
0 | 903 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
904 |
switch (GetTileType(tile)) { |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
905 |
case MP_CLEAR: return IsClearGround(tile, CL_SNOW); |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
906 |
case MP_TREES: return false; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
907 |
default: return true; |
0 | 908 |
} |
909 |
} |
|
910 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
911 |
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direction) |
0 | 912 |
{ |
913 |
do { |
|
914 |
tile = TILE_MASK(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
915 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
916 |
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
917 |
byte or = type; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
918 |
|
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
919 |
if (or == 1 && CHANCE16(1, 7)) or = 2; |
0 | 920 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
921 |
if (direction == AXIS_X) { |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
922 |
SetFenceSE(tile, or); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
923 |
} else { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
924 |
SetFenceSW(tile, or); |
0 | 925 |
} |
926 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
927 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
928 |
tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 929 |
} while (--size); |
930 |
} |
|
931 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
932 |
static void PlantFarmField(TileIndex tile) |
0 | 933 |
{ |
934 |
uint size_x, size_y; |
|
935 |
uint32 r; |
|
2133 | 936 |
uint count; |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
937 |
uint counter; |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
938 |
uint field_type; |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
939 |
int type; |
0 | 940 |
|
941 |
if (_opt.landscape == LT_HILLY) { |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1320
diff
changeset
|
942 |
if (GetTileZ(tile) + 16 >= _opt.snow_line) |
0 | 943 |
return; |
944 |
} |
|
945 |
||
946 |
/* determine field size */ |
|
947 |
r = (Random() & 0x303) + 0x404; |
|
948 |
if (_opt.landscape == LT_HILLY) r += 0x404; |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
949 |
size_x = GB(r, 0, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
950 |
size_y = GB(r, 8, 8); |
0 | 951 |
|
952 |
/* offset tile to match size */ |
|
1981 | 953 |
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
|
954 |
|
0 | 955 |
/* check the amount of bad tiles */ |
956 |
count = 0; |
|
957 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
958 |
cur_tile = TILE_MASK(cur_tile); |
|
959 |
count += IsBadFarmFieldTile(cur_tile); |
|
960 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
2133 | 961 |
if (count * 2 >= size_x * size_y) return; |
0 | 962 |
|
963 |
/* determine type of field */ |
|
964 |
r = Random(); |
|
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
965 |
counter = GB(r, 5, 3); |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
966 |
field_type = GB(r, 8, 8) * 9 >> 8; |
0 | 967 |
|
968 |
/* make field */ |
|
969 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
970 |
cur_tile = TILE_MASK(cur_tile); |
|
971 |
if (!IsBadFarmFieldTile2(cur_tile)) { |
|
3291 | 972 |
MakeField(cur_tile, field_type); |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
973 |
SetClearCounter(cur_tile, counter); |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
974 |
MarkTileDirtyByTile(cur_tile); |
0 | 975 |
} |
976 |
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
|
977 |
|
0 | 978 |
type = 3; |
979 |
if (_opt.landscape != LT_HILLY && _opt.landscape != LT_DESERT) { |
|
980 |
type = _plantfarmfield_type[Random() & 0xF]; |
|
981 |
} |
|
982 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
983 |
SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
984 |
SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
985 |
SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
986 |
SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X); |
0 | 987 |
} |
988 |
||
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
989 |
static void MaybePlantFarmField(const Industry* i) |
0 | 990 |
{ |
2549 | 991 |
if (CHANCE16(1, 8)) { |
992 |
int x = i->width / 2 + Random() % 31 - 16; |
|
993 |
int y = i->height / 2 + Random() % 31 - 16; |
|
994 |
TileIndex tile = TileAddWrap(i->xy, x, y); |
|
995 |
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
|
996 |
} |
0 | 997 |
} |
998 |
||
999 |
static void ChopLumberMillTrees(Industry *i) |
|
1000 |
{ |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1001 |
static const TileIndexDiffC _chop_dir[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1002 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1003 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1004 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1005 |
{-1, 0} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1006 |
}; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1007 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1008 |
TileIndex tile = i->xy; |
2639 | 1009 |
int a; |
0 | 1010 |
|
2639 | 1011 |
if ((_m[tile].m1 & 0x80) == 0) return; |
0 | 1012 |
|
1013 |
/* search outwards as a rectangular spiral */ |
|
2639 | 1014 |
for (a = 1; a != 41; a += 2) { |
1015 |
uint dir; |
|
1016 |
||
1017 |
for (dir = 0; dir != 4; dir++) { |
|
1018 |
int j = a; |
|
1019 |
||
0 | 1020 |
do { |
1021 |
tile = TILE_MASK(tile); |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
1022 |
if (IsTileType(tile, MP_TREES)) { |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1023 |
PlayerID old_player = _current_player; |
0 | 1024 |
/* found a tree */ |
1025 |
||
1026 |
_current_player = OWNER_NONE; |
|
1027 |
_industry_sound_ctr = 1; |
|
1028 |
_industry_sound_tile = tile; |
|
541 | 1029 |
SndPlayTileFx(SND_38_CHAINSAW, tile); |
0 | 1030 |
|
1031 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1032 |
SetMapExtraBits(tile, 0); |
|
1033 |
||
1034 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45); |
|
314 | 1035 |
|
1036 |
_current_player = old_player; |
|
0 | 1037 |
return; |
1038 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1039 |
tile += ToTileIndexDiff(_chop_dir[dir]); |
0 | 1040 |
} while (--j); |
1041 |
} |
|
1981 | 1042 |
tile -= TileDiffXY(1, 1); |
0 | 1043 |
} |
1044 |
} |
|
1045 |
||
1046 |
static const byte _industry_sounds[37][2] = { |
|
1047 |
{0}, |
|
1048 |
{0}, |
|
541 | 1049 |
{1, SND_28_SAWMILL}, |
0 | 1050 |
{0}, |
1051 |
{0}, |
|
1052 |
{0}, |
|
541 | 1053 |
{1, SND_03_FACTORY_WHISTLE}, |
1054 |
{1, SND_03_FACTORY_WHISTLE}, |
|
0 | 1055 |
{0}, |
541 | 1056 |
{3, SND_24_SHEEP}, |
0 | 1057 |
{0}, |
1058 |
{0}, |
|
1059 |
{0}, |
|
1060 |
{0}, |
|
541 | 1061 |
{1, SND_28_SAWMILL}, |
0 | 1062 |
{0}, |
1063 |
{0}, |
|
1064 |
{0}, |
|
1065 |
{0}, |
|
1066 |
{0}, |
|
1067 |
{0}, |
|
1068 |
{0}, |
|
1069 |
{0}, |
|
541 | 1070 |
{1, SND_03_FACTORY_WHISTLE}, |
0 | 1071 |
{0}, |
1072 |
{0}, |
|
1073 |
{0}, |
|
1074 |
{0}, |
|
1075 |
{0}, |
|
1076 |
{0}, |
|
1077 |
{0}, |
|
1078 |
{0}, |
|
541 | 1079 |
{1, SND_33_PLASTIC_MINE}, |
0 | 1080 |
{0}, |
1081 |
{0}, |
|
1082 |
{0}, |
|
1083 |
{0}, |
|
1084 |
}; |
|
1085 |
||
1086 |
||
1087 |
static void ProduceIndustryGoods(Industry *i) |
|
1088 |
{ |
|
1089 |
uint32 r; |
|
1090 |
uint num; |
|
1091 |
||
1092 |
/* play a sound? */ |
|
1093 |
if ((i->counter & 0x3F) == 0) { |
|
1094 |
if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) { |
|
1095 |
SndPlayTileFx( |
|
1096 |
_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16), |
|
1097 |
i->xy); |
|
1098 |
} |
|
1099 |
} |
|
1100 |
||
1101 |
i->counter--; |
|
1102 |
||
1103 |
/* produce some cargo */ |
|
1104 |
if ((i->counter & 0xFF) == 0) { |
|
1105 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]); |
|
1106 |
i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]); |
|
1107 |
||
2639 | 1108 |
if (i->type == IT_FARM) { |
0 | 1109 |
MaybePlantFarmField(i); |
2639 | 1110 |
} else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) { |
0 | 1111 |
ChopLumberMillTrees(i); |
2639 | 1112 |
} |
0 | 1113 |
} |
1114 |
} |
|
1115 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1116 |
void OnTick_Industry(void) |
0 | 1117 |
{ |
1118 |
Industry *i; |
|
1119 |
||
1120 |
if (_industry_sound_ctr != 0) { |
|
1121 |
_industry_sound_ctr++; |
|
1122 |
||
1123 |
if (_industry_sound_ctr == 75) { |
|
541 | 1124 |
SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile); |
0 | 1125 |
} 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
|
1126 |
_industry_sound_ctr = 0; |
541 | 1127 |
SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile); |
0 | 1128 |
} |
1129 |
} |
|
1130 |
||
2639 | 1131 |
if (_game_mode == GM_EDITOR) return; |
0 | 1132 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1133 |
FOR_ALL_INDUSTRIES(i) { |
2639 | 1134 |
if (i->xy != 0) ProduceIndustryGoods(i); |
0 | 1135 |
} |
1136 |
} |
|
1137 |
||
1138 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1139 |
static bool CheckNewIndustry_NULL(TileIndex tile, int type) |
0 | 1140 |
{ |
1141 |
return true; |
|
1142 |
} |
|
1143 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1144 |
static bool CheckNewIndustry_Forest(TileIndex tile, int type) |
0 | 1145 |
{ |
1146 |
if (_opt.landscape == LT_HILLY) { |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1320
diff
changeset
|
1147 |
if (GetTileZ(tile) < _opt.snow_line + 16U) { |
0 | 1148 |
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED; |
1149 |
return false; |
|
1150 |
} |
|
1151 |
} |
|
1152 |
return true; |
|
1153 |
} |
|
1154 |
||
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1155 |
extern bool _ignore_restrictions; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1156 |
|
1586
d179623e13c9
(svn r2090) CheckNewIndustry_Oilwell() -> CheckNewIndustry_Oil() since it was concerning oil rigs and oil rafineries, but specifically NOT oil wells. ;-) Documented that.
pasky
parents:
1373
diff
changeset
|
1157 |
/* Oil Rig and Oil Refinery */ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1158 |
static bool CheckNewIndustry_Oil(TileIndex tile, int type) |
0 | 1159 |
{ |
2639 | 1160 |
if (_game_mode == GM_EDITOR && _ignore_restrictions) return true; |
1161 |
if (_game_mode == GM_EDITOR && type != IT_OIL_RIG) return true; |
|
2868
9678db2d90e8
(svn r3416) - Fix: Disallow building an oil rig above sea level.
peter1138
parents:
2817
diff
changeset
|
1162 |
if ((type != IT_OIL_RIG || TileHeight(tile) == 0) && |
9678db2d90e8
(svn r3416) - Fix: Disallow building an oil rig above sea level.
peter1138
parents:
2817
diff
changeset
|
1163 |
DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < 16) return true; |
0 | 1164 |
|
1165 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
|
1166 |
return false; |
|
1167 |
} |
|
1168 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1169 |
static bool CheckNewIndustry_Farm(TileIndex tile, int type) |
0 | 1170 |
{ |
1171 |
if (_opt.landscape == LT_HILLY) { |
|
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1320
diff
changeset
|
1172 |
if (GetTileZ(tile) + 16 >= _opt.snow_line) { |
0 | 1173 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1174 |
return false; |
|
1175 |
} |
|
1176 |
} |
|
1177 |
return true; |
|
1178 |
} |
|
1179 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1180 |
static bool CheckNewIndustry_Plantation(TileIndex tile, int type) |
0 | 1181 |
{ |
1182 |
if (GetMapExtraBits(tile) == 1) { |
|
1183 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1184 |
return false; |
|
1185 |
} |
|
1186 |
||
1187 |
return true; |
|
1188 |
} |
|
1189 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1190 |
static bool CheckNewIndustry_Water(TileIndex tile, int type) |
0 | 1191 |
{ |
1192 |
if (GetMapExtraBits(tile) != 1) { |
|
1193 |
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; |
|
1194 |
return false; |
|
1195 |
} |
|
1196 |
||
1197 |
return true; |
|
1198 |
} |
|
1199 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1200 |
static bool CheckNewIndustry_Lumbermill(TileIndex tile, int type) |
0 | 1201 |
{ |
1202 |
if (GetMapExtraBits(tile) != 2) { |
|
1203 |
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; |
|
1204 |
return false; |
|
1205 |
} |
|
1206 |
return true; |
|
1207 |
} |
|
1208 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1209 |
static bool CheckNewIndustry_BubbleGen(TileIndex tile, int type) |
0 | 1210 |
{ |
2549 | 1211 |
return GetTileZ(tile) <= 32; |
0 | 1212 |
} |
1213 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1214 |
typedef bool CheckNewIndustryProc(TileIndex tile, int type); |
0 | 1215 |
static CheckNewIndustryProc * const _check_new_industry_procs[] = { |
1216 |
CheckNewIndustry_NULL, |
|
1217 |
CheckNewIndustry_Forest, |
|
1586
d179623e13c9
(svn r2090) CheckNewIndustry_Oilwell() -> CheckNewIndustry_Oil() since it was concerning oil rigs and oil rafineries, but specifically NOT oil wells. ;-) Documented that.
pasky
parents:
1373
diff
changeset
|
1218 |
CheckNewIndustry_Oil, |
0 | 1219 |
CheckNewIndustry_Farm, |
1220 |
CheckNewIndustry_Plantation, |
|
1221 |
CheckNewIndustry_Water, |
|
1222 |
CheckNewIndustry_Lumbermill, |
|
1223 |
CheckNewIndustry_BubbleGen, |
|
1224 |
}; |
|
1225 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1226 |
static bool CheckSuitableIndustryPos(TileIndex tile) |
0 | 1227 |
{ |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1228 |
uint x = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1229 |
uint y = TileY(tile); |
0 | 1230 |
|
2639 | 1231 |
if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { |
0 | 1232 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1233 |
return false; |
|
1234 |
} |
|
1235 |
||
1236 |
return true; |
|
1237 |
} |
|
1238 |
||
2630 | 1239 |
static const Town* CheckMultipleIndustryInTown(TileIndex tile, int type) |
0 | 1240 |
{ |
2630 | 1241 |
const Town* t; |
1242 |
const Industry* i; |
|
0 | 1243 |
|
1244 |
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
|
1245 |
|
2639 | 1246 |
if (_patches.multiple_industry_per_town) return t; |
0 | 1247 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1248 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1249 |
if (i->xy != 0 && |
1250 |
i->type == (byte)type && |
|
1251 |
i->town == t) { |
|
1252 |
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; |
|
1253 |
return NULL; |
|
1254 |
} |
|
1255 |
} |
|
1256 |
||
1257 |
return t; |
|
1258 |
} |
|
1259 |
||
1260 |
static const byte _industry_map5_bits[] = { |
|
1261 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1262 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1263 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1264 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1265 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1266 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1267 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1268 |
16, 16, 4, 2, 16, 16, 16, 16, |
|
1269 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1270 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1271 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1272 |
16, 4, 2, 16, 16, 16, 16, 16, |
|
1273 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1274 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1275 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1276 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1277 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1278 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1279 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1280 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1281 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1282 |
16, 16, 16, 16, 16, 16, 16, |
|
1283 |
}; |
|
1284 |
||
2630 | 1285 |
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable* it, int type, const Town* t) |
0 | 1286 |
{ |
1287 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1288 |
||
1289 |
do { |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1290 |
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1291 |
|
0 | 1292 |
if (!IsValidTile(cur_tile)) { |
2639 | 1293 |
if (it->map5 == 0xff) continue; |
0 | 1294 |
return false; |
1295 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1296 |
|
0 | 1297 |
if (it->map5 == 0xFF) { |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1298 |
if (!IsTileType(cur_tile, MP_WATER) || |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1299 |
GetTileSlope(cur_tile, NULL) != 0) { |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1300 |
return false; |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1301 |
} |
0 | 1302 |
} else { |
2639 | 1303 |
if (!EnsureNoVehicle(cur_tile)) return false; |
0 | 1304 |
|
1305 |
if (type == IT_OIL_RIG) { |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1306 |
if (!IsTileType(cur_tile, MP_WATER) || _m[cur_tile].m5 != 0) return false; |
0 | 1307 |
} else { |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1308 |
uint tileh; |
0 | 1309 |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1310 |
if (IsTileType(cur_tile, MP_WATER) && _m[cur_tile].m5 == 0) return false; |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1311 |
|
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1312 |
tileh = GetTileSlope(cur_tile, NULL); |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1313 |
if (IsSteepTileh(tileh)) return false; |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1314 |
|
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1315 |
if (tileh != 0) { |
0 | 1316 |
int t; |
1317 |
byte bits = _industry_map5_bits[it->map5]; |
|
1318 |
||
2639 | 1319 |
if (bits & 0x10) return false; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1320 |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1321 |
t = ~tileh; |
0 | 1322 |
|
2639 | 1323 |
if (bits & 1 && (t & (1 + 8))) return false; |
1324 |
if (bits & 2 && (t & (4 + 8))) return false; |
|
1325 |
if (bits & 4 && (t & (1 + 2))) return false; |
|
1326 |
if (bits & 8 && (t & (2 + 4))) return false; |
|
0 | 1327 |
} |
1328 |
||
1329 |
if (type == IT_BANK) { |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1330 |
if (!IsTileType(cur_tile, MP_HOUSE) || t->population < 1200) { |
0 | 1331 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
1332 |
return false; |
|
1333 |
} |
|
1334 |
} else if (type == IT_BANK_2) { |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1335 |
if (!IsTileType(cur_tile, MP_HOUSE)) { |
0 | 1336 |
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
1337 |
return false; |
|
1338 |
} |
|
1339 |
} else if (type == IT_TOY_SHOP) { |
|
2639 | 1340 |
if (DistanceMax(t->xy, cur_tile) > 9) return false; |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1341 |
if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear; |
0 | 1342 |
} else if (type == IT_WATER_TOWER) { |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1343 |
if (!IsTileType(cur_tile, MP_HOUSE)) { |
0 | 1344 |
_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS; |
1345 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1346 |
} |
0 | 1347 |
} else { |
1348 |
do_clear: |
|
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2663
diff
changeset
|
1349 |
if (CmdFailed(DoCommandByTile(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) |
0 | 1350 |
return false; |
1351 |
} |
|
1352 |
} |
|
1353 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1354 |
} while ((++it)->ti.x != -0x80); |
0 | 1355 |
|
1356 |
return true; |
|
1357 |
} |
|
1358 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1359 |
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) |
0 | 1360 |
{ |
2639 | 1361 |
const IndustrySpec* spec = &_industry_spec[type]; |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
1362 |
const Industry* i; |
0 | 1363 |
|
1364 |
// accepting industries won't be close, not even with patch |
|
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1365 |
if (_patches.same_industry_close && spec->accepts_cargo[0] == CT_INVALID) |
0 | 1366 |
return true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1367 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1368 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1369 |
// check if an industry that accepts the same goods is nearby |
1370 |
if (i->xy != 0 && |
|
2639 | 1371 |
DistanceMax(tile, i->xy) <= 14 && |
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1372 |
spec->accepts_cargo[0] != CT_INVALID && |
2639 | 1373 |
spec->accepts_cargo[0] == i->accepts_cargo[0] && ( |
1374 |
_game_mode != GM_EDITOR || |
|
1375 |
!_patches.same_industry_close || |
|
1376 |
!_patches.multiple_industry_per_town |
|
1377 |
)) { |
|
1378 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
|
1379 |
return false; |
|
1380 |
} |
|
0 | 1381 |
|
1382 |
// check "not close to" field. |
|
1383 |
if (i->xy != 0 && |
|
1384 |
(i->type == spec->a || i->type == spec->b || i->type == spec->c) && |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
1385 |
DistanceMax(tile, i->xy) <= 14) { |
0 | 1386 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1387 |
return false; |
|
1388 |
} |
|
1389 |
} |
|
1390 |
return true; |
|
1391 |
} |
|
1392 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1393 |
static Industry *AllocateIndustry(void) |
0 | 1394 |
{ |
1395 |
Industry *i; |
|
1396 |
||
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1397 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1398 |
if (i->xy == 0) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1399 |
uint index = i->index; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1400 |
|
2639 | 1401 |
if (i->index > _total_industries) _total_industries = i->index; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1402 |
|
2639 | 1403 |
memset(i, 0, sizeof(*i)); |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1404 |
i->index = index; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1405 |
|
0 | 1406 |
return i; |
1407 |
} |
|
1408 |
} |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1409 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1410 |
/* Check if we can add a block to the pool */ |
2549 | 1411 |
return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL; |
0 | 1412 |
} |
1413 |
||
2630 | 1414 |
static void DoCreateNewIndustry(Industry* i, TileIndex tile, int type, const IndustryTileTable* it, const Town* t, byte owner) |
0 | 1415 |
{ |
1416 |
const IndustrySpec *spec; |
|
1417 |
uint32 r; |
|
1418 |
int j; |
|
1419 |
||
1420 |
i->xy = tile; |
|
1421 |
i->width = i->height = 0; |
|
1422 |
i->type = type; |
|
1423 |
||
1424 |
spec = &_industry_spec[type]; |
|
1425 |
||
1426 |
i->produced_cargo[0] = spec->produced_cargo[0]; |
|
1427 |
i->produced_cargo[1] = spec->produced_cargo[1]; |
|
1428 |
i->accepts_cargo[0] = spec->accepts_cargo[0]; |
|
1429 |
i->accepts_cargo[1] = spec->accepts_cargo[1]; |
|
1430 |
i->accepts_cargo[2] = spec->accepts_cargo[2]; |
|
1431 |
i->production_rate[0] = spec->production_rate[0]; |
|
1432 |
i->production_rate[1] = spec->production_rate[1]; |
|
1433 |
||
1434 |
if (_patches.smooth_economy) { |
|
1435 |
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); |
|
1436 |
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); |
|
1437 |
} |
|
1438 |
||
1439 |
i->town = t; |
|
1440 |
i->owner = owner; |
|
1441 |
||
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2469
diff
changeset
|
1442 |
r = Random(); |
2492
b4785c8f3700
(svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents:
2484
diff
changeset
|
1443 |
i->color_map = GB(r, 8, 4); |
b4785c8f3700
(svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents:
2484
diff
changeset
|
1444 |
i->counter = GB(r, 0, 12); |
0 | 1445 |
i->cargo_waiting[0] = 0; |
1446 |
i->cargo_waiting[1] = 0; |
|
1447 |
i->last_mo_production[0] = 0; |
|
1448 |
i->last_mo_production[1] = 0; |
|
1449 |
i->last_mo_transported[0] = 0; |
|
1450 |
i->last_mo_transported[1] = 0; |
|
1451 |
i->pct_transported[0] = 0; |
|
1452 |
i->pct_transported[1] = 0; |
|
1453 |
i->total_transported[0] = 0; |
|
1454 |
i->total_transported[1] = 0; |
|
1455 |
i->was_cargo_delivered = false; |
|
1456 |
i->last_prod_year = _cur_year; |
|
1457 |
i->total_production[0] = i->production_rate[0] * 8; |
|
1458 |
i->total_production[1] = i->production_rate[1] * 8; |
|
1459 |
||
2639 | 1460 |
if (!_generating_world) 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
|
1461 |
|
0 | 1462 |
i->prod_level = 0x10; |
1463 |
||
1464 |
do { |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1465 |
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1466 |
|
1467 |
if (it->map5 != 0xFF) { |
|
1468 |
byte size; |
|
1469 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1470 |
size = it->ti.x; |
0 | 1471 |
if (size > i->width) i->width = size; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1472 |
size = it->ti.y; |
0 | 1473 |
if (size > i->height)i->height = size; |
1474 |
||
1475 |
DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1476 |
||
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1048
diff
changeset
|
1477 |
SetTileType(cur_tile, MP_INDUSTRY); |
2049
538e73c53f54
(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
|
1478 |
_m[cur_tile].m5 = it->map5; |
538e73c53f54
(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
|
1479 |
_m[cur_tile].m2 = i->index; |
2360
4e4ebe18e448
(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
|
1480 |
_m[cur_tile].m1 = _generating_world ? 0x1E : 0; /* maturity */ |
0 | 1481 |
} |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1482 |
} while ((++it)->ti.x != -0x80); |
0 | 1483 |
|
1484 |
i->width++; |
|
1485 |
i->height++; |
|
1486 |
||
1487 |
if (i->type == IT_FARM || i->type == IT_FARM_2) { |
|
1981 | 1488 |
tile = i->xy + TileDiffXY(i->width / 2, i->height / 2); |
2639 | 1489 |
for (j = 0; j != 50; j++) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1490 |
int x = Random() % 31 - 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1491 |
int y = Random() % 31 - 16; |
2639 | 1492 |
TileIndex new_tile = TileAddWrap(tile, x, y); |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1493 |
|
2639 | 1494 |
if (new_tile != INVALID_TILE) PlantFarmField(new_tile); |
131
16e59d059384
(svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents:
110
diff
changeset
|
1495 |
} |
0 | 1496 |
} |
1497 |
_industry_sort_dirty = true; |
|
1498 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1499 |
} |
|
1500 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1501 |
/** Build/Fund an industry |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1502 |
* @param x,y coordinates where industry is built |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1503 |
* @param p1 industry type @see build_industry.h and @see industry.h |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1504 |
* @param p2 unused |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1505 |
*/ |
0 | 1506 |
int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1507 |
{ |
|
2630 | 1508 |
const Town* t; |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1509 |
Industry *i; |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1510 |
TileIndex tile = TileVirtXY(x, y); |
0 | 1511 |
int num; |
1512 |
const IndustryTileTable * const *itt; |
|
1513 |
const IndustryTileTable *it; |
|
1514 |
const IndustrySpec *spec; |
|
1515 |
||
1516 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1517 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1518 |
if (!CheckSuitableIndustryPos(tile)) return CMD_ERROR; |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1519 |
|
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1520 |
/* Check if the to-be built/founded industry is available for this climate. |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1521 |
* Unfortunately we have no easy way of checking, except for looping the table */ |
2639 | 1522 |
{ |
1523 |
const byte* i; |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1524 |
bool found = false; |
2639 | 1525 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1526 |
for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) { |
2639 | 1527 |
if (*i == p1) { |
1528 |
found = true; |
|
1529 |
break; |
|
1530 |
} |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1531 |
} |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1532 |
if (!found) return CMD_ERROR; |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1533 |
} |
0 | 1534 |
|
1535 |
spec = &_industry_spec[p1]; |
|
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1536 |
/* If the patch for raw-material industries is not on, you cannot build raw-material industries. |
1800
1324958d7c73
(svn r2304) - Fix (regression): excuse the Lumber mill from the list of raw-industries build-restriction, as it can be built always, patch-setting, or no patch-setting.
Darkvater
parents:
1786
diff
changeset
|
1537 |
* Raw material industries are industries that do not accept cargo (at least for now) |
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1538 |
* Exclude the lumber mill (only "raw" industry that can be built) */ |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1539 |
if (!_patches.build_rawmaterial_ind && |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1540 |
spec->accepts_cargo[0] == CT_INVALID && |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1541 |
spec->accepts_cargo[1] == CT_INVALID && |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1542 |
spec->accepts_cargo[2] == CT_INVALID && |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1543 |
p1 != IT_LUMBER_MILL) { |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1544 |
return CMD_ERROR; |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1545 |
} |
0 | 1546 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1547 |
if (!_check_new_industry_procs[spec->check_proc](tile, p1)) return CMD_ERROR; |
0 | 1548 |
|
2639 | 1549 |
t = CheckMultipleIndustryInTown(tile, p1); |
1550 |
if (t == NULL) return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1551 |
|
0 | 1552 |
num = spec->num_table; |
1553 |
itt = spec->table; |
|
1554 |
||
1555 |
do { |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1556 |
if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE); |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1557 |
} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1, t)); |
0 | 1558 |
|
1559 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1560 |
if (!CheckIfTooCloseToIndustry(tile, p1)) return CMD_ERROR; |
0 | 1561 |
|
2639 | 1562 |
i = AllocateIndustry(); |
1563 |
if (i == NULL) return CMD_ERROR; |
|
0 | 1564 |
|
2639 | 1565 |
if (flags & DC_EXEC) 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
|
1566 |
|
0 | 1567 |
return (_price.build_industry >> 5) * _industry_type_costs[p1]; |
1568 |
} |
|
1569 |
||
1570 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1571 |
Industry *CreateNewIndustry(TileIndex tile, int type) |
0 | 1572 |
{ |
2630 | 1573 |
const Town* t; |
0 | 1574 |
const IndustryTileTable *it; |
1575 |
Industry *i; |
|
1576 |
||
1577 |
const IndustrySpec *spec; |
|
1578 |
||
2639 | 1579 |
if (!CheckSuitableIndustryPos(tile)) return NULL; |
0 | 1580 |
|
1581 |
spec = &_industry_spec[type]; |
|
1582 |
||
2639 | 1583 |
if (!_check_new_industry_procs[spec->check_proc](tile, type)) return NULL; |
0 | 1584 |
|
2639 | 1585 |
t = CheckMultipleIndustryInTown(tile, type); |
1586 |
if (t == NULL) return NULL; |
|
0 | 1587 |
|
1588 |
/* pick a random layout */ |
|
2639 | 1589 |
it = spec->table[RandomRange(spec->num_table)]; |
0 | 1590 |
|
2639 | 1591 |
if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) return NULL; |
1592 |
if (!CheckIfTooCloseToIndustry(tile, type)) return NULL; |
|
0 | 1593 |
|
2639 | 1594 |
i = AllocateIndustry(); |
1595 |
if (i == NULL) return NULL; |
|
0 | 1596 |
|
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1597 |
DoCreateNewIndustry(i, tile, type, 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 i; |
1600 |
} |
|
1601 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1602 |
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
|
1603 |
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
0 | 1604 |
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, |
1605 |
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
|
1606 |
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, |
|
1607 |
}; |
|
1608 |
||
1609 |
static void PlaceInitialIndustry(byte type, int amount) |
|
1610 |
{ |
|
2072
66d208875eda
(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
|
1611 |
int num = _numof_industry_table[_opt.diff.number_industries][amount]; |
66d208875eda
(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
|
1612 |
|
66d208875eda
(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
|
1613 |
if (type == IT_OIL_REFINERY || type == IT_OIL_RIG) { |
66d208875eda
(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
|
1614 |
// These are always placed next to the coastline, so we scale by the perimeter instead. |
66d208875eda
(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
|
1615 |
num = ScaleByMapSize1D(num); |
66d208875eda
(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
|
1616 |
} else { |
66d208875eda
(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
|
1617 |
num = ScaleByMapSize(num); |
66d208875eda
(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
|
1618 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1619 |
|
2639 | 1620 |
if (_opt.diff.number_industries != 0) { |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1621 |
PlayerID old_player = _current_player; |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1622 |
_current_player = OWNER_NONE; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1623 |
assert(num > 0); |
0 | 1624 |
|
1625 |
do { |
|
2639 | 1626 |
uint i; |
1627 |
||
1628 |
for (i = 0; i < 2000; i++) { |
|
1629 |
if (CreateNewIndustry(RandomTile(), type) != NULL) break; |
|
1630 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1631 |
} while (--num); |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1632 |
|
267 | 1633 |
_current_player = old_player; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1634 |
} |
0 | 1635 |
} |
1636 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1637 |
void GenerateIndustries(void) |
0 | 1638 |
{ |
1639 |
const byte *b; |
|
1640 |
||
1641 |
b = _industry_create_table[_opt.landscape]; |
|
1642 |
do { |
|
1643 |
PlaceInitialIndustry(b[1], b[0]); |
|
1644 |
} while ( (b+=2)[0] != 0); |
|
1645 |
} |
|
1646 |
||
1647 |
static void ExtChangeIndustryProduction(Industry *i) |
|
1648 |
{ |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1649 |
bool closeit = true; |
0 | 1650 |
int j; |
1651 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1652 |
switch (_industry_close_mode[i->type]) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1653 |
case INDUSTRY_NOT_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1654 |
return; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1655 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1656 |
case INDUSTRY_CLOSABLE: |
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1657 |
if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180)) |
0 | 1658 |
closeit = false; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1659 |
break; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1660 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1661 |
default: /* INDUSTRY_PRODUCTION */ |
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1662 |
for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){ |
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1663 |
uint32 r = Random(); |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1664 |
int old, new, percent; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1665 |
int mag; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1666 |
|
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1667 |
new = old = i->production_rate[j]; |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1668 |
if (CHANCE16I(20, 1024, r)) |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1669 |
new -= ((RandomRange(50) + 10) * old) >> 8; |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1670 |
if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16)) |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1671 |
new += ((RandomRange(50) + 10) * old) >> 8; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1672 |
|
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1673 |
new = clamp(new, 0, 255); |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1674 |
if (new == old) { |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1675 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1676 |
continue; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1677 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1678 |
|
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1679 |
percent = new * 100 / old - 100; |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1680 |
i->production_rate[j] = new; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1681 |
|
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1682 |
if (new >= _industry_spec[i->type].production_rate[j] / 4) |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1683 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1684 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1685 |
mag = abs(percent); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1686 |
if (mag >= 10) { |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1687 |
SetDParam(2, mag); |
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1688 |
SetDParam(0, _cargoc.names_s[i->produced_cargo[j]]); |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1689 |
SetDParam(1, i->index); |
2639 | 1690 |
AddNewsItem( |
1691 |
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, |
|
1692 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), |
|
1693 |
i->xy + TileDiffXY(1, 1), 0 |
|
1694 |
); |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1695 |
} |
0 | 1696 |
} |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1697 |
break; |
0 | 1698 |
} |
1699 |
||
1700 |
if (closeit) { |
|
1701 |
i->prod_level = 0; |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1702 |
SetDParam(0, i->index); |
2639 | 1703 |
AddNewsItem( |
1704 |
_industry_close_strings[i->type], |
|
1705 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), |
|
1706 |
i->xy + TileDiffXY(1, 1), 0 |
|
1707 |
); |
|
0 | 1708 |
} |
1709 |
} |
|
1710 |
||
1711 |
||
1712 |
static void UpdateIndustryStatistics(Industry *i) |
|
1713 |
{ |
|
1714 |
byte pct; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1715 |
|
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1716 |
if (i->produced_cargo[0] != CT_INVALID) { |
0 | 1717 |
pct = 0; |
1718 |
if (i->last_mo_production[0] != 0) { |
|
1719 |
i->last_prod_year = _cur_year; |
|
1720 |
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
|
1721 |
} |
0 | 1722 |
i->pct_transported[0] = pct; |
1723 |
||
1724 |
i->total_production[0] = i->last_mo_production[0]; |
|
1725 |
i->last_mo_production[0] = 0; |
|
1726 |
||
1727 |
i->total_transported[0] = i->last_mo_transported[0]; |
|
1728 |
i->last_mo_transported[0] = 0; |
|
1729 |
} |
|
1730 |
||
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1731 |
if (i->produced_cargo[1] != CT_INVALID) { |
0 | 1732 |
pct = 0; |
1733 |
if (i->last_mo_production[1] != 0) { |
|
1734 |
i->last_prod_year = _cur_year; |
|
1735 |
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
|
1736 |
} |
0 | 1737 |
i->pct_transported[1] = pct; |
1738 |
||
1739 |
i->total_production[1] = i->last_mo_production[1]; |
|
1740 |
i->last_mo_production[1] = 0; |
|
1741 |
||
1742 |
i->total_transported[1] = i->last_mo_transported[1]; |
|
1743 |
i->last_mo_transported[1] = 0; |
|
1744 |
} |
|
1745 |
||
1746 |
||
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1747 |
if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID) |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1748 |
InvalidateWindow(WC_INDUSTRY_VIEW, i->index); |
0 | 1749 |
|
2639 | 1750 |
if (i->prod_level == 0) { |
0 | 1751 |
DeleteIndustry(i); |
2639 | 1752 |
} else if (_patches.smooth_economy) { |
0 | 1753 |
ExtChangeIndustryProduction(i); |
2639 | 1754 |
} |
0 | 1755 |
} |
1756 |
||
1757 |
static const byte _new_industry_rand[4][32] = { |
|
1758 |
{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}, |
|
1759 |
{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}, |
|
1760 |
{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}, |
|
1761 |
{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}, |
|
1762 |
}; |
|
1763 |
||
1764 |
static void MaybeNewIndustry(uint32 r) |
|
1765 |
{ |
|
1766 |
int type; |
|
1767 |
int j; |
|
1768 |
Industry *i; |
|
1769 |
||
2140
a04d0142ad65
(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
|
1770 |
type = _new_industry_rand[_opt.landscape][GB(r, 16, 5)]; |
0 | 1771 |
|
2639 | 1772 |
if (type == IT_OIL_WELL && _date > 10958) return; |
1773 |
if (type == IT_OIL_RIG && _date < 14610) return; |
|
0 | 1774 |
|
1775 |
j = 2000; |
|
2639 | 1776 |
for (;;) { |
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
1777 |
i = CreateNewIndustry(RandomTile(), type); |
2639 | 1778 |
if (i != NULL) break; |
1779 |
if (--j == 0) return; |
|
0 | 1780 |
} |
1781 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1782 |
SetDParam(0, type + STR_4802_COAL_MINE); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1783 |
SetDParam(1, i->town->index); |
2260
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1784 |
AddNewsItem( |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1785 |
(type != IT_FOREST) ? |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1786 |
STR_482D_NEW_UNDER_CONSTRUCTION : STR_482E_NEW_BEING_PLANTED_NEAR, |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1787 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY,0), i->xy, 0 |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1788 |
); |
0 | 1789 |
} |
1790 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1791 |
static void ChangeIndustryProduction(Industry *i) |
0 | 1792 |
{ |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1793 |
bool only_decrease = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1794 |
StringID str = STR_NULL; |
0 | 1795 |
int type = i->type; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1796 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1797 |
switch (_industry_close_mode[type]) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1798 |
case INDUSTRY_NOT_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1799 |
return; |
0 | 1800 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1801 |
case INDUSTRY_PRODUCTION: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1802 |
/* decrease or increase */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1803 |
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1804 |
only_decrease = true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1805 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1806 |
if (only_decrease || CHANCE16(1,3)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1807 |
/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1808 |
if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1809 |
/* Increase production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1810 |
if (i->prod_level != 0x80) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1811 |
byte b; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1812 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1813 |
i->prod_level <<= 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1814 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1815 |
b = i->production_rate[0] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1816 |
if (i->production_rate[0] >= 128) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1817 |
b = 0xFF; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1818 |
i->production_rate[0] = b; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1819 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1820 |
b = i->production_rate[1] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1821 |
if (i->production_rate[1] >= 128) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1822 |
b = 0xFF; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1823 |
i->production_rate[1] = b; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1824 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1825 |
str = _industry_prod_up_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1826 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1827 |
} else { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1828 |
/* Decrease production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1829 |
if (i->prod_level == 4) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1830 |
i->prod_level = 0; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1831 |
str = _industry_close_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1832 |
} else { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1833 |
i->prod_level >>= 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1834 |
i->production_rate[0] = (i->production_rate[0] + 1) >> 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1835 |
i->production_rate[1] = (i->production_rate[1] + 1) >> 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1836 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1837 |
str = _industry_prod_down_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1838 |
} |
0 | 1839 |
} |
1840 |
} |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1841 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1842 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1843 |
case INDUSTRY_CLOSABLE: |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1844 |
/* maybe close */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1845 |
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1846 |
i->prod_level = 0; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1847 |
str = _industry_close_strings[type]; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1848 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1849 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1850 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1851 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1852 |
if (str != STR_NULL) { |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1853 |
SetDParam(0, i->index); |
1981 | 1854 |
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0); |
0 | 1855 |
} |
1856 |
} |
|
1857 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1858 |
void IndustryMonthlyLoop(void) |
0 | 1859 |
{ |
1860 |
Industry *i; |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1861 |
PlayerID old_player = _current_player; |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1862 |
_current_player = OWNER_NONE; |
0 | 1863 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1864 |
FOR_ALL_INDUSTRIES(i) { |
2639 | 1865 |
if (i->xy != 0) UpdateIndustryStatistics(i); |
0 | 1866 |
} |
1867 |
||
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1868 |
/* 3% chance that we start a new industry */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1869 |
if (CHANCE16(3, 100)) { |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1870 |
MaybeNewIndustry(Random()); |
1269
0c8818a1c07a
(svn r1773) -Fix: [ 1114950 ] Game crashed sometimes when there were no industries
truelight
parents:
1267
diff
changeset
|
1871 |
} else if (!_patches.smooth_economy && _total_industries > 0) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1872 |
i = GetIndustry(RandomRange(_total_industries)); |
2639 | 1873 |
if (i->xy != 0) ChangeIndustryProduction(i); |
0 | 1874 |
} |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1875 |
|
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1876 |
_current_player = old_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1877 |
|
0 | 1878 |
// production-change |
1879 |
_industry_sort_dirty = true; |
|
1880 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1881 |
} |
|
1882 |
||
1883 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1884 |
void InitializeIndustries(void) |
0 | 1885 |
{ |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1886 |
CleanPool(&_industry_pool); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1887 |
AddBlockToPool(&_industry_pool); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1888 |
|
0 | 1889 |
_total_industries = 0; |
1890 |
_industry_sort_dirty = true; |
|
1891 |
} |
|
1892 |
||
1893 |
const TileTypeProcs _tile_type_industry_procs = { |
|
1894 |
DrawTile_Industry, /* draw_tile_proc */ |
|
1895 |
GetSlopeZ_Industry, /* get_slope_z_proc */ |
|
1896 |
ClearTile_Industry, /* clear_tile_proc */ |
|
1897 |
GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
|
1898 |
GetTileDesc_Industry, /* get_tile_desc_proc */ |
|
1899 |
GetTileTrackStatus_Industry,/* get_tile_track_status_proc */ |
|
1900 |
ClickTile_Industry, /* click_tile_proc */ |
|
1901 |
AnimateTile_Industry, /* animate_tile_proc */ |
|
1902 |
TileLoop_Industry, /* tile_loop_proc */ |
|
1903 |
ChangeTileOwner_Industry, /* change_tile_owner_proc */ |
|
1904 |
GetProducedCargo_Industry, /* get_produced_cargo_proc */ |
|
1905 |
NULL, /* vehicle_enter_tile_proc */ |
|
1906 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1907 |
GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
0 | 1908 |
}; |
1909 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1800
diff
changeset
|
1910 |
static const SaveLoad _industry_desc[] = { |
1174
6a5e747f3ba6
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1093
diff
changeset
|
1911 |
SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
2979
diff
changeset
|
1912 |
SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
0 | 1913 |
SLE_VAR(Industry,width, SLE_UINT8), |
1914 |
SLE_VAR(Industry,height, SLE_UINT8), |
|
1915 |
SLE_REF(Industry,town, REF_TOWN), |
|
1916 |
SLE_ARR(Industry,produced_cargo, SLE_UINT8, 2), |
|
1917 |
SLE_ARR(Industry,cargo_waiting, SLE_UINT16, 2), |
|
1918 |
SLE_ARR(Industry,production_rate, SLE_UINT8, 2), |
|
1919 |
SLE_ARR(Industry,accepts_cargo, SLE_UINT8, 3), |
|
1920 |
SLE_VAR(Industry,prod_level, SLE_UINT8), |
|
1921 |
SLE_ARR(Industry,last_mo_production,SLE_UINT16, 2), |
|
1922 |
SLE_ARR(Industry,last_mo_transported,SLE_UINT16, 2), |
|
1923 |
SLE_ARR(Industry,pct_transported,SLE_UINT8, 2), |
|
1924 |
SLE_ARR(Industry,total_production,SLE_UINT16, 2), |
|
1925 |
SLE_ARR(Industry,total_transported,SLE_UINT16, 2), |
|
1926 |
||
1927 |
SLE_VAR(Industry,counter, SLE_UINT16), |
|
1928 |
||
1929 |
SLE_VAR(Industry,type, SLE_UINT8), |
|
1930 |
SLE_VAR(Industry,owner, SLE_UINT8), |
|
1931 |
SLE_VAR(Industry,color_map, SLE_UINT8), |
|
1932 |
SLE_VAR(Industry,last_prod_year, SLE_UINT8), |
|
1933 |
SLE_VAR(Industry,was_cargo_delivered,SLE_UINT8), |
|
1934 |
||
1935 |
// reserve extra space in savegame here. (currently 32 bytes) |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3173
diff
changeset
|
1936 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 1937 |
|
1938 |
SLE_END() |
|
1939 |
}; |
|
1940 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1941 |
static void Save_INDY(void) |
0 | 1942 |
{ |
1943 |
Industry *ind; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1944 |
|
0 | 1945 |
// Write the vehicles |
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1946 |
FOR_ALL_INDUSTRIES(ind) { |
0 | 1947 |
if (ind->xy != 0) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1948 |
SlSetArrayIndex(ind->index); |
0 | 1949 |
SlObject(ind, _industry_desc); |
1950 |
} |
|
1951 |
} |
|
1952 |
} |
|
1953 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1954 |
static void Load_INDY(void) |
0 | 1955 |
{ |
1956 |
int index; |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1957 |
|
0 | 1958 |
_total_industries = 0; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1959 |
|
0 | 1960 |
while ((index = SlIterateArray()) != -1) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1961 |
Industry *i; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1962 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1963 |
if (!AddBlockIfNeeded(&_industry_pool, index)) |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1964 |
error("Industries: failed loading savegame: too many industries"); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1965 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1966 |
i = GetIndustry(index); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1967 |
SlObject(i, _industry_desc); |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1968 |
|
2639 | 1969 |
if (index > _total_industries) _total_industries = index; |
0 | 1970 |
} |
1971 |
} |
|
1972 |
||
1973 |
const ChunkHandler _industry_chunk_handlers[] = { |
|
1974 |
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |
|
1975 |
}; |