author | rubidium |
Sun, 25 May 2008 19:17:03 +0000 | |
changeset 9354 | 845e07db4549 |
parent 9111 | 48ce04029fe4 |
child 9484 | 2e8749c6b560 |
permissions | -rw-r--r-- |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
1 |
/* $Id$ */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
2 |
|
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8970
diff
changeset
|
3 |
/** @file newgrf_industries.cpp Handling of NewGRF industries. */ |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
4 |
|
31c89aab2d61
(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" |
31c89aab2d61
(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" |
31c89aab2d61
(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" |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
8 |
#include "variables.h" |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
9 |
#include "landscape.h" |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
10 |
#include "industry.h" |
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
11 |
#include "industry_map.h" |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
12 |
#include "newgrf.h" |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
13 |
#include "newgrf_callbacks.h" |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
14 |
#include "newgrf_spritegroup.h" |
31c89aab2d61
(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_industries.h" |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7848
diff
changeset
|
16 |
#include "newgrf_industrytiles.h" |
6835
31c89aab2d61
(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_commons.h" |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
18 |
#include "newgrf_text.h" |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
19 |
#include "newgrf_town.h" |
8131
160939e24ed3
(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:
8113
diff
changeset
|
20 |
#include "window_func.h" |
8213
7bdd7593eb9b
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents:
8163
diff
changeset
|
21 |
#include "town.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8237
diff
changeset
|
22 |
#include "player_func.h" |
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8237
diff
changeset
|
23 |
#include "player_base.h" |
8275
f17d0c863ee3
(svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents:
8264
diff
changeset
|
24 |
#include "command_func.h" |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
25 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
26 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
27 |
|
8689
af0a4064b83e
(svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents:
8634
diff
changeset
|
28 |
static uint32 _industry_creation_random_bits; |
8436
c2600da0d3e3
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8427
diff
changeset
|
29 |
|
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
30 |
/* Since the industry IDs defined by the GRF file don't necessarily correlate |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
31 |
* to those used by the game, the IDs used for overriding old industries must be |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
32 |
* translated when the idustry spec is set. */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
33 |
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE); |
7000
603a41cb93f8
(svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents:
6884
diff
changeset
|
34 |
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
35 |
|
7233
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
36 |
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id) |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
37 |
{ |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
38 |
if (grf_type == IT_INVALID) return IT_INVALID; |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
39 |
if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 6); |
7233
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
40 |
|
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
41 |
return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id); |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
42 |
} |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
43 |
|
8090
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
44 |
static uint32 GetGRFParameter(IndustryType ind_id, byte parameter) |
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
45 |
{ |
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
46 |
const IndustrySpec *indspec = GetIndustrySpec(ind_id); |
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
47 |
const GRFFile *file = indspec->grf_prop.grffile; |
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
48 |
|
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
49 |
if (parameter >= file->param_end) return 0; |
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
50 |
return file->param[parameter]; |
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
51 |
} |
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
52 |
|
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
53 |
/** |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
54 |
* Finds the distance for the closest tile with water/land given a tile |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
55 |
* @param tile the tile to find the distance too |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
56 |
* @param water whether to find water or land |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
57 |
* @note FAILS when an industry should be seen as water |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
58 |
*/ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
59 |
static uint GetClosestWaterDistance(TileIndex tile, bool water) |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
60 |
{ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
61 |
TileIndex t; |
7236
07ceb37a1b63
(svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents:
7234
diff
changeset
|
62 |
int best_dist; |
07ceb37a1b63
(svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents:
7234
diff
changeset
|
63 |
for (t = 0; t < MapSize(); t++) { |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
64 |
if (IsTileType(t, MP_WATER) == water) break; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
65 |
} |
7599
0d6d44f403c5
(svn r11126) -Fix: the algorithm to determine the closest water/land was flawed.
rubidium
parents:
7462
diff
changeset
|
66 |
if (t == MapSize() && !water) return 0x200; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
67 |
best_dist = DistanceManhattan(tile, t); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
68 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
69 |
for (; t < MapSize(); t++) { |
7236
07ceb37a1b63
(svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents:
7234
diff
changeset
|
70 |
int dist = DistanceManhattan(tile, t); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
71 |
if (dist < best_dist) { |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
72 |
if (IsTileType(t, MP_WATER) == water) best_dist = dist; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
73 |
} else { |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
74 |
/* When the Y distance between the current row and the 'source' tile |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
75 |
* is larger than the best distance, we've found the best distance */ |
7236
07ceb37a1b63
(svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents:
7234
diff
changeset
|
76 |
if ((int)TileY(t) - (int)TileY(tile) > best_dist) break; |
7604
16666b8e91a4
(svn r11131) -Fix (r11126): forgot to commit the changes that performed the actual fix.
rubidium
parents:
7599
diff
changeset
|
77 |
if ((int)TileX(t) - (int)TileX(tile) > best_dist) { |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
78 |
/* We can safely skip this many tiles; from here all tiles have a |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
79 |
* higher or equal distance than the best distance */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
80 |
t |= MapMaxX(); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
81 |
continue; |
7604
16666b8e91a4
(svn r11131) -Fix (r11126): forgot to commit the changes that performed the actual fix.
rubidium
parents:
7599
diff
changeset
|
82 |
} else if (TileX(tile) < TileX(t)) { |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
83 |
/* We can safely skip this many tiles; up to here all tiles have a |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
84 |
* higher or equal distance than the best distance */ |
7236
07ceb37a1b63
(svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents:
7234
diff
changeset
|
85 |
t += max(best_dist - dist, 0); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
86 |
continue; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
87 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
88 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
89 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
90 |
|
7599
0d6d44f403c5
(svn r11126) -Fix: the algorithm to determine the closest water/land was flawed.
rubidium
parents:
7462
diff
changeset
|
91 |
return min(best_dist, water ? 0x7F : 0x1FF); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
92 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
93 |
|
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
94 |
/** Make an analysis of a tile and check for its belonging to the same |
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
95 |
* industry, and/or the same grf file |
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
96 |
* @param tile TileIndex of the tile to query |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
97 |
* @param i Industry to which to compare the tile to |
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
98 |
* @return value encoded as per NFO specs */ |
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
99 |
uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i) |
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
100 |
{ |
7706
bbf501d68106
(svn r11240) -Fix [FS#1323] (r11152): forgot to invert a test
glx
parents:
7685
diff
changeset
|
101 |
if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != i->index) { |
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
102 |
/* No industry and/or the tile does not have the same industry as the one we match it with */ |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
103 |
return 0xFFFF; |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
104 |
} |
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
105 |
|
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
106 |
IndustryGfx gfx = GetCleanIndustryGfx(tile); |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
107 |
const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx); |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
108 |
const IndustrySpec *indold = GetIndustrySpec(i->type); |
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
109 |
|
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
110 |
if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type? |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
111 |
/* It is an old tile. We have to see if it's been overriden */ |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
112 |
if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden? |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
113 |
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
114 |
} |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
115 |
/* Not overriden */ |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
116 |
const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override); |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
117 |
|
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
118 |
if (tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
119 |
return tile_ovr->grf_prop.local_id; // same grf file |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
120 |
} else { |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
121 |
return 0xFFFE; // not the same grf file |
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
122 |
} |
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
123 |
} |
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
124 |
/* Not an 'old type' tile */ |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
125 |
if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ? |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
126 |
if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ? |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
127 |
return indtsp->grf_prop.local_id; |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
128 |
} else { |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
129 |
return 0xFFFE; // Defined in another grf file |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
130 |
} |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
131 |
} |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
132 |
/* The tile has no spritegroup */ |
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
133 |
return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute |
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
134 |
} |
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
135 |
|
7233
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
136 |
static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current) |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
137 |
{ |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
138 |
uint32 best_dist = MAX_UVALUE(uint32); |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
139 |
const Industry *i; |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
140 |
FOR_ALL_INDUSTRIES(i) { |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
141 |
if (i->type != type || i == current) continue; |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
142 |
|
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
143 |
best_dist = min(best_dist, DistanceManhattan(tile, i->xy)); |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
144 |
} |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
145 |
|
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
146 |
return best_dist; |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
147 |
} |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7209
diff
changeset
|
148 |
|
7451
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
149 |
/** Implementation of both var 67 and 68 |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
150 |
* since the mechanism is almost the same, it is easier to regroup them on the same |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
151 |
* function. |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
152 |
* @param param_setID parameter given to the callback, which is the set id, or the local id, in our terminology |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
153 |
* @param layout_filter on what layout do we filter? |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
154 |
* @param current Industry for which the inquiry is made |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
155 |
* @return the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister) |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
156 |
*/ |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
157 |
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, const Industry *current) |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
158 |
{ |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
159 |
uint32 GrfID = GetRegister(0x100); ///< Get the GRFID of the definition to look for in register 100h |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
160 |
IndustryType ind_index; |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
161 |
uint32 closest_dist = MAX_UVALUE(uint32); |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
162 |
byte count = 0; |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
163 |
|
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
164 |
/* Determine what will be the industry type to look for */ |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
165 |
switch (GrfID) { |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
166 |
case 0: // this is a default industry type |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
167 |
ind_index = param_setID; |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
168 |
break; |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
169 |
|
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
170 |
case 0xFFFFFFFF: // current grf |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
171 |
GrfID = GetIndustrySpec(current->type)->grf_prop.grffile->grfid; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
172 |
/* Fall through */ |
7451
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
173 |
|
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
174 |
default: //use the grfid specified in register 100h |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
175 |
SetBit(param_setID, 7); // bit 7 means it is not an old type |
7451
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
176 |
ind_index = MapNewGRFIndustryType(param_setID, GrfID); |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
177 |
break; |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
178 |
} |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
179 |
|
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
180 |
if (layout_filter == 0) { |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
181 |
/* If the filter is 0, it could be because none was specified as well as being really a 0. |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
182 |
* In either case, just do the regular var67 */ |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
183 |
closest_dist = GetClosestIndustry(current->xy, ind_index, current); |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
184 |
count = GetIndustryTypeCount(ind_index); |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
185 |
} else { |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
186 |
/* Count only those who match the same industry type and layout filter |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
187 |
* Unfortunately, we have to do it manually */ |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
188 |
const Industry *i; |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
189 |
FOR_ALL_INDUSTRIES(i) { |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
190 |
if (i->type == ind_index && i != current && i->selected_layout == layout_filter) { |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
191 |
closest_dist = min(closest_dist, DistanceManhattan(current->xy, i->xy)); |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
192 |
count++; |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
193 |
} |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
194 |
} |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
195 |
} |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
196 |
|
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
197 |
return count << 16 | GB(closest_dist, 0, 16); |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
198 |
} |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
199 |
|
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
200 |
/** This function implements the industries variables that newGRF defines. |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
201 |
* @param variable that is queried |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
202 |
* @param parameter unused |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
203 |
* @param available will return false if ever the variable asked for does not exist |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
204 |
* @param ind is of course the industry we are inquiring |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
205 |
* @return the value stored in the corresponding variable*/ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
206 |
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
207 |
{ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
208 |
const Industry *industry = object->u.industry.ind; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
209 |
TileIndex tile = object->u.industry.tile; |
8233
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
210 |
IndustryType type = object->u.industry.type; |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
211 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
212 |
|
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
213 |
if (industry == NULL) { |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
214 |
/* industry does not exist, only use those variables that are "safe" */ |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
215 |
switch (variable) { |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
216 |
/* Read GRF parameter */ |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
217 |
case 0x7F: return GetGRFParameter(type, parameter); |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
218 |
/* Manhattan distance of closes dry/water tile */ |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
219 |
case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
220 |
} |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
221 |
|
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
222 |
DEBUG(grf, 1, "Unhandled property 0x%X (no available industry) in callback 0x%x", variable, object->callback); |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
223 |
|
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
224 |
*available = false; |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
225 |
return UINT_MAX; |
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
226 |
} |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
227 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
228 |
switch (variable) { |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
229 |
case 0x40: |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
230 |
case 0x41: |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
231 |
case 0x42: { // waiting cargo, but only if those two callback flags are set |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
232 |
uint16 callback = indspec->callback_flags; |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
233 |
if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) { |
7958
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
234 |
if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) { |
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
235 |
return min(industry->incoming_cargo_waiting[variable - 0x40] / industry->prod_level, (uint16)0xFFFF); |
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
236 |
} else { |
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
237 |
return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF); |
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
238 |
} |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
239 |
} else { |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
240 |
return 0; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
241 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
242 |
} |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
243 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
244 |
/* Manhattan distance of closes dry/water tile */ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
245 |
case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
246 |
|
7445
4d96e6e94d88
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7337
diff
changeset
|
247 |
/* Layout number */ |
4d96e6e94d88
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7337
diff
changeset
|
248 |
case 0x44: return industry->selected_layout; |
4d96e6e94d88
(svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents:
7337
diff
changeset
|
249 |
|
7671
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
250 |
/* player info */ |
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
251 |
case 0x45: { |
7685
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
252 |
byte colours; |
7671
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
253 |
bool is_ai = false; |
7685
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
254 |
|
7671
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
255 |
if (IsValidPlayer(industry->founder)) { |
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
256 |
const Player *p = GetPlayer(industry->founder); |
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
257 |
const Livery *l = &p->livery[LS_DEFAULT]; |
7685
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
258 |
|
7671
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
259 |
is_ai = p->is_ai; |
7685
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
260 |
colours = l->colour1 + l->colour2 * 16; |
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
261 |
} else { |
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
262 |
colours = GB(Random(), 0, 8); |
7671
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
263 |
} |
7685
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
264 |
|
20852b29c17b
(svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents:
7671
diff
changeset
|
265 |
return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24); |
7671
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
266 |
} |
21bc11c5265d
(svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents:
7668
diff
changeset
|
267 |
|
6868
abaf9e30691e
(svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents:
6835
diff
changeset
|
268 |
/* Get industry ID at offset param */ |
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
269 |
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), industry); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
270 |
|
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
271 |
/* Get random tile bits at offset param */ |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
272 |
case 0x61: |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
273 |
tile = GetNearbyTile(parameter, tile); |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
274 |
return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
275 |
|
7234
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
276 |
/* Land info of nearby tiles */ |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
277 |
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY); |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
278 |
|
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
279 |
/* Animation stage of nearby tiles */ |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
280 |
case 0x63: |
7234
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
281 |
tile = GetNearbyTile(parameter, tile); |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
282 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) { |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
283 |
return GetIndustryAnimationState(tile); |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
284 |
} |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
285 |
return 0xFFFFFFFF; |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
286 |
|
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
287 |
/* Distance of nearest industry of given type */ |
7314
bf53f5fe26a1
(svn r10669) -Codechange: Removed redundant comment
belugas
parents:
7260
diff
changeset
|
288 |
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
289 |
/* Get town zone and Manhattan distance of closest town */ |
8970
da7261f48b7e
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
8756
diff
changeset
|
290 |
case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
291 |
/* Get square of Euclidian distance of closes town */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
292 |
case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
293 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
294 |
/* Count of industry, distance of closest instance |
7451
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
295 |
* 68 is the same as 67, but with a filtering on selected layout */ |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
296 |
case 0x67: |
f2668c46aa21
(svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents:
7445
diff
changeset
|
297 |
case 0x68: return GetCountAndDistanceOfClosestInstance(parameter, variable == 0x68 ? GB(GetRegister(0x101), 0, 8) : 0, industry); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
298 |
|
7610
13b7d9e247d2
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents:
7604
diff
changeset
|
299 |
/* Get a variable from the persistent storage */ |
13b7d9e247d2
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents:
7604
diff
changeset
|
300 |
case 0x7C: return industry->psa.Get(parameter); |
13b7d9e247d2
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents:
7604
diff
changeset
|
301 |
|
8090
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
302 |
/* Read GRF parameter */ |
8233
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
303 |
case 0x7F: return GetGRFParameter(type, parameter); |
8090
d1b76fcc33a3
(svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents:
8048
diff
changeset
|
304 |
|
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
305 |
/* Industry structure access*/ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
306 |
case 0x80: return industry->xy; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
307 |
case 0x81: return GB(industry->xy, 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
308 |
/* Pointer to the town the industry is associated with */ |
7191
a877e27650aa
(svn r10466) -Fix: the minimum amount of waiting cargo shouldn't be 65535; that should be the maximum amount of waiting cargo.
rubidium
parents:
7186
diff
changeset
|
309 |
case 0x82: return industry->town->index; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
310 |
case 0x83: |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
311 |
case 0x84: |
7186
818eba1f20d5
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7168
diff
changeset
|
312 |
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
313 |
case 0x86: return industry->width; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
314 |
case 0x87: return industry->height;// xy dimensions |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
315 |
/* */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
316 |
case 0x88: |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7622
diff
changeset
|
317 |
case 0x89: return industry->produced_cargo[variable - 0x88]; |
7165
fb78336b205f
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7102
diff
changeset
|
318 |
case 0x8A: return industry->produced_cargo_waiting[0]; |
fb78336b205f
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7102
diff
changeset
|
319 |
case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8); |
fb78336b205f
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7102
diff
changeset
|
320 |
case 0x8C: return industry->produced_cargo_waiting[1]; |
fb78336b205f
(svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents:
7102
diff
changeset
|
321 |
case 0x8D: return GB(industry->produced_cargo_waiting[1], 8, 8); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
322 |
case 0x8E: |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
323 |
case 0x8F: return industry->production_rate[variable - 0x8E]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
324 |
case 0x90: |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
325 |
case 0x91: |
7645
efa25fcf7917
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7622
diff
changeset
|
326 |
case 0x92: return industry->accepts_cargo[variable - 0x90]; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
327 |
case 0x93: return industry->prod_level; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
328 |
/* amount of cargo produced so far THIS month. */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
329 |
case 0x94: return industry->this_month_production[0]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
330 |
case 0x95: return GB(industry->this_month_production[0], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
331 |
case 0x96: return industry->this_month_production[1]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
332 |
case 0x97: return GB(industry->this_month_production[1], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
333 |
/* amount of cargo transported so far THIS month. */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
334 |
case 0x98: return industry->this_month_transported[0]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
335 |
case 0x99: return GB(industry->this_month_transported[0], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
336 |
case 0x9A: return industry->this_month_transported[1]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
337 |
case 0x9B: return GB(industry->this_month_transported[0], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
338 |
/* fraction of cargo transported LAST month. */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
339 |
case 0x9C: |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
340 |
case 0x9D: return industry->last_month_pct_transported[variable - 0x9C]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
341 |
/* amount of cargo produced LAST month. */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
342 |
case 0x9E: return industry->last_month_production[0]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
343 |
case 0x9F: return GB(industry->last_month_production[0], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
344 |
case 0xA0: return industry->last_month_production[1]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
345 |
case 0xA1: return GB(industry->last_month_production[1], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
346 |
/* amount of cargo transported last month. */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
347 |
case 0xA2: return industry->last_month_transported[0]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
348 |
case 0xA3: return GB(industry->last_month_transported[0], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
349 |
case 0xA4: return industry->last_month_transported[1]; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
350 |
case 0xA5: return GB(industry->last_month_transported[0], 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
351 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
352 |
case 0xA6: return industry->type; |
7186
818eba1f20d5
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7168
diff
changeset
|
353 |
case 0xA7: return industry->founder; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
354 |
case 0xA8: return industry->random_color; |
8634
496c3fb47daf
(svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents:
8436
diff
changeset
|
355 |
case 0xA9: return Clamp(industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 255); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
356 |
case 0xAA: return industry->counter; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
357 |
case 0xAB: return GB(industry->counter, 8, 8); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
358 |
case 0xAC: return industry->was_cargo_delivered; |
7186
818eba1f20d5
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7168
diff
changeset
|
359 |
|
8634
496c3fb47daf
(svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents:
8436
diff
changeset
|
360 |
case 0xB0: return Clamp(industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days) |
7186
818eba1f20d5
(svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents:
7168
diff
changeset
|
361 |
case 0xB3: return industry->construction_type; // Construction type |
8634
496c3fb47daf
(svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents:
8436
diff
changeset
|
362 |
case 0xB4: return Clamp(industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days) |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
363 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
364 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
365 |
DEBUG(grf, 1, "Unhandled industry property 0x%X", variable); |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
366 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
367 |
*available = false; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
368 |
return (uint32)-1; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
369 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
370 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
371 |
static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, const SpriteGroup *group) |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
372 |
{ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
373 |
/* IndustryTile do not have 'real' groups */ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
374 |
return NULL; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
375 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
376 |
|
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
377 |
static uint32 IndustryGetRandomBits(const ResolverObject *object) |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
378 |
{ |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7848
diff
changeset
|
379 |
return object->u.industry.ind == NULL ? 0 : object->u.industry.ind->random; |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
380 |
} |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
381 |
|
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
382 |
static uint32 IndustryGetTriggers(const ResolverObject *object) |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
383 |
{ |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7848
diff
changeset
|
384 |
return object->u.industry.ind == NULL ? 0 : object->u.industry.ind->random_triggers; |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
385 |
} |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
386 |
|
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
387 |
static void IndustrySetTriggers(const ResolverObject *object, int triggers) |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
388 |
{ |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
389 |
if (object->u.industry.ind == NULL) return; |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7848
diff
changeset
|
390 |
object->u.industry.ind->random_triggers = triggers; |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
391 |
} |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
392 |
|
8233
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
393 |
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type) |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
394 |
{ |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
395 |
res->GetRandomBits = IndustryGetRandomBits; |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
396 |
res->GetTriggers = IndustryGetTriggers; |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7614
diff
changeset
|
397 |
res->SetTriggers = IndustrySetTriggers; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
398 |
res->GetVariable = IndustryGetVariable; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
399 |
res->ResolveReal = IndustryResolveReal; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
400 |
|
7610
13b7d9e247d2
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents:
7604
diff
changeset
|
401 |
res->psa = &indus->psa; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
402 |
res->u.industry.tile = tile; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
403 |
res->u.industry.ind = indus; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
6868
diff
changeset
|
404 |
res->u.industry.gfx = INVALID_INDUSTRYTILE; |
8233
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
405 |
res->u.industry.type = type; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
406 |
|
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7314
diff
changeset
|
407 |
res->callback = CBID_NO_CALLBACK; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
408 |
res->callback_param1 = 0; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
409 |
res->callback_param2 = 0; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
410 |
res->last_value = 0; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
411 |
res->trigger = 0; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
412 |
res->reseed = 0; |
8756
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8689
diff
changeset
|
413 |
res->count = 0; |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
414 |
} |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
415 |
|
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7314
diff
changeset
|
416 |
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile) |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
417 |
{ |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
418 |
ResolverObject object; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
419 |
const SpriteGroup *group; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
420 |
|
8233
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
421 |
NewIndustryResolver(&object, tile, industry, type); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
422 |
object.callback = callback; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
423 |
object.callback_param1 = param1; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
424 |
object.callback_param2 = param2; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
425 |
|
7102
fe01c264132b
(svn r10369) -Codechange: Add the IndustryType parameter to the GetIndustryCallback function.
belugas
parents:
7000
diff
changeset
|
426 |
group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
6835
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
427 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
428 |
|
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
429 |
return group->g.callback.result; |
31c89aab2d61
(svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff
changeset
|
430 |
} |
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
431 |
|
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
432 |
uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
433 |
{ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
434 |
const Industry *industry = object->u.industry.ind; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
435 |
TileIndex tile = object->u.industry.tile; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
436 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
437 |
if (object->scope == VSG_SCOPE_PARENT) { |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
438 |
return TownGetVariable(variable, parameter, available, industry->town); |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
439 |
} |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
440 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
441 |
switch (variable) { |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
442 |
case 0x80: return tile; |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
443 |
case 0x81: return GB(tile, 8, 8); |
7234
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
444 |
|
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
445 |
/* Pointer to the town the industry is associated with */ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
446 |
case 0x82: return industry->town->index; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
447 |
case 0x83: |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
448 |
case 0x84: |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
449 |
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
450 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
451 |
/* Number of the layout */ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
452 |
case 0x86: return industry->selected_layout; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
453 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
454 |
/* Ground type */ |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
455 |
case 0x87: return GetTerrainType(tile); |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
456 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
457 |
/* Town zone */ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
458 |
case 0x88: return GetTownRadiusGroup(industry->town, tile); |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
459 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
460 |
/* Manhattan distance of the closest town */ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
461 |
case 0x89: return min(DistanceManhattan(industry->town->xy, tile), 255); |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
462 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
463 |
/* Lowest height of the tile */ |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
464 |
case 0x8A: return GetTileZ(tile); |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
465 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
466 |
/* Distance to the nearest water/land tile */ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
467 |
case 0x8B: return GetClosestWaterDistance(tile, (GetIndustrySpec(industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
468 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
469 |
/* Square of Euclidian distance from town */ |
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
470 |
case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535); |
8415
41a623a9fdb5
(svn r11985) -Feature[FS#1697, newGRF]: Implement var 8F(random bits) during callback 28 (Industry location permissibility)
belugas
parents:
8275
diff
changeset
|
471 |
|
8436
c2600da0d3e3
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8427
diff
changeset
|
472 |
/* 32 random bits */ |
8689
af0a4064b83e
(svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents:
8634
diff
changeset
|
473 |
case 0x8F: return _industry_creation_random_bits; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
474 |
} |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
475 |
|
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
476 |
/* None of the special ones, so try the general ones */ |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
477 |
return IndustryGetVariable(object, variable, parameter, available); |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
478 |
} |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
479 |
|
8436
c2600da0d3e3
(svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents:
8427
diff
changeset
|
480 |
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed) |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
481 |
{ |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
482 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
483 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
484 |
ResolverObject object; |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
485 |
const SpriteGroup *group; |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
486 |
|
7668
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
487 |
Industry ind; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
488 |
ind.index = INVALID_INDUSTRY; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
489 |
ind.xy = tile; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
490 |
ind.width = 0; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
491 |
ind.type = type; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
492 |
ind.selected_layout = itspec_index; |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
493 |
ind.town = ClosestTownFromTile(tile, (uint)-1); |
fd98cd8a83fd
(svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents:
7658
diff
changeset
|
494 |
|
8233
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
495 |
NewIndustryResolver(&object, tile, &ind, type); |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
496 |
object.GetVariable = IndustryLocationGetVariable; |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
497 |
object.callback = CBID_INDUSTRY_LOCATION; |
8689
af0a4064b83e
(svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents:
8634
diff
changeset
|
498 |
_industry_creation_random_bits = seed; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
499 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
500 |
group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
501 |
|
7658
509348d18665
(svn r11189) -Fix: if the location check callback results in something invalid (i.e. not a callback result), the industry should be allowed to be build as that's how TTDP does it.
rubidium
parents:
7645
diff
changeset
|
502 |
/* Unlike the "normal" cases, not having a valid result means we allow |
509348d18665
(svn r11189) -Fix: if the location check callback results in something invalid (i.e. not a callback result), the industry should be allowed to be build as that's how TTDP does it.
rubidium
parents:
7645
diff
changeset
|
503 |
* the building of the industry, as that's how it's done in TTDP. */ |
509348d18665
(svn r11189) -Fix: if the location check callback results in something invalid (i.e. not a callback result), the industry should be allowed to be build as that's how TTDP does it.
rubidium
parents:
7645
diff
changeset
|
504 |
if (group == NULL || group->type != SGT_CALLBACK) return true; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
505 |
|
7750
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7706
diff
changeset
|
506 |
/* Copy some parameters from the registers to the error message text ref. stack */ |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7706
diff
changeset
|
507 |
SwitchToErrorRefStack(); |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7706
diff
changeset
|
508 |
PrepareTextRefStackUsage(4); |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7706
diff
changeset
|
509 |
SwitchToNormalRefStack(); |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7706
diff
changeset
|
510 |
|
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
511 |
switch (group->g.callback.result) { |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
512 |
case 0x400: return true; |
7209
30b3bc8c177b
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7207
diff
changeset
|
513 |
case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; break; |
30b3bc8c177b
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7207
diff
changeset
|
514 |
case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; break; |
30b3bc8c177b
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7207
diff
changeset
|
515 |
case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; break; |
30b3bc8c177b
(svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents:
7207
diff
changeset
|
516 |
default: _error_message = GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + group->g.callback.result); break; |
7207
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
517 |
} |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
518 |
|
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
519 |
return false; |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
520 |
} |
277c6c315403
(svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents:
7195
diff
changeset
|
521 |
|
7260
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
522 |
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type) |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
523 |
{ |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
524 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
525 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
526 |
if (HasBit(indspec->callback_flags, CBM_IND_AVAILABLE)) { |
7260
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
527 |
uint16 res = GetIndustryCallback(CBID_INDUSTRY_AVAILABLE, 0, creation_type, NULL, type, INVALID_TILE); |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
528 |
if (res != CALLBACK_FAILED) { |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
529 |
return (res == 0); |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
530 |
} |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
531 |
} |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
532 |
return true; |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
533 |
} |
487c5de4fe2c
(svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents:
7237
diff
changeset
|
534 |
|
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
535 |
static int32 DerefIndProd(uint field, bool use_register) |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
536 |
{ |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
537 |
return use_register ? (int32)GetRegister(field) : field; |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
538 |
} |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
539 |
|
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
540 |
/** |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
541 |
* Get the industry production callback and apply it to the industry. |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
542 |
* @param ind the industry this callback has to be called for |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
543 |
* @param reason the reason it is called (0 = incoming cargo, 1 = periodic tick callback) |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
544 |
*/ |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
545 |
void IndustryProductionCallback(Industry *ind, int reason) |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
546 |
{ |
7614
edf90d673e04
(svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents:
7610
diff
changeset
|
547 |
const IndustrySpec *spec = GetIndustrySpec(ind->type); |
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
548 |
ResolverObject object; |
8233
560ddd54f068
(svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents:
8213
diff
changeset
|
549 |
NewIndustryResolver(&object, ind->xy, ind, ind->type); |
7614
edf90d673e04
(svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents:
7610
diff
changeset
|
550 |
if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random(); |
7958
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
551 |
int multiplier = 1; |
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
552 |
if ((spec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) multiplier = ind->prod_level; |
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
553 |
object.callback_param2 = reason; |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
554 |
|
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
555 |
for (uint loop = 0;; loop++) { |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
556 |
SB(object.callback_param2, 8, 16, loop); |
7614
edf90d673e04
(svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents:
7610
diff
changeset
|
557 |
const SpriteGroup *group = Resolve(spec->grf_prop.spritegroup, &object); |
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
558 |
if (group == NULL || group->type != SGT_INDUSTRY_PRODUCTION) break; |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
559 |
|
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
560 |
bool deref = (group->g.indprod.version == 1); |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
561 |
|
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
562 |
for (uint i = 0; i < 3; i++) { |
7958
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
563 |
ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref) * multiplier, 0, 0xFFFF); |
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
564 |
} |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
565 |
for (uint i = 0; i < 2; i++) { |
7958
e42fa05eb045
(svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents:
7931
diff
changeset
|
566 |
ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + max(DerefIndProd(group->g.indprod.add_output[i], deref), 0) * multiplier, 0, 0xFFFF); |
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
567 |
} |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
568 |
|
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
569 |
int32 again = DerefIndProd(group->g.indprod.again, deref); |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
570 |
if (again == 0) break; |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
571 |
|
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
572 |
SB(object.callback_param2, 24, 8, again); |
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
573 |
} |
7195
8c728b5fef43
(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:
7191
diff
changeset
|
574 |
|
8c728b5fef43
(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:
7191
diff
changeset
|
575 |
InvalidateWindow(WC_INDUSTRY_VIEW, ind->index); |
7168
25e07ccb4a3d
(svn r10442) -Codechange: implement the industry production callback.
rubidium
parents:
7166
diff
changeset
|
576 |
} |