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