author | glx |
Sun, 15 Jun 2008 22:18:10 +0000 | |
branch | noai |
changeset 10971 | aaf89f8c59b9 |
parent 10455 | 22c441f5adf9 |
child 11044 | 097ea3e7ec56 |
permissions | -rw-r--r-- |
9628 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
3 |
/** @file newgrf_industrytiles.cpp NewGRF handling of industry tiles. */ |
9628 | 4 |
|
5 |
#include "stdafx.h" |
|
6 |
#include "openttd.h" |
|
7 |
#include "variables.h" |
|
8 |
#include "debug.h" |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
9 |
#include "viewport_func.h" |
9628 | 10 |
#include "landscape.h" |
11 |
#include "newgrf.h" |
|
12 |
#include "industry.h" |
|
13 |
#include "newgrf_commons.h" |
|
14 |
#include "newgrf_spritegroup.h" |
|
15 |
#include "newgrf_callbacks.h" |
|
16 |
#include "newgrf_industries.h" |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
17 |
#include "newgrf_industrytiles.h" |
10294 | 18 |
#include "newgrf_sound.h" |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
19 |
#include "newgrf_text.h" |
9628 | 20 |
#include "industry_map.h" |
21 |
#include "clear_map.h" |
|
22 |
#include "sprite.h" |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
23 |
#include "transparency.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
24 |
#include "functions.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
25 |
#include "town.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
26 |
#include "command_func.h" |
10294 | 27 |
#include "animated_tile_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
28 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
29 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
30 |
#include "table/strings.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
31 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
32 |
static uint32 GetGRFParameter(IndustryGfx indtile_id, byte parameter) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
33 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
34 |
const IndustryTileSpec *indtspec = GetIndustryTileSpec(indtile_id); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
35 |
const GRFFile *file = indtspec->grf_prop.grffile; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
36 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
37 |
if (parameter >= file->param_end) return 0; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
38 |
return file->param[parameter]; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
39 |
} |
9628 | 40 |
|
41 |
/** |
|
42 |
* Based on newhouses equivalent, but adapted for newindustries |
|
43 |
* @param parameter from callback. It's in fact a pair of coordinates |
|
44 |
* @param tile TileIndex from which the callback was initiated |
|
45 |
* @param index of the industry been queried for |
|
46 |
* @return a construction of bits obeying the newgrf format |
|
47 |
*/ |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
48 |
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index) |
9628 | 49 |
{ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
50 |
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
51 |
bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index); |
9628 | 52 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
53 |
return GetNearbyTileInformation(tile) | (is_same_industry ? 1 : 0) << 8; |
9628 | 54 |
} |
55 |
||
56 |
/** This is the position of the tile relative to the northernmost tile of the industry. |
|
57 |
* Format: 00yxYYXX |
|
58 |
* Variable Content |
|
59 |
* x the x offset from the northernmost tile |
|
60 |
* XX same, but stored in a byte instead of a nibble |
|
61 |
* y the y offset from the northernmost tile |
|
62 |
* YY same, but stored in a byte instead of a nibble |
|
63 |
* @param tile TileIndex of the tile to evaluate |
|
64 |
* @param ind_tile northernmost tile of the industry |
|
65 |
*/ |
|
66 |
static uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile) |
|
67 |
{ |
|
68 |
byte x = TileX(tile) - TileX(ind_tile); |
|
69 |
byte y = TileY(tile) - TileY(ind_tile); |
|
70 |
||
71 |
return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x; |
|
72 |
} |
|
73 |
||
74 |
static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
|
75 |
{ |
|
76 |
const Industry *inds = object->u.industry.ind; |
|
77 |
TileIndex tile = object->u.industry.tile; |
|
78 |
||
79 |
if (object->scope == VSG_SCOPE_PARENT) { |
|
80 |
return IndustryGetVariable(object, variable, parameter, available); |
|
81 |
} |
|
82 |
||
83 |
switch (variable) { |
|
84 |
/* Construction state of the tile: a value between 0 and 3 */ |
|
85 |
case 0x40 : return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(tile) : 0; |
|
86 |
||
87 |
case 0x41 : return GetTerrainType(tile); |
|
88 |
||
89 |
/* Current town zone of the tile in the nearest town */ |
|
90 |
case 0x42 : return GetTownRadiusGroup(ClosestTownFromTile(tile, (uint)-1), tile); |
|
91 |
||
92 |
/* Relative position */ |
|
93 |
case 0x43 : return GetRelativePosition(tile, inds->xy); |
|
94 |
||
95 |
/* Animation frame. Like house variable 46 but can contain anything 0..FF. */ |
|
96 |
case 0x44 : return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryAnimationState(tile) : 0; |
|
97 |
||
98 |
/* Land info of nearby tiles */ |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
99 |
case 0x60 : return GetNearbyIndustryTileInformation(parameter, tile, inds == NULL ? (IndustryID)INVALID_INDUSTRY : inds->index); |
9628 | 100 |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
101 |
/* Animation stage of nearby tiles */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
102 |
case 0x61 : { |
9628 | 103 |
tile = GetNearbyTile(parameter, tile); |
104 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == inds) { |
|
105 |
return GetIndustryAnimationState(tile); |
|
106 |
} |
|
107 |
return 0xFFFFFFFF; |
|
108 |
} |
|
109 |
||
110 |
/* Get industry tile ID at offset */ |
|
9704 | 111 |
case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
112 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
113 |
/* Read GRF parameter */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
114 |
case 0x7F: return GetGRFParameter(GetIndustryGfx(tile), parameter); |
9628 | 115 |
} |
116 |
||
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
117 |
DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
118 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
119 |
*available = false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
120 |
return (uint32)-1; |
9628 | 121 |
} |
122 |
||
123 |
static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, const SpriteGroup *group) |
|
124 |
{ |
|
125 |
/* IndustryTile do not have 'real' groups. Or do they?? */ |
|
126 |
return NULL; |
|
127 |
} |
|
128 |
||
9704 | 129 |
static uint32 IndustryTileGetRandomBits(const ResolverObject *object) |
9628 | 130 |
{ |
131 |
const TileIndex tile = object->u.industry.tile; |
|
9704 | 132 |
if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
133 |
return (object->scope == VSG_SCOPE_SELF) ? GetIndustryRandomBits(tile) : GetIndustryByTile(tile)->random; |
9628 | 134 |
} |
135 |
||
9704 | 136 |
static uint32 IndustryTileGetTriggers(const ResolverObject *object) |
9628 | 137 |
{ |
138 |
const TileIndex tile = object->u.industry.tile; |
|
9704 | 139 |
if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
140 |
return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : GetIndustryByTile(tile)->random_triggers; |
9628 | 141 |
} |
142 |
||
9704 | 143 |
static void IndustryTileSetTriggers(const ResolverObject *object, int triggers) |
9628 | 144 |
{ |
145 |
const TileIndex tile = object->u.industry.tile; |
|
9704 | 146 |
if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return; |
147 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
148 |
if (object->scope == VSG_SCOPE_SELF) { |
9704 | 149 |
SetIndustryTriggers(tile, triggers); |
150 |
} else { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
151 |
GetIndustryByTile(tile)->random_triggers = triggers; |
9704 | 152 |
} |
9628 | 153 |
} |
154 |
||
155 |
static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus) |
|
156 |
{ |
|
157 |
res->GetRandomBits = IndustryTileGetRandomBits; |
|
158 |
res->GetTriggers = IndustryTileGetTriggers; |
|
159 |
res->SetTriggers = IndustryTileSetTriggers; |
|
160 |
res->GetVariable = IndustryTileGetVariable; |
|
161 |
res->ResolveReal = IndustryTileResolveReal; |
|
162 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
163 |
res->psa = &indus->psa; |
9628 | 164 |
res->u.industry.tile = tile; |
165 |
res->u.industry.ind = indus; |
|
166 |
res->u.industry.gfx = gfx; |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
167 |
res->u.industry.type = indus->type; |
9628 | 168 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
169 |
res->callback = CBID_NO_CALLBACK; |
9628 | 170 |
res->callback_param1 = 0; |
171 |
res->callback_param2 = 0; |
|
172 |
res->last_value = 0; |
|
173 |
res->trigger = 0; |
|
174 |
res->reseed = 0; |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
175 |
res->count = 0; |
9628 | 176 |
} |
177 |
||
9629 | 178 |
void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte rnd_color, byte stage, IndustryGfx gfx) |
179 |
{ |
|
180 |
const DrawTileSprites *dts = group->g.layout.dts; |
|
181 |
const DrawTileSeqStruct *dtss; |
|
182 |
||
9732 | 183 |
SpriteID image = dts->ground.sprite; |
184 |
SpriteID pal = dts->ground.pal; |
|
9629 | 185 |
|
9704 | 186 |
if (IS_CUSTOM_SPRITE(image)) image += stage; |
187 |
||
9629 | 188 |
if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); |
189 |
||
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
190 |
/* End now if industries are invisible */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
191 |
if (IsInvisibilitySet(TO_INDUSTRIES)) return; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
192 |
|
9629 | 193 |
foreach_draw_tile_seq(dtss, dts->seq) { |
9732 | 194 |
if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue; |
9629 | 195 |
|
9732 | 196 |
image = dtss->image.sprite; |
197 |
pal = dtss->image.pal; |
|
9629 | 198 |
|
9704 | 199 |
if (IS_CUSTOM_SPRITE(image)) image += stage; |
200 |
||
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
201 |
if (HasBit(image, PALETTE_MODIFIER_COLOR)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
202 |
if (pal == 0) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
203 |
pal = GENERAL_SPRITE_COLOR(rnd_color); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
204 |
} |
9629 | 205 |
} else { |
206 |
pal = PAL_NONE; |
|
207 |
} |
|
208 |
||
209 |
if ((byte)dtss->delta_z != 0x80) { |
|
210 |
AddSortableSpriteToDraw( |
|
211 |
image, pal, |
|
212 |
ti->x + dtss->delta_x, ti->y + dtss->delta_y, |
|
213 |
dtss->size_x, dtss->size_y, |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
214 |
dtss->size_z, ti->z + dtss->delta_z, |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
215 |
!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_INDUSTRIES) |
9629 | 216 |
); |
217 |
} else { |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
218 |
AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, IsTransparencySet(TO_INDUSTRIES)); |
9629 | 219 |
} |
220 |
} |
|
221 |
} |
|
222 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
223 |
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile) |
9628 | 224 |
{ |
225 |
ResolverObject object; |
|
226 |
const SpriteGroup *group; |
|
227 |
||
228 |
NewIndustryTileResolver(&object, gfx_id, tile, industry); |
|
229 |
object.callback = callback; |
|
230 |
object.callback_param1 = param1; |
|
231 |
object.callback_param2 = param2; |
|
232 |
||
233 |
group = Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object); |
|
234 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
|
235 |
||
236 |
return group->g.callback.result; |
|
237 |
} |
|
9629 | 238 |
|
239 |
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds) |
|
240 |
{ |
|
241 |
const SpriteGroup *group; |
|
242 |
ResolverObject object; |
|
243 |
||
244 |
if (ti->tileh != SLOPE_FLAT) { |
|
245 |
bool draw_old_one = true; |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
246 |
if (HasBit(inds->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) { |
9629 | 247 |
/* Called to determine the type (if any) of foundation to draw for industry tile */ |
248 |
uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile); |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
249 |
draw_old_one = callback_res != 0; |
9629 | 250 |
} |
251 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
252 |
if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED); |
9629 | 253 |
} |
254 |
||
255 |
NewIndustryTileResolver(&object, gfx, ti->tile, i); |
|
256 |
||
257 |
group = Resolve(inds->grf_prop.spritegroup, &object); |
|
258 |
if (group == NULL || group->type != SGT_TILELAYOUT) { |
|
259 |
return false; |
|
260 |
} else { |
|
261 |
/* Limit the building stage to the number of stages supplied. */ |
|
262 |
byte stage = GetIndustryConstructionStage(ti->tile); |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
263 |
stage = Clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1); |
9629 | 264 |
IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx); |
265 |
return true; |
|
266 |
} |
|
267 |
} |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
268 |
|
9704 | 269 |
extern bool IsSlopeRefused(Slope current, Slope refused); |
270 |
||
271 |
bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index) |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
272 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
273 |
Industry ind; |
9704 | 274 |
ind.index = INVALID_INDUSTRY; |
275 |
ind.xy = ind_base_tile; |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
276 |
ind.width = 0; |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
277 |
ind.type = type; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
278 |
|
9704 | 279 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile); |
280 |
if (callback_res == CALLBACK_FAILED) { |
|
281 |
return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused); |
|
282 |
} |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
283 |
if (its->grf_prop.grffile->grf_version < 7) { |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
9869
diff
changeset
|
284 |
return callback_res != 0; |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
285 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
286 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
287 |
/* Copy some parameters from the registers to the error message text ref. stack */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
288 |
SwitchToErrorRefStack(); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
289 |
PrepareTextRefStackUsage(4); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
290 |
SwitchToNormalRefStack(); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
291 |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
292 |
switch (callback_res) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
293 |
case 0x400: return true; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
294 |
case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; return false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
295 |
case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; return false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
296 |
case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; return false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
297 |
default: _error_message = GetGRFStringID(its->grf_prop.grffile->grfid, 0xD000 + callback_res); return false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
298 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
299 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
300 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
301 |
void AnimateNewIndustryTile(TileIndex tile) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
302 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
303 |
Industry *ind = GetIndustryByTile(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
304 |
IndustryGfx gfx = GetIndustryGfx(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
305 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
306 |
byte animation_speed = itspec->animation_speed; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
307 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
308 |
if (HasBit(itspec->callback_flags, CBM_INDT_ANIM_SPEED)) { |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
309 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIMATION_SPEED, 0, 0, gfx, ind, tile); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
310 |
if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 0, 16); |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
311 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
312 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
313 |
/* An animation speed of 2 means the animation frame changes 4 ticks, and |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
314 |
* increasing this value by one doubles the wait. 0 is the minimum value |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
315 |
* allowed for animation_speed, which corresponds to 30ms, and 16 is the |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
316 |
* maximum, corresponding to around 33 minutes. */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
317 |
if ((_tick_counter % (1 << animation_speed)) != 0) return; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
318 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
319 |
bool frame_set_by_callback = false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
320 |
byte frame = GetIndustryAnimationState(tile); |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
321 |
uint16 num_frames = GB(itspec->animation_info, 0, 8); |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
322 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
323 |
if (HasBit(itspec->callback_flags, CBM_INDT_ANIM_NEXT_FRAME)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
324 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_NEXT_FRAME, HasBit(itspec->animation_special_flags, 0) ? Random() : 0, 0, gfx, ind, tile); |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
325 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
326 |
if (callback_res != CALLBACK_FAILED) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
327 |
frame_set_by_callback = true; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
328 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
329 |
switch (callback_res & 0xFF) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
330 |
case 0xFF: |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
331 |
DeleteAnimatedTile(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
332 |
break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
333 |
case 0xFE: |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
334 |
/* Carry on as normal. */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
335 |
frame_set_by_callback = false; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
336 |
break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
337 |
default: |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
338 |
frame = callback_res & 0xFF; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
339 |
break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
340 |
} |
10294 | 341 |
|
342 |
/* If the lower 7 bits of the upper byte of the callback |
|
343 |
* result are not empty, it is a sound effect. */ |
|
344 |
if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile); |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
345 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
346 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
347 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
348 |
if (!frame_set_by_callback) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
349 |
if (frame < num_frames) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
350 |
frame++; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
351 |
} else if (frame == num_frames && GB(itspec->animation_info, 8, 8) == 1) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
352 |
/* This animation loops, so start again from the beginning */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
353 |
frame = 0; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
354 |
} else { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
355 |
/* This animation doesn't loop, so stay here */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
356 |
DeleteAnimatedTile(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
357 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
358 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
359 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
360 |
SetIndustryAnimationState(tile, frame); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
361 |
MarkTileDirtyByTile(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
362 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
363 |
|
10294 | 364 |
static void ChangeIndustryTileAnimationFrame(const IndustryTileSpec *itspec, TileIndex tile, IndustryAnimationTrigger iat, uint32 random_bits, IndustryGfx gfx, Industry *ind) |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
365 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
366 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_START_STOP, random_bits, iat, gfx, ind, tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
367 |
if (callback_res == CALLBACK_FAILED) return; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
368 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
369 |
switch (callback_res & 0xFF) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
370 |
case 0xFD: /* Do nothing. */ break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
371 |
case 0xFE: AddAnimatedTile(tile); break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
372 |
case 0xFF: DeleteAnimatedTile(tile); break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
373 |
default: |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
374 |
SetIndustryAnimationState(tile, callback_res & 0xFF); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
375 |
AddAnimatedTile(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
376 |
break; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
377 |
} |
10294 | 378 |
|
379 |
/* If the lower 7 bits of the upper byte of the callback |
|
380 |
* result are not empty, it is a sound effect. */ |
|
381 |
if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile); |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
382 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
383 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
384 |
bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
385 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
386 |
IndustryGfx gfx = GetIndustryGfx(tile); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
387 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
388 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
389 |
if (!HasBit(itspec->animation_triggers, iat)) return false; |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
390 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
391 |
Industry *ind = GetIndustryByTile(tile); |
10294 | 392 |
ChangeIndustryTileAnimationFrame(itspec, tile, iat, random, gfx, ind); |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
393 |
return true; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
394 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
395 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
396 |
bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
397 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
398 |
bool ret = true; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
399 |
uint32 random = Random(); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
400 |
BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
401 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { |
9704 | 402 |
if (StartStopIndustryTileAnimation(tile, iat, random)) { |
403 |
SB(random, 0, 16, Random()); |
|
404 |
} else { |
|
405 |
ret = false; |
|
406 |
} |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
407 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
408 |
END_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
409 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
410 |
return ret; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9629
diff
changeset
|
411 |
} |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
412 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
413 |
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
414 |
{ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
415 |
ResolverObject object; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
416 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
417 |
IndustryGfx gfx = GetIndustryGfx(tile); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
418 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
419 |
|
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
420 |
if (itspec->grf_prop.spritegroup == NULL) return; |
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10294
diff
changeset
|
421 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
422 |
NewIndustryTileResolver(&object, gfx, tile, ind); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
423 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
424 |
object.callback = CBID_RANDOM_TRIGGER; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
425 |
object.trigger = trigger; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
426 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
427 |
const SpriteGroup *group = Resolve(itspec->grf_prop.spritegroup, &object); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
428 |
if (group == NULL) return; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
429 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
430 |
byte new_random_bits = Random(); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
431 |
byte random_bits = GetIndustryRandomBits(tile); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
432 |
random_bits &= ~object.reseed; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
433 |
random_bits |= new_random_bits & object.reseed; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
434 |
SetIndustryRandomBits(tile, random_bits); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
435 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
436 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
437 |
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
438 |
{ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
439 |
DoTriggerIndustryTile(tile, trigger, GetIndustryByTile(tile)); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
440 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
441 |
|
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
442 |
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
443 |
{ |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
444 |
BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
445 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
446 |
DoTriggerIndustryTile(tile, trigger, ind); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
447 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
448 |
END_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
449 |
} |