author | rubidium |
Wed, 11 Jul 2007 23:10:22 +0000 | |
changeset 7730 | a7b31d4fcc40 |
parent 7729 | 21b3ddd80928 |
child 7732 | f25c8aa26cc3 |
permissions | -rw-r--r-- |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
1 |
/* $Id$ */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
2 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
3 |
/** @file newgrf_industries.cpp */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
4 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
6 |
#include "openttd.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
7 |
#include "debug.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
8 |
#include "functions.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
9 |
#include "macros.h" |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
10 |
#include "variables.h" |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
11 |
#include "landscape.h" |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
12 |
#include "table/strings.h" |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
13 |
#include "industry.h" |
7364
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
14 |
#include "industry_map.h" |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
15 |
#include "newgrf.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
16 |
#include "newgrf_callbacks.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
17 |
#include "newgrf_spritegroup.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
18 |
#include "newgrf_industries.h" |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
19 |
#include "newgrf_commons.h" |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
20 |
#include "newgrf_text.h" |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
21 |
#include "newgrf_town.h" |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
22 |
#include "date.h" |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
23 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
24 |
/* Since the industry IDs defined by the GRF file don't necessarily correlate |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
25 |
* to those used by the game, the IDs used for overriding old industries must be |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
26 |
* translated when the idustry spec is set. */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
27 |
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE); |
7496
628e1191ee45
(svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents:
7380
diff
changeset
|
28 |
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
29 |
|
7729
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
30 |
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id) |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
31 |
{ |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
32 |
if (grf_type == IT_INVALID) return IT_INVALID; |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
33 |
if (!HASBIT(grf_type, 7)) return GB(grf_type, 0, 6); |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
34 |
|
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
35 |
return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id); |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
36 |
} |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
37 |
|
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
38 |
/** |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
39 |
* Finds the distance for the closest tile with water/land given a tile |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
40 |
* @param tile the tile to find the distance too |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
41 |
* @param water whether to find water or land |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
42 |
* @note FAILS when an industry should be seen as water |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
43 |
*/ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
44 |
static uint GetClosestWaterDistance(TileIndex tile, bool water) |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
45 |
{ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
46 |
TileIndex t; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
47 |
uint best_dist; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
48 |
for (t = 1; t < MapSize(); t++) { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
49 |
if (IsTileType(t, MP_WATER) == water) break; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
50 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
51 |
best_dist = DistanceManhattan(tile, t); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
52 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
53 |
for (; t < MapSize(); t++) { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
54 |
uint dist = DistanceManhattan(tile, t); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
55 |
if (dist < best_dist) { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
56 |
if (IsTileType(t, MP_WATER) == water) best_dist = dist; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
57 |
} else { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
58 |
/* When the Y distance between the current row and the 'source' tile |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
59 |
* is larger than the best distance, we've found the best distance */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
60 |
if (TileY(t) - TileY(tile) > best_dist) return best_dist; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
61 |
if (TileX(tile) > TileX(t)) { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
62 |
/* We can safely skip this many tiles; from here all tiles have a |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
63 |
* higher or equal distance than the best distance */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
64 |
t |= MapMaxX(); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
65 |
continue; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
66 |
} else { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
67 |
/* We can safely skip this many tiles; up to here all tiles have a |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
68 |
* higher or equal distance than the best distance */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
69 |
t += best_dist - dist; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
70 |
continue; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
71 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
72 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
73 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
74 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
75 |
return best_dist; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
76 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
77 |
|
7364
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
78 |
/** Make an analysis of a tile and check for its belonging to the same |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
79 |
* industry, and/or the same grf file |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
80 |
* @param new_tile TileIndex of the tile to query |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
81 |
* @param old_tile TileINdex of teh reference tile |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
82 |
* @param i Industry to which old_tile belongs to |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
83 |
* @return value encoded as per NFO specs */ |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
84 |
uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Industry *i) |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
85 |
{ |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
86 |
if (IsTileType(new_tile, MP_INDUSTRY)) { // Is this an industry tile? |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
87 |
|
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
88 |
if (GetIndustryIndex(new_tile) == i->index) { // Does it belong to the same industry? |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
89 |
IndustryGfx gfx = GetIndustryGfx(new_tile); |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
90 |
const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx); |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
91 |
const IndustryTileSpec *indold = GetIndustryTileSpec(GetIndustryGfx(old_tile)); |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
92 |
|
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
93 |
if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type? |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
94 |
/* It is an old tile. We have to see if it's been overriden */ |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
95 |
if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden? |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
96 |
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
97 |
} else { // yes. FInd out if it is from the same grf file or not |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
98 |
const IndustryTileSpec *old_tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override); |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
99 |
|
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
100 |
if (old_tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
101 |
return old_tile_ovr->grf_prop.local_id; // same grf file |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
102 |
} else { |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
103 |
return 0xFFFE; // not the same grf file |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
104 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
105 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
106 |
} else { |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
107 |
if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ? |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
108 |
if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ? |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
109 |
return indtsp->grf_prop.local_id; |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
110 |
} else { |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
111 |
return 0xFFFE; // Defined in another grf file |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
112 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
113 |
} else { // tile has no spritegroup |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
114 |
return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
115 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
116 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
117 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
118 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
119 |
|
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
120 |
return 0xFFFF; // tile is not an industry one or does not belong to the current industry |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
121 |
} |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
122 |
|
7729
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
123 |
static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current) |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
124 |
{ |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
125 |
uint32 best_dist = MAX_UVALUE(uint32); |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
126 |
const Industry *i; |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
127 |
FOR_ALL_INDUSTRIES(i) { |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
128 |
if (i->type != type || i == current) continue; |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
129 |
|
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
130 |
best_dist = min(best_dist, DistanceManhattan(tile, i->xy)); |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
131 |
} |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
132 |
|
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
133 |
return best_dist; |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
134 |
} |
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
135 |
|
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
136 |
/** This function implements the industries variables that newGRF defines. |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
137 |
* @param variable that is queried |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
138 |
* @param parameter unused |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
139 |
* @param available will return false if ever the variable asked for does not exist |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
140 |
* @param ind is of course the industry we are inquiring |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
141 |
* @return the value stored in the corresponding variable*/ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
142 |
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
143 |
{ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
144 |
const Industry *industry = object->u.industry.ind; |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
145 |
TileIndex tile = object->u.industry.tile; |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
146 |
const IndustrySpec *indspec = GetIndustrySpec(industry->type); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
147 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
148 |
switch (variable) { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
149 |
case 0x40: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
150 |
case 0x41: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
151 |
case 0x42: { // waiting cargo, but only if those two callback flags are set |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
152 |
uint16 callback = indspec->callback_flags; |
7662
60f877c832d9
(svn r10440) -Fix: CBM_IND defines bits to be set, not bitsets.
rubidium
parents:
7661
diff
changeset
|
153 |
if (HASBIT(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(callback, CBM_IND_PRODUCTION_256_TICKS)) { |
7687
0ed68892bc29
(svn r10466) -Fix: the minimum amount of waiting cargo shouldn't be 65535; that should be the maximum amount of waiting cargo.
rubidium
parents:
7682
diff
changeset
|
154 |
return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
155 |
} else { |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
156 |
return 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
157 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
158 |
} |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
159 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
160 |
/* Manhattan distance of closes dry/water tile */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
161 |
case 0x43: return GetClosestWaterDistance(tile, (object->u.industry_location.spec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
162 |
|
7364
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
163 |
/* Get industry ID at offset param */ |
f72f9b742c34
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
7331
diff
changeset
|
164 |
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), tile, industry); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
165 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
166 |
case 0x61: return 0; // Get random tile bits at offset param |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
167 |
|
7730
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
168 |
/* Land info of nearby tiles */ |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
169 |
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY); |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
170 |
|
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
171 |
/* Animation stage of nearby tiles */ |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
172 |
case 0x63 : { |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
173 |
tile = GetNearbyTile(parameter, tile); |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
174 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) { |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
175 |
return GetIndustryAnimationState(tile); |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
176 |
} |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
177 |
return 0xFFFFFFFF; |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
178 |
} |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
179 |
|
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
180 |
/* Distance of nearest industry of given type */ |
7729
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
181 |
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry); // Distance of nearest industry of given type |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
182 |
/* Get town zone and Manhattan distance of closest town */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
183 |
case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
184 |
/* Get square of Euclidian distance of closes town */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
185 |
case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
186 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
187 |
/* Count of industry, distance of closest instance |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
188 |
* format is rr(reserved) cc(count) dddd(manhattan distance of closest sister) |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
189 |
* A lot more should be done, since it has to check for local id, grf id etc... |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
190 |
* let's just say it is a beginning ;) */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
191 |
case 0x67: return GetIndustryTypeCount(industry->type) << 16 | 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
192 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
193 |
/* Industry structure access*/ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
194 |
case 0x80: return industry->xy; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
195 |
case 0x81: return GB(industry->xy, 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
196 |
/* Pointer to the town the industry is associated with */ |
7687
0ed68892bc29
(svn r10466) -Fix: the minimum amount of waiting cargo shouldn't be 65535; that should be the maximum amount of waiting cargo.
rubidium
parents:
7682
diff
changeset
|
197 |
case 0x82: return industry->town->index; |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
198 |
case 0x83: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
199 |
case 0x84: |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
200 |
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
201 |
case 0x86: return industry->width; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
202 |
case 0x87: return industry->height;// xy dimensions |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
203 |
/* */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
204 |
case 0x88: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
205 |
case 0x89: return indspec->produced_cargo[variable - 0x88]; |
7661
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7598
diff
changeset
|
206 |
case 0x8A: return industry->produced_cargo_waiting[0]; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7598
diff
changeset
|
207 |
case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8); |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7598
diff
changeset
|
208 |
case 0x8C: return industry->produced_cargo_waiting[1]; |
40c7a63ad9a1
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7598
diff
changeset
|
209 |
case 0x8D: return GB(industry->produced_cargo_waiting[1], 8, 8); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
210 |
case 0x8E: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
211 |
case 0x8F: return industry->production_rate[variable - 0x8E]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
212 |
case 0x90: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
213 |
case 0x91: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
214 |
case 0x92: return indspec->accepts_cargo[variable - 0x90]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
215 |
case 0x93: return industry->prod_level; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
216 |
/* amount of cargo produced so far THIS month. */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
217 |
case 0x94: return industry->this_month_production[0]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
218 |
case 0x95: return GB(industry->this_month_production[0], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
219 |
case 0x96: return industry->this_month_production[1]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
220 |
case 0x97: return GB(industry->this_month_production[1], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
221 |
/* amount of cargo transported so far THIS month. */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
222 |
case 0x98: return industry->this_month_transported[0]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
223 |
case 0x99: return GB(industry->this_month_transported[0], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
224 |
case 0x9A: return industry->this_month_transported[1]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
225 |
case 0x9B: return GB(industry->this_month_transported[0], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
226 |
/* fraction of cargo transported LAST month. */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
227 |
case 0x9C: |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
228 |
case 0x9D: return industry->last_month_pct_transported[variable - 0x9C]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
229 |
/* amount of cargo produced LAST month. */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
230 |
case 0x9E: return industry->last_month_production[0]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
231 |
case 0x9F: return GB(industry->last_month_production[0], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
232 |
case 0xA0: return industry->last_month_production[1]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
233 |
case 0xA1: return GB(industry->last_month_production[1], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
234 |
/* amount of cargo transported last month. */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
235 |
case 0xA2: return industry->last_month_transported[0]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
236 |
case 0xA3: return GB(industry->last_month_transported[0], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
237 |
case 0xA4: return industry->last_month_transported[1]; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
238 |
case 0xA5: return GB(industry->last_month_transported[0], 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
239 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
240 |
case 0xA6: return industry->type; |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
241 |
case 0xA7: return industry->founder; |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
242 |
case 0xA8: return industry->random_color; |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
243 |
case 0xA9: return clamp(0, industry->last_prod_year - 1920, 255); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
244 |
case 0xAA: return industry->counter; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
245 |
case 0xAB: return GB(industry->counter, 8, 8); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
246 |
case 0xAC: return industry->was_cargo_delivered; |
7682
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
247 |
|
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
248 |
case 0xB0: return clamp(0, industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date when built since 1920 (in days) |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
249 |
case 0xB3: return industry->construction_type; // Construction type |
263dbeceba12
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7664
diff
changeset
|
250 |
case 0xB4: return clamp(0, industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date last cargo accepted since 1920 (in days) |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
251 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
252 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
253 |
DEBUG(grf, 1, "Unhandled industry property 0x%X", variable); |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
254 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
255 |
*available = false; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
256 |
return (uint32)-1; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
257 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
258 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
259 |
static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, const SpriteGroup *group) |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
260 |
{ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
261 |
/* IndustryTile do not have 'real' groups */ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
262 |
return NULL; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
263 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
264 |
|
7380
a9d0047b015c
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
7364
diff
changeset
|
265 |
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus) |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
266 |
{ |
7380
a9d0047b015c
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
7364
diff
changeset
|
267 |
res->GetRandomBits = IndustryTileGetRandomBits; |
a9d0047b015c
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
7364
diff
changeset
|
268 |
res->GetTriggers = IndustryTileGetTriggers; |
a9d0047b015c
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
7364
diff
changeset
|
269 |
res->SetTriggers = IndustryTileSetTriggers; |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
270 |
res->GetVariable = IndustryGetVariable; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
271 |
res->ResolveReal = IndustryResolveReal; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
272 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
273 |
res->u.industry.tile = tile; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
274 |
res->u.industry.ind = indus; |
7380
a9d0047b015c
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
7364
diff
changeset
|
275 |
res->u.industry.gfx = INVALID_INDUSTRYTILE; |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
276 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
277 |
res->callback = 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
278 |
res->callback_param1 = 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
279 |
res->callback_param2 = 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
280 |
res->last_value = 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
281 |
res->trigger = 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
282 |
res->reseed = 0; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
283 |
} |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
284 |
|
7598
c12c2d7e0b55
(svn r10369) -Codechange: Add the IndustryType parameter to the GetIndustryCallback function.
belugas
parents:
7496
diff
changeset
|
285 |
uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile) |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
286 |
{ |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
287 |
ResolverObject object; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
288 |
const SpriteGroup *group; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
289 |
|
7380
a9d0047b015c
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
7364
diff
changeset
|
290 |
NewIndustryResolver(&object, tile, industry); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
291 |
object.callback = callback; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
292 |
object.callback_param1 = param1; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
293 |
object.callback_param2 = param2; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
294 |
|
7598
c12c2d7e0b55
(svn r10369) -Codechange: Add the IndustryType parameter to the GetIndustryCallback function.
belugas
parents:
7496
diff
changeset
|
295 |
group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
7331
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
296 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
297 |
|
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
298 |
return group->g.callback.result; |
0a7f00fed4e6
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
299 |
} |
7664
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
300 |
|
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
301 |
uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
302 |
{ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
303 |
TileIndex tile = object->u.industry_location.tile; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
304 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
305 |
if (object->scope == VSG_SCOPE_PARENT) { |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
306 |
return TownGetVariable(variable, parameter, available, ClosestTownFromTile(tile, (uint)-1)); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
307 |
} |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
308 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
309 |
switch (variable) { |
7730
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
310 |
/* Land info of nearby tiles */ |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
311 |
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY); |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
312 |
|
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
313 |
/* Distance of nearest industry of given type */ |
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
314 |
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, object->u.industry_location.spec->grf_prop.grffile->grfid), NULL); |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
315 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
316 |
/* Location where to build the industry */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
317 |
case 0x80: return tile; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
318 |
case 0x81: return GB(tile, 8, 8); |
7730
a7b31d4fcc40
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7729
diff
changeset
|
319 |
|
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
320 |
/* Pointer to the town the industry is associated with */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
321 |
case 0x82: return ClosestTownFromTile(tile, (uint)-1)->index; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
322 |
case 0x83: |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
323 |
case 0x84: |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
324 |
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
325 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
326 |
/* Number of the layout */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
327 |
case 0x86: return object->u.industry_location.itspec_index; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
328 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
329 |
/* Ground type */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
330 |
case 0x87: return GetTerrainType(tile); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
331 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
332 |
/* Town zone */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
333 |
case 0x88: return GetTownRadiusGroup(ClosestTownFromTile(tile, (uint)-1), tile); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
334 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
335 |
/* Manhattan distance of the closest town */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
336 |
case 0x89: return min(DistanceManhattan(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 255); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
337 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
338 |
/* Lowest height of the tile */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
339 |
case 0x8A: return GetTileZ(tile); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
340 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
341 |
/* Distance to the nearest water/land tile */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
342 |
case 0x8B: return GetClosestWaterDistance(tile, (object->u.industry_location.spec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
343 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
344 |
/* Square of Euclidian distance from town */ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
345 |
case 0x8D: return min(DistanceSquare(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 65535); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
346 |
} |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
347 |
|
7729
21b3ddd80928
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7705
diff
changeset
|
348 |
DEBUG(grf, 1, "Unhandled location industry property 0x%X", variable); |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
349 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
350 |
*available = false; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
351 |
return (uint32)-1; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
352 |
} |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
353 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
354 |
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index) |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
355 |
{ |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
356 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
357 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
358 |
ResolverObject object; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
359 |
const SpriteGroup *group; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
360 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
361 |
NewIndustryResolver(&object, tile, NULL); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
362 |
object.GetVariable = IndustryLocationGetVariable; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
363 |
object.callback = CBID_INDUSTRY_LOCATION; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
364 |
object.u.industry_location.tile = tile; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
365 |
object.u.industry_location.spec = indspec; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
366 |
object.u.industry_location.itspec_index = itspec_index; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
367 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
368 |
group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
369 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
370 |
if (group == NULL || group->type != SGT_CALLBACK) return false; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
371 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
372 |
switch (group->g.callback.result) { |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
373 |
case 0x400: return true; |
7705
c605a86e5713
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7703
diff
changeset
|
374 |
case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; break; |
c605a86e5713
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7703
diff
changeset
|
375 |
case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; break; |
c605a86e5713
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7703
diff
changeset
|
376 |
case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; break; |
c605a86e5713
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7703
diff
changeset
|
377 |
default: _error_message = GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + group->g.callback.result); break; |
7703
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
378 |
} |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
379 |
|
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
380 |
return false; |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
381 |
} |
bc4b879b7324
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7691
diff
changeset
|
382 |
|
7664
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
383 |
static int32 DerefIndProd(uint field, bool use_register) |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
384 |
{ |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
385 |
return use_register ? (int32)GetRegister(field) : field; |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
386 |
} |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
387 |
|
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
388 |
/** |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
389 |
* Get the industry production callback and apply it to the industry. |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
390 |
* @param ind the industry this callback has to be called for |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
391 |
* @param reason the reason it is called (0 = incoming cargo, 1 = periodic tick callback) |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
392 |
*/ |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
393 |
void IndustryProductionCallback(Industry *ind, int reason) |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
394 |
{ |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
395 |
ResolverObject object; |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
396 |
NewIndustryResolver(&object, INVALID_TILE, ind); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
397 |
object.callback_param2 = reason; |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
398 |
|
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
399 |
for (uint loop = 0;; loop++) { |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
400 |
SB(object.callback_param2, 8, 16, loop); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
401 |
const SpriteGroup *group = Resolve(GetIndustrySpec(ind->type)->grf_prop.spritegroup, &object); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
402 |
if (group == NULL || group->type != SGT_INDUSTRY_PRODUCTION) break; |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
403 |
|
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
404 |
bool deref = (group->g.indprod.version == 1); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
405 |
|
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
406 |
for (uint i = 0; i < 3; i++) { |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
407 |
ind->incoming_cargo_waiting[i] = clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref), 0, 0xFFFF); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
408 |
} |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
409 |
for (uint i = 0; i < 2; i++) { |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
410 |
ind->produced_cargo_waiting[i] = clamp(ind->produced_cargo_waiting[i] + DerefIndProd(group->g.indprod.add_output[i], deref), 0, 0xFFFF); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
411 |
} |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
412 |
|
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
413 |
int32 again = DerefIndProd(group->g.indprod.again, deref); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
414 |
if (again == 0) break; |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
415 |
|
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
416 |
SB(object.callback_param2, 24, 8, again); |
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
417 |
} |
7691
64063937da38
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7687
diff
changeset
|
418 |
|
64063937da38
(svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents:
7687
diff
changeset
|
419 |
InvalidateWindow(WC_INDUSTRY_VIEW, ind->index); |
7664
81c35390400e
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7662
diff
changeset
|
420 |
} |