author | rubidium |
Sun, 23 Sep 2007 07:37:38 +0000 | |
branch | noai |
changeset 9703 | d2a6acdbd665 |
parent 9701 | d1ac22c62f64 |
child 9704 | 197cb8c6ae17 |
permissions | -rw-r--r-- |
9626 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file newgrf_industries.cpp */ |
|
4 |
||
5 |
#include "stdafx.h" |
|
6 |
#include "openttd.h" |
|
7 |
#include "debug.h" |
|
8 |
#include "functions.h" |
|
9 |
#include "macros.h" |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
10 |
#include "variables.h" |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
11 |
#include "landscape.h" |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
12 |
#include "table/strings.h" |
9626 | 13 |
#include "industry.h" |
9627 | 14 |
#include "industry_map.h" |
9626 | 15 |
#include "newgrf.h" |
16 |
#include "newgrf_callbacks.h" |
|
17 |
#include "newgrf_spritegroup.h" |
|
18 |
#include "newgrf_industries.h" |
|
19 |
#include "newgrf_commons.h" |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
20 |
#include "newgrf_text.h" |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
21 |
#include "newgrf_town.h" |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
22 |
#include "date.h" |
9626 | 23 |
|
24 |
/* Since the industry IDs defined by the GRF file don't necessarily correlate |
|
25 |
* to those used by the game, the IDs used for overriding old industries must be |
|
26 |
* translated when the idustry spec is set. */ |
|
27 |
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE); |
|
9629 | 28 |
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE); |
9626 | 29 |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
30 |
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
31 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
32 |
if (grf_type == IT_INVALID) return IT_INVALID; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
33 |
if (!HASBIT(grf_type, 7)) return GB(grf_type, 0, 6); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
34 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
35 |
return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
36 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
37 |
|
9626 | 38 |
/** |
39 |
* Finds the distance for the closest tile with water/land given a tile |
|
40 |
* @param tile the tile to find the distance too |
|
41 |
* @param water whether to find water or land |
|
42 |
* @note FAILS when an industry should be seen as water |
|
43 |
*/ |
|
44 |
static uint GetClosestWaterDistance(TileIndex tile, bool water) |
|
45 |
{ |
|
46 |
TileIndex t; |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
47 |
int best_dist; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
48 |
for (t = 0; t < MapSize(); t++) { |
9626 | 49 |
if (IsTileType(t, MP_WATER) == water) break; |
50 |
} |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
51 |
if (t == MapSize() && !water) return 0x200; |
9626 | 52 |
best_dist = DistanceManhattan(tile, t); |
53 |
||
54 |
for (; t < MapSize(); t++) { |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
55 |
int dist = DistanceManhattan(tile, t); |
9626 | 56 |
if (dist < best_dist) { |
57 |
if (IsTileType(t, MP_WATER) == water) best_dist = dist; |
|
58 |
} else { |
|
59 |
/* When the Y distance between the current row and the 'source' tile |
|
60 |
* is larger than the best distance, we've found the best distance */ |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
61 |
if ((int)TileY(t) - (int)TileY(tile) > best_dist) break; |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
62 |
if ((int)TileX(t) - (int)TileX(tile) > best_dist) { |
9626 | 63 |
/* We can safely skip this many tiles; from here all tiles have a |
64 |
* higher or equal distance than the best distance */ |
|
65 |
t |= MapMaxX(); |
|
66 |
continue; |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
67 |
} else if (TileX(tile) < TileX(t)) { |
9626 | 68 |
/* We can safely skip this many tiles; up to here all tiles have a |
69 |
* higher or equal distance than the best distance */ |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
70 |
t += max(best_dist - dist, 0); |
9626 | 71 |
continue; |
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
76 |
return min(best_dist, water ? 0x7F : 0x1FF); |
9626 | 77 |
} |
78 |
||
9627 | 79 |
/** Make an analysis of a tile and check for its belonging to the same |
80 |
* industry, and/or the same grf file |
|
81 |
* @param new_tile TileIndex of the tile to query |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
82 |
* @param old_tile TileIndex of the reference tile |
9627 | 83 |
* @param i Industry to which old_tile belongs to |
84 |
* @return value encoded as per NFO specs */ |
|
85 |
uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Industry *i) |
|
86 |
{ |
|
87 |
if (IsTileType(new_tile, MP_INDUSTRY)) { // Is this an industry tile? |
|
88 |
||
89 |
if (GetIndustryIndex(new_tile) == i->index) { // Does it belong to the same industry? |
|
90 |
IndustryGfx gfx = GetIndustryGfx(new_tile); |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
91 |
const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
92 |
const IndustryTileSpec *indold = GetIndustryTileSpec(GetIndustryGfx(old_tile)); |
9627 | 93 |
|
94 |
if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type? |
|
95 |
/* It is an old tile. We have to see if it's been overriden */ |
|
96 |
if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden? |
|
97 |
return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile |
|
98 |
} else { // yes. FInd out if it is from the same grf file or not |
|
99 |
const IndustryTileSpec *old_tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override); |
|
100 |
||
101 |
if (old_tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { |
|
102 |
return old_tile_ovr->grf_prop.local_id; // same grf file |
|
103 |
} else { |
|
104 |
return 0xFFFE; // not the same grf file |
|
105 |
} |
|
106 |
} |
|
107 |
} else { |
|
108 |
if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ? |
|
109 |
if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ? |
|
110 |
return indtsp->grf_prop.local_id; |
|
111 |
} else { |
|
112 |
return 0xFFFE; // Defined in another grf file |
|
113 |
} |
|
114 |
} else { // tile has no spritegroup |
|
115 |
return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
return 0xFFFF; // tile is not an industry one or does not belong to the current industry |
|
122 |
} |
|
123 |
||
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
124 |
static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
125 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
126 |
uint32 best_dist = MAX_UVALUE(uint32); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
127 |
const Industry *i; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
128 |
FOR_ALL_INDUSTRIES(i) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
129 |
if (i->type != type || i == current) continue; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
130 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
131 |
best_dist = min(best_dist, DistanceManhattan(tile, i->xy)); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
132 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
133 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
134 |
return best_dist; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
135 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
136 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
137 |
/** Implementation of both var 67 and 68 |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
138 |
* since the mechanism is almost the same, it is easier to regroup them on the same |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
139 |
* function. |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
140 |
* @param param_setID parameter given to the callback, which is the set id, or the local id, in our terminology |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
141 |
* @param layout_filter on what layout do we filter? |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
142 |
* @param current Industry for which the inquiry is made |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
143 |
* @return the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
144 |
*/ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
145 |
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, const Industry *current) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
146 |
{ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
147 |
uint32 GrfID = GetRegister(0x100); ///< Get the GRFID of the definition to look for in register 100h |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
148 |
IndustryType ind_index; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
149 |
uint32 closest_dist = MAX_UVALUE(uint32); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
150 |
byte count = 0; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
151 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
152 |
/* Determine what will be the industry type to look for */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
153 |
switch (GrfID) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
154 |
case 0: // this is a default industry type |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
155 |
ind_index = param_setID; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
156 |
break; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
157 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
158 |
case 0xFFFFFFFF: // current grf |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
159 |
ind_index = GetIndustrySpec(current->type)->grf_prop.grffile->grfid; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
160 |
/*Fall through*/ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
161 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
162 |
default: //use the grfid specified in register 100h |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
163 |
ind_index = MapNewGRFIndustryType(param_setID, GrfID); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
164 |
break; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
165 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
166 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
167 |
if (layout_filter == 0) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
168 |
/* If the filter is 0, it could be because none was specified as well as being really a 0. |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
169 |
* In either case, just do the regular var67 */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
170 |
closest_dist = GetClosestIndustry(current->xy, ind_index, current); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
171 |
count = GetIndustryTypeCount(ind_index); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
172 |
} else { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
173 |
/* Count only those who match the same industry type and layout filter |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
174 |
* Unfortunately, we have to do it manually */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
175 |
const Industry *i; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
176 |
FOR_ALL_INDUSTRIES(i) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
177 |
if (i->type == ind_index && i != current && i->selected_layout == layout_filter) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
178 |
closest_dist = min(closest_dist, DistanceManhattan(current->xy, i->xy)); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
179 |
count++; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
180 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
181 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
182 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
183 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
184 |
return count << 16 | GB(closest_dist, 0, 16); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
185 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
186 |
|
9626 | 187 |
/** This function implements the industries variables that newGRF defines. |
188 |
* @param variable that is queried |
|
189 |
* @param parameter unused |
|
190 |
* @param available will return false if ever the variable asked for does not exist |
|
191 |
* @param ind is of course the industry we are inquiring |
|
192 |
* @return the value stored in the corresponding variable*/ |
|
193 |
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
|
194 |
{ |
|
195 |
const Industry *industry = object->u.industry.ind; |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
196 |
TileIndex tile = object->u.industry.tile; |
9626 | 197 |
const IndustrySpec *indspec = GetIndustrySpec(industry->type); |
198 |
||
199 |
switch (variable) { |
|
200 |
case 0x40: |
|
201 |
case 0x41: |
|
202 |
case 0x42: { // waiting cargo, but only if those two callback flags are set |
|
203 |
uint16 callback = indspec->callback_flags; |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
204 |
if (HASBIT(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(callback, CBM_IND_PRODUCTION_256_TICKS)) { |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
205 |
return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF); |
9626 | 206 |
} else { |
207 |
return 0; |
|
208 |
} |
|
209 |
} |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
210 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
211 |
/* Manhattan distance of closes dry/water tile */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
212 |
case 0x43: return GetClosestWaterDistance(tile, (object->u.industry_location.spec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); |
9626 | 213 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
214 |
/* Layout number */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
215 |
case 0x44: return industry->selected_layout; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
216 |
|
9627 | 217 |
/* Get industry ID at offset param */ |
218 |
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), tile, industry); |
|
9626 | 219 |
|
220 |
case 0x61: return 0; // Get random tile bits at offset param |
|
221 |
||
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
222 |
/* Land info of nearby tiles */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
223 |
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
224 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
225 |
/* Animation stage of nearby tiles */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
226 |
case 0x63: { |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
227 |
tile = GetNearbyTile(parameter, tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
228 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
229 |
return GetIndustryAnimationState(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
230 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
231 |
return 0xFFFFFFFF; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
232 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
233 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
234 |
/* Distance of nearest industry of given type */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
235 |
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry); |
9626 | 236 |
/* Get town zone and Manhattan distance of closest town */ |
237 |
case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF); |
|
238 |
/* Get square of Euclidian distance of closes town */ |
|
239 |
case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF); |
|
240 |
||
241 |
/* Count of industry, distance of closest instance |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
242 |
* 68 is the same as 67, but with a filtering on selected layout */ |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
243 |
case 0x67: |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
244 |
case 0x68: return GetCountAndDistanceOfClosestInstance(parameter, variable == 0x68 ? GB(GetRegister(0x101), 0, 8) : 0, industry); |
9626 | 245 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
246 |
/* Get a variable from the persistent storage */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
247 |
case 0x7C: return industry->psa.Get(parameter); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
248 |
|
9626 | 249 |
/* Industry structure access*/ |
250 |
case 0x80: return industry->xy; |
|
251 |
case 0x81: return GB(industry->xy, 8, 8); |
|
252 |
/* Pointer to the town the industry is associated with */ |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
253 |
case 0x82: return industry->town->index; |
9626 | 254 |
case 0x83: |
255 |
case 0x84: |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
256 |
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported |
9626 | 257 |
case 0x86: return industry->width; |
258 |
case 0x87: return industry->height;// xy dimensions |
|
259 |
/* */ |
|
260 |
case 0x88: |
|
261 |
case 0x89: return indspec->produced_cargo[variable - 0x88]; |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
262 |
case 0x8A: return industry->produced_cargo_waiting[0]; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
263 |
case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
264 |
case 0x8C: return industry->produced_cargo_waiting[1]; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
265 |
case 0x8D: return GB(industry->produced_cargo_waiting[1], 8, 8); |
9626 | 266 |
case 0x8E: |
267 |
case 0x8F: return industry->production_rate[variable - 0x8E]; |
|
268 |
case 0x90: |
|
269 |
case 0x91: |
|
270 |
case 0x92: return indspec->accepts_cargo[variable - 0x90]; |
|
271 |
case 0x93: return industry->prod_level; |
|
272 |
/* amount of cargo produced so far THIS month. */ |
|
273 |
case 0x94: return industry->this_month_production[0]; |
|
274 |
case 0x95: return GB(industry->this_month_production[0], 8, 8); |
|
275 |
case 0x96: return industry->this_month_production[1]; |
|
276 |
case 0x97: return GB(industry->this_month_production[1], 8, 8); |
|
277 |
/* amount of cargo transported so far THIS month. */ |
|
278 |
case 0x98: return industry->this_month_transported[0]; |
|
279 |
case 0x99: return GB(industry->this_month_transported[0], 8, 8); |
|
280 |
case 0x9A: return industry->this_month_transported[1]; |
|
281 |
case 0x9B: return GB(industry->this_month_transported[0], 8, 8); |
|
282 |
/* fraction of cargo transported LAST month. */ |
|
283 |
case 0x9C: |
|
284 |
case 0x9D: return industry->last_month_pct_transported[variable - 0x9C]; |
|
285 |
/* amount of cargo produced LAST month. */ |
|
286 |
case 0x9E: return industry->last_month_production[0]; |
|
287 |
case 0x9F: return GB(industry->last_month_production[0], 8, 8); |
|
288 |
case 0xA0: return industry->last_month_production[1]; |
|
289 |
case 0xA1: return GB(industry->last_month_production[1], 8, 8); |
|
290 |
/* amount of cargo transported last month. */ |
|
291 |
case 0xA2: return industry->last_month_transported[0]; |
|
292 |
case 0xA3: return GB(industry->last_month_transported[0], 8, 8); |
|
293 |
case 0xA4: return industry->last_month_transported[1]; |
|
294 |
case 0xA5: return GB(industry->last_month_transported[0], 8, 8); |
|
295 |
||
296 |
case 0xA6: return industry->type; |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
297 |
case 0xA7: return industry->founder; |
9626 | 298 |
case 0xA8: return industry->random_color; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
299 |
case 0xA9: return clamp(0, industry->last_prod_year - 1920, 255); |
9626 | 300 |
case 0xAA: return industry->counter; |
301 |
case 0xAB: return GB(industry->counter, 8, 8); |
|
302 |
case 0xAC: return industry->was_cargo_delivered; |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
303 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
304 |
case 0xB0: return clamp(0, industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date when built since 1920 (in days) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
305 |
case 0xB3: return industry->construction_type; // Construction type |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
306 |
case 0xB4: return clamp(0, industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date last cargo accepted since 1920 (in days) |
9626 | 307 |
} |
308 |
||
309 |
DEBUG(grf, 1, "Unhandled industry property 0x%X", variable); |
|
310 |
||
311 |
*available = false; |
|
312 |
return (uint32)-1; |
|
313 |
} |
|
314 |
||
315 |
static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, const SpriteGroup *group) |
|
316 |
{ |
|
317 |
/* IndustryTile do not have 'real' groups */ |
|
318 |
return NULL; |
|
319 |
} |
|
320 |
||
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
321 |
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus) |
9626 | 322 |
{ |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
323 |
res->GetRandomBits = IndustryTileGetRandomBits; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
324 |
res->GetTriggers = IndustryTileGetTriggers; |
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
325 |
res->SetTriggers = IndustryTileSetTriggers; |
9626 | 326 |
res->GetVariable = IndustryGetVariable; |
327 |
res->ResolveReal = IndustryResolveReal; |
|
328 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
329 |
res->psa = &indus->psa; |
9626 | 330 |
res->u.industry.tile = tile; |
331 |
res->u.industry.ind = indus; |
|
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
332 |
res->u.industry.gfx = INVALID_INDUSTRYTILE; |
9626 | 333 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
334 |
res->callback = CBID_NO_CALLBACK; |
9626 | 335 |
res->callback_param1 = 0; |
336 |
res->callback_param2 = 0; |
|
337 |
res->last_value = 0; |
|
338 |
res->trigger = 0; |
|
339 |
res->reseed = 0; |
|
340 |
} |
|
341 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
342 |
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile) |
9626 | 343 |
{ |
344 |
ResolverObject object; |
|
345 |
const SpriteGroup *group; |
|
346 |
||
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9627
diff
changeset
|
347 |
NewIndustryResolver(&object, tile, industry); |
9626 | 348 |
object.callback = callback; |
349 |
object.callback_param1 = param1; |
|
350 |
object.callback_param2 = param2; |
|
351 |
||
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
352 |
group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
9626 | 353 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
354 |
||
355 |
return group->g.callback.result; |
|
356 |
} |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
357 |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
358 |
uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
359 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
360 |
TileIndex tile = object->u.industry_location.tile; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
361 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
362 |
if (object->scope == VSG_SCOPE_PARENT) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
363 |
return TownGetVariable(variable, parameter, available, ClosestTownFromTile(tile, (uint)-1)); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
364 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
365 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
366 |
switch (variable) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
367 |
/* Land info of nearby tiles */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
368 |
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
369 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
370 |
/* Distance of nearest industry of given type */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
371 |
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, object->u.industry_location.spec->grf_prop.grffile->grfid), NULL); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
372 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
373 |
/* Location where to build the industry */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
374 |
case 0x80: return tile; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
375 |
case 0x81: return GB(tile, 8, 8); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
376 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
377 |
/* Pointer to the town the industry is associated with */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
378 |
case 0x82: return ClosestTownFromTile(tile, (uint)-1)->index; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
379 |
case 0x83: |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
380 |
case 0x84: |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
381 |
case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
382 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
383 |
/* Number of the layout */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
384 |
case 0x86: return object->u.industry_location.itspec_index; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
385 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
386 |
/* Ground type */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
387 |
case 0x87: return GetTerrainType(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
388 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
389 |
/* Town zone */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
390 |
case 0x88: return GetTownRadiusGroup(ClosestTownFromTile(tile, (uint)-1), tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
391 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
392 |
/* Manhattan distance of the closest town */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
393 |
case 0x89: return min(DistanceManhattan(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 255); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
394 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
395 |
/* Lowest height of the tile */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
396 |
case 0x8A: return GetTileZ(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
397 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
398 |
/* Distance to the nearest water/land tile */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
399 |
case 0x8B: return GetClosestWaterDistance(tile, (object->u.industry_location.spec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
400 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
401 |
/* Square of Euclidian distance from town */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
402 |
case 0x8D: return min(DistanceSquare(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 65535); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
403 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
404 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
405 |
DEBUG(grf, 1, "Unhandled location industry property 0x%X", variable); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
406 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
407 |
*available = false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
408 |
return (uint32)-1; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
409 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
410 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
411 |
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
412 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
413 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
414 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
415 |
ResolverObject object; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
416 |
const SpriteGroup *group; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
417 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
418 |
NewIndustryResolver(&object, tile, NULL); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
419 |
object.GetVariable = IndustryLocationGetVariable; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
420 |
object.callback = CBID_INDUSTRY_LOCATION; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
421 |
object.u.industry_location.tile = tile; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
422 |
object.u.industry_location.spec = indspec; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
423 |
object.u.industry_location.itspec_index = itspec_index; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
424 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
425 |
group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
426 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
427 |
if (group == NULL || group->type != SGT_CALLBACK) return false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
428 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
429 |
switch (group->g.callback.result) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
430 |
case 0x400: return true; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
431 |
case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
432 |
case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
433 |
case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
434 |
default: _error_message = GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + group->g.callback.result); break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
435 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
436 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
437 |
return false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
438 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
439 |
|
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
440 |
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type) |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
441 |
{ |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
442 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
443 |
|
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
444 |
if (HASBIT(indspec->callback_flags, CBM_IND_AVAILABLE)) { |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
445 |
uint16 res = GetIndustryCallback(CBID_INDUSTRY_AVAILABLE, 0, creation_type, NULL, type, INVALID_TILE); |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
446 |
if (res != CALLBACK_FAILED) { |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
447 |
return (res == 0); |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
448 |
} |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
449 |
} |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
450 |
return true; |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
451 |
} |
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9641
diff
changeset
|
452 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
453 |
static int32 DerefIndProd(uint field, bool use_register) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
454 |
{ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
455 |
return use_register ? (int32)GetRegister(field) : field; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
456 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
457 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
458 |
/** |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
459 |
* Get the industry production callback and apply it to the industry. |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
460 |
* @param ind the industry this callback has to be called for |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
461 |
* @param reason the reason it is called (0 = incoming cargo, 1 = periodic tick callback) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
462 |
*/ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
463 |
void IndustryProductionCallback(Industry *ind, int reason) |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
464 |
{ |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
465 |
const IndustrySpec *spec = GetIndustrySpec(ind->type); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
466 |
ResolverObject object; |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
467 |
NewIndustryResolver(&object, ind->xy, ind); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
468 |
if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random(); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
469 |
object.callback_param2 = reason; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
470 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
471 |
for (uint loop = 0;; loop++) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
472 |
SB(object.callback_param2, 8, 16, loop); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
473 |
const SpriteGroup *group = Resolve(spec->grf_prop.spritegroup, &object); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
474 |
if (group == NULL || group->type != SGT_INDUSTRY_PRODUCTION) break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
475 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
476 |
bool deref = (group->g.indprod.version == 1); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
477 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
478 |
for (uint i = 0; i < 3; i++) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
479 |
ind->incoming_cargo_waiting[i] = clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref), 0, 0xFFFF); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
480 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
481 |
for (uint i = 0; i < 2; i++) { |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
482 |
ind->produced_cargo_waiting[i] = clamp(ind->produced_cargo_waiting[i] + DerefIndProd(group->g.indprod.add_output[i], deref), 0, 0xFFFF); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
483 |
} |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
484 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
485 |
int32 again = DerefIndProd(group->g.indprod.again, deref); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
486 |
if (again == 0) break; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
487 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
488 |
SB(object.callback_param2, 24, 8, again); |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
489 |
} |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
490 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9631
diff
changeset
|
491 |
InvalidateWindow(WC_INDUSTRY_VIEW, ind->index); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
492 |
} |