author | rubidium |
Wed, 23 Apr 2008 20:56:08 +0000 | |
changeset 10314 | 9cfcdd5b5ddb |
parent 10303 | 78028cd29075 |
child 10391 | 19bd4835125f |
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" |
3314
b8b234d4584f
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
8 |
#include "industry_map.h" |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3331
diff
changeset
|
9 |
#include "station_map.h" |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
10 |
#include "train.h" |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6633
diff
changeset
|
11 |
#include "landscape.h" |
8721
b7971ad9bdd9
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8699
diff
changeset
|
12 |
#include "viewport_func.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
13 |
#include "command_func.h" |
0 | 14 |
#include "industry.h" |
15 |
#include "town.h" |
|
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9152
diff
changeset
|
16 |
#include "news_func.h" |
0 | 17 |
#include "saveload.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
18 |
#include "variables.h" |
10225
8becb17444a7
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
10081
diff
changeset
|
19 |
#include "cheat_func.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
20 |
#include "genworld.h" |
5056
20369e09627b
(svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents:
4976
diff
changeset
|
21 |
#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
|
22 |
#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
|
23 |
#include "cargotype.h" |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
24 |
#include "newgrf.h" |
7789
bda67a697f68
(svn r10641) -Fix(r10638): Forgotten Son... err...include
belugas
parents:
7788
diff
changeset
|
25 |
#include "newgrf_commons.h" |
7664
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7661
diff
changeset
|
26 |
#include "newgrf_industries.h" |
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
27 |
#include "newgrf_industrytiles.h" |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
28 |
#include "newgrf_callbacks.h" |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
29 |
#include "autoslope.h" |
8345
6caa3fdb972c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
8319
diff
changeset
|
30 |
#include "transparency.h" |
8444
9317090e9c8c
(svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents:
8443
diff
changeset
|
31 |
#include "water.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8604
diff
changeset
|
32 |
#include "strings_func.h" |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8612
diff
changeset
|
33 |
#include "tile_cmd.h" |
8627
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8615
diff
changeset
|
34 |
#include "functions.h" |
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8615
diff
changeset
|
35 |
#include "window_func.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
36 |
#include "date_func.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
37 |
#include "vehicle_func.h" |
8653
a83f7a536919
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8650
diff
changeset
|
38 |
#include "sound_func.h" |
9281
d8cd9ac52a68
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
9259
diff
changeset
|
39 |
#include "station_base.h" |
9343
c30fd350dd8c
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents:
9339
diff
changeset
|
40 |
#include "oldpool_func.h" |
10268
434c8d706e7e
(svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
rubidium
parents:
10225
diff
changeset
|
41 |
#include "animated_tile_func.h" |
10272
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
42 |
#include "effectvehicle_func.h" |
0 | 43 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8730
diff
changeset
|
44 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8730
diff
changeset
|
45 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8730
diff
changeset
|
46 |
#include "table/industry_land.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8730
diff
changeset
|
47 |
#include "table/build_industry.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8730
diff
changeset
|
48 |
|
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
49 |
void ShowIndustryViewWindow(int industry); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
50 |
void BuildOilRig(TileIndex tile); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
51 |
|
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
52 |
static byte _industry_sound_ctr; |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
53 |
static TileIndex _industry_sound_tile; |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
54 |
|
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
55 |
int _total_industries; //general counter |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
56 |
uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
57 |
|
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
58 |
const Industry **_industry_sort; |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
59 |
bool _industry_sort_dirty; |
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
60 |
|
7239
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
|
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
64 |
/** 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
|
65 |
* industry and industry tiles. |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
66 |
* 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
|
67 |
* 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
|
68 |
void ResetIndustries() |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
69 |
{ |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
|
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
73 |
/* 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
|
74 |
for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) { |
8150
3b6a36860a47
(svn r11185) -Codechange: prepare some more code for the introduction of NewIndustries. Patch by Belugas.
rubidium
parents:
8146
diff
changeset
|
75 |
_industry_specs[i].enabled = i < NEW_INDUSTRYOFFSET && |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
76 |
HasBit(_origin_industry_specs[i].climate_availability, _opt.landscape); |
7239
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
77 |
} |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
78 |
|
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
79 |
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
|
80 |
memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs)); |
8162
8e15b94334b5
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
8159
diff
changeset
|
81 |
|
8e15b94334b5
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
8159
diff
changeset
|
82 |
/* Reset any overrides that have been set. */ |
8e15b94334b5
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
8159
diff
changeset
|
83 |
_industile_mngr.ResetOverride(); |
8e15b94334b5
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
8159
diff
changeset
|
84 |
_industry_mngr.ResetOverride(); |
7239
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
85 |
} |
68e722150cba
(svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents:
7232
diff
changeset
|
86 |
|
7757
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
87 |
void ResetIndustryCreationProbility(IndustryType type) |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
88 |
{ |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
89 |
assert(type < INVALID_INDUSTRYTYPE); |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
90 |
_industry_specs[type].appear_creation[_opt.landscape] = 0; |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
91 |
} |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
92 |
|
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
93 |
DEFINE_OLD_POOL_GENERIC(Industry, Industry) |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
94 |
|
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
|
95 |
/** |
e95d6e5f66ae
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
96 |
* 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
|
97 |
* 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
|
98 |
* 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
|
99 |
* @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
|
100 |
* @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
|
101 |
* @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
|
102 |
**/ |
e95d6e5f66ae
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
103 |
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
|
104 |
{ |
e95d6e5f66ae
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
105 |
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
|
106 |
|
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
|
107 |
const Industry *ind = GetIndustryByTile(tile); |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
108 |
return ind->IsValid() ? 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
|
109 |
} |
0 | 110 |
|
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
111 |
/** |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
112 |
* Accessor for array _industry_specs. |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
113 |
* This will ensure at once : proper access and |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
114 |
* not allowing modifications of it. |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
115 |
* @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
|
116 |
* @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
|
117 |
* @return a pointer to the corresponding industry spec |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
118 |
**/ |
3689
db67c356f44b
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3669
diff
changeset
|
119 |
const IndustrySpec *GetIndustrySpec(IndustryType thistype) |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
120 |
{ |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
121 |
assert(thistype < NUM_INDUSTRYTYPES); |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
122 |
return &_industry_specs[thistype]; |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
123 |
} |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
124 |
|
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
|
125 |
/** |
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
|
126 |
* 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
|
127 |
* 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
|
128 |
* not allowing modifications of it. |
7784
efb98124ce51
(svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents:
7762
diff
changeset
|
129 |
* @param gfx of industrytile (which is the index in _industry_tile_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
|
130 |
* @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
|
131 |
* @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
|
132 |
**/ |
7958
86754174b58f
(svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents:
7957
diff
changeset
|
133 |
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx) |
6418
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
134 |
{ |
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
|
135 |
assert(gfx < INVALID_INDUSTRYTILE); |
7958
86754174b58f
(svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents:
7957
diff
changeset
|
136 |
return &_industry_tile_specs[gfx]; |
6418
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
137 |
} |
a80dba2d8243
(svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents:
6417
diff
changeset
|
138 |
|
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
139 |
Industry::~Industry() |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
140 |
{ |
7916
8bc57ab02de6
(svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents:
7897
diff
changeset
|
141 |
if (CleaningPool()) return; |
8bc57ab02de6
(svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents:
7897
diff
changeset
|
142 |
|
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
143 |
/* Industry can also be destroyed when not fully initialized. |
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
144 |
* This means that we do not have to clear tiles either. */ |
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
145 |
if (this->width == 0) { |
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
146 |
this->xy = 0; |
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
147 |
return; |
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
148 |
} |
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
149 |
|
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
150 |
BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy); |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
151 |
if (IsTileType(tile_cur, MP_INDUSTRY)) { |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
152 |
if (GetIndustryIndex(tile_cur) == this->index) { |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
153 |
DoClearSquare(tile_cur); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
154 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
155 |
} 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
|
156 |
DeleteOilRig(tile_cur); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
157 |
} |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
158 |
END_TILE_LOOP(tile_cur, this->width, this->height, this->xy); |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
159 |
|
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
160 |
if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) { |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
161 |
/* Remove the farmland and convert it to regular tiles over time. */ |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
162 |
BEGIN_TILE_LOOP(tile_cur, 42, 42, this->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
|
163 |
tile_cur = TILE_MASK(tile_cur); |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
164 |
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
165 |
GetIndustryIndexOfField(tile_cur) == this->index) { |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
166 |
SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY); |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
167 |
} |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
168 |
} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21)) |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
169 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
170 |
|
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
171 |
_industry_sort_dirty = true; |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
172 |
DecIndustryTypeCount(this->type); |
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
173 |
|
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
174 |
DeleteSubsidyWithIndustry(this->index); |
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
175 |
DeleteWindowById(WC_INDUSTRY_VIEW, this->index); |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
176 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
177 |
this->xy = 0; |
4403
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
178 |
} |
851d2a602806
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
179 |
|
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
180 |
static void IndustryDrawSugarMine(const TileInfo *ti) |
0 | 181 |
{ |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
182 |
const DrawIndustryAnimationStruct *d; |
0 | 183 |
|
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
184 |
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
|
185 |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
186 |
d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)]; |
0 | 187 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
188 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0); |
0 | 189 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
190 |
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
|
191 |
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
|
192 |
} |
0 | 193 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
_drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y); |
2639 | 197 |
} |
0 | 198 |
} |
199 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
200 |
static void IndustryDrawToffeeQuarry(const TileInfo *ti) |
0 | 201 |
{ |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
202 |
uint8 x = 0; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
203 |
|
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
if (x == 0xFF) |
0 | 207 |
x = 0; |
208 |
} |
|
209 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
210 |
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
|
211 |
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, PAL_NONE, 6, 14); |
0 | 212 |
} |
213 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
214 |
static void IndustryDrawBubbleGenerator( const TileInfo *ti) |
0 | 215 |
{ |
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
216 |
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
|
217 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]); |
2639 | 218 |
} else { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
219 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67); |
0 | 220 |
} |
221 |
} |
|
222 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
223 |
static void IndustryDrawToyFactory(const TileInfo *ti) |
0 | 224 |
{ |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
225 |
const DrawIndustryAnimationStruct *d; |
0 | 226 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
227 |
d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)]; |
0 | 228 |
|
229 |
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
|
230 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1); |
0 | 231 |
} |
232 |
||
233 |
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
|
234 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, PAL_NONE, 16 - d->image_2 * 2, 100 + d->image_2); |
0 | 235 |
} |
236 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
237 |
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
|
238 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, PAL_NONE, 0, 42); |
0 | 239 |
} |
240 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
241 |
static void IndustryDrawCoalPlantSparks(const TileInfo *ti) |
0 | 242 |
{ |
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
243 |
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
|
244 |
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
|
245 |
|
0 | 246 |
if (image != 0 && image < 7) { |
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
247 |
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
|
248 |
PAL_NONE, |
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
249 |
_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
|
250 |
_coal_plant_sparks[image - 1].y |
0 | 251 |
); |
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
||
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
|
256 |
typedef void IndustryDrawTileProc(const TileInfo *ti); |
0 | 257 |
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = { |
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
258 |
IndustryDrawSugarMine, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
259 |
IndustryDrawToffeeQuarry, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
260 |
IndustryDrawBubbleGenerator, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
261 |
IndustryDrawToyFactory, |
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
262 |
IndustryDrawCoalPlantSparks, |
0 | 263 |
}; |
264 |
||
265 |
static void DrawTile_Industry(TileInfo *ti) |
|
266 |
{ |
|
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
267 |
IndustryGfx gfx = GetIndustryGfx(ti->tile); |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
268 |
Industry *ind = GetIndustryByTile(ti->tile); |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
269 |
const IndustryTileSpec *indts = GetIndustryTileSpec(gfx); |
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
270 |
const DrawBuildingsTileStruct *dits; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
271 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
272 |
SpriteID pal; |
0 | 273 |
|
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
274 |
/* Retrieve pointer to the draw industry tile struct */ |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
275 |
if (gfx >= NEW_INDUSTRYTILEOFFSET) { |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
276 |
/* 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
|
277 |
* 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
|
278 |
* 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
|
279 |
* substitute gfx instead. */ |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
280 |
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
|
281 |
return; |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
282 |
} else { |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
283 |
/* 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
|
284 |
* Use the substitute one instead */ |
7957
62dc8719052a
(svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents:
7941
diff
changeset
|
285 |
if (indts->grf_prop.subst_id != INVALID_INDUSTRYTILE) { |
62dc8719052a
(svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents:
7941
diff
changeset
|
286 |
gfx = indts->grf_prop.subst_id; |
62dc8719052a
(svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents:
7941
diff
changeset
|
287 |
/* And point the industrytile spec accordingly */ |
62dc8719052a
(svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents:
7941
diff
changeset
|
288 |
indts = GetIndustryTileSpec(gfx); |
62dc8719052a
(svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents:
7941
diff
changeset
|
289 |
} |
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
290 |
} |
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
291 |
} |
0 | 292 |
|
7466
01be88d1c0a6
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
7446
diff
changeset
|
293 |
dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ? |
7787
6e0b6ea38850
(svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents:
7786
diff
changeset
|
294 |
GetIndustryAnimationState(ti->tile) & INDUSTRY_COMPLETED : |
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
|
295 |
GetIndustryConstructionStage(ti->tile))]; |
0 | 296 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
297 |
image = dits->ground.sprite; |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
298 |
if (HasBit(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
299 |
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
|
300 |
} else { |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
301 |
pal = dits->ground.pal; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
302 |
} |
0 | 303 |
|
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7830
diff
changeset
|
304 |
/* DrawFoundation() modifes ti->z and ti->tileh */ |
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7830
diff
changeset
|
305 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
0 | 306 |
|
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
|
307 |
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
|
308 |
|
9302
4aa3c4a44b16
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
9281
diff
changeset
|
309 |
/* If industries are transparent and invisible, do not draw the upper part */ |
4aa3c4a44b16
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
9281
diff
changeset
|
310 |
if (IsInvisibilitySet(TO_INDUSTRIES)) return; |
4aa3c4a44b16
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
9281
diff
changeset
|
311 |
|
0 | 312 |
/* 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
|
313 |
image = dits->building.sprite; |
2639 | 314 |
if (image != 0) { |
7829
88883899c9e6
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7815
diff
changeset
|
315 |
AddSortableSpriteToDraw(image, |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
316 |
(HasBit(image, PALETTE_MODIFIER_COLOR) && dits->building.pal == PAL_NONE) ? GENERAL_SPRITE_COLOR(ind->random_color) : dits->building.pal, |
2653
4173d9a0a27e
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
317 |
ti->x + dits->subtile_x, |
4173d9a0a27e
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
318 |
ti->y + dits->subtile_y, |
8073
42007d9c81bb
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents:
8027
diff
changeset
|
319 |
dits->width, |
42007d9c81bb
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents:
8027
diff
changeset
|
320 |
dits->height, |
0 | 321 |
dits->dz, |
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7830
diff
changeset
|
322 |
ti->z, |
8345
6caa3fdb972c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
8319
diff
changeset
|
323 |
IsTransparencySet(TO_INDUSTRIES)); |
0 | 324 |
|
8345
6caa3fdb972c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
8319
diff
changeset
|
325 |
if (IsTransparencySet(TO_INDUSTRIES)) return; |
0 | 326 |
} |
327 |
||
2639 | 328 |
{ |
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
329 |
int proc = dits->draw_proc - 1; |
2639 | 330 |
if (proc >= 0) _industry_draw_tile_procs[proc](ti); |
0 | 331 |
} |
332 |
} |
|
333 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
334 |
static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y) |
2537 | 335 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
336 |
return GetTileMaxZ(tile); |
0 | 337 |
} |
338 |
||
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7830
diff
changeset
|
339 |
static Foundation GetFoundation_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
|
340 |
{ |
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7830
diff
changeset
|
341 |
return FlatteningFoundation(tileh); |
39 | 342 |
} |
343 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
344 |
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) |
0 | 345 |
{ |
7695
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
346 |
IndustryGfx gfx = GetIndustryGfx(tile); |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
347 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
348 |
|
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
349 |
/* When we have to use a callback, we put our data in the next two variables */ |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
350 |
CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)]; |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
351 |
uint8 raw_acceptance[lengthof(itspec->acceptance)]; |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
352 |
|
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
353 |
/* And then these will always point to a same sized array with the required data */ |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
354 |
const CargoID *accepts_cargo = itspec->accepts_cargo; |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
355 |
const uint8 *acceptance = itspec->acceptance; |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
356 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
357 |
if (HasBit(itspec->callback_flags, CBM_INDT_ACCEPT_CARGO)) { |
7695
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
358 |
uint16 res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, GetIndustryByTile(tile), tile); |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
359 |
if (res != CALLBACK_FAILED) { |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
360 |
accepts_cargo = raw_accepts_cargo; |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
361 |
for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile); |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
362 |
} |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
363 |
} |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
364 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
365 |
if (HasBit(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) { |
7695
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
366 |
uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile); |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
367 |
if (res != CALLBACK_FAILED) { |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
368 |
acceptance = raw_acceptance; |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
369 |
for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4); |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
370 |
} |
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
371 |
} |
0 | 372 |
|
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
|
373 |
for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) { |
7695
b15538ba7152
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents:
7682
diff
changeset
|
374 |
CargoID a = accepts_cargo[i]; |
8151
b4a7b7edcb42
(svn r11186) -Fix: only fill the accepted cargo fields once, not multiple times.
rubidium
parents:
8150
diff
changeset
|
375 |
/* Only set the value once. */ |
b4a7b7edcb42
(svn r11186) -Fix: only fill the accepted cargo fields once, not multiple times.
rubidium
parents:
8150
diff
changeset
|
376 |
if (a != CT_INVALID && ac[a] == 0) ac[a] = acceptance[i]; |
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
|
377 |
} |
0 | 378 |
} |
379 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
380 |
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) |
0 | 381 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
382 |
const Industry *i = GetIndustryByTile(tile); |
0 | 383 |
|
384 |
td->owner = i->owner; |
|
4942
f990abfa4438
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
385 |
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
|
386 |
if (!IsIndustryCompleted(tile)) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
387 |
SetDParamX(td->dparam, 0, td->str); |
0 | 388 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
389 |
} |
|
390 |
} |
|
391 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7406
diff
changeset
|
392 |
static CommandCost ClearTile_Industry(TileIndex tile, byte flags) |
0 | 393 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
394 |
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
|
395 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
0 | 396 |
|
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
|
397 |
/* 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
|
398 |
* 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
|
399 |
* 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
|
400 |
* (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
|
401 |
*/ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
402 |
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
|
403 |
!_cheats.magic_bulldozer.value) || |
8133
597f682ff48d
(svn r11168) -Fix [FS#1256]: assert on terraforming of industries. Patch by frosch.
rubidium
parents:
8125
diff
changeset
|
404 |
((flags & DC_AUTO) != 0) || |
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
|
405 |
(_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
|
406 |
SetDParam(0, indspec->name); |
0 | 407 |
return_cmd_error(STR_4800_IN_THE_WAY); |
408 |
} |
|
409 |
||
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
410 |
if (flags & DC_EXEC) delete i; |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
411 |
return CommandCost(EXPENSES_CONSTRUCTION, indspec->GetRemovalCost()); |
0 | 412 |
} |
413 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
414 |
static void TransportIndustryGoods(TileIndex tile) |
0 | 415 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
416 |
Industry *i = GetIndustryByTile(tile); |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
417 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
8295
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
418 |
bool moved_cargo = false; |
0 | 419 |
|
8295
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
420 |
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) { |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
421 |
uint cw = min(i->produced_cargo_waiting[j], 255); |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
422 |
if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) { |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
423 |
i->produced_cargo_waiting[j] -= cw; |
3331 | 424 |
|
8295
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
425 |
/* fluctuating economy? */ |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
426 |
if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
427 |
|
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
428 |
i->this_month_production[j] += cw; |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
429 |
|
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
430 |
uint am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[j], cw); |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
431 |
i->this_month_transported[j] += am; |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
432 |
|
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
433 |
moved_cargo |= (am != 0); |
0 | 434 |
} |
435 |
} |
|
436 |
||
8295
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
437 |
if (moved_cargo && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) { |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
438 |
uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
439 |
|
8295
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
440 |
if (newgfx != INDUSTRYTILE_NOANIM) { |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
441 |
ResetIndustryConstructionStage(tile); |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
442 |
SetIndustryCompleted(tile, true); |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
443 |
SetIndustryGfx(tile, newgfx); |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
444 |
MarkTileDirtyByTile(tile); |
8ab54ba3ba7d
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents:
8256
diff
changeset
|
445 |
} |
0 | 446 |
} |
447 |
} |
|
448 |
||
449 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
450 |
static void AnimateTile_Industry(TileIndex tile) |
0 | 451 |
{ |
3331 | 452 |
byte m; |
7725
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
453 |
IndustryGfx gfx = GetIndustryGfx(tile); |
0 | 454 |
|
7725
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
455 |
if (GetIndustryTileSpec(gfx)->animation_info != 0xFFFF) { |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
456 |
AnimateNewIndustryTile(tile); |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
457 |
return; |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
458 |
} |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
459 |
|
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
460 |
switch (gfx) { |
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
|
461 |
case GFX_SUGAR_MINE_SIEVE: |
0 | 462 |
if ((_tick_counter & 1) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
463 |
m = GetIndustryAnimationState(tile) + 1; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
464 |
|
2952 | 465 |
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
|
466 |
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; |
541 | 467 |
case 6: SndPlayTileFx(SND_29_RIP, tile); break; |
0 | 468 |
} |
469 |
||
470 |
if (m >= 96) { |
|
471 |
m = 0; |
|
472 |
DeleteAnimatedTile(tile); |
|
473 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
474 |
SetIndustryAnimationState(tile, m); |
0 | 475 |
|
476 |
MarkTileDirtyByTile(tile); |
|
477 |
} |
|
478 |
break; |
|
479 |
||
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
|
480 |
case GFX_TOFFEE_QUARY: |
0 | 481 |
if ((_tick_counter & 3) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
482 |
m = GetIndustryAnimationState(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
483 |
|
7015
af363e4290ab
(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents:
6989
diff
changeset
|
484 |
if (_industry_anim_offs_toffee[m] == 0xFF) { |
541 | 485 |
SndPlayTileFx(SND_30_CARTOON_SOUND, tile); |
0 | 486 |
} |
487 |
||
488 |
if (++m >= 70) { |
|
489 |
m = 0; |
|
490 |
DeleteAnimatedTile(tile); |
|
491 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
492 |
SetIndustryAnimationState(tile, m); |
0 | 493 |
|
494 |
MarkTileDirtyByTile(tile); |
|
495 |
} |
|
496 |
break; |
|
497 |
||
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
|
498 |
case GFX_BUBBLE_CATCHER: |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
499 |
if ((_tick_counter & 1) == 0) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
500 |
m = GetIndustryAnimationState(tile); |
0 | 501 |
|
502 |
if (++m >= 40) { |
|
503 |
m = 0; |
|
504 |
DeleteAnimatedTile(tile); |
|
505 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
506 |
SetIndustryAnimationState(tile, m); |
0 | 507 |
|
508 |
MarkTileDirtyByTile(tile); |
|
509 |
} |
|
510 |
break; |
|
511 |
||
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
|
512 |
/* 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
|
513 |
case GFX_POWERPLANT_SPARKS: |
0 | 514 |
if ((_tick_counter & 3) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
515 |
m = GetIndustryAnimationState(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
516 |
if (m == 6) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
517 |
SetIndustryAnimationState(tile, 0); |
0 | 518 |
DeleteAnimatedTile(tile); |
519 |
} else { |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
520 |
SetIndustryAnimationState(tile, m + 1); |
0 | 521 |
MarkTileDirtyByTile(tile); |
522 |
} |
|
523 |
} |
|
524 |
break; |
|
525 |
||
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
|
526 |
case GFX_TOY_FACTORY: |
0 | 527 |
if ((_tick_counter & 1) == 0) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
528 |
m = GetIndustryAnimationState(tile) + 1; |
0 | 529 |
|
6964
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
530 |
switch (m) { |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
531 |
case 1: SndPlayTileFx(SND_2C_MACHINERY, tile); break; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
532 |
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
|
533 |
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
|
534 |
default: |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
535 |
if (m >= 50) { |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
536 |
int n = GetIndustryAnimationLoop(tile) + 1; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
537 |
m = 0; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
538 |
if (n >= 8) { |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
539 |
n = 0; |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
540 |
DeleteAnimatedTile(tile); |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
541 |
} |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
542 |
SetIndustryAnimationLoop(tile, n); |
737c8b546ca5
(svn r9644) -Codechange: if else cascade into a switch case
belugas
parents:
6963
diff
changeset
|
543 |
} |
0 | 544 |
} |
545 |
||
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
546 |
SetIndustryAnimationState(tile, m); |
0 | 547 |
MarkTileDirtyByTile(tile); |
548 |
} |
|
549 |
break; |
|
550 |
||
5685
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
551 |
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
|
552 |
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
|
553 |
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
|
554 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: |
0 | 555 |
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
|
556 |
IndustryGfx gfx = GetIndustryGfx(tile); |
0 | 557 |
|
3331 | 558 |
gfx = (gfx < 155) ? gfx + 1 : 148; |
559 |
SetIndustryGfx(tile, gfx); |
|
0 | 560 |
MarkTileDirtyByTile(tile); |
561 |
} |
|
562 |
break; |
|
563 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
564 |
case GFX_OILWELL_ANIMATED_1: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
565 |
case GFX_OILWELL_ANIMATED_2: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
566 |
case GFX_OILWELL_ANIMATED_3: |
0 | 567 |
if ((_tick_counter & 7) == 0) { |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
568 |
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
|
569 |
IndustryGfx gfx = GetIndustryGfx(tile); |
3331 | 570 |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
571 |
m = GetIndustryAnimationState(tile) + 1; |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
572 |
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
|
573 |
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
|
574 |
SetIndustryConstructionStage(tile, 3); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
575 |
DeleteAnimatedTile(tile); |
0 | 576 |
} else { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
577 |
SetIndustryAnimationState(tile, m); |
3331 | 578 |
SetIndustryGfx(tile, gfx); |
0 | 579 |
MarkTileDirtyByTile(tile); |
580 |
} |
|
581 |
} |
|
582 |
break; |
|
583 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
584 |
case GFX_COAL_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
585 |
case GFX_COPPER_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
586 |
case GFX_GOLD_MINE_TOWER_ANIMATED: { |
0 | 587 |
int state = _tick_counter & 0x7FF; |
588 |
||
589 |
if ((state -= 0x400) < 0) |
|
590 |
return; |
|
591 |
||
592 |
if (state < 0x1A0) { |
|
593 |
if (state < 0x20 || state >= 0x180) { |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
594 |
m = GetIndustryAnimationState(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
595 |
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
|
596 |
SetIndustryAnimationState(tile, m | 0x40); |
541 | 597 |
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); |
0 | 598 |
} |
599 |
if (state & 7) |
|
600 |
return; |
|
601 |
} else { |
|
602 |
if (state & 3) |
|
603 |
return; |
|
604 |
} |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
605 |
m = (GetIndustryAnimationState(tile) + 1) | 0x40; |
0 | 606 |
if (m > 0xC2) m = 0xC0; |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
607 |
SetIndustryAnimationState(tile, m); |
0 | 608 |
MarkTileDirtyByTile(tile); |
609 |
} else if (state >= 0x200 && state < 0x3A0) { |
|
610 |
int i; |
|
611 |
i = (state < 0x220 || state >= 0x380) ? 7 : 3; |
|
612 |
if (state & i) |
|
613 |
return; |
|
614 |
||
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
615 |
m = (GetIndustryAnimationState(tile) & 0xBF) - 1; |
0 | 616 |
if (m < 0x80) m = 0x82; |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
617 |
SetIndustryAnimationState(tile, m); |
0 | 618 |
MarkTileDirtyByTile(tile); |
619 |
} |
|
620 |
} break; |
|
621 |
} |
|
622 |
} |
|
623 |
||
10272
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
624 |
static void CreateChimneySmoke(TileIndex tile) |
0 | 625 |
{ |
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
|
626 |
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
|
627 |
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
|
628 |
uint z = GetTileMaxZ(tile); |
3094 | 629 |
|
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
|
630 |
CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE); |
0 | 631 |
} |
632 |
||
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
|
633 |
static void MakeIndustryTileBigger(TileIndex tile) |
0 | 634 |
{ |
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
|
635 |
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
|
636 |
byte stage; |
0 | 637 |
|
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
|
638 |
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
|
639 |
SetIndustryConstructionCounter(tile, cnt); |
0 | 640 |
return; |
641 |
} |
|
642 |
||
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
|
643 |
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
|
644 |
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
|
645 |
SetIndustryConstructionStage(tile, stage); |
7725
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
646 |
StartStopIndustryTileAnimation(tile, IAT_CONSTRUCTION_STATE_CHANGE); |
7787
6e0b6ea38850
(svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents:
7786
diff
changeset
|
647 |
if (stage == INDUSTRY_COMPLETED) SetIndustryCompleted(tile, true); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
648 |
|
0 | 649 |
MarkTileDirtyByTile(tile); |
650 |
||
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
651 |
if (!IsIndustryCompleted(tile)) return; |
0 | 652 |
|
7725
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
653 |
IndustryGfx gfx = GetIndustryGfx(tile); |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
654 |
if (gfx >= NEW_INDUSTRYTILEOFFSET) { |
8349
011e0ee04e43
(svn r11403) -Fix: NewIndustries GRF assume that tiles are already animated during construction.
rubidium
parents:
8348
diff
changeset
|
655 |
/* New industries are already animated on construction. */ |
7725
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
656 |
return; |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
657 |
} |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
658 |
|
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
659 |
switch (gfx) { |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
660 |
case GFX_POWERPLANT_CHIMNEY: |
10272
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
661 |
CreateChimneySmoke(tile); |
0 | 662 |
break; |
663 |
||
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
|
664 |
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
|
665 |
if (GetIndustryGfx(tile + TileDiffXY(0, 1)) == GFX_OILRIG_1) BuildOilRig(tile); |
0 | 666 |
break; |
667 |
||
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
|
668 |
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
|
669 |
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
|
670 |
case GFX_TOFFEE_QUARY: |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
671 |
SetIndustryAnimationState(tile, 0); |
3538
3eb71c726341
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
672 |
SetIndustryAnimationLoop(tile, 0); |
0 | 673 |
break; |
674 |
||
5685
b88aca81aa7b
(svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents:
5319
diff
changeset
|
675 |
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
|
676 |
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
|
677 |
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
|
678 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: |
0 | 679 |
AddAnimatedTile(tile); |
680 |
break; |
|
681 |
} |
|
682 |
} |
|
683 |
||
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
684 |
static void TileLoopIndustry_BubbleGenerator(TileIndex tile) |
0 | 685 |
{ |
686 |
int dir; |
|
687 |
Vehicle *v; |
|
10272
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
688 |
static const int8 _bubble_spawn_location[3][4] = { |
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
689 |
{ 11, 0, -4, -14 }, |
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
690 |
{ -4, -10, -4, 1 }, |
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
691 |
{ 49, 59, 60, 65 }, |
0 | 692 |
}; |
693 |
||
541 | 694 |
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
|
695 |
|
0 | 696 |
dir = Random() & 3; |
697 |
||
698 |
v = CreateEffectVehicleAbove( |
|
10272
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
699 |
TileX(tile) * TILE_SIZE + _bubble_spawn_location[0][dir], |
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
700 |
TileY(tile) * TILE_SIZE + _bubble_spawn_location[1][dir], |
2014f0bdc800
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
10271
diff
changeset
|
701 |
_bubble_spawn_location[2][dir], |
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
|
702 |
EV_BUBBLE |
0 | 703 |
); |
704 |
||
10271
a20997d33fe8
(svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents:
10268
diff
changeset
|
705 |
if (v != NULL) v->u.effect.animation_substate = dir; |
0 | 706 |
} |
707 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
708 |
static void TileLoop_Industry(TileIndex tile) |
0 | 709 |
{ |
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
|
710 |
IndustryGfx newgfx; |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
711 |
IndustryGfx gfx; |
0 | 712 |
|
8356
4d72bac74977
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
8349
diff
changeset
|
713 |
TriggerIndustryTile(tile, INDTILE_TRIGGER_TILE_LOOP); |
4d72bac74977
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
8349
diff
changeset
|
714 |
|
3321
c5f2375046bc
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
715 |
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
|
716 |
MakeIndustryTileBigger(tile); |
0 | 717 |
return; |
718 |
} |
|
719 |
||
2639 | 720 |
if (_game_mode == GM_EDITOR) return; |
0 | 721 |
|
722 |
TransportIndustryGoods(tile); |
|
723 |
||
7725
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
724 |
if (StartStopIndustryTileAnimation(tile, IAT_TILELOOP)) return; |
e3892b38aa14
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7723
diff
changeset
|
725 |
|
6631
dc3480a670cc
(svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents:
6609
diff
changeset
|
726 |
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
|
727 |
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
|
728 |
ResetIndustryConstructionStage(tile); |
3331 | 729 |
SetIndustryGfx(tile, newgfx); |
0 | 730 |
MarkTileDirtyByTile(tile); |
731 |
return; |
|
732 |
} |
|
733 |
||
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
734 |
gfx = GetIndustryGfx(tile); |
0 | 735 |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
736 |
switch (gfx) { |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
737 |
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
|
738 |
case GFX_OILRIG_2: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
739 |
case GFX_OILRIG_3: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
740 |
case GFX_OILRIG_4: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
741 |
case GFX_OILRIG_5: |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
742 |
TileLoop_Water(tile); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
743 |
break; |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
744 |
|
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
745 |
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
|
746 |
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
|
747 |
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
748 |
if (!(_tick_counter & 0x400) && Chance16(1, 2)) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
749 |
switch (gfx) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
} |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
754 |
SetIndustryGfx(tile, gfx); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
755 |
SetIndustryAnimationState(tile, 0x80); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
756 |
AddAnimatedTile(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
757 |
} |
0 | 758 |
break; |
759 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
760 |
case GFX_OILWELL_NOT_ANIMATED: |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
761 |
if (Chance16(1, 6)) { |
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
762 |
SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
763 |
SetIndustryAnimationState(tile, 0); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
764 |
AddAnimatedTile(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
765 |
} |
0 | 766 |
break; |
767 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
768 |
case GFX_COAL_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
769 |
case GFX_COPPER_MINE_TOWER_ANIMATED: |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
770 |
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
|
771 |
if (!(_tick_counter & 0x400)) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
772 |
switch (gfx) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
773 |
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
|
774 |
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
|
775 |
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
|
776 |
} |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
777 |
SetIndustryGfx(tile, gfx); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
778 |
SetIndustryCompleted(tile, true); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
779 |
SetIndustryConstructionStage(tile, 3); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
780 |
DeleteAnimatedTile(tile); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
781 |
} |
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
782 |
break; |
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
783 |
|
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
784 |
case GFX_POWERPLANT_SPARKS: |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
785 |
if (Chance16(1, 3)) { |
541 | 786 |
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile); |
0 | 787 |
AddAnimatedTile(tile); |
788 |
} |
|
789 |
break; |
|
790 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
791 |
case GFX_COPPER_MINE_CHIMNEY: |
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
792 |
CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE); |
2639 | 793 |
break; |
0 | 794 |
|
795 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
796 |
case GFX_TOY_FACTORY: { |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
797 |
Industry *i = GetIndustryByTile(tile); |
0 | 798 |
if (i->was_cargo_delivered) { |
799 |
i->was_cargo_delivered = false; |
|
3538
3eb71c726341
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
800 |
SetIndustryAnimationLoop(tile, 0); |
0 | 801 |
AddAnimatedTile(tile); |
802 |
} |
|
803 |
} |
|
804 |
break; |
|
805 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
806 |
case GFX_BUBBLE_GENERATOR: |
3290
1a02d5e9205c
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
807 |
TileLoopIndustry_BubbleGenerator(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
808 |
break; |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
809 |
|
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
810 |
case GFX_TOFFEE_QUARY: |
0 | 811 |
AddAnimatedTile(tile); |
812 |
break; |
|
813 |
||
4583
45b8bf91b1e3
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
814 |
case GFX_SUGAR_MINE_SIEVE: |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
815 |
if (Chance16(1, 3)) AddAnimatedTile(tile); |
0 | 816 |
break; |
817 |
} |
|
818 |
} |
|
819 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
820 |
static void ClickTile_Industry(TileIndex tile) |
0 | 821 |
{ |
3314
b8b234d4584f
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
822 |
ShowIndustryViewWindow(GetIndustryIndex(tile)); |
0 | 823 |
} |
824 |
||
9112
ec6800eaa340
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
9092
diff
changeset
|
825 |
static TrackStatus GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) |
0 | 826 |
{ |
827 |
return 0; |
|
828 |
} |
|
829 |
||
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
|
830 |
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) |
0 | 831 |
{ |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
832 |
const Industry *i = GetIndustryByTile(tile); |
2630 | 833 |
|
0 | 834 |
b[0] = i->produced_cargo[0]; |
835 |
b[1] = i->produced_cargo[1]; |
|
836 |
} |
|
837 |
||
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
|
838 |
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 839 |
{ |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
840 |
/* If the founder merges, the industry was created by the merged company */ |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
841 |
Industry *i = GetIndustryByTile(tile); |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
842 |
if (i->founder == old_player) i->founder = (new_player == PLAYER_SPECTATOR) ? OWNER_NONE : new_player; |
0 | 843 |
} |
844 |
||
845 |
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; |
|
846 |
||
1048 | 847 |
static bool IsBadFarmFieldTile(TileIndex tile) |
0 | 848 |
{ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
849 |
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
|
850 |
case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); |
8955 | 851 |
case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE); |
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
|
852 |
default: return true; |
0 | 853 |
} |
854 |
} |
|
855 |
||
1048 | 856 |
static bool IsBadFarmFieldTile2(TileIndex tile) |
0 | 857 |
{ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
858 |
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
|
859 |
case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); |
8955 | 860 |
case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE); |
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
|
861 |
default: return true; |
0 | 862 |
} |
863 |
} |
|
864 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
865 |
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direction) |
0 | 866 |
{ |
867 |
do { |
|
868 |
tile = TILE_MASK(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
869 |
|
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
|
870 |
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
|
871 |
byte or_ = type; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
872 |
|
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
873 |
if (or_ == 1 && Chance16(1, 7)) or_ = 2; |
0 | 874 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
875 |
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
|
876 |
SetFenceSE(tile, or_); |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
877 |
} else { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
878 |
SetFenceSW(tile, or_); |
0 | 879 |
} |
880 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
881 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
882 |
tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 883 |
} while (--size); |
884 |
} |
|
885 |
||
4330
7306bda145ab
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4329
diff
changeset
|
886 |
static void PlantFarmField(TileIndex tile, IndustryID industry) |
0 | 887 |
{ |
888 |
uint size_x, size_y; |
|
889 |
uint32 r; |
|
2133 | 890 |
uint count; |
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
891 |
uint counter; |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
892 |
uint field_type; |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
893 |
int type; |
0 | 894 |
|
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
895 |
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
|
896 |
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine()) |
0 | 897 |
return; |
898 |
} |
|
899 |
||
900 |
/* determine field size */ |
|
901 |
r = (Random() & 0x303) + 0x404; |
|
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
902 |
if (_opt.landscape == LT_ARCTIC) r += 0x404; |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
903 |
size_x = GB(r, 0, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
904 |
size_y = GB(r, 8, 8); |
0 | 905 |
|
906 |
/* offset tile to match size */ |
|
1981 | 907 |
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
|
908 |
|
0 | 909 |
/* check the amount of bad tiles */ |
910 |
count = 0; |
|
911 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
912 |
cur_tile = TILE_MASK(cur_tile); |
|
913 |
count += IsBadFarmFieldTile(cur_tile); |
|
914 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
2133 | 915 |
if (count * 2 >= size_x * size_y) return; |
0 | 916 |
|
917 |
/* determine type of field */ |
|
918 |
r = Random(); |
|
2979
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
919 |
counter = GB(r, 5, 3); |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
920 |
field_type = GB(r, 8, 8) * 9 >> 8; |
0 | 921 |
|
922 |
/* make field */ |
|
923 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
924 |
cur_tile = TILE_MASK(cur_tile); |
|
925 |
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
|
926 |
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
|
927 |
SetClearCounter(cur_tile, counter); |
883788245931
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
928 |
MarkTileDirtyByTile(cur_tile); |
0 | 929 |
} |
930 |
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
|
931 |
|
0 | 932 |
type = 3; |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
933 |
if (_opt.landscape != LT_ARCTIC && _opt.landscape != LT_TROPIC) { |
0 | 934 |
type = _plantfarmfield_type[Random() & 0xF]; |
935 |
} |
|
936 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
937 |
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
|
938 |
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
|
939 |
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
|
940 |
SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X); |
0 | 941 |
} |
942 |
||
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
|
943 |
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
|
944 |
{ |
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
|
945 |
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
|
946 |
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
|
947 |
|
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
|
948 |
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
|
949 |
|
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
|
950 |
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
|
951 |
} |
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
|
952 |
|
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
953 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
954 |
* Search callback function for ChopLumberMillTrees |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
955 |
* @param tile to test |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
956 |
* @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
|
957 |
* @return the result of the test |
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
958 |
*/ |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
959 |
static bool SearchLumberMillTrees(TileIndex tile, uint32 data) |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
960 |
{ |
6160
126831e48987
(svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents:
6135
diff
changeset
|
961 |
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
|
962 |
PlayerID old_player = _current_player; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
963 |
/* found a tree */ |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
964 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
965 |
_current_player = OWNER_NONE; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
966 |
_industry_sound_ctr = 1; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
967 |
_industry_sound_tile = tile; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
968 |
SndPlayTileFx(SND_38_CHAINSAW, tile); |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
969 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
970 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
971 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
972 |
_current_player = old_player; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
973 |
return true; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
974 |
} |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
975 |
return false; |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
976 |
} |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
977 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
978 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
979 |
* 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
|
980 |
* @param i industry |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
981 |
*/ |
0 | 982 |
static void ChopLumberMillTrees(Industry *i) |
983 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
984 |
TileIndex tile = i->xy; |
2639 | 985 |
|
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
986 |
if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed |
0 | 987 |
|
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5056
diff
changeset
|
988 |
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
|
989 |
i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo |
0 | 990 |
} |
991 |
||
992 |
static void ProduceIndustryGoods(Industry *i) |
|
993 |
{ |
|
994 |
uint32 r; |
|
995 |
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
|
996 |
const IndustrySpec *indsp = GetIndustrySpec(i->type); |
0 | 997 |
|
998 |
/* play a sound? */ |
|
999 |
if ((i->counter & 0x3F) == 0) { |
|
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
1000 |
if (Chance16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) { |
0 | 1001 |
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
|
1002 |
(SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]), |
0 | 1003 |
i->xy); |
1004 |
} |
|
1005 |
} |
|
1006 |
||
1007 |
i->counter--; |
|
1008 |
||
1009 |
/* produce some cargo */ |
|
1010 |
if ((i->counter & 0xFF) == 0) { |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1011 |
if (HasBit(indsp->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1); |
7664
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7661
diff
changeset
|
1012 |
|
8253 | 1013 |
IndustryBehaviour indbehav = indsp->behaviour; |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1014 |
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
|
1015 |
i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]); |
0 | 1016 |
|
7701
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1017 |
if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) { |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1018 |
bool plant; |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1019 |
if (HasBit(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) { |
7701
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1020 |
plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0); |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1021 |
} else { |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
1022 |
plant = Chance16(1, 8); |
7701
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1023 |
} |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1024 |
|
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1025 |
if (plant) PlantRandomFarmField(i); |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1026 |
} |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1027 |
if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) { |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1028 |
bool cut = ((i->counter & 0x1FF) == 0); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1029 |
if (HasBit(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) { |
7701
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1030 |
cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->xy) != 0); |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1031 |
} |
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1032 |
|
72d4e674ca6e
(svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents:
7699
diff
changeset
|
1033 |
if (cut) ChopLumberMillTrees(i); |
2639 | 1034 |
} |
10303
78028cd29075
(svn r12844) -Fix: the industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway.
rubidium
parents:
10272
diff
changeset
|
1035 |
|
78028cd29075
(svn r12844) -Fix: the industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway.
rubidium
parents:
10272
diff
changeset
|
1036 |
TriggerIndustry(i, INDUSTRY_TRIGGER_INDUSTRY_TICK); |
78028cd29075
(svn r12844) -Fix: the industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway.
rubidium
parents:
10272
diff
changeset
|
1037 |
StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK); |
0 | 1038 |
} |
1039 |
} |
|
1040 |
||
6573 | 1041 |
void OnTick_Industry() |
0 | 1042 |
{ |
1043 |
Industry *i; |
|
1044 |
||
1045 |
if (_industry_sound_ctr != 0) { |
|
1046 |
_industry_sound_ctr++; |
|
1047 |
||
1048 |
if (_industry_sound_ctr == 75) { |
|
541 | 1049 |
SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile); |
0 | 1050 |
} 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
|
1051 |
_industry_sound_ctr = 0; |
541 | 1052 |
SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile); |
0 | 1053 |
} |
1054 |
} |
|
1055 |
||
2639 | 1056 |
if (_game_mode == GM_EDITOR) return; |
0 | 1057 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1058 |
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
|
1059 |
ProduceIndustryGoods(i); |
0 | 1060 |
} |
1061 |
} |
|
1062 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1063 |
static bool CheckNewIndustry_NULL(TileIndex tile) |
0 | 1064 |
{ |
1065 |
return true; |
|
1066 |
} |
|
1067 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1068 |
static bool CheckNewIndustry_Forest(TileIndex tile) |
0 | 1069 |
{ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
1070 |
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
|
1071 |
if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) { |
0 | 1072 |
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED; |
1073 |
return false; |
|
1074 |
} |
|
1075 |
} |
|
1076 |
return true; |
|
1077 |
} |
|
1078 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1079 |
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
|
1080 |
{ |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1081 |
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
|
1082 |
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
|
1083 |
|
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1084 |
_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
|
1085 |
return false; |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1086 |
} |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1087 |
|
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1088 |
extern bool _ignore_restrictions; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1089 |
|
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1090 |
static bool CheckNewIndustry_OilRig(TileIndex tile) |
0 | 1091 |
{ |
2639 | 1092 |
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
|
1093 |
if (TileHeight(tile) == 0 && |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1094 |
DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true; |
0 | 1095 |
|
1096 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
|
1097 |
return false; |
|
1098 |
} |
|
1099 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1100 |
static bool CheckNewIndustry_Farm(TileIndex tile) |
0 | 1101 |
{ |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6669
diff
changeset
|
1102 |
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
|
1103 |
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) { |
0 | 1104 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1105 |
return false; |
|
1106 |
} |
|
1107 |
} |
|
1108 |
return true; |
|
1109 |
} |
|
1110 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1111 |
static bool CheckNewIndustry_Plantation(TileIndex tile) |
0 | 1112 |
{ |
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
|
1113 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
0 | 1114 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1115 |
return false; |
|
1116 |
} |
|
1117 |
||
1118 |
return true; |
|
1119 |
} |
|
1120 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1121 |
static bool CheckNewIndustry_Water(TileIndex tile) |
0 | 1122 |
{ |
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
|
1123 |
if (GetTropicZone(tile) != TROPICZONE_DESERT) { |
0 | 1124 |
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; |
1125 |
return false; |
|
1126 |
} |
|
1127 |
||
1128 |
return true; |
|
1129 |
} |
|
1130 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1131 |
static bool CheckNewIndustry_Lumbermill(TileIndex tile) |
0 | 1132 |
{ |
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
|
1133 |
if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) { |
0 | 1134 |
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; |
1135 |
return false; |
|
1136 |
} |
|
1137 |
return true; |
|
1138 |
} |
|
1139 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1140 |
static bool CheckNewIndustry_BubbleGen(TileIndex tile) |
0 | 1141 |
{ |
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
1142 |
return GetTileZ(tile) <= TILE_HEIGHT * 4; |
0 | 1143 |
} |
1144 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1145 |
typedef bool CheckNewIndustryProc(TileIndex tile); |
3663
50fbc1639a3f
(svn r4578) CodeChange : Cleanup of industry_cmd (Step-2).
belugas
parents:
3662
diff
changeset
|
1146 |
static CheckNewIndustryProc * const _check_new_industry_procs[CHECK_END] = { |
0 | 1147 |
CheckNewIndustry_NULL, |
1148 |
CheckNewIndustry_Forest, |
|
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1149 |
CheckNewIndustry_OilRefinery, |
0 | 1150 |
CheckNewIndustry_Farm, |
1151 |
CheckNewIndustry_Plantation, |
|
1152 |
CheckNewIndustry_Water, |
|
1153 |
CheckNewIndustry_Lumbermill, |
|
1154 |
CheckNewIndustry_BubbleGen, |
|
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1155 |
CheckNewIndustry_OilRig |
0 | 1156 |
}; |
1157 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1158 |
static bool CheckSuitableIndustryPos(TileIndex tile) |
0 | 1159 |
{ |
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
|
1160 |
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
|
1161 |
uint y = TileY(tile); |
0 | 1162 |
|
2639 | 1163 |
if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { |
0 | 1164 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1165 |
return false; |
|
1166 |
} |
|
1167 |
||
1168 |
return true; |
|
1169 |
} |
|
1170 |
||
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1171 |
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type) |
0 | 1172 |
{ |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1173 |
const Town *t; |
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1174 |
const Industry *i; |
0 | 1175 |
|
1176 |
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
|
1177 |
|
2639 | 1178 |
if (_patches.multiple_industry_per_town) return t; |
0 | 1179 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1180 |
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
|
1181 |
if (i->type == (byte)type && |
0 | 1182 |
i->town == t) { |
1183 |
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; |
|
1184 |
return NULL; |
|
1185 |
} |
|
1186 |
} |
|
1187 |
||
1188 |
return t; |
|
1189 |
} |
|
1190 |
||
8158
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1191 |
bool IsSlopeRefused(Slope current, Slope refused) |
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1192 |
{ |
8229
580e6d337be5
(svn r11268) -Fix[FS#1336]: Call IsSlopeRefused whenever it is required. Looks like there was one spot missing. Thanks frosch
belugas
parents:
8172
diff
changeset
|
1193 |
if (IsSteepSlope(current)) return true; |
8158
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1194 |
if (current != SLOPE_FLAT) { |
8526
3804c50aeb9f
(svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents:
8485
diff
changeset
|
1195 |
if (IsSteepSlope(refused)) return true; |
8158
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1196 |
|
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1197 |
Slope t = ComplementSlope(current); |
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1198 |
|
8526
3804c50aeb9f
(svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents:
8485
diff
changeset
|
1199 |
if (refused & SLOPE_W && (t & SLOPE_NW)) return true; |
3804c50aeb9f
(svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents:
8485
diff
changeset
|
1200 |
if (refused & SLOPE_S && (t & SLOPE_NE)) return true; |
3804c50aeb9f
(svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents:
8485
diff
changeset
|
1201 |
if (refused & SLOPE_E && (t & SLOPE_SW)) return true; |
3804c50aeb9f
(svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents:
8485
diff
changeset
|
1202 |
if (refused & SLOPE_N && (t & SLOPE_SE)) return true; |
8158
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1203 |
} |
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1204 |
|
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1205 |
return false; |
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1206 |
} |
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1207 |
|
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1208 |
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, bool *custom_shape_check = NULL) |
0 | 1209 |
{ |
1210 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
8159
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1211 |
bool refused_slope = false; |
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1212 |
bool custom_shape = false; |
0 | 1213 |
|
1214 |
do { |
|
7963
e04dbb203f3e
(svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to.
belugas
parents:
7958
diff
changeset
|
1215 |
IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx); |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1216 |
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
|
1217 |
|
0 | 1218 |
if (!IsValidTile(cur_tile)) { |
7969
9050701304bd
(svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents:
7963
diff
changeset
|
1219 |
if (gfx == GFX_WATERTILE_SPECIALCHECK) continue; |
0 | 1220 |
return false; |
1221 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1222 |
|
7969
9050701304bd
(svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents:
7963
diff
changeset
|
1223 |
if (gfx == GFX_WATERTILE_SPECIALCHECK) { |
3296
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1224 |
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
|
1225 |
GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) { |
3296
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1226 |
return false; |
69c0c6e467bb
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1227 |
} |
0 | 1228 |
} else { |
8254
5de2bbd26163
(svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents:
8253
diff
changeset
|
1229 |
if (!EnsureNoVehicleOnGround(cur_tile)) return false; |
7389
d8bc6472130b
(svn r10140) -Fix [FS#867]: an industry could overbuild a bridge.
rubidium
parents:
7355
diff
changeset
|
1230 |
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
|
1231 |
|
8027
80ddda328596
(svn r11050) -Codechange: Use the translated gfx, not the original one.
belugas
parents:
8018
diff
changeset
|
1232 |
const IndustryTileSpec *its = GetIndustryTileSpec(gfx); |
80ddda328596
(svn r11050) -Codechange: Use the translated gfx, not the original one.
belugas
parents:
8018
diff
changeset
|
1233 |
|
8253 | 1234 |
IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour; |
0 | 1235 |
|
8252
396c795ecf31
(svn r11301) -Fix: water check when building industries didn't work
glx
parents:
8251
diff
changeset
|
1236 |
/* Perform land/water check if not disabled */ |
8967
0b56f973bcf0
(svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents:
8955
diff
changeset
|
1237 |
if (!HasBit(its->slopes_refused, 5) && (IsWaterTile(cur_tile) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return false; |
8252
396c795ecf31
(svn r11301) -Fix: water check when building industries didn't work
glx
parents:
8251
diff
changeset
|
1238 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1239 |
if (HasBit(its->callback_flags, CBM_INDT_SHAPE_CHECK)) { |
8159
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1240 |
custom_shape = true; |
8158
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1241 |
if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return false; |
0 | 1242 |
} else { |
8252
396c795ecf31
(svn r11301) -Fix: water check when building industries didn't work
glx
parents:
8251
diff
changeset
|
1243 |
Slope tileh = GetTileSlope(cur_tile, NULL); |
396c795ecf31
(svn r11301) -Fix: water check when building industries didn't work
glx
parents:
8251
diff
changeset
|
1244 |
refused_slope |= IsSlopeRefused(tileh, its->slopes_refused); |
7708
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1245 |
} |
0 | 1246 |
|
8550
106be4d4bd49
(svn r11615) -Fix (r11609): temperate banks can only be built in towns (over a house)
glx
parents:
8545
diff
changeset
|
1247 |
if (ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) { |
7708
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1248 |
if (!IsTileType(cur_tile, MP_HOUSE)) { |
8545
0f083181232e
(svn r11609) -Fix [FS#1524]: wrong error messages were shown when trying to build some industries in the scenario editor.
rubidium
parents:
8526
diff
changeset
|
1249 |
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
7708
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1250 |
return false; |
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1251 |
} |
7723
e6785e8fec08
(svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents:
7712
diff
changeset
|
1252 |
if (CmdFailed(DoCommand(cur_tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR))) return false; |
e6785e8fec08
(svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents:
7712
diff
changeset
|
1253 |
} else if ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) == 0 || !IsTileType(cur_tile, MP_HOUSE)) { |
e6785e8fec08
(svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents:
7712
diff
changeset
|
1254 |
if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) return false; |
0 | 1255 |
} |
1256 |
} |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1257 |
} while ((++it)->ti.x != -0x80); |
0 | 1258 |
|
8159
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1259 |
if (custom_shape_check != NULL) *custom_shape_check = custom_shape; |
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1260 |
|
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1261 |
/* It is almost impossible to have a fully flat land in TG, so what we |
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1262 |
* do is that we check if we can make the land flat later on. See |
7a36d78b2343
(svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents:
8158
diff
changeset
|
1263 |
* CheckIfCanLevelIndustryPlatform(). */ |
8545
0f083181232e
(svn r11609) -Fix [FS#1524]: wrong error messages were shown when trying to build some industries in the scenario editor.
rubidium
parents:
8526
diff
changeset
|
1264 |
return !refused_slope || (_patches.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions); |
0 | 1265 |
} |
1266 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1267 |
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
|
1268 |
{ |
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
|
1269 |
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
|
1270 |
_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
|
1271 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1272 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1273 |
|
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
|
1274 |
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
|
1275 |
_error_message = STR_0239_SITE_UNSUITABLE; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1276 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1277 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1278 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1279 |
return true; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1280 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1281 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1282 |
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
|
1283 |
{ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1284 |
int size_x, size_y; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1285 |
uint curh; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1286 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1287 |
size_x = 2; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1288 |
size_y = 2; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1289 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1290 |
/* 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
|
1291 |
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
|
1292 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1293 |
tile += TileDiffXY(-1, -1); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1294 |
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
|
1295 |
curh = TileHeight(tile_walk); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1296 |
/* Is the tile clear? */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1297 |
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
|
1298 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1299 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1300 |
/* Don't allow too big of a change if this is the sub-tile check */ |
8466
9ce95e16f9f9
(svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents:
8463
diff
changeset
|
1301 |
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
|
1302 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1303 |
/* 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
|
1304 |
* 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
|
1305 |
* 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
|
1306 |
if (internal == 0 && curh != height) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1307 |
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
|
1308 |
return false; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1309 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1310 |
} 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
|
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 |
/** |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1316 |
* 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
|
1317 |
* damaging the surroundings too much. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1318 |
*/ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1319 |
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
|
1320 |
{ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1321 |
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
|
1322 |
int max_x = 0; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1323 |
int max_y = 0; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1324 |
TileIndex cur_tile; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1325 |
uint size_x, size_y; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1326 |
uint h, curh; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1327 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1328 |
/* 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
|
1329 |
do { |
8125
df9b65517e19
(svn r11160) -Fix: A gfx of 0xFF does not count when it's time to establish the size of the industry.
belugas
parents:
8111
diff
changeset
|
1330 |
if (it->gfx == 0xFF) continue; // FF been a marquer for a check on clear water, skip it |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1331 |
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
|
1332 |
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
|
1333 |
} while ((++it)->ti.x != MKEND); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1334 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1335 |
/* Remember level height */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1336 |
h = TileHeight(tile); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1337 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1338 |
/* 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
|
1339 |
* 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
|
1340 |
cur_tile = tile + TileDiffXY(-1, -1); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1341 |
size_x = max_x + 4; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1342 |
size_y = max_y + 4; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1343 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1344 |
/* 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
|
1345 |
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
|
1346 |
|
8136
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1347 |
/* _current_player is OWNER_NONE for randomly generated industries and in editor, or the player who funded or prospected the industry. |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1348 |
* Perform terraforming as OWNER_TOWN to disable autoslope. */ |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1349 |
PlayerID old_player = _current_player; |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1350 |
_current_player = OWNER_TOWN; |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1351 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1352 |
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
|
1353 |
curh = TileHeight(tile_walk); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1354 |
if (curh != h) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1355 |
/* 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
|
1356 |
* damaging the surroundings too much. */ |
8136
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1357 |
if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) { |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1358 |
_current_player = old_player; |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1359 |
return false; |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1360 |
} |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1361 |
/* 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
|
1362 |
* What is missing, is if the difference in height is more than 1.. */ |
8136
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1363 |
if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) { |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1364 |
_current_player = old_player; |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1365 |
return false; |
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1366 |
} |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1367 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1368 |
} 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
|
1369 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1370 |
if (flags & DC_EXEC) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1371 |
/* Terraform the land under the industry */ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1372 |
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
|
1373 |
curh = TileHeight(tile_walk); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1374 |
while (curh != h) { |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1375 |
/* 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
|
1376 |
* 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
|
1377 |
* a nice assert if they don't match ;) */ |
7976
5d93386b748b
(svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents:
7969
diff
changeset
|
1378 |
DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1379 |
curh += (curh > h) ? -1 : 1; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1380 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1381 |
} 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
|
1382 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1383 |
|
8136
d1a4486be2fd
(svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents:
8133
diff
changeset
|
1384 |
_current_player = old_player; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1385 |
return true; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1386 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1387 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1388 |
|
8730
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1389 |
static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type) |
0 | 1390 |
{ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1391 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
3662
e9e1533c758b
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1392 |
const Industry *i; |
0 | 1393 |
|
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1394 |
if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID) |
8730
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1395 |
/* Allow primary industries to be placed close to any other industry */ |
0 | 1396 |
return true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1397 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1398 |
FOR_ALL_INDUSTRIES(i) { |
8730
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1399 |
/* Within 14 tiles from another industry is considered close */ |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1400 |
bool in_low_distance = DistanceMax(tile, i->xy) <= 14; |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1401 |
|
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
|
1402 |
/* check if an industry that accepts the same goods is nearby */ |
8730
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1403 |
if (in_low_distance && |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1404 |
indspec->accepts_cargo[0] != CT_INVALID && // not a primary industry? |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1405 |
indspec->accepts_cargo[0] == i->accepts_cargo[0] && ( |
8730
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1406 |
/* at least one of those options must be true */ |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1407 |
_game_mode != GM_EDITOR || // editor must not be stopped |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1408 |
!_patches.same_industry_close || |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1409 |
!_patches.multiple_industry_per_town)) { |
2639 | 1410 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1411 |
return false; |
|
1412 |
} |
|
0 | 1413 |
|
8730
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1414 |
/* check if there are any conflicting industry types around */ |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1415 |
if ((i->type == indspec->conflicting[0] || |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1416 |
i->type == indspec->conflicting[1] || |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1417 |
i->type == indspec->conflicting[2]) && |
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1418 |
in_low_distance) { |
0 | 1419 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1420 |
return false; |
|
1421 |
} |
|
1422 |
} |
|
1423 |
return true; |
|
1424 |
} |
|
1425 |
||
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1426 |
/** Production level maximum, minimum and default values. |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1427 |
* It is not a value been really used in order to change, but rather an indicator |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1428 |
* of how the industry is behaving. */ |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1429 |
enum ProductionLevels { |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1430 |
PRODLEVEL_CLOSURE = 0x00, ///< signal set to actually close the industry |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1431 |
PRODLEVEL_MINIMUM = 0x04, ///< below this level, the industry is set to be closing |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1432 |
PRODLEVEL_DEFAULT = 0x10, ///< default level set when the industry is created |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1433 |
PRODLEVEL_MAXIMUM = 0x80, ///< the industry is running at full speed |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1434 |
}; |
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1435 |
|
7941
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
1436 |
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner) |
0 | 1437 |
{ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1438 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
0 | 1439 |
uint32 r; |
8142
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1440 |
uint j; |
0 | 1441 |
|
1442 |
i->xy = tile; |
|
1443 |
i->width = i->height = 0; |
|
1444 |
i->type = type; |
|
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
1445 |
IncIndustryTypeCount(type); |
0 | 1446 |
|
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1447 |
i->produced_cargo[0] = indspec->produced_cargo[0]; |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1448 |
i->produced_cargo[1] = indspec->produced_cargo[1]; |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1449 |
i->accepts_cargo[0] = indspec->accepts_cargo[0]; |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1450 |
i->accepts_cargo[1] = indspec->accepts_cargo[1]; |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1451 |
i->accepts_cargo[2] = indspec->accepts_cargo[2]; |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1452 |
i->production_rate[0] = indspec->production_rate[0]; |
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1453 |
i->production_rate[1] = indspec->production_rate[1]; |
0 | 1454 |
|
8443
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
1455 |
/* don't use smooth economy for industries using production related callbacks */ |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
1456 |
if (_patches.smooth_economy && |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
1457 |
!(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
1458 |
!(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE)) // production change callbacks |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
1459 |
) { |
0 | 1460 |
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); |
1461 |
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); |
|
1462 |
} |
|
1463 |
||
1464 |
i->town = t; |
|
1465 |
i->owner = owner; |
|
1466 |
||
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
|
1467 |
r = Random(); |
8358
79bdf95a862c
(svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents:
8356
diff
changeset
|
1468 |
i->random_color = GB(r, 0, 4); |
79bdf95a862c
(svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents:
8356
diff
changeset
|
1469 |
i->counter = GB(r, 4, 12); |
79bdf95a862c
(svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents:
8356
diff
changeset
|
1470 |
i->random = GB(r, 16, 16); |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1471 |
i->produced_cargo_waiting[0] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1472 |
i->produced_cargo_waiting[1] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1473 |
i->incoming_cargo_waiting[0] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1474 |
i->incoming_cargo_waiting[1] = 0; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
1475 |
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
|
1476 |
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
|
1477 |
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
|
1478 |
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
|
1479 |
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
|
1480 |
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
|
1481 |
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
|
1482 |
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
|
1483 |
i->last_month_transported[1] = 0; |
0 | 1484 |
i->was_cargo_delivered = false; |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4328
diff
changeset
|
1485 |
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
|
1486 |
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
|
1487 |
i->last_month_production[1] = i->production_rate[1] * 8; |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
1488 |
i->founder = _current_player; |
8142
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1489 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1490 |
if (HasBit(indspec->callback_flags, CBM_IND_DECIDE_COLOUR)) { |
8146
fae08d49a223
(svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents:
8142
diff
changeset
|
1491 |
uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE); |
fae08d49a223
(svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents:
8142
diff
changeset
|
1492 |
if (res != CALLBACK_FAILED) i->random_color = GB(res, 0, 4); |
fae08d49a223
(svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents:
8142
diff
changeset
|
1493 |
} |
fae08d49a223
(svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents:
8142
diff
changeset
|
1494 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1495 |
if (HasBit(indspec->callback_flags, CBM_IND_INPUT_CARGO_TYPES)) { |
8142
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1496 |
for (j = 0; j < lengthof(i->accepts_cargo); j++) i->accepts_cargo[j] = CT_INVALID; |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1497 |
for (j = 0; j < lengthof(i->accepts_cargo); j++) { |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1498 |
uint16 res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE); |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1499 |
if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break; |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1500 |
i->accepts_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile); |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1501 |
} |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1502 |
} |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1503 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1504 |
if (HasBit(indspec->callback_flags, CBM_IND_OUTPUT_CARGO_TYPES)) { |
8142
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1505 |
for (j = 0; j < lengthof(i->produced_cargo); j++) i->produced_cargo[j] = CT_INVALID; |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1506 |
for (j = 0; j < lengthof(i->produced_cargo); j++) { |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1507 |
uint16 res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE); |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1508 |
if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break; |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1509 |
i->produced_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile); |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1510 |
} |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1511 |
} |
aaac2a5f116b
(svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents:
8141
diff
changeset
|
1512 |
|
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
1513 |
i->construction_date = _date; |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
1514 |
i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR : |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
1515 |
(_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY); |
0 | 1516 |
|
7941
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
1517 |
/* Adding 1 here makes it conform to specs of var44 of varaction2 for industries |
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
1518 |
* 0 = created prior of newindustries |
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
1519 |
* else, chosen layout + 1 */ |
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
1520 |
i->selected_layout = layout + 1; |
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
1521 |
|
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
|
1522 |
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
|
1523 |
|
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
1524 |
i->prod_level = PRODLEVEL_DEFAULT; |
0 | 1525 |
|
1526 |
do { |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1527 |
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1528 |
|
7969
9050701304bd
(svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents:
7963
diff
changeset
|
1529 |
if (it->gfx != GFX_WATERTILE_SPECIALCHECK) { |
0 | 1530 |
byte size; |
1531 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1532 |
size = it->ti.x; |
0 | 1533 |
if (size > i->width) i->width = size; |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1534 |
size = it->ti.y; |
0 | 1535 |
if (size > i->height)i->height = size; |
1536 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
1537 |
DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 1538 |
|
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8612
diff
changeset
|
1539 |
MakeIndustry(cur_tile, i->index, it->gfx, Random()); |
8349
011e0ee04e43
(svn r11403) -Fix: NewIndustries GRF assume that tiles are already animated during construction.
rubidium
parents:
8348
diff
changeset
|
1540 |
|
5686
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
1541 |
if (_generating_world) { |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
1542 |
SetIndustryConstructionCounter(cur_tile, 3); |
03c3d3b3e7eb
(svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents:
5685
diff
changeset
|
1543 |
SetIndustryConstructionStage(cur_tile, 2); |
8358
79bdf95a862c
(svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents:
8356
diff
changeset
|
1544 |
} |
8807
32ea2a58806a
(svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents:
8798
diff
changeset
|
1545 |
|
32ea2a58806a
(svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents:
8798
diff
changeset
|
1546 |
/* it->gfx is stored in the map. But the translated ID cur_gfx is the interesting one */ |
32ea2a58806a
(svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents:
8798
diff
changeset
|
1547 |
IndustryGfx cur_gfx = GetTranslatedIndustryTileID(it->gfx); |
32ea2a58806a
(svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents:
8798
diff
changeset
|
1548 |
const IndustryTileSpec *its = GetIndustryTileSpec(cur_gfx); |
32ea2a58806a
(svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents:
8798
diff
changeset
|
1549 |
if (its->animation_info != 0xFFFF) AddAnimatedTile(cur_tile); |
0 | 1550 |
} |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1551 |
} while ((++it)->ti.x != -0x80); |
0 | 1552 |
|
1553 |
i->width++; |
|
1554 |
i->height++; |
|
1555 |
||
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
|
1556 |
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
|
1557 |
for (j = 0; j != 50; j++) PlantRandomFarmField(i); |
0 | 1558 |
} |
1559 |
_industry_sort_dirty = true; |
|
1560 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1561 |
} |
|
1562 |
||
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
|
1563 |
/** 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
|
1564 |
* @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
|
1565 |
* @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
|
1566 |
* @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
|
1567 |
* @param indspec pointer to industry specifications |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7701
diff
changeset
|
1568 |
* @param itspec_index the index of the itsepc to build/fund |
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1569 |
* @param seed random seed (possibly) used by industries |
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
|
1570 |
* @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
|
1571 |
*/ |
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1572 |
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed) |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1573 |
{ |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7701
diff
changeset
|
1574 |
const IndustryTileTable *it = indspec->table[itspec_index]; |
7708
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1575 |
bool custom_shape_check = false; |
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1576 |
|
8158
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1577 |
if (!CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, &custom_shape_check)) return NULL; |
7708
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1578 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1579 |
if (HasBit(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) { |
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1580 |
if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed)) return NULL; |
7708
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1581 |
} else { |
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1582 |
if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL; |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7701
diff
changeset
|
1583 |
} |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1584 |
|
8545
0f083181232e
(svn r11609) -Fix [FS#1524]: wrong error messages were shown when trying to build some industries in the scenario editor.
rubidium
parents:
8526
diff
changeset
|
1585 |
if (!custom_shape_check && _patches.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL; |
8730
41a25de56561
(svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents:
8726
diff
changeset
|
1586 |
if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1587 |
|
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7701
diff
changeset
|
1588 |
const Town *t = CheckMultipleIndustryInTown(tile, type); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1589 |
if (t == NULL) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1590 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1591 |
if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1592 |
if (!CheckSuitableIndustryPos(tile)) return NULL; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1593 |
|
10314
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
10303
diff
changeset
|
1594 |
if (!Industry::CanAllocateItem()) return NULL; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1595 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1596 |
if (flags & DC_EXEC) { |
10314
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
10303
diff
changeset
|
1597 |
Industry *i = new Industry(tile); |
7708
595630b38fbf
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7703
diff
changeset
|
1598 |
if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type); |
7941
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
1599 |
DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE); |
10314
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
10303
diff
changeset
|
1600 |
|
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
10303
diff
changeset
|
1601 |
return i; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1602 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1603 |
|
10314
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
10303
diff
changeset
|
1604 |
/* We need to return a non-NULL pointer to tell we have created an industry. |
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
10303
diff
changeset
|
1605 |
* However, we haven't created a real one (no DC_EXEC), so return a fake one. */ |
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
10303
diff
changeset
|
1606 |
return GetIndustry(0); |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1607 |
} |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1608 |
|
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
|
1609 |
/** 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
|
1610 |
* @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
|
1611 |
* @param flags of operations to conduct |
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1612 |
* @param p1 various bitstuffed elements |
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1613 |
* - p1 = (bit 0 - 15) - industry type see build_industry.h and see industry.h |
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1614 |
* - p1 = (bit 16 - 31) - first layout to try |
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1615 |
* @param p2 seed to use for variable 8F |
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
|
1616 |
* @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
|
1617 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7406
diff
changeset
|
1618 |
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1619 |
{ |
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1620 |
const IndustrySpec *indspec = GetIndustrySpec(GB(p1, 0, 16)); |
2639 | 1621 |
|
4965
9d4ad0851fde
(svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents:
4942
diff
changeset
|
1622 |
/* 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
|
1623 |
if (!indspec->enabled) { |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1624 |
return CMD_ERROR; |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1625 |
} |
0 | 1626 |
|
2638
0c9b00251fce
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1627 |
/* If the patch for raw-material industries is not on, you cannot build raw-material industries. |
7681
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
1628 |
* Raw material industries are industries that do not accept cargo (at least for now) */ |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7701
diff
changeset
|
1629 |
if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 0 && indspec->IsRawIndustry()) { |
2638
0c9b00251fce
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1630 |
return CMD_ERROR; |
0c9b00251fce
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1631 |
} |
0 | 1632 |
|
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7701
diff
changeset
|
1633 |
if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && indspec->IsRawIndustry()) { |
7673
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1634 |
if (flags & DC_EXEC) { |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1635 |
/* Prospecting has a chance to fail, however we cannot guarantee that something can |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1636 |
* be built on the map, so the chance gets lower when the map is fuller, but there |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1637 |
* is nothing we can really do about that. */ |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1638 |
if (Random() <= indspec->prospecting_chance) { |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1639 |
for (int i = 0; i < 5000; i++) { |
8650
ee0811b937a8
(svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents:
8640
diff
changeset
|
1640 |
/* We should not have more than one Random() in a function call |
ee0811b937a8
(svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents:
8640
diff
changeset
|
1641 |
* because parameter evaluation order is not guaranteed in the c++ standard |
ee0811b937a8
(svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents:
8640
diff
changeset
|
1642 |
*/ |
ee0811b937a8
(svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents:
8640
diff
changeset
|
1643 |
tile = RandomTile(); |
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1644 |
const Industry *ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2); |
7699
c750f7b360b9
(svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents:
7695
diff
changeset
|
1645 |
if (ind != NULL) { |
c750f7b360b9
(svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents:
7695
diff
changeset
|
1646 |
SetDParam(0, indspec->name); |
8251
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1647 |
if (indspec->new_industry_text > STR_LAST_STRINGID) { |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1648 |
SetDParam(1, STR_TOWN); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1649 |
SetDParam(2, ind->town->index); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1650 |
} else { |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1651 |
SetDParam(1, ind->town->index); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1652 |
} |
7699
c750f7b360b9
(svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents:
7695
diff
changeset
|
1653 |
AddNewsItem(indspec->new_industry_text, |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9152
diff
changeset
|
1654 |
NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, DNC_NONE, ind->xy, 0); |
7699
c750f7b360b9
(svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents:
7695
diff
changeset
|
1655 |
break; |
c750f7b360b9
(svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents:
7695
diff
changeset
|
1656 |
} |
7673
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1657 |
} |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1658 |
} |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1659 |
} |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1660 |
} else { |
8256
4f95ba635f0b
(svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents:
8254
diff
changeset
|
1661 |
int count = indspec->num_table; |
4f95ba635f0b
(svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents:
8254
diff
changeset
|
1662 |
const IndustryTileTable * const *itt = indspec->table; |
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1663 |
int num = Clamp(GB(p1, 16, 16), 0, count - 1); |
0 | 1664 |
|
8244
e23cac10e7fd
(svn r11285) -Fix: 'site unsuitable' was always shown instead specified message when trying to build industry ingame (Csaboka)
glx
parents:
8235
diff
changeset
|
1665 |
_error_message = STR_0239_SITE_UNSUITABLE; |
7673
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1666 |
do { |
8256
4f95ba635f0b
(svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents:
8254
diff
changeset
|
1667 |
if (--count < 0) return CMD_ERROR; |
4f95ba635f0b
(svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents:
8254
diff
changeset
|
1668 |
if (--num < 0) num = indspec->num_table - 1; |
8158
84c773075796
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
8151
diff
changeset
|
1669 |
} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1)); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1670 |
|
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1671 |
if (CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2) == NULL) return CMD_ERROR; |
7673
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1672 |
} |
3ab9344bd532
(svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents:
7664
diff
changeset
|
1673 |
|
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
1674 |
return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost()); |
0 | 1675 |
} |
1676 |
||
1677 |
||
3538
3eb71c726341
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
1678 |
Industry *CreateNewIndustry(TileIndex tile, IndustryType type) |
0 | 1679 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1680 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
0 | 1681 |
|
8932
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1682 |
uint32 seed = Random(); |
989fe2280933
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8903
diff
changeset
|
1683 |
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table), seed); |
0 | 1684 |
} |
1685 |
||
7834
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1686 |
enum { |
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1687 |
NB_NUMOFINDUSTRY = 11, |
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1688 |
NB_DIFFICULTY_LEVEL = 5, |
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1689 |
}; |
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1690 |
|
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1691 |
static const byte _numof_industry_table[NB_DIFFICULTY_LEVEL][NB_NUMOFINDUSTRY] = { |
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
|
1692 |
/* difficulty settings for number of industries */ |
3669
8a3a5d008971
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1693 |
{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
|
1694 |
{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
|
1695 |
{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
|
1696 |
{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
|
1697 |
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, //high |
0 | 1698 |
}; |
1699 |
||
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
|
1700 |
/** 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
|
1701 |
* 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
|
1702 |
* @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
|
1703 |
* @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
|
1704 |
static void PlaceInitialIndustry(IndustryType type, int amount) |
0 | 1705 |
{ |
7834
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1706 |
/* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the |
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1707 |
* _numof_industry_table. newgrf can specify a big amount */ |
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1708 |
int num = (amount > NB_NUMOFINDUSTRY) ? amount : _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
|
1709 |
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
|
1710 |
|
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
|
1711 |
/* 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
|
1712 |
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
|
1713 |
|
2639 | 1714 |
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
|
1715 |
PlayerID old_player = _current_player; |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1716 |
_current_player = OWNER_NONE; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1717 |
assert(num > 0); |
0 | 1718 |
|
1719 |
do { |
|
2639 | 1720 |
uint i; |
1721 |
||
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1722 |
IncreaseGeneratingWorldProgress(GWP_INDUSTRY); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1723 |
|
2639 | 1724 |
for (i = 0; i < 2000; i++) { |
1725 |
if (CreateNewIndustry(RandomTile(), type) != NULL) break; |
|
1726 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1727 |
} while (--num); |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1728 |
|
267 | 1729 |
_current_player = old_player; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1730 |
} |
0 | 1731 |
} |
1732 |
||
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
|
1733 |
/** 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
|
1734 |
* It will scale the amount of industries by map size as well as difficulty level */ |
6573 | 1735 |
void GenerateIndustries() |
0 | 1736 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1737 |
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
|
1738 |
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
|
1739 |
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
|
1740 |
const IndustrySpec *ind_spc; |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1741 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1742 |
/* Find the total amount of industries */ |
7757
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1743 |
if (_opt.diff.number_industries > 0) { |
7815
04deaeb181ab
(svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents:
7789
diff
changeset
|
1744 |
for (it = 0; it < NUM_INDUSTRYTYPES; it++) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1745 |
|
7757
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1746 |
ind_spc = GetIndustrySpec(it); |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1747 |
|
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1748 |
if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) { |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1749 |
ResetIndustryCreationProbility(it); |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1750 |
} |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1751 |
|
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1752 |
chance = ind_spc->appear_creation[_opt.landscape]; |
7758 | 1753 |
if (ind_spc->enabled && chance > 0) { |
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1754 |
/* 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
|
1755 |
* 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
|
1756 |
* the _numof_industry_table,in fact */ |
7834
00abd0f1ea03
(svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents:
7833
diff
changeset
|
1757 |
int num = (chance > NB_NUMOFINDUSTRY) ? chance : _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
|
1758 |
|
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1759 |
/* 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
|
1760 |
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
|
1761 |
i += num; |
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1762 |
} |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1763 |
} |
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
|
1764 |
} |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1765 |
|
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1766 |
SetGeneratingWorldProgress(GWP_INDUSTRY, i); |
0 | 1767 |
|
7757
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1768 |
if (_opt.diff.number_industries > 0) { |
7815
04deaeb181ab
(svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents:
7789
diff
changeset
|
1769 |
for (it = 0; it < NUM_INDUSTRYTYPES; it++) { |
7757
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1770 |
/* Once the number of industries has been determined, let's really create them. |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1771 |
* The test for chance allows us to try create industries that are available only |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1772 |
* for this landscape. |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1773 |
* @todo : Do we really have to pass chance as un-scaled value, since we've already |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1774 |
* processed that scaling above? No, don't think so. Will find a way. */ |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1775 |
ind_spc = GetIndustrySpec(it); |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1776 |
if (ind_spc->enabled) { |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1777 |
chance = ind_spc->appear_creation[_opt.landscape]; |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1778 |
if (chance > 0) PlaceInitialIndustry(it, chance); |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1779 |
} |
7244
7baac45a972c
(svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents:
7239
diff
changeset
|
1780 |
} |
7757
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1781 |
} |
0 | 1782 |
} |
1783 |
||
1784 |
static void UpdateIndustryStatistics(Industry *i) |
|
1785 |
{ |
|
1786 |
byte pct; |
|
6963 | 1787 |
bool refresh = false; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1788 |
|
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1789 |
for (byte j = 0; j < lengthof(i->produced_cargo); j++) { |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
1790 |
if (i->produced_cargo[j] != CT_INVALID) { |
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
|
1791 |
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
|
1792 |
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
|
1793 |
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
|
1794 |
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
|
1795 |
} |
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
|
1796 |
i->last_month_pct_transported[j] = pct; |
0 | 1797 |
|
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
|
1798 |
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
|
1799 |
i->this_month_production[j] = 0; |
0 | 1800 |
|
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
|
1801 |
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
|
1802 |
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
|
1803 |
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
|
1804 |
} |
0 | 1805 |
} |
1806 |
||
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1807 |
if (refresh) InvalidateWindow(WC_INDUSTRY_VIEW, i->index); |
0 | 1808 |
} |
1809 |
||
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
|
1810 |
/** 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
|
1811 |
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
|
1812 |
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
|
1813 |
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
|
1814 |
}; |
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
|
1815 |
|
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1816 |
/** |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1817 |
* 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
|
1818 |
*/ |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1819 |
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
|
1820 |
{ |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1821 |
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
|
1822 |
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
|
1823 |
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
|
1824 |
uint num = 0; |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
1825 |
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
|
1826 |
uint16 probability_max = 0; |
0 | 1827 |
|
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1828 |
/* 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
|
1829 |
for (j = 0; j < NUM_INDUSTRYTYPES; j++) { |
8319
434ce8c1e463
(svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents:
8317
diff
changeset
|
1830 |
ind_spc = GetIndustrySpec(j); |
434ce8c1e463
(svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents:
8317
diff
changeset
|
1831 |
byte chance = ind_spc->appear_ingame[_opt.landscape]; |
434ce8c1e463
(svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents:
8317
diff
changeset
|
1832 |
|
434ce8c1e463
(svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents:
8317
diff
changeset
|
1833 |
if (!ind_spc->enabled || chance == 0) continue; |
0 | 1834 |
|
7757
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1835 |
/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed, |
6335bd827212
(svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents:
7725
diff
changeset
|
1836 |
* and if appearing chance for this landscape is above 0, this industry can be chosen */ |
8319
434ce8c1e463
(svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents:
8317
diff
changeset
|
1837 |
if (CheckIfCallBackAllowsAvailability(j, IACT_RANDOMCREATION)) { |
6915
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1838 |
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
|
1839 |
/* 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
|
1840 |
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
|
1841 |
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
|
1842 |
} |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1843 |
} |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1844 |
|
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
|
1845 |
/* 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
|
1846 |
rndtype = RandomRange(probability_max); |
6989
43b359b4cb86
(svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents:
6987
diff
changeset
|
1847 |
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
|
1848 |
/* 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
|
1849 |
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
|
1850 |
} |
99e67df845fd
(svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents:
6886
diff
changeset
|
1851 |
|
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
|
1852 |
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
|
1853 |
/* 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
|
1854 |
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
|
1855 |
if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return; |
0 | 1856 |
|
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
|
1857 |
/* 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
|
1858 |
num = 2000; |
2639 | 1859 |
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
|
1860 |
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
|
1861 |
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
|
1862 |
if (--num == 0) return; |
0 | 1863 |
} |
1864 |
||
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
|
1865 |
SetDParam(0, ind_spc->name); |
8251
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1866 |
if (ind_spc->new_industry_text > STR_LAST_STRINGID) { |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1867 |
SetDParam(1, STR_TOWN); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1868 |
SetDParam(2, ind->town->index); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1869 |
} else { |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1870 |
SetDParam(1, ind->town->index); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
1871 |
} |
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
|
1872 |
AddNewsItem(ind_spc->new_industry_text, |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9152
diff
changeset
|
1873 |
NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, DNC_NONE, ind->xy, 0); |
0 | 1874 |
} |
1875 |
||
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1876 |
/** |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1877 |
* Protects an industry from closure if the appropriate flags and conditions are met |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1878 |
* INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1879 |
* count of industries of this type must one (or lower) in order to be protected |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1880 |
* against closure. |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1881 |
* @param type IndustryType been queried |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1882 |
* @result true if protection is on, false otherwise (except for oil wells) |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1883 |
*/ |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1884 |
static bool CheckIndustryCloseDownProtection(IndustryType type) |
0 | 1885 |
{ |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1886 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1887 |
|
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1888 |
/* oil wells (or the industries with that flag set) are always allowed to closedown */ |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1889 |
if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _opt.landscape == LT_TEMPERATE) return false; |
8317
fc30c847970b
(svn r11371) -Fix [FS#1396]: the industry protection only kicked in when it should not kick in.
rubidium
parents:
8302
diff
changeset
|
1890 |
return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) == 0 && GetIndustryTypeCount(type) <= 1; |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1891 |
} |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
1892 |
|
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1893 |
/** |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1894 |
* Can given cargo type be accepted or produced by the industry? |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1895 |
* @param cargo: Cargo type |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1896 |
* @param ind: Industry |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1897 |
* @param *c_accepts: Pointer to boolean for acceptance of cargo |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1898 |
* @param *c_produces: Pointer to boolean for production of cargo |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1899 |
* @return: \c *c_accepts is set when industry accepts the cargo type, |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1900 |
* \c *c_produces is set when the industry produces the cargo type |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1901 |
*/ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1902 |
static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces) |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1903 |
{ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1904 |
const IndustrySpec *indspec = GetIndustrySpec(ind->type); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1905 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1906 |
/* Check for acceptance of cargo */ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1907 |
for (uint j = 0; j < lengthof(ind->accepts_cargo) && ind->accepts_cargo[j] != CT_INVALID; j++) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1908 |
if (cargo == ind->accepts_cargo[j]) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1909 |
if (HasBit(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) { |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1910 |
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1911 |
0, GetReverseCargoTranslation(cargo, indspec->grf_prop.grffile), |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1912 |
ind, ind->type, ind->xy); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1913 |
if (res == 0) continue; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1914 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1915 |
*c_accepts = true; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1916 |
break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1917 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1918 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1919 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1920 |
/* Check for produced cargo */ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1921 |
for (uint j = 0; j < lengthof(ind->produced_cargo) && ind->produced_cargo[j] != CT_INVALID; j++) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1922 |
if (cargo == ind->produced_cargo[j]) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1923 |
*c_produces = true; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1924 |
break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1925 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1926 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1927 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1928 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1929 |
/** |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1930 |
* Compute who can service the industry. |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1931 |
* |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1932 |
* Here, 'can service' means that he/she has trains and stations close enough |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1933 |
* to the industry with the right cargo type and the right orders (ie has the |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1934 |
* technical means). |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1935 |
* |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1936 |
* @param ind: Industry being investigated. |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1937 |
* |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1938 |
* @return: 0 if nobody can service the industry, 2 if the local player can |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1939 |
* service the industry, and 1 otherwise (only competitors can service the |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1940 |
* industry) |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1941 |
*/ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1942 |
int WhoCanServiceIndustry(Industry* ind) |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1943 |
{ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1944 |
/* Find all stations within reach of the industry */ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1945 |
StationSet stations = FindStationsAroundIndustryTile(ind->xy, ind->width, ind->height); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1946 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1947 |
if (stations.size() == 0) return 0; // No stations found at all => nobody services |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1948 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1949 |
const Vehicle *v; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1950 |
int result = 0; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1951 |
FOR_ALL_VEHICLES(v) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1952 |
/* Is it worthwhile to try this vehicle? */ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1953 |
if (v->owner != _local_player && result != 0) continue; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1954 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1955 |
/* Check whether it accepts the right kind of cargo */ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1956 |
bool c_accepts = false; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1957 |
bool c_produces = false; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1958 |
if (v->type == VEH_TRAIN && IsFrontEngine(v)) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1959 |
const Vehicle *u = v; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1960 |
BEGIN_ENUM_WAGONS(u) |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1961 |
CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1962 |
END_ENUM_WAGONS(u) |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1963 |
} else if (v->type == VEH_ROAD || v->type == VEH_SHIP || v->type == VEH_AIRCRAFT) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1964 |
CanCargoServiceIndustry(v->cargo_type, ind, &c_accepts, &c_produces); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1965 |
} else { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1966 |
continue; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1967 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1968 |
if (!c_accepts && !c_produces) continue; // Wrong cargo |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1969 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1970 |
/* Check orders of the vehicle. |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1971 |
* We cannot check the first of shared orders only, since the first vehicle in such a chain |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1972 |
* may have a different cargo type. |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1973 |
*/ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1974 |
const Order *o; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1975 |
FOR_VEHICLE_ORDERS(v, o) { |
10081
e46b9eb2f9c1
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents:
9343
diff
changeset
|
1976 |
if (o->IsType(OT_GOTO_STATION) && !(o->GetUnloadType() & OUFB_TRANSFER)) { |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1977 |
/* Vehicle visits a station to load or unload */ |
9336
3f75a2c5e0d3
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
9332
diff
changeset
|
1978 |
Station *st = GetStation(o->GetDestination()); |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1979 |
if (!st->IsValid()) continue; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1980 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1981 |
/* Same cargo produced by industry is dropped here => not serviced by vehicle v */ |
10081
e46b9eb2f9c1
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents:
9343
diff
changeset
|
1982 |
if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break; |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1983 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1984 |
if (stations.find(st) != stations.end()) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1985 |
if (v->owner == _local_player) return 2; // Player services industry |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1986 |
result = 1; // Competitor services industry |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1987 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1988 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1989 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1990 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1991 |
return result; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1992 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1993 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1994 |
/** |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1995 |
* Report news that industry production has changed significantly |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1996 |
* |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1997 |
* @param ind: Industry with changed production |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1998 |
* @param type: Cargo type that has changed |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
1999 |
* @param percent: Percentage of change (>0 means increase, <0 means decrease) |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2000 |
*/ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2001 |
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent) |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2002 |
{ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2003 |
NewsType nt; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2004 |
|
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2005 |
switch (WhoCanServiceIndustry(ind)) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2006 |
case 0: nt = NT_INDUSTRY_NOBODY; break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2007 |
case 1: nt = NT_INDUSTRY_OTHER; break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2008 |
case 2: nt = NT_INDUSTRY_PLAYER; break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2009 |
default: NOT_REACHED(); break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2010 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2011 |
SetDParam(2, abs(percent)); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2012 |
SetDParam(0, GetCargo(type)->name); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2013 |
SetDParam(1, ind->index); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2014 |
AddNewsItem( |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2015 |
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9152
diff
changeset
|
2016 |
NM_THIN, NF_VIEWPORT | NF_TILE, nt, DNC_NONE, |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2017 |
ind->xy + TileDiffXY(1, 1), 0 |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2018 |
); |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2019 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2020 |
|
8441
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2021 |
enum { |
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2022 |
PERCENT_TRANSPORTED_60 = 153, |
8699
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2023 |
PERCENT_TRANSPORTED_80 = 204, |
8441
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2024 |
}; |
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2025 |
|
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2026 |
/** Change industry production or do closure |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2027 |
* @param i Industry for which changes are performed |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2028 |
* @param monthly true if it's the monthly call, false if it's the random call |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2029 |
*/ |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2030 |
static void ChangeIndustryProduction(Industry *i, bool monthly) |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2031 |
{ |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
2032 |
StringID str = STR_NULL; |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2033 |
bool closeit = false; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2034 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2035 |
bool standard = true; |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2036 |
bool suppress_message = false; |
8443
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
2037 |
/* don't use smooth economy for industries using production related callbacks */ |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
2038 |
bool smooth_economy = _patches.smooth_economy && |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
2039 |
!(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
2040 |
!(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE)); // production change callbacks |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2041 |
byte div = 0; |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2042 |
byte mul = 0; |
8472
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2043 |
int8 increment = 0; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
2044 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
2045 |
if (HasBit(indspec->callback_flags, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE)) { |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2046 |
uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->xy); |
8443
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
2047 |
standard = false; |
8282423fd688
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents:
8441
diff
changeset
|
2048 |
monthly = false; // smooth economy is disabled so we need to fake random industry production change to allow 'use standard' result |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2049 |
if (res != CALLBACK_FAILED) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
2050 |
suppress_message = HasBit(res, 7); |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2051 |
/* Get the custom message if any */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
2052 |
if (HasBit(res, 8)) str = MapGRFStringID(indspec->grf_prop.grffile->grfid, GB(GetRegister(0x100), 0, 16)); |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2053 |
res = GB(res, 0, 4); |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2054 |
switch(res) { |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2055 |
default: NOT_REACHED(); |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2056 |
case 0x0: break; // Do nothing, but show the custom message if any |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2057 |
case 0x1: div = 1; break; // Halve industry production. If production reaches the quarter of the default, the industry is closed instead. |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2058 |
case 0x2: mul = 1; break; // Double industry production if it hasn't reached eight times of the original yet. |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2059 |
case 0x3: closeit = true; break; // The industry announces imminent closure, and is physically removed from the map next month. |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2060 |
case 0x4: standard = true; break; // Do the standard random production change as if this industry was a primary one. |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2061 |
case 0x5: case 0x6: case 0x7: // Divide production by 4, 8, 16 |
8440
defae749cc64
(svn r11499) -Fix (r11144): mul/div factor were wrong (off by two)
glx
parents:
8424
diff
changeset
|
2062 |
case 0x8: div = res - 0x3; break; // Divide production by 32 |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2063 |
case 0x9: case 0xA: case 0xB: // Multiply production by 4, 8, 16 |
8440
defae749cc64
(svn r11499) -Fix (r11144): mul/div factor were wrong (off by two)
glx
parents:
8424
diff
changeset
|
2064 |
case 0xC: mul = res - 0x7; break; // Multiply production by 32 |
8472
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2065 |
case 0xD: // decrement production |
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2066 |
case 0xE: // increment production |
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2067 |
increment = res == 0x0D ? -1 : 1; |
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2068 |
break; |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2069 |
} |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2070 |
} |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2071 |
} |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
2072 |
|
8172
1e26cade13cb
(svn r11207) -Fix [FS#1301]: don't use smooth_economy for industries using production callbacks as they may have no production for more than a month
glx
parents:
8162
diff
changeset
|
2073 |
if (standard && monthly != smooth_economy) return; |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2074 |
|
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2075 |
if (standard && indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return; |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2076 |
|
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2077 |
if (standard && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) { |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
2078 |
/* decrease or increase */ |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2079 |
bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE; |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
2080 |
|
8172
1e26cade13cb
(svn r11207) -Fix [FS#1301]: don't use smooth_economy for industries using production callbacks as they may have no production for more than a month
glx
parents:
8162
diff
changeset
|
2081 |
if (smooth_economy) { |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2082 |
closeit = true; |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
2083 |
for (byte j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){ |
8699
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2084 |
uint32 r = Random(); |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2085 |
int old_prod, new_prod, percent; |
8699
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2086 |
/* If over 60% is transported, mult is 1, else mult is -1. */ |
8441
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2087 |
int mult = (i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_60) ? 1 : -1; |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
2088 |
|
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2089 |
new_prod = old_prod = i->production_rate[j]; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2090 |
|
8699
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2091 |
/* For industries with only_decrease flags (temperate terrain Oil Wells), |
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2092 |
* the multiplier will always be -1 so they will only decrease. */ |
8468
49005a635367
(svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents:
8466
diff
changeset
|
2093 |
if (only_decrease) { |
49005a635367
(svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents:
8466
diff
changeset
|
2094 |
mult = -1; |
8699
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2095 |
/* For normal industries, if over 60% is transported, 33% chance for decrease. |
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2096 |
* Bonus for very high station ratings (over 80%): 16% chance for decrease. */ |
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2097 |
} else if (Chance16I(1, ((i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_80) ? 6 : 3), r)) { |
8468
49005a635367
(svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents:
8466
diff
changeset
|
2098 |
mult *= -1; |
49005a635367
(svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents:
8466
diff
changeset
|
2099 |
} |
8441
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2100 |
|
8699
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2101 |
/* 4.5% chance for 3-23% (or 1 unit for very low productions) production change, |
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2102 |
* determined by mult value. If mult = 1 prod. increases, else (-1) it decreases. */ |
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2103 |
if (Chance16I(1, 22, r >> 16)) { |
8441
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2104 |
new_prod += mult * (max(((RandomRange(50) + 10) * old_prod) >> 8, 1U)); |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
2105 |
} |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2106 |
|
8441
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2107 |
/* Prevent production to overflow or Oil Rig passengers to be over-"produced" */ |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8387
diff
changeset
|
2108 |
new_prod = Clamp(new_prod, 1, 255); |
8441
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2109 |
|
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2110 |
if (((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) && j == 1) |
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2111 |
new_prod = Clamp(new_prod, 0, 16); |
02fa5c49a79b
(svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents:
8440
diff
changeset
|
2112 |
|
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2113 |
/* Do not stop closing the industry when it has the lowest possible production rate */ |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2114 |
if (new_prod == old_prod && old_prod > 1) { |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2115 |
closeit = false; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2116 |
continue; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2117 |
} |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2118 |
|
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2119 |
percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100); |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2120 |
i->production_rate[j] = new_prod; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2121 |
|
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2122 |
/* Close the industry when it has the lowest possible production rate */ |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2123 |
if (new_prod > 1) closeit = false; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2124 |
|
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2125 |
if (abs(percent) >= 10) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2126 |
ReportNewsProductionChangeIndustry(i, i->produced_cargo[j], percent); |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2127 |
} |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2128 |
} |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2129 |
} else { |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
2130 |
if (only_decrease || Chance16(1, 3)) { |
8699
a7b564b9c9b1
(svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents:
8653
diff
changeset
|
2131 |
/* If more than 60% transported, 66% chance of increase, else 33% chance of increase */ |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
2132 |
if (!only_decrease && (i->last_month_pct_transported[0] > PERCENT_TRANSPORTED_60) != Chance16(1, 3)) { |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2133 |
mul = 1; // Increase production |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
2134 |
} else { |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2135 |
div = 1; // Decrease production |
0 | 2136 |
} |
2137 |
} |
|
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
2138 |
} |
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
2139 |
} |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2140 |
|
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2141 |
if (standard && indspec->life_type & INDUSTRYLIFE_PROCESSING) { |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
2142 |
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && Chance16(1, smooth_economy ? 180 : 2)) { |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2143 |
closeit = true; |
7640
81b9fe4a2631
(svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents:
7628
diff
changeset
|
2144 |
} |
1320
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
2145 |
} |
bf9623526d71
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
2146 |
|
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2147 |
/* Increase if needed */ |
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
2148 |
while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) { |
9013
a1e323756e1d
(svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents:
9012
diff
changeset
|
2149 |
i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM); |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2150 |
i->production_rate[0] = min(i->production_rate[0] * 2, 0xFF); |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2151 |
i->production_rate[1] = min(i->production_rate[1] * 2, 0xFF); |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2152 |
if (str == STR_NULL) str = indspec->production_up_text; |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2153 |
} |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2154 |
|
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2155 |
/* Decrease if needed */ |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2156 |
while (div-- != 0 && !closeit) { |
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
2157 |
if (i->prod_level == PRODLEVEL_MINIMUM) { |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2158 |
closeit = true; |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2159 |
} else { |
9013
a1e323756e1d
(svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents:
9012
diff
changeset
|
2160 |
i->prod_level = max(i->prod_level / 2, (int)PRODLEVEL_MINIMUM); // typecast to int required to please MSVC |
a1e323756e1d
(svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents:
9012
diff
changeset
|
2161 |
i->production_rate[0] = (i->production_rate[0] + 1) / 2; |
a1e323756e1d
(svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents:
9012
diff
changeset
|
2162 |
i->production_rate[1] = (i->production_rate[1] + 1) / 2; |
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2163 |
if (str == STR_NULL) str = indspec->production_down_text; |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2164 |
} |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2165 |
} |
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2166 |
|
8902
dd99c00f4dbe
(svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents:
8879
diff
changeset
|
2167 |
/* Increase or Decreasing the production level if needed */ |
8472
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2168 |
if (increment != 0) { |
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
2169 |
if (increment < 0 && i->prod_level == PRODLEVEL_MINIMUM) { |
8902
dd99c00f4dbe
(svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents:
8879
diff
changeset
|
2170 |
closeit = true; |
dd99c00f4dbe
(svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents:
8879
diff
changeset
|
2171 |
} else { |
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
2172 |
i->prod_level = ClampU(i->prod_level + increment, PRODLEVEL_MINIMUM, PRODLEVEL_MAXIMUM); |
8902
dd99c00f4dbe
(svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents:
8879
diff
changeset
|
2173 |
} |
8472
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2174 |
} |
88d932993efd
(svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents:
8468
diff
changeset
|
2175 |
|
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2176 |
/* Close if needed and allowed */ |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2177 |
if (closeit && !CheckIndustryCloseDownProtection(i->type)) { |
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
2178 |
i->prod_level = PRODLEVEL_CLOSURE; |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2179 |
str = indspec->closure_text; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2180 |
} |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2181 |
|
8111
23e6be5756bb
(svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents:
8109
diff
changeset
|
2182 |
if (!suppress_message && str != STR_NULL) { |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2183 |
NewsType nt; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2184 |
/* Compute news category */ |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2185 |
if (closeit) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2186 |
nt = NT_OPENCLOSE; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2187 |
} else { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2188 |
switch (WhoCanServiceIndustry(i)) { |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2189 |
case 0: nt = NT_INDUSTRY_NOBODY; break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2190 |
case 1: nt = NT_INDUSTRY_OTHER; break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2191 |
case 2: nt = NT_INDUSTRY_PLAYER; break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2192 |
default: NOT_REACHED(); break; |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2193 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2194 |
} |
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2195 |
/* Set parameters of news string */ |
8251
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
2196 |
if (str > STR_LAST_STRINGID) { |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
2197 |
SetDParam(0, STR_TOWN); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
2198 |
SetDParam(1, i->town->index); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
2199 |
SetDParam(2, indspec->name); |
8366
3655a6a37683
(svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents:
8358
diff
changeset
|
2200 |
} else if (closeit) { |
3655a6a37683
(svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents:
8358
diff
changeset
|
2201 |
SetDParam(0, STR_INDUSTRY_FORMAT); |
3655a6a37683
(svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents:
8358
diff
changeset
|
2202 |
SetDParam(1, i->town->index); |
3655a6a37683
(svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents:
8358
diff
changeset
|
2203 |
SetDParam(2, indspec->name); |
8251
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
2204 |
} else { |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
2205 |
SetDParam(0, i->index); |
2791c76125c0
(svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents:
8244
diff
changeset
|
2206 |
} |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2207 |
/* and report the news to the user */ |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2208 |
AddNewsItem(str, |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9152
diff
changeset
|
2209 |
NM_THIN, NF_VIEWPORT | NF_TILE, nt, DNC_NONE, |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2210 |
i->xy + TileDiffXY(1, 1), 0); |
0 | 2211 |
} |
2212 |
} |
|
2213 |
||
6573 | 2214 |
void IndustryMonthlyLoop() |
0 | 2215 |
{ |
2216 |
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
|
2217 |
PlayerID old_player = _current_player; |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
2218 |
_current_player = OWNER_NONE; |
0 | 2219 |
|
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
2220 |
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
|
2221 |
UpdateIndustryStatistics(i); |
9012
c72dc34ffa79
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents:
8967
diff
changeset
|
2222 |
if (i->prod_level == PRODLEVEL_CLOSURE) { |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2223 |
delete i; |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2224 |
} else { |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2225 |
ChangeIndustryProduction(i, true); |
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2226 |
} |
0 | 2227 |
} |
2228 |
||
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
2229 |
/* 3% chance that we start a new industry */ |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8444
diff
changeset
|
2230 |
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
|
2231 |
MaybeNewIndustry(); |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2232 |
} else { |
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
|
2233 |
i = GetRandomIndustry(); |
8109
6bd72fb7d645
(svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents:
8106
diff
changeset
|
2234 |
if (i != NULL) ChangeIndustryProduction(i, false); |
0 | 2235 |
} |
266
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
2236 |
|
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
2237 |
_current_player = old_player; |
d704fabab036
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
2238 |
|
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
|
2239 |
/* production-change */ |
0 | 2240 |
_industry_sort_dirty = true; |
2241 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
2242 |
} |
|
2243 |
||
2244 |
||
6573 | 2245 |
void InitializeIndustries() |
0 | 2246 |
{ |
7897
222641b84fc4
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7886
diff
changeset
|
2247 |
_Industry_pool.CleanPool(); |
222641b84fc4
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7886
diff
changeset
|
2248 |
_Industry_pool.AddBlockToPool(); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2249 |
|
7335
027d2caa4646
(svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents:
7320
diff
changeset
|
2250 |
ResetIndustryCounts(); |
0 | 2251 |
_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
|
2252 |
_industry_sound_tile = 0; |
0 | 2253 |
} |
2254 |
||
7681
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2255 |
bool IndustrySpec::IsRawIndustry() const |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2256 |
{ |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2257 |
/* Lumber mills are extractive/organic, but can always be built like a non-raw industry */ |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2258 |
return (this->life_type & (INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC)) != 0 && |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2259 |
(this->behaviour & INDUSTRYBEH_CUT_TREES) == 0; |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2260 |
} |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2261 |
|
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2262 |
Money IndustrySpec::GetConstructionCost() const |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2263 |
{ |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2264 |
return (_price.build_industry * |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2265 |
(_patches.raw_industry_construction == 1 && this->IsRawIndustry() ? |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2266 |
this->raw_industry_cost_multiplier : |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2267 |
this->cost_multiplier |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2268 |
)) >> 8; |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2269 |
} |
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2270 |
|
8474
358b35762f02
(svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents:
8472
diff
changeset
|
2271 |
Money IndustrySpec::GetRemovalCost() const |
358b35762f02
(svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents:
8472
diff
changeset
|
2272 |
{ |
358b35762f02
(svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents:
8472
diff
changeset
|
2273 |
return (_price.remove_house * this->removal_cost_multiplier) >> 8; |
358b35762f02
(svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents:
8472
diff
changeset
|
2274 |
} |
358b35762f02
(svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents:
8472
diff
changeset
|
2275 |
|
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7976
diff
changeset
|
2276 |
static CommandCost TerraformTile_Industry(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7976
diff
changeset
|
2277 |
{ |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2278 |
if (AutoslopeEnabled()) { |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2279 |
/* We imitate here TTDP's behaviour: |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2280 |
* - Both new and old slope must not be steep. |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2281 |
* - TileMaxZ must not be changed. |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2282 |
* - Allow autoslope by default. |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2283 |
* - Disallow autoslope if callback succeeds and returns non-zero. |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2284 |
*/ |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2285 |
Slope tileh_old = GetTileSlope(tile, NULL); |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2286 |
/* TileMaxZ must not be changed. Slopes must not be steep. */ |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2287 |
if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) { |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2288 |
const IndustryGfx gfx = GetIndustryGfx(tile); |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2289 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2290 |
|
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2291 |
/* Call callback 3C 'disable autosloping for industry tiles'. */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
2292 |
if (HasBit(itspec->callback_flags, CBM_INDT_AUTOSLOPE)) { |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2293 |
/* If the callback fails, allow autoslope. */ |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2294 |
uint16 res = GetIndustryTileCallback(CBID_INDUSTRY_AUTOSLOPE, 0, 0, gfx, GetIndustryByTile(tile), tile); |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
2295 |
if ((res == 0) || (res == CALLBACK_FAILED)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2296 |
} else { |
8387
30f519812d62
(svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents:
8366
diff
changeset
|
2297 |
/* allow autoslope */ |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
2298 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2299 |
} |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2300 |
} |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2301 |
} |
8133
597f682ff48d
(svn r11168) -Fix [FS#1256]: assert on terraforming of industries. Patch by frosch.
rubidium
parents:
8125
diff
changeset
|
2302 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7976
diff
changeset
|
2303 |
} |
7681
0105448f6e5c
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents:
7673
diff
changeset
|
2304 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2305 |
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
|
2306 |
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
|
2307 |
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
|
2308 |
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
|
2309 |
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
|
2310 |
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
|
2311 |
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
|
2312 |
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
|
2313 |
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
|
2314 |
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
|
2315 |
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
|
2316 |
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
|
2317 |
NULL, /* vehicle_enter_tile_proc */ |
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7830
diff
changeset
|
2318 |
GetFoundation_Industry, /* get_foundation_proc */ |
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7976
diff
changeset
|
2319 |
TerraformTile_Industry, /* terraform_tile_proc */ |
0 | 2320 |
}; |
2321 |
||
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
|
2322 |
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
|
2323 |
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
|
2324 |
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
|
2325 |
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
|
2326 |
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
|
2327 |
SLE_REF(Industry, town, REF_TOWN), |
8855
e7a6bbce5400
(svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents:
8807
diff
changeset
|
2328 |
SLE_CONDNULL( 2, 0, 60), ///< used to be industry's produced_cargo |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
2329 |
SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, SL_MAX_VERSION), |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7647
diff
changeset
|
2330 |
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
|
2331 |
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
|
2332 |
SLE_ARR(Industry, production_rate, SLE_UINT8, 2), |
8855
e7a6bbce5400
(svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents:
8807
diff
changeset
|
2333 |
SLE_CONDNULL( 3, 0, 60), ///< used to be industry's accepts_cargo |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
8136
diff
changeset
|
2334 |
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, 78, SL_MAX_VERSION), |
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
|
2335 |
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
|
2336 |
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
|
2337 |
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
|
2338 |
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
|
2339 |
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
|
2340 |
SLE_ARR(Industry, last_month_transported, SLE_UINT16, 2), |
0 | 2341 |
|
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
|
2342 |
SLE_VAR(Industry, counter, SLE_UINT16), |
0 | 2343 |
|
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
|
2344 |
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
|
2345 |
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
|
2346 |
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
|
2347 |
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
|
2348 |
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
|
2349 |
SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8), |
0 | 2350 |
|
8018
03b60ab13605
(svn r11041) -Fix (r10460) [FS#1195]: the industry's owner was saved twice instead of the owner and the founder. Patch by frosch.
rubidium
parents:
7990
diff
changeset
|
2351 |
SLE_CONDVAR(Industry, founder, SLE_UINT8, 70, SL_MAX_VERSION), |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
2352 |
SLE_CONDVAR(Industry, construction_date, SLE_INT32, 70, SL_MAX_VERSION), |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
2353 |
SLE_CONDVAR(Industry, construction_type, SLE_UINT8, 70, SL_MAX_VERSION), |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
2354 |
SLE_CONDVAR(Industry, last_cargo_accepted_at, SLE_INT32, 70, SL_MAX_VERSION), |
7941
ddf9d11e6df8
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7916
diff
changeset
|
2355 |
SLE_CONDVAR(Industry, selected_layout, SLE_UINT8, 73, SL_MAX_VERSION), |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7681
diff
changeset
|
2356 |
|
8106
9f527cc360cf
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents:
8104
diff
changeset
|
2357 |
SLE_CONDARRX(cpp_offsetof(Industry, psa) + cpp_offsetof(Industry::PersistentStorage, storage), SLE_UINT32, 16, 76, SL_MAX_VERSION), |
9f527cc360cf
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents:
8104
diff
changeset
|
2358 |
|
8356
4d72bac74977
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
8349
diff
changeset
|
2359 |
SLE_CONDVAR(Industry, random_triggers, SLE_UINT8, 82, SL_MAX_VERSION), |
4d72bac74977
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
8349
diff
changeset
|
2360 |
SLE_CONDVAR(Industry, random, SLE_UINT16, 82, SL_MAX_VERSION), |
4d72bac74977
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
8349
diff
changeset
|
2361 |
|
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
|
2362 |
/* 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
|
2363 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 2364 |
|
2365 |
SLE_END() |
|
2366 |
}; |
|
2367 |
||
6573 | 2368 |
static void Save_INDY() |
0 | 2369 |
{ |
2370 |
Industry *ind; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2371 |
|
7784
efb98124ce51
(svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents:
7762
diff
changeset
|
2372 |
/* Write the industries */ |
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
2373 |
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
|
2374 |
SlSetArrayIndex(ind->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2375 |
SlObject(ind, _industry_desc); |
0 | 2376 |
} |
2377 |
} |
|
2378 |
||
7786
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2379 |
/* Save and load the mapping between the industry/tile id on the map, and the grf file |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2380 |
* it came from. */ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2381 |
static const SaveLoad _industries_id_mapping_desc[] = { |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2382 |
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32), |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2383 |
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8), |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2384 |
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8), |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2385 |
SLE_END() |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2386 |
}; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2387 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2388 |
static void Save_IIDS() |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2389 |
{ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2390 |
uint i; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2391 |
uint j = _industry_mngr.GetMaxMapping(); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2392 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2393 |
for (i = 0; i < j; i++) { |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2394 |
SlSetArrayIndex(i); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2395 |
SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2396 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2397 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2398 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2399 |
static void Save_TIDS() |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2400 |
{ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2401 |
uint i; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2402 |
uint j = _industile_mngr.GetMaxMapping(); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2403 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2404 |
for (i = 0; i < j; i++) { |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2405 |
SlSetArrayIndex(i); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2406 |
SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2407 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2408 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2409 |
|
6573 | 2410 |
static void Load_INDY() |
0 | 2411 |
{ |
2412 |
int index; |
|
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
2413 |
|
7335
027d2caa4646
(svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents:
7320
diff
changeset
|
2414 |
ResetIndustryCounts(); |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
2415 |
|
0 | 2416 |
while ((index = SlIterateArray()) != -1) { |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7834
diff
changeset
|
2417 |
Industry *i = new (index) Industry(); |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2418 |
SlObject(i, _industry_desc); |
7320
052da893fbd9
(svn r10063) -Codechange: Change VARDEF for extern
belugas
parents:
7315
diff
changeset
|
2419 |
IncIndustryTypeCount(i->type); |
0 | 2420 |
} |
2421 |
} |
|
2422 |
||
7786
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2423 |
static void Load_IIDS() |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2424 |
{ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2425 |
int index; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2426 |
uint max_id; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2427 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2428 |
/* clear the current mapping stored. |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2429 |
* This will create the manager if ever it is not yet done */ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2430 |
_industry_mngr.ResetMapping(); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2431 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2432 |
/* get boundary for the temporary map loader NUM_INDUSTRYTYPES? */ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2433 |
max_id = _industry_mngr.GetMaxMapping(); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2434 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2435 |
while ((index = SlIterateArray()) != -1) { |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2436 |
if ((uint)index >= max_id) break; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2437 |
SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2438 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2439 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2440 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2441 |
static void Load_TIDS() |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2442 |
{ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2443 |
int index; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2444 |
uint max_id; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2445 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2446 |
/* clear the current mapping stored. |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2447 |
* This will create the manager if ever it is not yet done */ |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2448 |
_industile_mngr.ResetMapping(); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2449 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2450 |
/* get boundary for the temporary map loader NUM_INDUSTILES? */ |
7788 | 2451 |
max_id = _industile_mngr.GetMaxMapping(); |
7786
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2452 |
|
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2453 |
while ((index = SlIterateArray()) != -1) { |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2454 |
if ((uint)index >= max_id) break; |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2455 |
SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc); |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2456 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2457 |
} |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2458 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2459 |
extern const ChunkHandler _industry_chunk_handlers[] = { |
7786
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2460 |
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY}, |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2461 |
{ 'IIDS', Save_IIDS, Load_IIDS, CH_ARRAY}, |
7a03d776107a
(svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents:
7784
diff
changeset
|
2462 |
{ 'TIDS', Save_TIDS, Load_TIDS, CH_ARRAY | CH_LAST}, |
0 | 2463 |
}; |