author | rubidium |
Wed, 04 Jul 2007 18:27:21 +0000 | |
changeset 7661 | 40c7a63ad9a1 |
parent 7647 | 446896960367 |
child 7664 | 81c35390400e |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
3 |
/** @file industry_cmd.cpp */ |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3094
diff
changeset
|
7 |
#include "clear_map.h" |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
8 |
#include "functions.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
|
9 |
#include "industry_map.h" |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3331
diff
changeset
|
10 |
#include "station_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
11 |
#include "table/strings.h" |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
12 |
#include "table/sprites.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
|
13 |
#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
|
14 |
#include "tile.h" |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6633
diff
changeset
|
15 |
#include "landscape.h" |
0 | 16 |
#include "viewport.h" |
17 |
#include "command.h" |
|
18 |
#include "industry.h" |
|
19 |
#include "town.h" |
|
20 |
#include "vehicle.h" |
|
21 |
#include "news.h" |
|
22 |
#include "saveload.h" |
|
23 |
#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
|
24 |
#include "sound.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
25 |
#include "variables.h" |
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
26 |
#include "table/industry_land.h" |
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
27 |
#include "table/build_industry.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
28 |
#include "genworld.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4231
diff
changeset
|
29 |
#include "date.h" |
5056
20369e09627b
(svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents:
4976
diff
changeset
|
30 |
#include "water_map.h" |
6160
126831e48987
(svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents:
6135
diff
changeset
|
31 |
#include "tree_map.h" |
6417
26acff62d001
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
6160
diff
changeset
|
32 |
#include "cargotype.h" |
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
33 |
#include "newgrf_industrytiles.h" |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
34 |
#include "newgrf_callbacks.h" |
0 | 35 |
|
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
36 |
void ShowIndustryViewWindow(int industry); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
37 |
void BuildOilRig(TileIndex tile); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
38 |
|
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
39 |
static byte _industry_sound_ctr; |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
40 |
static TileIndex _industry_sound_tile; |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
41 |
|
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
42 |
int _total_industries; //general counter |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
43 |
uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
44 |
|
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
45 |
const Industry **_industry_sort; |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
46 |
bool _industry_sort_dirty; |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
47 |
|
7239
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
48 |
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES]; |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
49 |
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES]; |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
50 |
|
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
51 |
/** This function initialize the spec arrays of both |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
52 |
* industry and industry tiles. |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
53 |
* It adjusts the enabling of the industry too, based on climate availability. |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
54 |
* This will allow for clearer testings */ |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
55 |
void ResetIndustries() |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
56 |
{ |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
57 |
memset(&_industry_specs, 0, sizeof(_industry_specs)); |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
58 |
memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs)); |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
59 |
|
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
60 |
/* once performed, enable only the current climate industries */ |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
61 |
for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) { |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
62 |
_industry_specs[i].enabled = HASBIT(_origin_industry_specs[i].climate_availability, _opt.landscape); |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
63 |
} |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
64 |
|
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
65 |
|
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
66 |
memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs)); |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
67 |
memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs)); |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
68 |
} |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
69 |
|
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
70 |
/** |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
71 |
* 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
|
72 |
*/ |
2817 | 73 |
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
|
74 |
{ |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
75 |
Industry *i; |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
76 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
77 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
78 |
* TODO - This is just a temporary stage, this will be removed. */ |
4976
a0d7f63c35b5
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
79 |
for (i = GetIndustry(start_item); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) i->index = start_item++; |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
80 |
} |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
81 |
|
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
5118
diff
changeset
|
82 |
DEFINE_OLD_POOL(Industry, Industry, IndustryPoolNewBlock, NULL) |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
83 |
|
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
|
84 |
/** |
e95d6e5f66ae
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
85 |
* 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
|
86 |
* 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
|
87 |
* 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
|
88 |
* @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
|
89 |
* @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
|
90 |
* @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
|
91 |
**/ |
e95d6e5f66ae
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
92 |
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
|
93 |
{ |
e95d6e5f66ae
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
94 |
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
|
95 |
|
7135
8078f2b614e4
(svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas
parents:
7132
diff
changeset
|
96 |
const Industry *ind = GetIndustryByTile(tile); |
8078f2b614e4
(svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas
parents:
7132
diff
changeset
|
97 |
return IsValidIndustry(ind) ? ind->type : (IndustryType)IT_INVALID; |
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
|
98 |
} |
0 | 99 |
|
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
100 |
/** |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
101 |
* Accessor for array _industry_specs. |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
102 |
* This will ensure at once : proper access and |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
103 |
* not allowing modifications of it. |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
104 |
* @param thistype of industry (which is the index in _industry_specs) |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
105 |
* @pre thistype < NUM_INDUSTRYTYPES |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
106 |
* @return a pointer to the corresponding industry spec |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
107 |
**/ |
3689
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3669
diff
changeset
|
108 |
const IndustrySpec *GetIndustrySpec(IndustryType thistype) |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
109 |
{ |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
110 |
assert(thistype < NUM_INDUSTRYTYPES); |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
111 |
return &_industry_specs[thistype]; |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
112 |
} |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
113 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
114 |
/** |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
115 |
* Accessor for array _industry_tile_specs. |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
116 |
* This will ensure at once : proper access and |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
117 |
* not allowing modifications of it. |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
118 |
* @param gfx of industrytile (which is the index in _industry_specs) |
7245
f868248ecf83
(svn r9984) -Codechange: Remove an obsolete structure and a now meaningless enum, in favor of the "real thing"
belugas
parents:
7244
diff
changeset
|
119 |
* @pre gfx < INVALID_INDUSTRYTILE |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
120 |
* @return a pointer to the corresponding industrytile spec |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
121 |
**/ |
6418
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
122 |
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx) |
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
123 |
{ |
7245
f868248ecf83
(svn r9984) -Codechange: Remove an obsolete structure and a now meaningless enum, in favor of the "real thing"
belugas
parents:
7244
diff
changeset
|
124 |
assert(gfx < INVALID_INDUSTRYTILE); |
6418
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
125 |
return &_industry_tile_specs[gfx]; |
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
126 |
} |
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
127 |
|
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
128 |
void DestroyIndustry(Industry *i) |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
129 |
{ |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
130 |
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
131 |
if (IsTileType(tile_cur, MP_INDUSTRY)) { |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
132 |
if (GetIndustryIndex(tile_cur) == i->index) { |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
133 |
DoClearSquare(tile_cur); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
134 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
135 |
} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
136 |
DeleteOilRig(tile_cur); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
137 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
138 |
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
139 |
|
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
140 |
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) { |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
141 |
/* Remove the farmland and convert it to regular tiles over time. */ |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
142 |
BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) { |
4815
c2a54b213fde
(svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents:
4607
diff
changeset
|
143 |
tile_cur = TILE_MASK(tile_cur); |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
144 |
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
145 |
GetIndustryIndexOfField(tile_cur) == i->index) { |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
146 |
SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
147 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
148 |
} END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21)) |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
149 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
150 |
|
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
151 |
_industry_sort_dirty = true; |
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
152 |
DecIndustryTypeCount(i->type); |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
153 |
|
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
154 |
DeleteSubsidyWithIndustry(i->index); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
155 |
DeleteWindowById(WC_INDUSTRY_VIEW, i->index); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
156 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
157 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
158 |
|
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
159 |
static void IndustryDrawSugarMine(const TileInfo *ti) |
0 | 160 |
{ |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
161 |
const DrawIndustryAnimationStruct *d; |
0 | 162 |
|
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
163 |
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
|
164 |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
165 |
d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)]; |
0 | 166 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
167 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0); |
0 | 168 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
169 |
if (d->image_2 != 0) { |
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
170 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41); |
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
171 |
} |
0 | 172 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
173 |
if (d->image_3 != 0) { |
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
174 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE, |
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
175 |
_drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y); |
2639 | 176 |
} |
0 | 177 |
} |
178 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
179 |
static void IndustryDrawToffeeQuarry(const TileInfo *ti) |
0 | 180 |
{ |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
181 |
uint8 x = 0; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
182 |
|
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
183 |
if (IsIndustryCompleted(ti->tile)) { |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
184 |
x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)]; |
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
185 |
if (x == 0xFF) |
0 | 186 |
x = 0; |
187 |
} |
|
188 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
189 |
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, PAL_NONE, 22 - x, 24 + x); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
190 |
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, PAL_NONE, 6, 14); |
0 | 191 |
} |
192 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
193 |
static void IndustryDrawBubbleGenerator( const TileInfo *ti) |
0 | 194 |
{ |
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
195 |
if (IsIndustryCompleted(ti->tile)) { |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
196 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]); |
2639 | 197 |
} else { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
198 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67); |
0 | 199 |
} |
200 |
} |
|
201 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
202 |
static void IndustryDrawToyFactory(const TileInfo *ti) |
0 | 203 |
{ |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
204 |
const DrawIndustryAnimationStruct *d; |
0 | 205 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
206 |
d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)]; |
0 | 207 |
|
208 |
if (d->image_1 != 0xFF) { |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
209 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1); |
0 | 210 |
} |
211 |
||
212 |
if (d->image_2 != 0xFF) { |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
213 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, PAL_NONE, 16 - d->image_2 * 2, 100 + d->image_2); |
0 | 214 |
} |
215 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
216 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, PAL_NONE, 7, d->image_3); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
217 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, PAL_NONE, 0, 42); |
0 | 218 |
} |
219 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
220 |
static void IndustryDrawCoalPlantSparks(const TileInfo *ti) |
0 | 221 |
{ |
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
222 |
if (IsIndustryCompleted(ti->tile)) { |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
223 |
uint8 image = GetIndustryAnimationState(ti->tile); |
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
224 |
|
0 | 225 |
if (image != 0 && image < 7) { |
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
226 |
AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS, |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
227 |
PAL_NONE, |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
228 |
_coal_plant_sparks[image - 1].x, |
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
229 |
_coal_plant_sparks[image - 1].y |
0 | 230 |
); |
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
||
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
|
235 |
typedef void IndustryDrawTileProc(const TileInfo *ti); |
0 | 236 |
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = { |
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
237 |
IndustryDrawSugarMine, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
238 |
IndustryDrawToffeeQuarry, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
239 |
IndustryDrawBubbleGenerator, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
240 |
IndustryDrawToyFactory, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
241 |
IndustryDrawCoalPlantSparks, |
0 | 242 |
}; |
243 |
||
244 |
static void DrawTile_Industry(TileInfo *ti) |
|
245 |
{ |
|
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
246 |
IndustryGfx gfx = GetIndustryGfx(ti->tile); |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
247 |
Industry *ind = GetIndustryByTile(ti->tile); |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
248 |
const IndustryTileSpec *indts = GetIndustryTileSpec(gfx); |
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
249 |
const DrawBuildingsTileStruct *dits; |
0 | 250 |
byte z; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
251 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
252 |
SpriteID pal; |
0 | 253 |
|
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
254 |
/* Retrieve pointer to the draw industry tile struct */ |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
255 |
if (gfx >= NEW_INDUSTRYTILEOFFSET) { |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
256 |
/* Draw the tile using the specialized method of newgrf industrytile. |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
257 |
* DrawNewIndustry will return false if ever the resolver could not |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
258 |
* find any sprite to display. So in this case, we will jump on the |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
259 |
* substitute gfx instead. */ |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
260 |
if (indts->grf_prop.spritegroup != NULL && DrawNewIndustryTile(ti, ind, gfx, indts)) { |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
261 |
return; |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
262 |
} else { |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
263 |
/* No sprite group (or no valid one) found, meaning no graphics associated. |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
264 |
* Use the substitute one instead */ |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
265 |
gfx = indts->grf_prop.subst_id; |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
266 |
/* And point the industrytile spec accordingly */ |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
267 |
indts = GetIndustryTileSpec(indts->grf_prop.subst_id); |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
268 |
} |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
269 |
} |
0 | 270 |
|
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
271 |
dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ? |
5687
a6f0e780d714
(svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents:
5686
diff
changeset
|
272 |
GetIndustryAnimationState(ti->tile) & 3 : |
a6f0e780d714
(svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents:
5686
diff
changeset
|
273 |
GetIndustryConstructionStage(ti->tile))]; |
0 | 274 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
275 |
image = dits->ground.sprite; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
276 |
if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
277 |
pal = GENERAL_SPRITE_COLOR(ind->random_color); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
278 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
279 |
pal = dits->ground.pal; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
280 |
} |
0 | 281 |
|
282 |
z = ti->z; |
|
283 |
/* Add bricks below the industry? */ |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
284 |
if (ti->tileh != SLOPE_FLAT) { |
7531
fa6a933b71d2
(svn r10299) -Codechange [FS#931]: industry foundations should be drawn as all other foundations, i.e. with DrawFoundation, instead of writing the same functionality itself.
rubidium
parents:
7522
diff
changeset
|
285 |
DrawFoundation(ti, ti->tileh); |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
286 |
z += TILE_HEIGHT; |
0 | 287 |
} |
288 |
||
7531
fa6a933b71d2
(svn r10299) -Codechange [FS#931]: industry foundations should be drawn as all other foundations, i.e. with DrawFoundation, instead of writing the same functionality itself.
rubidium
parents:
7522
diff
changeset
|
289 |
DrawGroundSprite(image, pal); |
fa6a933b71d2
(svn r10299) -Codechange [FS#931]: industry foundations should be drawn as all other foundations, i.e. with DrawFoundation, instead of writing the same functionality itself.
rubidium
parents:
7522
diff
changeset
|
290 |
|
0 | 291 |
/* Add industry on top of the ground? */ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
292 |
image = dits->building.sprite; |
2639 | 293 |
if (image != 0) { |
6923
6913c8a82cc0
(svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
6915
diff
changeset
|
294 |
if (HASBIT(_transparent_opt, TO_INDUSTRIES)) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
295 |
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
296 |
pal = PALETTE_TO_TRANSPARENT; |
7406
c626390d81a9
(svn r10163) -Fix(r8128): Industries had lost their random recoloring. A test was removed and is now reintroduced in another way.
belugas
parents:
7389
diff
changeset
|
297 |
} else if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->building.pal == PAL_NONE) { |
c626390d81a9
(svn r10163) -Fix(r8128): Industries had lost their random recoloring. A test was removed and is now reintroduced in another way.
belugas
parents:
7389
diff
changeset
|
298 |
pal = GENERAL_SPRITE_COLOR(ind->random_color); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
299 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
300 |
pal = dits->building.pal; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
301 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
302 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
303 |
AddSortableSpriteToDraw(image, pal, |
2653
4173d9a0a27e
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
304 |
ti->x + dits->subtile_x, |
4173d9a0a27e
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
305 |
ti->y + dits->subtile_y, |
4173d9a0a27e
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
306 |
dits->width + 1, |
4173d9a0a27e
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
307 |
dits->height + 1, |
0 | 308 |
dits->dz, |
309 |
z); |
|
310 |
||
6923
6913c8a82cc0
(svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
6915
diff
changeset
|
311 |
if (HASBIT(_transparent_opt, TO_INDUSTRIES)) return; |
0 | 312 |
} |
313 |
||
2639 | 314 |
{ |
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
315 |
int proc = dits->draw_proc - 1; |
2639 | 316 |
if (proc >= 0) _industry_draw_tile_procs[proc](ti); |
0 | 317 |
} |
318 |
} |
|
319 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
320 |
static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y) |
2537 | 321 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
322 |
return GetTileMaxZ(tile); |
0 | 323 |
} |
324 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
325 |
static Slope GetSlopeTileh_Industry(TileIndex tile, Slope 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
|
326 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
327 |
return SLOPE_FLAT; |
39 | 328 |
} |
329 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
330 |
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) |
0 | 331 |
{ |
6418
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
332 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(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
|
333 |
CargoID a; |
0 | 334 |
|
7232
2476045c6aed
(svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents:
7179
diff
changeset
|
335 |
for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) { |
2476045c6aed
(svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents:
7179
diff
changeset
|
336 |
a = itspec->accepts_cargo[i]; |
2476045c6aed
(svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents:
7179
diff
changeset
|
337 |
if (a != CT_INVALID) ac[a] = itspec->acceptance[i]; |
2476045c6aed
(svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents:
7179
diff
changeset
|
338 |
} |
0 | 339 |
} |
340 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
341 |
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) |
0 | 342 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
343 |
const Industry *i = GetIndustryByTile(tile); |
0 | 344 |
|
345 |
td->owner = i->owner; |
|
4942
f990abfa4438
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
346 |
td->str = GetIndustrySpec(i->type)->name; |
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
347 |
if (!IsIndustryCompleted(tile)) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
348 |
SetDParamX(td->dparam, 0, td->str); |
0 | 349 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
350 |
} |
|
351 |
} |
|
352 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7406
diff
changeset
|
353 |
static CommandCost ClearTile_Industry(TileIndex tile, byte flags) |
0 | 354 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
355 |
Industry *i = GetIndustryByTile(tile); |
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
356 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
0 | 357 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
358 |
/* water can destroy industries |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
359 |
* in editor you can bulldoze industries |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
360 |
* with magic_bulldozer cheat you can destroy industries |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
361 |
* (area around OILRIG is water, so water shouldn't flood it |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
362 |
*/ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
363 |
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
|
364 |
!_cheats.magic_bulldozer.value) || |
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
365 |
(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) { |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
366 |
SetDParam(0, indspec->name); |
0 | 367 |
return_cmd_error(STR_4800_IN_THE_WAY); |
368 |
} |
|
369 |
||
2639 | 370 |
if (flags & DC_EXEC) DeleteIndustry(i); |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
371 |
return CommandCost(); |
0 | 372 |
} |
373 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
374 |
static void TransportIndustryGoods(TileIndex tile) |
0 | 375 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
376 |
Industry *i = GetIndustryByTile(tile); |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
377 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
0 | 378 |
uint cw, am; |
379 |
||
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
380 |
cw = min(i->produced_cargo_waiting[0], 255); |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
381 |
if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) { |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
382 |
i->produced_cargo_waiting[0] -= cw; |
0 | 383 |
|
384 |
/* fluctuating economy? */ |
|
2639 | 385 |
if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
0 | 386 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
387 |
i->this_month_production[0] += cw; |
0 | 388 |
|
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
389 |
am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw); |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
390 |
i->this_month_transported[0] += am; |
3331 | 391 |
if (am != 0) { |
6631
dc3480a670cc
(svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents:
6609
diff
changeset
|
392 |
uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production; |
3331 | 393 |
|
7239
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
394 |
if (newgfx != INDUSTRYTILE_NOANIM) { |
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
|
395 |
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
|
396 |
SetIndustryCompleted(tile, true); |
3331 | 397 |
SetIndustryGfx(tile, newgfx); |
398 |
MarkTileDirtyByTile(tile); |
|
399 |
} |
|
0 | 400 |
} |
401 |
} |
|
402 |
||
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
403 |
cw = min(i->produced_cargo_waiting[1], 255); |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
404 |
if (cw > indspec->minimal_cargo) { |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
405 |
i->produced_cargo_waiting[1] -= cw; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
406 |
|
2639 | 407 |
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
|
408 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
409 |
i->this_month_production[1] += cw; |
0 | 410 |
|
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
411 |
am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw); |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
412 |
i->this_month_transported[1] += am; |
0 | 413 |
} |
414 |
} |
|
415 |
||
416 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
417 |
static void AnimateTile_Industry(TileIndex tile) |
0 | 418 |
{ |
3331 | 419 |
byte m; |
0 | 420 |
|
3331 | 421 |
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
|
422 |
case GFX_SUGAR_MINE_SIEVE: |
0 | 423 |
if ((_tick_counter & 1) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
424 |
m = GetIndustryAnimationState(tile) + 1; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
425 |
|
2952 | 426 |
switch (m & 7) { |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
427 |
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; |
541 | 428 |
case 6: SndPlayTileFx(SND_29_RIP, tile); break; |
0 | 429 |
} |
430 |
||
431 |
if (m >= 96) { |
|
432 |
m = 0; |
|
433 |
DeleteAnimatedTile(tile); |
|
434 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
435 |
SetIndustryAnimationState(tile, m); |
0 | 436 |
|
437 |
MarkTileDirtyByTile(tile); |
|
438 |
} |
|
439 |
break; |
|
440 |
||
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
|
441 |
case GFX_TOFFEE_QUARY: |
0 | 442 |
if ((_tick_counter & 3) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
443 |
m = GetIndustryAnimationState(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
444 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
445 |
if (_industry_anim_offs_toffee[m] == 0xFF) { |
541 | 446 |
SndPlayTileFx(SND_30_CARTOON_SOUND, tile); |
0 | 447 |
} |
448 |
||
449 |
if (++m >= 70) { |
|
450 |
m = 0; |
|
451 |
DeleteAnimatedTile(tile); |
|
452 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
453 |
SetIndustryAnimationState(tile, m); |
0 | 454 |
|
455 |
MarkTileDirtyByTile(tile); |
|
456 |
} |
|
457 |
break; |
|
458 |
||
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
|
459 |
case GFX_BUBBLE_CATCHER: |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
460 |
if ((_tick_counter & 1) == 0) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
461 |
m = GetIndustryAnimationState(tile); |
0 | 462 |
|
463 |
if (++m >= 40) { |
|
464 |
m = 0; |
|
465 |
DeleteAnimatedTile(tile); |
|
466 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
467 |
SetIndustryAnimationState(tile, m); |
0 | 468 |
|
469 |
MarkTileDirtyByTile(tile); |
|
470 |
} |
|
471 |
break; |
|
472 |
||
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
473 |
/* 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
|
474 |
case GFX_POWERPLANT_SPARKS: |
0 | 475 |
if ((_tick_counter & 3) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
476 |
m = GetIndustryAnimationState(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
477 |
if (m == 6) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
478 |
SetIndustryAnimationState(tile, 0); |
0 | 479 |
DeleteAnimatedTile(tile); |
480 |
} else { |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
481 |
SetIndustryAnimationState(tile, m + 1); |
0 | 482 |
MarkTileDirtyByTile(tile); |
483 |
} |
|
484 |
} |
|
485 |
break; |
|
486 |
||
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
|
487 |
case GFX_TOY_FACTORY: |
0 | 488 |
if ((_tick_counter & 1) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
489 |
m = GetIndustryAnimationState(tile) + 1; |
0 | 490 |
|
6964
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
491 |
switch (m) { |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
492 |
case 1: SndPlayTileFx(SND_2C_MACHINERY, tile); break; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
493 |
case 23: SndPlayTileFx(SND_2B_COMEDY_HIT, tile); break; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
494 |
case 28: SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); break; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
495 |
default: |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
496 |
if (m >= 50) { |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
497 |
int n = GetIndustryAnimationLoop(tile) + 1; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
498 |
m = 0; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
499 |
if (n >= 8) { |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
500 |
n = 0; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
501 |
DeleteAnimatedTile(tile); |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
502 |
} |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
503 |
SetIndustryAnimationLoop(tile, n); |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
504 |
} |
0 | 505 |
} |
506 |
||
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
507 |
SetIndustryAnimationState(tile, m); |
0 | 508 |
MarkTileDirtyByTile(tile); |
509 |
} |
|
510 |
break; |
|
511 |
||
5685
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
512 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2: |
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
513 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4: |
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
514 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6: |
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
515 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: |
0 | 516 |
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
|
517 |
IndustryGfx gfx = GetIndustryGfx(tile); |
0 | 518 |
|
3331 | 519 |
gfx = (gfx < 155) ? gfx + 1 : 148; |
520 |
SetIndustryGfx(tile, gfx); |
|
0 | 521 |
MarkTileDirtyByTile(tile); |
522 |
} |
|
523 |
break; |
|
524 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
525 |
case GFX_OILWELL_ANIMATED_1: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
526 |
case GFX_OILWELL_ANIMATED_2: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
527 |
case GFX_OILWELL_ANIMATED_3: |
0 | 528 |
if ((_tick_counter & 7) == 0) { |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6964
diff
changeset
|
529 |
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
|
530 |
IndustryGfx gfx = GetIndustryGfx(tile); |
3331 | 531 |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
532 |
m = GetIndustryAnimationState(tile) + 1; |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
533 |
if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) { |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
534 |
SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED); |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
535 |
SetIndustryConstructionStage(tile, 3); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
536 |
DeleteAnimatedTile(tile); |
0 | 537 |
} else { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
538 |
SetIndustryAnimationState(tile, m); |
3331 | 539 |
SetIndustryGfx(tile, gfx); |
0 | 540 |
MarkTileDirtyByTile(tile); |
541 |
} |
|
542 |
} |
|
543 |
break; |
|
544 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
545 |
case GFX_COAL_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
546 |
case GFX_COPPER_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
547 |
case GFX_GOLD_MINE_TOWER_ANIMATED: { |
0 | 548 |
int state = _tick_counter & 0x7FF; |
549 |
||
550 |
if ((state -= 0x400) < 0) |
|
551 |
return; |
|
552 |
||
553 |
if (state < 0x1A0) { |
|
554 |
if (state < 0x20 || state >= 0x180) { |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
555 |
m = GetIndustryAnimationState(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
556 |
if (!(m & 0x40)) { |
5687
a6f0e780d714
(svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents:
5686
diff
changeset
|
557 |
SetIndustryAnimationState(tile, m | 0x40); |
541 | 558 |
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); |
0 | 559 |
} |
560 |
if (state & 7) |
|
561 |
return; |
|
562 |
} else { |
|
563 |
if (state & 3) |
|
564 |
return; |
|
565 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
566 |
m = (GetIndustryAnimationState(tile) + 1) | 0x40; |
0 | 567 |
if (m > 0xC2) m = 0xC0; |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
568 |
SetIndustryAnimationState(tile, m); |
0 | 569 |
MarkTileDirtyByTile(tile); |
570 |
} else if (state >= 0x200 && state < 0x3A0) { |
|
571 |
int i; |
|
572 |
i = (state < 0x220 || state >= 0x380) ? 7 : 3; |
|
573 |
if (state & i) |
|
574 |
return; |
|
575 |
||
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
576 |
m = (GetIndustryAnimationState(tile) & 0xBF) - 1; |
0 | 577 |
if (m < 0x80) m = 0x82; |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
578 |
SetIndustryAnimationState(tile, m); |
0 | 579 |
MarkTileDirtyByTile(tile); |
580 |
} |
|
581 |
} break; |
|
582 |
} |
|
583 |
} |
|
584 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
585 |
static void CreateIndustryEffectSmoke(TileIndex tile) |
0 | 586 |
{ |
3773
996897ffc8ea
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
587 |
uint x = TileX(tile) * TILE_SIZE; |
996897ffc8ea
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
588 |
uint y = TileY(tile) * TILE_SIZE; |
996897ffc8ea
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
589 |
uint z = GetTileMaxZ(tile); |
3094 | 590 |
|
3773
996897ffc8ea
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
591 |
CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE); |
0 | 592 |
} |
593 |
||
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
|
594 |
static void MakeIndustryTileBigger(TileIndex tile) |
0 | 595 |
{ |
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
|
596 |
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
|
597 |
byte stage; |
0 | 598 |
|
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
|
599 |
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
|
600 |
SetIndustryConstructionCounter(tile, cnt); |
0 | 601 |
return; |
602 |
} |
|
603 |
||
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
|
604 |
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
|
605 |
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
|
606 |
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
|
607 |
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
|
608 |
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
|
609 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
610 |
|
0 | 611 |
MarkTileDirtyByTile(tile); |
612 |
||
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
613 |
if (!IsIndustryCompleted(tile)) return; |
0 | 614 |
|
3331 | 615 |
switch (GetIndustryGfx(tile)) { |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
616 |
case GFX_POWERPLANT_CHIMNEY: |
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
617 |
CreateIndustryEffectSmoke(tile); |
0 | 618 |
break; |
619 |
||
4607
2215d3175ad1
(svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents:
4587
diff
changeset
|
620 |
case GFX_OILRIG_1: |
2215d3175ad1
(svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents:
4587
diff
changeset
|
621 |
if (GetIndustryGfx(tile + TileDiffXY(0, 1)) == GFX_OILRIG_1) BuildOilRig(tile); |
0 | 622 |
break; |
623 |
||
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
|
624 |
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
|
625 |
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
|
626 |
case GFX_TOFFEE_QUARY: |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
627 |
SetIndustryAnimationState(tile, 0); |
3538
3eb71c726341
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
628 |
SetIndustryAnimationLoop(tile, 0); |
0 | 629 |
break; |
630 |
||
5685
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
631 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2: |
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
632 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4: |
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
633 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6: |
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
634 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: |
0 | 635 |
AddAnimatedTile(tile); |
636 |
break; |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
641 |
static void TileLoopIndustry_BubbleGenerator(TileIndex tile) |
0 | 642 |
{ |
643 |
int dir; |
|
644 |
Vehicle *v; |
|
645 |
static const int8 _tileloop_ind_case_161[12] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
646 |
11, 0, -4, -14, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
647 |
-4, -10, -4, 1, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
648 |
49, 59, 60, 65, |
0 | 649 |
}; |
650 |
||
541 | 651 |
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
|
652 |
|
0 | 653 |
dir = Random() & 3; |
654 |
||
655 |
v = CreateEffectVehicleAbove( |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
656 |
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
|
657 |
TileY(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 4], |
0 | 658 |
_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
|
659 |
EV_BUBBLE |
0 | 660 |
); |
661 |
||
2639 | 662 |
if (v != NULL) v->u.special.unk2 = dir; |
0 | 663 |
} |
664 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
665 |
static void TileLoop_Industry(TileIndex tile) |
0 | 666 |
{ |
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
|
667 |
IndustryGfx newgfx; |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
668 |
IndustryGfx gfx; |
0 | 669 |
|
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
670 |
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
|
671 |
MakeIndustryTileBigger(tile); |
0 | 672 |
return; |
673 |
} |
|
674 |
||
2639 | 675 |
if (_game_mode == GM_EDITOR) return; |
0 | 676 |
|
677 |
TransportIndustryGoods(tile); |
|
678 |
||
6631
dc3480a670cc
(svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents:
6609
diff
changeset
|
679 |
newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next; |
7239
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
680 |
if (newgfx != INDUSTRYTILE_NOANIM) { |
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
|
681 |
ResetIndustryConstructionStage(tile); |
3331 | 682 |
SetIndustryGfx(tile, newgfx); |
0 | 683 |
MarkTileDirtyByTile(tile); |
684 |
return; |
|
685 |
} |
|
686 |
||
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
687 |
gfx = GetIndustryGfx(tile); |
0 | 688 |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
689 |
switch (gfx) { |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
690 |
case GFX_OILRIG_1: // coast line at oilrigs |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
691 |
case GFX_OILRIG_2: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
692 |
case GFX_OILRIG_3: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
693 |
case GFX_OILRIG_4: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
694 |
case GFX_OILRIG_5: |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
695 |
TileLoop_Water(tile); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
696 |
break; |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
697 |
|
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
698 |
case GFX_COAL_MINE_TOWER_NOT_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
699 |
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
700 |
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
701 |
if (!(_tick_counter & 0x400) && CHANCE16(1, 2)) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
702 |
switch (gfx) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
703 |
case GFX_COAL_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COAL_MINE_TOWER_ANIMATED; break; |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
704 |
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break; |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
705 |
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_ANIMATED; break; |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
706 |
} |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
707 |
SetIndustryGfx(tile, gfx); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
708 |
SetIndustryAnimationState(tile, 0x80); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
709 |
AddAnimatedTile(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
710 |
} |
0 | 711 |
break; |
712 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
713 |
case GFX_OILWELL_NOT_ANIMATED: |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
714 |
if (CHANCE16(1, 6)) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
715 |
SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
716 |
SetIndustryAnimationState(tile, 0); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
717 |
AddAnimatedTile(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
718 |
} |
0 | 719 |
break; |
720 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
721 |
case GFX_COAL_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
722 |
case GFX_COPPER_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
723 |
case GFX_GOLD_MINE_TOWER_ANIMATED: |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
724 |
if (!(_tick_counter & 0x400)) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
725 |
switch (gfx) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
726 |
case GFX_COAL_MINE_TOWER_ANIMATED: gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED; break; |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
727 |
case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break; |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
728 |
case GFX_GOLD_MINE_TOWER_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED; break; |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
729 |
} |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
730 |
SetIndustryGfx(tile, gfx); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
731 |
SetIndustryCompleted(tile, true); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
732 |
SetIndustryConstructionStage(tile, 3); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
733 |
DeleteAnimatedTile(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
734 |
} |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
735 |
break; |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
736 |
|
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
737 |
case GFX_POWERPLANT_SPARKS: |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6964
diff
changeset
|
738 |
if (CHANCE16(1, 3)) { |
541 | 739 |
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile); |
0 | 740 |
AddAnimatedTile(tile); |
741 |
} |
|
742 |
break; |
|
743 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
744 |
case GFX_COPPER_MINE_CHIMNEY: |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
745 |
CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE); |
2639 | 746 |
break; |
0 | 747 |
|
748 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
749 |
case GFX_TOY_FACTORY: { |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
750 |
Industry *i = GetIndustryByTile(tile); |
0 | 751 |
if (i->was_cargo_delivered) { |
752 |
i->was_cargo_delivered = false; |
|
3538
3eb71c726341
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
753 |
SetIndustryAnimationLoop(tile, 0); |
0 | 754 |
AddAnimatedTile(tile); |
755 |
} |
|
756 |
} |
|
757 |
break; |
|
758 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
759 |
case GFX_BUBBLE_GENERATOR: |
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
760 |
TileLoopIndustry_BubbleGenerator(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
761 |
break; |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
762 |
|
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
763 |
case GFX_TOFFEE_QUARY: |
0 | 764 |
AddAnimatedTile(tile); |
765 |
break; |
|
766 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
767 |
case GFX_SUGAR_MINE_SIEVE: |
2639 | 768 |
if (CHANCE16(1, 3)) AddAnimatedTile(tile); |
0 | 769 |
break; |
770 |
} |
|
771 |
} |
|
772 |
||
773 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
774 |
static void ClickTile_Industry(TileIndex tile) |
0 | 775 |
{ |
3314
b8b234d4584f
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
776 |
ShowIndustryViewWindow(GetIndustryIndex(tile)); |
0 | 777 |
} |
778 |
||
7179
3e123c2b7c93
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
7152
diff
changeset
|
779 |
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode) |
0 | 780 |
{ |
781 |
return 0; |
|
782 |
} |
|
783 |
||
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
|
784 |
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) |
0 | 785 |
{ |
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
786 |
const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type); |
2630 | 787 |
|
0 | 788 |
b[0] = i->produced_cargo[0]; |
789 |
b[1] = i->produced_cargo[1]; |
|
790 |
} |
|
791 |
||
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
|
792 |
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 793 |
{ |
794 |
/* not used */ |
|
795 |
} |
|
796 |
||
797 |
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; |
|
798 |
||
1048 | 799 |
static bool IsBadFarmFieldTile(TileIndex tile) |
0 | 800 |
{ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
801 |
switch (GetTileType(tile)) { |
5935
6f5ae5d8d407
(svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents:
5919
diff
changeset
|
802 |
case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); |
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
|
803 |
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
|
804 |
default: return true; |
0 | 805 |
} |
806 |
} |
|
807 |
||
1048 | 808 |
static bool IsBadFarmFieldTile2(TileIndex tile) |
0 | 809 |
{ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
810 |
switch (GetTileType(tile)) { |
5935
6f5ae5d8d407
(svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents:
5919
diff
changeset
|
811 |
case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); |
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
|
812 |
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
|
813 |
default: return true; |
0 | 814 |
} |
815 |
} |
|
816 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
817 |
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direction) |
0 | 818 |
{ |
819 |
do { |
|
820 |
tile = TILE_MASK(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
821 |
|
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
|
822 |
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
823 |
byte or_ = type; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
824 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
825 |
if (or_ == 1 && CHANCE16(1, 7)) or_ = 2; |
0 | 826 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
827 |
if (direction == AXIS_X) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
828 |
SetFenceSE(tile, or_); |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
829 |
} else { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
830 |
SetFenceSW(tile, or_); |
0 | 831 |
} |
832 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
833 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
834 |
tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 835 |
} while (--size); |
836 |
} |
|
837 |
||
4330
7306bda145ab
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4329
diff
changeset
|
838 |
static void PlantFarmField(TileIndex tile, IndustryID industry) |
0 | 839 |
{ |
840 |
uint size_x, size_y; |
|
841 |
uint32 r; |
|
2133 | 842 |
uint count; |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
843 |
uint counter; |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
844 |
uint field_type; |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
845 |
int type; |
0 | 846 |
|
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
847 |
if (_opt.landscape == LT_ARCTIC) { |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6633
diff
changeset
|
848 |
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine()) |
0 | 849 |
return; |
850 |
} |
|
851 |
||
852 |
/* determine field size */ |
|
853 |
r = (Random() & 0x303) + 0x404; |
|
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
854 |
if (_opt.landscape == LT_ARCTIC) r += 0x404; |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
855 |
size_x = GB(r, 0, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
856 |
size_y = GB(r, 8, 8); |
0 | 857 |
|
858 |
/* offset tile to match size */ |
|
1981 | 859 |
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
|
860 |
|
0 | 861 |
/* check the amount of bad tiles */ |
862 |
count = 0; |
|
863 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
864 |
cur_tile = TILE_MASK(cur_tile); |
|
865 |
count += IsBadFarmFieldTile(cur_tile); |
|
866 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
2133 | 867 |
if (count * 2 >= size_x * size_y) return; |
0 | 868 |
|
869 |
/* determine type of field */ |
|
870 |
r = Random(); |
|
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
871 |
counter = GB(r, 5, 3); |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
872 |
field_type = GB(r, 8, 8) * 9 >> 8; |
0 | 873 |
|
874 |
/* make field */ |
|
875 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
876 |
cur_tile = TILE_MASK(cur_tile); |
|
877 |
if (!IsBadFarmFieldTile2(cur_tile)) { |
|
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
878 |
MakeField(cur_tile, field_type, industry); |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
879 |
SetClearCounter(cur_tile, counter); |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
880 |
MarkTileDirtyByTile(cur_tile); |
0 | 881 |
} |
882 |
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
|
883 |
|
0 | 884 |
type = 3; |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
885 |
if (_opt.landscape != LT_ARCTIC && _opt.landscape != LT_TROPIC) { |
0 | 886 |
type = _plantfarmfield_type[Random() & 0xF]; |
887 |
} |
|
888 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
889 |
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
|
890 |
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
|
891 |
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
|
892 |
SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X); |
0 | 893 |
} |
894 |
||
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
895 |
void PlantRandomFarmField(const Industry *i) |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
896 |
{ |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
897 |
int x = i->width / 2 + Random() % 31 - 16; |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
898 |
int y = i->height / 2 + Random() % 31 - 16; |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
899 |
|
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
900 |
TileIndex tile = TileAddWrap(i->xy, x, y); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
901 |
|
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
902 |
if (tile != INVALID_TILE) PlantFarmField(tile, i->index); |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
903 |
} |
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
904 |
|
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
905 |
static void MaybePlantFarmField(const Industry *i) |
0 | 906 |
{ |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
907 |
if (CHANCE16(1, 8)) PlantRandomFarmField(i); |
0 | 908 |
} |
909 |
||
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
910 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
911 |
* Search callback function for ChopLumberMillTrees |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
912 |
* @param tile to test |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
913 |
* @param data that is passed by the caller. In this case, nothing |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
914 |
* @return the result of the test |
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
915 |
*/ |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
916 |
static bool SearchLumberMillTrees(TileIndex tile, uint32 data) |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
917 |
{ |
6160
126831e48987
(svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents:
6135
diff
changeset
|
918 |
if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees |
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
919 |
PlayerID old_player = _current_player; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
920 |
/* found a tree */ |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
921 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
922 |
_current_player = OWNER_NONE; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
923 |
_industry_sound_ctr = 1; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
924 |
_industry_sound_tile = tile; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
925 |
SndPlayTileFx(SND_38_CHAINSAW, tile); |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
926 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
927 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
928 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
929 |
_current_player = old_player; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
930 |
return true; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
931 |
} |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
932 |
return false; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
933 |
} |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
934 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
935 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
936 |
* Perform a circular search around the Lumber Mill in order to find trees to cut |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
937 |
* @param i industry |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
938 |
*/ |
0 | 939 |
static void ChopLumberMillTrees(Industry *i) |
940 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
941 |
TileIndex tile = i->xy; |
2639 | 942 |
|
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
943 |
if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed |
0 | 944 |
|
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
945 |
if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles to search |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
946 |
i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo |
0 | 947 |
} |
948 |
||
949 |
static void ProduceIndustryGoods(Industry *i) |
|
950 |
{ |
|
951 |
uint32 r; |
|
952 |
uint num; |
|
7151
d811c3f808bd
(svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents:
7135
diff
changeset
|
953 |
const IndustrySpec *indsp = GetIndustrySpec(i->type); |
0 | 954 |
|
955 |
/* play a sound? */ |
|
956 |
if ((i->counter & 0x3F) == 0) { |
|
7151
d811c3f808bd
(svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents:
7135
diff
changeset
|
957 |
if (CHANCE16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) { |
0 | 958 |
SndPlayTileFx( |
7151
d811c3f808bd
(svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents:
7135
diff
changeset
|
959 |
(SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]), |
0 | 960 |
i->xy); |
961 |
} |
|
962 |
} |
|
963 |
||
964 |
i->counter--; |
|
965 |
||
966 |
/* produce some cargo */ |
|
967 |
if ((i->counter & 0xFF) == 0) { |
|
7151
d811c3f808bd
(svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents:
7135
diff
changeset
|
968 |
IndustyBehaviour indbehav = indsp->behaviour; |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
969 |
i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]); |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
970 |
i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]); |
0 | 971 |
|
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
972 |
if (indbehav & INDUSTRYBEH_PLANT_FIELDS) { |
0 | 973 |
MaybePlantFarmField(i); |
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
974 |
} else if ((indbehav & INDUSTRYBEH_CUT_TREES) && (i->counter & 0x1FF) == 0) { |
0 | 975 |
ChopLumberMillTrees(i); |
2639 | 976 |
} |
0 | 977 |
} |
978 |
} |
|
979 |
||
6573 | 980 |
void OnTick_Industry() |
0 | 981 |
{ |
982 |
Industry *i; |
|
983 |
||
984 |
if (_industry_sound_ctr != 0) { |
|
985 |
_industry_sound_ctr++; |
|
986 |
||
987 |
if (_industry_sound_ctr == 75) { |
|
541 | 988 |
SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile); |
0 | 989 |
} 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
|
990 |
_industry_sound_ctr = 0; |
541 | 991 |
SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile); |
0 | 992 |
} |
993 |
} |
|
994 |
||
2639 | 995 |
if (_game_mode == GM_EDITOR) return; |
0 | 996 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
997 |
FOR_ALL_INDUSTRIES(i) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
998 |
ProduceIndustryGoods(i); |
0 | 999 |
} |
1000 |
} |
|
1001 |
||
1002 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1003 |
static bool CheckNewIndustry_NULL(TileIndex tile) |
0 | 1004 |
{ |
1005 |
return true; |
|
1006 |
} |
|
1007 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1008 |
static bool CheckNewIndustry_Forest(TileIndex tile) |
0 | 1009 |
{ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
1010 |
if (_opt.landscape == LT_ARCTIC) { |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6633
diff
changeset
|
1011 |
if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) { |
0 | 1012 |
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED; |
1013 |
return false; |
|
1014 |
} |
|
1015 |
} |
|
1016 |
return true; |
|
1017 |
} |
|
1018 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1019 |
static bool CheckNewIndustry_OilRefinery(TileIndex tile) |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1020 |
{ |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1021 |
if (_game_mode == GM_EDITOR) return true; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1022 |
if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true; |
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1023 |
|
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1024 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1025 |
return false; |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1026 |
} |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1027 |
|
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1028 |
extern bool _ignore_restrictions; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1029 |
|
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1030 |
static bool CheckNewIndustry_OilRig(TileIndex tile) |
0 | 1031 |
{ |
2639 | 1032 |
if (_game_mode == GM_EDITOR && _ignore_restrictions) return true; |
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1033 |
if (TileHeight(tile) == 0 && |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1034 |
DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true; |
0 | 1035 |
|
1036 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
|
1037 |
return false; |
|
1038 |
} |
|
1039 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1040 |
static bool CheckNewIndustry_Farm(TileIndex tile) |
0 | 1041 |
{ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
1042 |
if (_opt.landscape == LT_ARCTIC) { |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6633
diff
changeset
|
1043 |
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) { |
0 | 1044 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1045 |
return false; |
|
1046 |
} |
|
1047 |
} |
|
1048 |
return true; |
|
1049 |
} |
|
1050 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1051 |
static bool CheckNewIndustry_Plantation(TileIndex tile) |
0 | 1052 |
{ |
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
|
1053 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
0 | 1054 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1055 |
return false; |
|
1056 |
} |
|
1057 |
||
1058 |
return true; |
|
1059 |
} |
|
1060 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1061 |
static bool CheckNewIndustry_Water(TileIndex tile) |
0 | 1062 |
{ |
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
|
1063 |
if (GetTropicZone(tile) != TROPICZONE_DESERT) { |
0 | 1064 |
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; |
1065 |
return false; |
|
1066 |
} |
|
1067 |
||
1068 |
return true; |
|
1069 |
} |
|
1070 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1071 |
static bool CheckNewIndustry_Lumbermill(TileIndex tile) |
0 | 1072 |
{ |
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
|
1073 |
if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) { |
0 | 1074 |
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; |
1075 |
return false; |
|
1076 |
} |
|
1077 |
return true; |
|
1078 |
} |
|
1079 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1080 |
static bool CheckNewIndustry_BubbleGen(TileIndex tile) |
0 | 1081 |
{ |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
1082 |
return GetTileZ(tile) <= TILE_HEIGHT * 4; |
0 | 1083 |
} |
1084 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1085 |
typedef bool CheckNewIndustryProc(TileIndex tile); |
3663
50fbc1639a3f
(svn r4578) CodeChange : Cleanup of industry_cmd (Step-2).
belugas
parents:
3662
diff
changeset
|
1086 |
static CheckNewIndustryProc * const _check_new_industry_procs[CHECK_END] = { |
0 | 1087 |
CheckNewIndustry_NULL, |
1088 |
CheckNewIndustry_Forest, |
|
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1089 |
CheckNewIndustry_OilRefinery, |
0 | 1090 |
CheckNewIndustry_Farm, |
1091 |
CheckNewIndustry_Plantation, |
|
1092 |
CheckNewIndustry_Water, |
|
1093 |
CheckNewIndustry_Lumbermill, |
|
1094 |
CheckNewIndustry_BubbleGen, |
|
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1095 |
CheckNewIndustry_OilRig |
0 | 1096 |
}; |
1097 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1098 |
static bool CheckSuitableIndustryPos(TileIndex tile) |
0 | 1099 |
{ |
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
|
1100 |
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
|
1101 |
uint y = TileY(tile); |
0 | 1102 |
|
2639 | 1103 |
if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { |
0 | 1104 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1105 |
return false; |
|
1106 |
} |
|
1107 |
||
1108 |
return true; |
|
1109 |
} |
|
1110 |
||
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1111 |
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type) |
0 | 1112 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1113 |
const Town *t; |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1114 |
const Industry *i; |
0 | 1115 |
|
1116 |
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
|
1117 |
|
2639 | 1118 |
if (_patches.multiple_industry_per_town) return t; |
0 | 1119 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1120 |
FOR_ALL_INDUSTRIES(i) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1121 |
if (i->type == (byte)type && |
0 | 1122 |
i->town == t) { |
1123 |
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; |
|
1124 |
return NULL; |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
1128 |
return t; |
|
1129 |
} |
|
1130 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1131 |
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type) |
0 | 1132 |
{ |
1133 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1134 |
||
1135 |
do { |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1136 |
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
|
1137 |
|
0 | 1138 |
if (!IsValidTile(cur_tile)) { |
3440 | 1139 |
if (it->gfx == 0xff) continue; |
0 | 1140 |
return false; |
1141 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1142 |
|
3440 | 1143 |
if (it->gfx == 0xFF) { |
3296
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1144 |
if (!IsTileType(cur_tile, MP_WATER) || |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1145 |
GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) { |
3296
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1146 |
return false; |
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1147 |
} |
0 | 1148 |
} else { |
2639 | 1149 |
if (!EnsureNoVehicle(cur_tile)) return false; |
7389
d8bc6472130b
(svn r10140) -Fix [FS#867]: an industry could overbuild a bridge.
rubidium
parents:
7355
diff
changeset
|
1150 |
if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false; |
d8bc6472130b
(svn r10140) -Fix [FS#867]: an industry could overbuild a bridge.
rubidium
parents:
7355
diff
changeset
|
1151 |
|
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1152 |
IndustyBehaviour ind_behav = GetIndustrySpec(type)->behaviour; |
0 | 1153 |
|
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1154 |
if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) { |
6934
ec763aa1cab5
(svn r9574) -Fix(r9520, FS#721): Oil Rig ( or industry with behaviour INDUSTRYBEH_BUILT_ONWATER) should check all tiles before leaving the test. A tile in water does not ensure that all required tiles will necessary be on water.
belugas
parents:
6929
diff
changeset
|
1155 |
/* As soon as the tile is not water, bail out. |
ec763aa1cab5
(svn r9574) -Fix(r9520, FS#721): Oil Rig ( or industry with behaviour INDUSTRYBEH_BUILT_ONWATER) should check all tiles before leaving the test. A tile in water does not ensure that all required tiles will necessary be on water.
belugas
parents:
6929
diff
changeset
|
1156 |
* But that does not mean the search is over. You have |
ec763aa1cab5
(svn r9574) -Fix(r9520, FS#721): Oil Rig ( or industry with behaviour INDUSTRYBEH_BUILT_ONWATER) should check all tiles before leaving the test. A tile in water does not ensure that all required tiles will necessary be on water.
belugas
parents:
6929
diff
changeset
|
1157 |
* to make sure every tile of the industry will be only water*/ |
ec763aa1cab5
(svn r9574) -Fix(r9520, FS#721): Oil Rig ( or industry with behaviour INDUSTRYBEH_BUILT_ONWATER) should check all tiles before leaving the test. A tile in water does not ensure that all required tiles will necessary be on water.
belugas
parents:
6929
diff
changeset
|
1158 |
if (!IsClearWaterTile(cur_tile)) return false; |
0 | 1159 |
} else { |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1160 |
Slope tileh; |
0 | 1161 |
|
5056
20369e09627b
(svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents:
4976
diff
changeset
|
1162 |
if (IsClearWaterTile(cur_tile)) return false; |
3296
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1163 |
|
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1164 |
tileh = GetTileSlope(cur_tile, NULL); |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1165 |
if (IsSteepSlope(tileh)) return false; |
3296
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1166 |
|
4301
1352486059b3
(svn r5948) -Fix: inversed check caused oringal land-generator to put industries on mountains (tnx Darkvater)
truelight
parents:
4300
diff
changeset
|
1167 |
if (_patches.land_generator != LG_TERRAGENESIS || !_generating_world) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1168 |
/* It is almost impossible to have a fully flat land in TG, so what we |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1169 |
* do is that we check if we can make the land flat later on. See |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1170 |
* CheckIfCanLevelIndustryPlatform(). */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1171 |
if (tileh != SLOPE_FLAT) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1172 |
Slope t; |
6418
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
1173 |
byte bits = GetIndustryTileSpec(it->gfx)->slopes_refused; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1174 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1175 |
if (bits & 0x10) return false; |
0 | 1176 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1177 |
t = ComplementSlope(tileh); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1178 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1179 |
if (bits & 1 && (t & SLOPE_NW)) return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1180 |
if (bits & 2 && (t & SLOPE_NE)) return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1181 |
if (bits & 4 && (t & SLOPE_SW)) return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1182 |
if (bits & 8 && (t & SLOPE_SE)) return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1183 |
} |
0 | 1184 |
} |
1185 |
||
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1186 |
if (ind_behav & INDUSTRYBEH_ONLY_INTOWN) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1187 |
if (!IsTileType(cur_tile, MP_HOUSE)) { |
0 | 1188 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
1189 |
return false; |
|
1190 |
} |
|
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1191 |
} else { |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1192 |
if (ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) { |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1193 |
if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear; |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1194 |
} else { |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1195 |
do_clear: |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1196 |
if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1197 |
return false; |
0 | 1198 |
} |
1199 |
} |
|
1200 |
} |
|
1201 |
} |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1202 |
} while ((++it)->ti.x != -0x80); |
0 | 1203 |
|
1204 |
return true; |
|
1205 |
} |
|
1206 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1207 |
static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1208 |
{ |
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1209 |
if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1210 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1211 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1212 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1213 |
|
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1214 |
if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1215 |
_error_message = STR_0239_SITE_UNSUITABLE; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1216 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1217 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1218 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1219 |
return true; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1220 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1221 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1222 |
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1223 |
{ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1224 |
int size_x, size_y; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1225 |
uint curh; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1226 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1227 |
size_x = 2; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1228 |
size_y = 2; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1229 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1230 |
/* Check if we don't leave the map */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1231 |
if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1232 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1233 |
tile += TileDiffXY(-1, -1); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1234 |
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1235 |
curh = TileHeight(tile_walk); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1236 |
/* Is the tile clear? */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1237 |
if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1238 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1239 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1240 |
/* Don't allow too big of a change if this is the sub-tile check */ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1241 |
if (internal != 0 && delta(curh, height) > 1) return false; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1242 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1243 |
/* Different height, so the surrounding tiles of this tile |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1244 |
* has to be correct too (in level, or almost in level) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1245 |
* else you get a chain-reaction of terraforming. */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1246 |
if (internal == 0 && curh != height) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1247 |
if (!CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1)) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1248 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1249 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1250 |
} END_TILE_LOOP(tile_walk, size_x, size_y, tile); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1251 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1252 |
return true; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1253 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1254 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1255 |
/** |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1256 |
* This function tries to flatten out the land below an industry, without |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1257 |
* damaging the surroundings too much. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1258 |
*/ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1259 |
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const IndustryTileTable* it, int type) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1260 |
{ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1261 |
const int MKEND = -0x80; // used for last element in an IndustryTileTable (see build_industry.h) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1262 |
int max_x = 0; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1263 |
int max_y = 0; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1264 |
TileIndex cur_tile; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1265 |
uint size_x, size_y; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1266 |
uint h, curh; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1267 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1268 |
/* Finds dimensions of largest variant of this industry */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1269 |
do { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1270 |
if (it->ti.x > max_x) max_x = it->ti.x; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1271 |
if (it->ti.y > max_y) max_y = it->ti.y; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1272 |
} while ((++it)->ti.x != MKEND); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1273 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1274 |
/* Remember level height */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1275 |
h = TileHeight(tile); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1276 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1277 |
/* Check that all tiles in area and surrounding are clear |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1278 |
* this determines that there are no obstructing items */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1279 |
cur_tile = tile + TileDiffXY(-1, -1); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1280 |
size_x = max_x + 4; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1281 |
size_y = max_y + 4; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1282 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1283 |
/* Check if we don't leave the map */ |
4313
bbd84f6e21b0
(svn r5966) -Fix: prevent that the industry placement's terraforming checks can leave the map on the southern side
rubidium
parents:
4301
diff
changeset
|
1284 |
if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1285 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1286 |
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1287 |
curh = TileHeight(tile_walk); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1288 |
if (curh != h) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1289 |
/* This tile needs terraforming. Check if we can do that without |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1290 |
* damaging the surroundings too much. */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1291 |
if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1292 |
/* This is not 100% correct check, but the best we can do without modifying the map. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1293 |
* What is missing, is if the difference in height is more than 1.. */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1294 |
if (CmdFailed(DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1295 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1296 |
} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1297 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1298 |
if (flags & DC_EXEC) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1299 |
/* Terraform the land under the industry */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1300 |
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1301 |
curh = TileHeight(tile_walk); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1302 |
while (curh != h) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1303 |
/* We give the terraforming for free here, because we can't calculate |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1304 |
* exact cost in the test-round, and as we all know, that will cause |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1305 |
* a nice assert if they don't match ;) */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1306 |
DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1307 |
curh += (curh > h) ? -1 : 1; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1308 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1309 |
} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1310 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1311 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1312 |
return true; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1313 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1314 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1315 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1316 |
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) |
0 | 1317 |
{ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1318 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1319 |
const Industry *i; |
0 | 1320 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1321 |
/* accepting industries won't be close, not even with patch */ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1322 |
if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID) |
0 | 1323 |
return true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1324 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1325 |
FOR_ALL_INDUSTRIES(i) { |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1326 |
/* check if an industry that accepts the same goods is nearby */ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1327 |
if (DistanceMax(tile, i->xy) <= 14 && |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1328 |
indspec->accepts_cargo[0] != CT_INVALID && |
7355
8fd37a636f6d
(svn r10099) -Fix(r9867, FS860): Use the specs of the to-be-created industry instead of the scanned industry
belugas
parents:
7335
diff
changeset
|
1329 |
indspec->accepts_cargo[0] == GetIndustrySpec(i->type)->accepts_cargo[0] && ( |
2639 | 1330 |
_game_mode != GM_EDITOR || |
1331 |
!_patches.same_industry_close || |
|
1332 |
!_patches.multiple_industry_per_town |
|
1333 |
)) { |
|
1334 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
|
1335 |
return false; |
|
1336 |
} |
|
0 | 1337 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1338 |
/* check "not close to" field. */ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1339 |
if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) && |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
1340 |
DistanceMax(tile, i->xy) <= 14) { |
0 | 1341 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1342 |
return false; |
|
1343 |
} |
|
1344 |
} |
|
1345 |
return true; |
|
1346 |
} |
|
1347 |
||
6573 | 1348 |
static Industry *AllocateIndustry() |
0 | 1349 |
{ |
1350 |
Industry *i; |
|
1351 |
||
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1352 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1353 |
* TODO - This is just a temporary stage, this will be removed. */ |
4976
a0d7f63c35b5
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1354 |
for (i = GetIndustry(0); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1355 |
IndustryID index = i->index; |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1356 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1357 |
if (IsValidIndustry(i)) continue; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1358 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1359 |
memset(i, 0, sizeof(*i)); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1360 |
i->index = index; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1361 |
|
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1362 |
return i; |
0 | 1363 |
} |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1364 |
|
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1365 |
/* Check if we can add a block to the pool */ |
4976
a0d7f63c35b5
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1366 |
return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL; |
0 | 1367 |
} |
1368 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1369 |
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, Owner owner) |
0 | 1370 |
{ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1371 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
0 | 1372 |
uint32 r; |
1373 |
int j; |
|
1374 |
||
1375 |
i->xy = tile; |
|
1376 |
i->width = i->height = 0; |
|
1377 |
i->type = type; |
|
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
1378 |
IncIndustryTypeCount(type); |
0 | 1379 |
|
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1380 |
i->production_rate[0] = indspec->production_rate[0]; |
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1381 |
i->production_rate[1] = indspec->production_rate[1]; |
0 | 1382 |
|
1383 |
if (_patches.smooth_economy) { |
|
1384 |
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); |
|
1385 |
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); |
|
1386 |
} |
|
1387 |
||
1388 |
i->town = t; |
|
1389 |
i->owner = owner; |
|
1390 |
||
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
|
1391 |
r = Random(); |
4942
f990abfa4438
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
1392 |
i->random_color = GB(r, 8, 4); |
2492
3f32f9f9fd78
(svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents:
2484
diff
changeset
|
1393 |
i->counter = GB(r, 0, 12); |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1394 |
i->produced_cargo_waiting[0] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1395 |
i->produced_cargo_waiting[1] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1396 |
i->incoming_cargo_waiting[0] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1397 |
i->incoming_cargo_waiting[1] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1398 |
i->incoming_cargo_waiting[2] = 0; |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1399 |
i->this_month_production[0] = 0; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1400 |
i->this_month_production[1] = 0; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1401 |
i->this_month_transported[0] = 0; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1402 |
i->this_month_transported[1] = 0; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1403 |
i->last_month_pct_transported[0] = 0; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1404 |
i->last_month_pct_transported[1] = 0; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1405 |
i->last_month_transported[0] = 0; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1406 |
i->last_month_transported[1] = 0; |
0 | 1407 |
i->was_cargo_delivered = false; |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4328
diff
changeset
|
1408 |
i->last_prod_year = _cur_year; |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1409 |
i->last_month_production[0] = i->production_rate[0] * 8; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1410 |
i->last_month_production[1] = i->production_rate[1] * 8; |
0 | 1411 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1412 |
if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1413 |
|
0 | 1414 |
i->prod_level = 0x10; |
1415 |
||
1416 |
do { |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1417 |
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1418 |
|
3440 | 1419 |
if (it->gfx != 0xFF) { |
0 | 1420 |
byte size; |
1421 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1422 |
size = it->ti.x; |
0 | 1423 |
if (size > i->width) i->width = size; |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1424 |
size = it->ti.y; |
0 | 1425 |
if (size > i->height)i->height = size; |
1426 |
||
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
|
1427 |
DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 1428 |
|
3440 | 1429 |
MakeIndustry(cur_tile, i->index, it->gfx); |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
1430 |
if (_generating_world) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
1431 |
SetIndustryConstructionCounter(cur_tile, 3); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
1432 |
SetIndustryConstructionStage(cur_tile, 2); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
1433 |
} |
0 | 1434 |
} |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1435 |
} while ((++it)->ti.x != -0x80); |
0 | 1436 |
|
1437 |
i->width++; |
|
1438 |
i->height++; |
|
1439 |
||
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1440 |
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) { |
4328
23dd79414386
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents:
4326
diff
changeset
|
1441 |
for (j = 0; j != 50; j++) PlantRandomFarmField(i); |
0 | 1442 |
} |
1443 |
_industry_sort_dirty = true; |
|
1444 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1445 |
} |
|
1446 |
||
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1447 |
/** Helper function for Build/Fund an industry |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1448 |
* @param tile tile where industry is built |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1449 |
* @param type of industry to build |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1450 |
* @param flags of operations to conduct |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1451 |
* @param indspec pointer to industry specifications |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1452 |
* @param it pointer to list of tile type to build |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1453 |
* @return the pointer of the newly created industry, or NULL if it failed |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1454 |
*/ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1455 |
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, const IndustryTileTable *it) |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1456 |
{ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1457 |
const Town *t; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1458 |
Industry *i; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1459 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1460 |
if (!CheckIfIndustryTilesAreFree(tile, it, type)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1461 |
if (_patches.land_generator == LG_TERRAGENESIS && _generating_world && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1462 |
if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1463 |
if (!CheckIfTooCloseToIndustry(tile, type)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1464 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1465 |
t = CheckMultipleIndustryInTown(tile, type); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1466 |
if (t == NULL) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1467 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1468 |
if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1469 |
if (!CheckSuitableIndustryPos(tile)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1470 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1471 |
i = AllocateIndustry(); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1472 |
if (i == NULL) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1473 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1474 |
if (flags & DC_EXEC) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1475 |
CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1476 |
DoCreateNewIndustry(i, tile, type, it, t, OWNER_NONE); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1477 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1478 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1479 |
return i; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1480 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1481 |
|
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
|
1482 |
/** 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
|
1483 |
* @param tile tile where industry is built |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1484 |
* @param flags of operations to conduct |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1485 |
* @param p1 industry type see build_industry.h and see industry.h |
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
|
1486 |
* @param p2 unused |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1487 |
* @return index of the newly create industry, or CMD_ERROR if it failed |
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
|
1488 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7406
diff
changeset
|
1489 |
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1490 |
{ |
1491 |
int num; |
|
1492 |
const IndustryTileTable * const *itt; |
|
1493 |
const IndustryTileTable *it; |
|
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1494 |
const IndustrySpec *indspec; |
0 | 1495 |
|
1496 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1497 |
||
4965
9d4ad0851fde
(svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents:
4942
diff
changeset
|
1498 |
indspec = GetIndustrySpec(p1); |
2639 | 1499 |
|
4965
9d4ad0851fde
(svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents:
4942
diff
changeset
|
1500 |
/* Check if the to-be built/founded industry is available for this climate. */ |
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1501 |
if (!indspec->enabled) { |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1502 |
return CMD_ERROR; |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1503 |
} |
0 | 1504 |
|
2638
0c9b00251fce
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1505 |
/* 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
|
1506 |
* 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
|
1507 |
* 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
|
1508 |
if (!_patches.build_rawmaterial_ind && |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1509 |
indspec->accepts_cargo[0] == CT_INVALID && |
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1510 |
indspec->accepts_cargo[1] == CT_INVALID && |
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1511 |
indspec->accepts_cargo[2] == CT_INVALID && |
7254
6af772949b50
(svn r9993) -Fix (r9992): smallish typos resulting in compile time errors.
rubidium
parents:
7253
diff
changeset
|
1512 |
!(indspec->behaviour & INDUSTRYBEH_CUT_TREES)) { |
2638
0c9b00251fce
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1513 |
return CMD_ERROR; |
0c9b00251fce
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1514 |
} |
0 | 1515 |
|
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1516 |
num = indspec->num_table; |
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1517 |
itt = indspec->table; |
0 | 1518 |
|
1519 |
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
|
1520 |
if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1521 |
} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1)); |
0 | 1522 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1523 |
if (CreateNewIndustryHelper(tile, p1, flags, indspec, it) == NULL) return CMD_ERROR; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1524 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
1525 |
return CommandCost((_price.build_industry >> 8) * indspec->cost_multiplier); |
0 | 1526 |
} |
1527 |
||
1528 |
||
3538
3eb71c726341
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
1529 |
Industry *CreateNewIndustry(TileIndex tile, IndustryType type) |
0 | 1530 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1531 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1532 |
const IndustryTileTable *it = indspec->table[RandomRange(indspec->num_table)]; |
0 | 1533 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1534 |
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, it); |
0 | 1535 |
} |
1536 |
||
7472
95ad05bcff78
(svn r10232) -Fix(r1): _numof_industry_table never was composed of 12 entries. Only 11.
belugas
parents:
7466
diff
changeset
|
1537 |
static const byte _numof_industry_table[5][11] = { |
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1538 |
/* difficulty settings for number of industries */ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1539 |
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //none |
7056
b4f146586c97
(svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents:
7015
diff
changeset
|
1540 |
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //very low |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1541 |
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, //low |
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1542 |
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, //normal |
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1543 |
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, //high |
0 | 1544 |
}; |
1545 |
||
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1546 |
/** This function is the one who really do the creation work |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1547 |
* of random industries during game creation |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1548 |
* @param type IndustryType of the desired industry |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1549 |
* @param amount of industries that need to be built */ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1550 |
static void PlaceInitialIndustry(IndustryType type, int amount) |
0 | 1551 |
{ |
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
|
1552 |
int num = _numof_industry_table[_opt.diff.number_industries][amount]; |
7253
18dca03d0c67
(svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents:
7245
diff
changeset
|
1553 |
const IndustrySpec *ind_spc = GetIndustrySpec(type); |
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
|
1554 |
|
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1555 |
/* These are always placed next to the coastline, so we scale by the perimeter instead. */ |
7253
18dca03d0c67
(svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents:
7245
diff
changeset
|
1556 |
num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1557 |
|
2639 | 1558 |
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
|
1559 |
PlayerID old_player = _current_player; |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1560 |
_current_player = OWNER_NONE; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1561 |
assert(num > 0); |
0 | 1562 |
|
1563 |
do { |
|
2639 | 1564 |
uint i; |
1565 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1566 |
IncreaseGeneratingWorldProgress(GWP_INDUSTRY); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1567 |
|
2639 | 1568 |
for (i = 0; i < 2000; i++) { |
1569 |
if (CreateNewIndustry(RandomTile(), type) != NULL) break; |
|
1570 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1571 |
} while (--num); |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1572 |
|
267 | 1573 |
_current_player = old_player; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1574 |
} |
0 | 1575 |
} |
1576 |
||
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1577 |
/** This function will create ramdon industries during game creation. |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1578 |
* It will scale the amount of industries by map size as well as difficulty level */ |
6573 | 1579 |
void GenerateIndustries() |
0 | 1580 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1581 |
uint i = 0; |
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1582 |
uint8 chance; |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1583 |
IndustryType it; |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1584 |
const IndustrySpec *ind_spc; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1585 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1586 |
/* Find the total amount of industries */ |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
1587 |
for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1588 |
|
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1589 |
ind_spc = GetIndustrySpec(it); |
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1590 |
if (ind_spc->enabled) { |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1591 |
chance = ind_spc->appear_creation[_opt.landscape]; |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1592 |
if (chance > 0) { |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1593 |
/* once the chance of appearance is determind, it have to be scaled by |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1594 |
* the difficulty level. The "chance" in question is more an index into |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1595 |
* the _numof_industry_table,in fact */ |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1596 |
int num = _numof_industry_table[_opt.diff.number_industries][chance]; |
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1597 |
|
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1598 |
/* These are always placed next to the coastline, so we scale by the perimeter instead. */ |
7253
18dca03d0c67
(svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents:
7245
diff
changeset
|
1599 |
num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); |
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1600 |
i += num; |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1601 |
} |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1602 |
} |
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1603 |
} |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1604 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1605 |
SetGeneratingWorldProgress(GWP_INDUSTRY, i); |
0 | 1606 |
|
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
1607 |
for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) { |
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1608 |
/* Once the number of industries has been determined, let's really create them. |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1609 |
* The test for chance allows us to try create industries that are available only |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1610 |
* for this landscape. |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1611 |
* @todo : Do we really have to pass chance as un-scaled value, since we've already |
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1612 |
* processed that scaling above? No, don't think so. Will find a way. */ |
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1613 |
ind_spc = GetIndustrySpec(it); |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1614 |
if (ind_spc->enabled) { |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1615 |
chance = ind_spc->appear_creation[_opt.landscape]; |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1616 |
if (chance > 0) PlaceInitialIndustry(it, chance); |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1617 |
} |
6938
37018cdc1ea3
(svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents:
6934
diff
changeset
|
1618 |
}; |
0 | 1619 |
} |
1620 |
||
3496
2775485abdf6
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1621 |
/* Change industry production or do closure */ |
0 | 1622 |
static void ExtChangeIndustryProduction(Industry *i) |
1623 |
{ |
|
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1624 |
bool closeit = true; |
0 | 1625 |
int j; |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1626 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
0 | 1627 |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1628 |
if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return; |
7578
c9aa99cf6f80
(svn r10347) -Fix [FS#948]: industries with a very low production could never recover when using smooth economy.
rubidium
parents:
7571
diff
changeset
|
1629 |
|
7641
6fb5fa2bab4b
(svn r10419) -Fix (r10418): do not compare bitmasks with HASBIT. Thanks to Maedhros for spotting this.
rubidium
parents:
7640
diff
changeset
|
1630 |
if ((indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) { |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1631 |
for (j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1632 |
uint32 r = Random(); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1633 |
int old_prod, new_prod, percent; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1634 |
int mag; |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1635 |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1636 |
new_prod = old_prod = i->production_rate[j]; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1637 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1638 |
if (CHANCE16I(20, 1024, r)) new_prod -= max(((RandomRange(50) + 10) * old_prod) >> 8, 1U); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1639 |
/* Chance of increasing becomes better when more is transported */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1640 |
if (CHANCE16I(20 + (i->last_month_pct_transported[j] * 20 >> 8), 1024, r >> 16) && |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1641 |
((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) == 0 || _opt.landscape != LT_TEMPERATE)) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1642 |
new_prod += max(((RandomRange(50) + 10) * old_prod) >> 8, 1U); |
0 | 1643 |
} |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1644 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1645 |
new_prod = clamp(new_prod, 1, 255); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1646 |
/* Do not stop closing the industry when it has the lowest possible production rate */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1647 |
if (new_prod == old_prod && old_prod > 1) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1648 |
closeit = false; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1649 |
continue; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1650 |
} |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1651 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1652 |
percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1653 |
i->production_rate[j] = new_prod; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1654 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1655 |
/* Close the industry when it has the lowest possible production rate */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1656 |
if (new_prod > 1) closeit = false; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1657 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1658 |
mag = abs(percent); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1659 |
if (mag >= 10) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1660 |
SetDParam(2, mag); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1661 |
SetDParam(0, GetCargo(indspec->produced_cargo[j])->name); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1662 |
SetDParam(1, i->index); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1663 |
AddNewsItem( |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1664 |
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1665 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ECONOMY, 0), |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1666 |
i->xy + TileDiffXY(1, 1), 0 |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1667 |
); |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1668 |
} |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1669 |
} |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1670 |
} |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1671 |
|
7641
6fb5fa2bab4b
(svn r10419) -Fix (r10418): do not compare bitmasks with HASBIT. Thanks to Maedhros for spotting this.
rubidium
parents:
7640
diff
changeset
|
1672 |
if ((indspec->life_type & INDUSTRYLIFE_PROCESSING) != 0) { |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1673 |
if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180)) closeit = false; |
0 | 1674 |
} |
1675 |
||
3496
2775485abdf6
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1676 |
/* If industry will be closed down, show this */ |
0 | 1677 |
if (closeit) { |
1678 |
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
|
1679 |
SetDParam(0, i->index); |
2639 | 1680 |
AddNewsItem( |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1681 |
indspec->closure_text, |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6964
diff
changeset
|
1682 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), |
2639 | 1683 |
i->xy + TileDiffXY(1, 1), 0 |
1684 |
); |
|
0 | 1685 |
} |
1686 |
} |
|
1687 |
||
1688 |
||
1689 |
static void UpdateIndustryStatistics(Industry *i) |
|
1690 |
{ |
|
1691 |
byte pct; |
|
6963 | 1692 |
bool refresh = false; |
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1693 |
const IndustrySpec *indsp = GetIndustrySpec(i->type); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1694 |
|
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1695 |
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) { |
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1696 |
if (indsp->produced_cargo[j] != CT_INVALID) { |
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1697 |
pct = 0; |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1698 |
if (i->this_month_production[j] != 0) { |
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1699 |
i->last_prod_year = _cur_year; |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1700 |
pct = min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255); |
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1701 |
} |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1702 |
i->last_month_pct_transported[j] = pct; |
0 | 1703 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1704 |
i->last_month_production[j] = i->this_month_production[j]; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1705 |
i->this_month_production[j] = 0; |
0 | 1706 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1707 |
i->last_month_transported[j] = i->this_month_transported[j]; |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1708 |
i->this_month_transported[j] = 0; |
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1709 |
refresh = true; |
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1710 |
} |
0 | 1711 |
} |
1712 |
||
6963 | 1713 |
if (refresh) |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1714 |
InvalidateWindow(WC_INDUSTRY_VIEW, i->index); |
0 | 1715 |
|
2639 | 1716 |
if (i->prod_level == 0) { |
0 | 1717 |
DeleteIndustry(i); |
2639 | 1718 |
} else if (_patches.smooth_economy) { |
0 | 1719 |
ExtChangeIndustryProduction(i); |
2639 | 1720 |
} |
0 | 1721 |
} |
1722 |
||
6927
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1723 |
/** Simple helper that will collect data for the generation of industries */ |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1724 |
struct ProbabilityHelper { |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1725 |
uint16 prob; ///< probability |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1726 |
IndustryType ind; ///< industry id correcponding |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1727 |
}; |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1728 |
|
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1729 |
/** |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1730 |
* Try to create a random industry, during gameplay |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1731 |
*/ |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1732 |
static void MaybeNewIndustry(void) |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1733 |
{ |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1734 |
Industry *ind; //will receive the industry's creation pointer |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1735 |
IndustryType rndtype, j; // Loop controlers |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1736 |
const IndustrySpec *ind_spc; |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1737 |
uint num = 0; |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
1738 |
ProbabilityHelper cumulative_probs[NUM_INDUSTRYTYPES]; // probability collector |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1739 |
uint16 probability_max = 0; |
0 | 1740 |
|
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1741 |
/* Generate a list of all possible industries that can be built. */ |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
1742 |
for (j = 0; j < NUM_INDUSTRYTYPES; j++) { |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1743 |
byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape]; |
0 | 1744 |
|
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1745 |
/* if appearing chance for this landscape is above 0, this industry can be chosen */ |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1746 |
if (chance != 0) { |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1747 |
probability_max += chance; |
6927
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1748 |
/* adds the result for this industry */ |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1749 |
cumulative_probs[num].ind = j; |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1750 |
cumulative_probs[num++].prob = probability_max; |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1751 |
} |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1752 |
} |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1753 |
|
6927
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1754 |
/* Find a random type, with maximum being what has been evaluate above*/ |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1755 |
rndtype = RandomRange(probability_max); |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
1756 |
for (j = 0; j < NUM_INDUSTRYTYPES; j++) { |
6927
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1757 |
/* and choose the index of the industry that matches as close as possible this random type */ |
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1758 |
if (cumulative_probs[j].prob >= rndtype) break; |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1759 |
} |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1760 |
|
6927
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1761 |
ind_spc = GetIndustrySpec(cumulative_probs[j].ind); |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1762 |
/* Check if it is allowed */ |
6886
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1763 |
if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return; |
742e1d75f442
(svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents:
6683
diff
changeset
|
1764 |
if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return; |
0 | 1765 |
|
6927
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1766 |
/* try to create 2000 times this industry */ |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1767 |
num = 2000; |
2639 | 1768 |
for (;;) { |
6927
0ed416264b17
(svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents:
6923
diff
changeset
|
1769 |
ind = CreateNewIndustry(RandomTile(), cumulative_probs[j].ind); |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1770 |
if (ind != NULL) break; |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1771 |
if (--num == 0) return; |
0 | 1772 |
} |
1773 |
||
6592
fe9298ade0a8
(svn r9075) -Codechange: Cleanup of industry_cmd (Step-7). Small step that is. The new industry messages do not need a series of tests. Only one property to use.
belugas
parents:
6573
diff
changeset
|
1774 |
SetDParam(0, ind_spc->name); |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1775 |
SetDParam(1, ind->town->index); |
6592
fe9298ade0a8
(svn r9075) -Codechange: Cleanup of industry_cmd (Step-7). Small step that is. The new industry messages do not need a series of tests. Only one property to use.
belugas
parents:
6573
diff
changeset
|
1776 |
AddNewsItem(ind_spc->new_industry_text, |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6964
diff
changeset
|
1777 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0); |
0 | 1778 |
} |
1779 |
||
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1780 |
static void ChangeIndustryProduction(Industry *i) |
0 | 1781 |
{ |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1782 |
StringID str = STR_NULL; |
0 | 1783 |
int type = i->type; |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1784 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1785 |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1786 |
if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return; |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1787 |
|
7647
446896960367
(svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents:
7641
diff
changeset
|
1788 |
if ((indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) { |
446896960367
(svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents:
7641
diff
changeset
|
1789 |
bool only_decrease = false; |
446896960367
(svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents:
7641
diff
changeset
|
1790 |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1791 |
/* decrease or increase */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1792 |
if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE) |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1793 |
only_decrease = true; |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1794 |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1795 |
if (only_decrease || CHANCE16(1, 3)) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1796 |
/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1797 |
if (!only_decrease && (i->last_month_pct_transported[0] > 153) != CHANCE16(1, 3)) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1798 |
/* Increase production */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1799 |
if (i->prod_level != 0x80) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1800 |
byte b; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1801 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1802 |
i->prod_level <<= 1; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1803 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1804 |
b = i->production_rate[0] * 2; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1805 |
if (i->production_rate[0] >= 128) |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1806 |
b = 0xFF; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1807 |
i->production_rate[0] = b; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1808 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1809 |
b = i->production_rate[1] * 2; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1810 |
if (i->production_rate[1] >= 128) |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1811 |
b = 0xFF; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1812 |
i->production_rate[1] = b; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1813 |
|
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1814 |
str = indspec->production_up_text; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1815 |
} |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1816 |
} else { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1817 |
/* Decrease production */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1818 |
if (i->prod_level == 4) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1819 |
i->prod_level = 0; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1820 |
str = indspec->closure_text; |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1821 |
} else { |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1822 |
i->prod_level >>= 1; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1823 |
i->production_rate[0] = (i->production_rate[0] + 1) >> 1; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1824 |
i->production_rate[1] = (i->production_rate[1] + 1) >> 1; |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1825 |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1826 |
str = indspec->production_down_text; |
0 | 1827 |
} |
1828 |
} |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1829 |
} |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1830 |
} |
7647
446896960367
(svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents:
7641
diff
changeset
|
1831 |
if (indspec->life_type & INDUSTRYLIFE_PROCESSING) { |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1832 |
/* maybe close */ |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1833 |
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, 2)) { |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1834 |
i->prod_level = 0; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1835 |
str = indspec->closure_text; |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
1836 |
} |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1837 |
} |
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1838 |
|
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1839 |
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
|
1840 |
SetDParam(0, i->index); |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6964
diff
changeset
|
1841 |
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, str == indspec->closure_text ? NT_OPENCLOSE : NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0); |
0 | 1842 |
} |
1843 |
} |
|
1844 |
||
6573 | 1845 |
void IndustryMonthlyLoop() |
0 | 1846 |
{ |
1847 |
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
|
1848 |
PlayerID old_player = _current_player; |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1849 |
_current_player = OWNER_NONE; |
0 | 1850 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1851 |
FOR_ALL_INDUSTRIES(i) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1852 |
UpdateIndustryStatistics(i); |
0 | 1853 |
} |
1854 |
||
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1855 |
/* 3% chance that we start a new industry */ |
6929 | 1856 |
if (CHANCE16(3, 100)) { |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1857 |
MaybeNewIndustry(); |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
1858 |
} else if (!_patches.smooth_economy) { |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
1859 |
i = GetRandomIndustry(); |
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
1860 |
if (i != NULL) ChangeIndustryProduction(i); |
0 | 1861 |
} |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1862 |
|
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1863 |
_current_player = old_player; |
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1864 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1865 |
/* production-change */ |
0 | 1866 |
_industry_sort_dirty = true; |
1867 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1868 |
} |
|
1869 |
||
1870 |
||
6573 | 1871 |
void InitializeIndustries() |
0 | 1872 |
{ |
4976
a0d7f63c35b5
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1873 |
CleanPool(&_Industry_pool); |
a0d7f63c35b5
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1874 |
AddBlockToPool(&_Industry_pool); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1875 |
|
7335
027d2caa4646
(svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents:
7320
diff
changeset
|
1876 |
ResetIndustryCounts(); |
0 | 1877 |
_industry_sort_dirty = true; |
4587
47bdc67193da
(svn r6437) -Fix: reset the location of the last sound as that location can be outside the map when you are loading another (smaller) map. Thanks to MeusH for noticing.
rubidium
parents:
4583
diff
changeset
|
1878 |
_industry_sound_tile = 0; |
0 | 1879 |
} |
1880 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1881 |
extern const TileTypeProcs _tile_type_industry_procs = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1882 |
DrawTile_Industry, /* draw_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1883 |
GetSlopeZ_Industry, /* get_slope_z_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1884 |
ClearTile_Industry, /* clear_tile_proc */ |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
1885 |
GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1886 |
GetTileDesc_Industry, /* get_tile_desc_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1887 |
GetTileTrackStatus_Industry, /* get_tile_track_status_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1888 |
ClickTile_Industry, /* click_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1889 |
AnimateTile_Industry, /* animate_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1890 |
TileLoop_Industry, /* tile_loop_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1891 |
ChangeTileOwner_Industry, /* change_tile_owner_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1892 |
GetProducedCargo_Industry, /* get_produced_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1893 |
NULL, /* vehicle_enter_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1894 |
GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
0 | 1895 |
}; |
1896 |
||
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
|
1897 |
static const SaveLoad _industry_desc[] = { |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1898 |
SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1899 |
SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1900 |
SLE_VAR(Industry, width, SLE_UINT8), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1901 |
SLE_VAR(Industry, height, SLE_UINT8), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1902 |
SLE_REF(Industry, town, REF_TOWN), |
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1903 |
SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1904 |
SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, SL_MAX_VERSION), |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1905 |
SLE_ARR(Industry, produced_cargo_waiting, SLE_UINT16, 2), |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1906 |
SLE_ARR(Industry, production_rate, SLE_UINT8, 2), |
7132
08abbae3073e
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents:
7056
diff
changeset
|
1907 |
SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1908 |
SLE_VAR(Industry, prod_level, SLE_UINT8), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1909 |
SLE_ARR(Industry, this_month_production, SLE_UINT16, 2), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1910 |
SLE_ARR(Industry, this_month_transported, SLE_UINT16, 2), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1911 |
SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8, 2), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1912 |
SLE_ARR(Industry, last_month_production, SLE_UINT16, 2), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1913 |
SLE_ARR(Industry, last_month_transported, SLE_UINT16, 2), |
0 | 1914 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1915 |
SLE_VAR(Industry, counter, SLE_UINT16), |
0 | 1916 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1917 |
SLE_VAR(Industry, type, SLE_UINT8), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1918 |
SLE_VAR(Industry, owner, SLE_UINT8), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1919 |
SLE_VAR(Industry, random_color, SLE_UINT8), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1920 |
SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1921 |
SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION), |
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7311
diff
changeset
|
1922 |
SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8), |
0 | 1923 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1924 |
/* 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
|
1925 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 1926 |
|
1927 |
SLE_END() |
|
1928 |
}; |
|
1929 |
||
6573 | 1930 |
static void Save_INDY() |
0 | 1931 |
{ |
1932 |
Industry *ind; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1933 |
|
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6418
diff
changeset
|
1934 |
/* Write the vehicles */ |
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1935 |
FOR_ALL_INDUSTRIES(ind) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1936 |
SlSetArrayIndex(ind->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1937 |
SlObject(ind, _industry_desc); |
0 | 1938 |
} |
1939 |
} |
|
1940 |
||
6573 | 1941 |
static void Load_INDY() |
0 | 1942 |
{ |
1943 |
int index; |
|
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1944 |
|
7335
027d2caa4646
(svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents:
7320
diff
changeset
|
1945 |
ResetIndustryCounts(); |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1946 |
|
0 | 1947 |
while ((index = SlIterateArray()) != -1) { |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1948 |
Industry *i; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1949 |
|
4976
a0d7f63c35b5
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1950 |
if (!AddBlockIfNeeded(&_Industry_pool, index)) |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1951 |
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
|
1952 |
|
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1953 |
i = GetIndustry(index); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1954 |
SlObject(i, _industry_desc); |
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
1955 |
IncIndustryTypeCount(i->type); |
0 | 1956 |
} |
1957 |
} |
|
1958 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1959 |
extern const ChunkHandler _industry_chunk_handlers[] = { |
0 | 1960 |
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |
1961 |
}; |