OpenTTD

newgrf_industrytiles.cpp
Go to the documentation of this file.
1 /* $Id: newgrf_industrytiles.cpp 27984 2018-03-11 13:19:41Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #include "stdafx.h"
13 #include "debug.h"
14 #include "landscape.h"
15 #include "newgrf_industrytiles.h"
16 #include "newgrf_sound.h"
17 #include "industry.h"
18 #include "town.h"
19 #include "command_func.h"
20 #include "water.h"
21 #include "newgrf_animation_base.h"
22
23 #include "table/strings.h"
24
25 #include "safeguards.h"
26
36 uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
37 {
38 if (parameter != 0) tile = GetNearbyTile(parameter, tile, signed_offsets); // only perform if it is required
39 bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
40
41 return GetNearbyTileInformation(tile, grf_version8) | (is_same_industry ? 1 : 0) << 8;
42 }
43
55 uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
56 {
57 byte x = TileX(tile) - TileX(ind_tile);
58 byte y = TileY(tile) - TileY(ind_tile);
59
60 return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x;
61 }
62
63 /* virtual */ uint32 IndustryTileScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
64 {
65 switch (variable) {
66 /* Construction state of the tile: a value between 0 and 3 */
67 case 0x40: return (IsTileType(this->tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(this->tile) : 0;
68
69 /* Terrain type */
70 case 0x41: return GetTerrainType(this->tile);
71
72 /* Current town zone of the tile in the nearest town */
73 case 0x42: return GetTownRadiusGroup(ClosestTownFromTile(this->tile, UINT_MAX), this->tile);
74
75 /* Relative position */
76 case 0x43: return GetRelativePosition(this->tile, this->industry->location.tile);
77
78 /* Animation frame. Like house variable 46 but can contain anything 0..FF. */
79 case 0x44: return IsTileType(this->tile, MP_INDUSTRY) ? GetAnimationFrame(this->tile) : 0;
80
81 /* Land info of nearby tiles */
82 case 0x60: return GetNearbyIndustryTileInformation(parameter, this->tile,
83 this->industry == NULL ? (IndustryID)INVALID_INDUSTRY : this->industry->index, true, this->ro.grffile->grf_version >= 8);
84
85 /* Animation stage of nearby tiles */
86 case 0x61: {
87 TileIndex tile = GetNearbyTile(parameter, this->tile);
88 if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == this->industry) {
89 return GetAnimationFrame(tile);
90 }
91 return UINT_MAX;
92 }
93
94 /* Get industry tile ID at offset */
95 case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid);
96 }
97
98 DEBUG(grf, 1, "Unhandled industry tile variable 0x%X", variable);
99
100 *available = false;
101 return UINT_MAX;
102 }
103
104 /* virtual */ uint32 IndustryTileScopeResolver::GetRandomBits() const
105 {
106 assert(this->industry != NULL && IsValidTile(this->tile));
107 assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY));
108
109 return (this->industry->index != INVALID_INDUSTRY) ? GetIndustryRandomBits(this->tile) : 0;
110 }
111
112 /* virtual */ uint32 IndustryTileScopeResolver::GetTriggers() const
113 {
114 assert(this->industry != NULL && IsValidTile(this->tile));
115 assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY));
116 if (this->industry->index == INVALID_INDUSTRY) return 0;
117 return GetIndustryTriggers(this->tile);
118 }
119
125 static const GRFFile *GetIndTileGrffile(IndustryGfx gfx)
126 {
127 const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
128 return (its != NULL) ? its->grf_prop.grffile : NULL;
129 }
130
140 IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus,
141 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
142 : ResolverObject(GetIndTileGrffile(gfx), callback, callback_param1, callback_param2),
143 indtile_scope(*this, indus, tile),
144 ind_scope(*this, tile, indus, indus->type)
145 {
146 this->root_spritegroup = GetIndustryTileSpec(gfx)->grf_prop.spritegroup[0];
147 }
148
149 static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage, IndustryGfx gfx)
150 {
151 const DrawTileSprites *dts = group->ProcessRegisters(&stage);
152
153 SpriteID image = dts->ground.sprite;
154 PaletteID pal = dts->ground.pal;
155
156 if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
157 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
158
159 if (GB(image, 0, SPRITE_WIDTH) != 0) {
160 /* If the ground sprite is the default flat water sprite, draw also canal/river borders
161 * Do not do this if the tile's WaterClass is 'land'. */
162 if (image == SPR_FLAT_WATER_TILE && IsTileOnWater(ti->tile)) {
163 DrawWaterClassGround(ti);
164 } else {
165 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, GENERAL_SPRITE_COLOUR(rnd_colour)));
166 }
167 }
168
169 DrawNewGRFTileSeq(ti, dts, TO_INDUSTRIES, stage, GENERAL_SPRITE_COLOUR(rnd_colour));
170 }
171
172 uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
173 {
174 assert(industry != NULL && IsValidTile(tile));
175 assert(industry->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY));
176
177 IndustryTileResolverObject object(gfx_id, tile, industry, callback, param1, param2);
178 return object.ResolveCallback();
179 }
180
181 bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
182 {
183 if (ti->tileh != SLOPE_FLAT) {
184 bool draw_old_one = true;
185 if (HasBit(inds->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) {
186 /* Called to determine the type (if any) of foundation to draw for industry tile */
187 uint32 callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile);
188 if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(inds->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res);
189 }
190
191 if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
192 }
193
194 IndustryTileResolverObject object(gfx, ti->tile, i);
195
196 const SpriteGroup *group = object.Resolve();
197 if (group == NULL || group->type != SGT_TILELAYOUT) return false;
198
199 /* Limit the building stage to the number of stages supplied. */
200 const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
201 byte stage = GetIndustryConstructionStage(ti->tile);
202 IndustryDrawTileLayout(ti, tlgroup, i->random_colour, stage, gfx);
203 return true;
204 }
205
206 extern bool IsSlopeRefused(Slope current, Slope refused);
207
221 CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
222 {
223 Industry ind;
224 ind.index = INVALID_INDUSTRY;
225 ind.location.tile = ind_base_tile;
226 ind.location.w = 0;
227 ind.type = type;
228 ind.random = initial_random_bits;
229 ind.founder = founder;
230
231 uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, creation_type << 8 | itspec_index, gfx, &ind, ind_tile);
232 if (callback_res == CALLBACK_FAILED) {
233 if (!IsSlopeRefused(GetTileSlope(ind_tile), its->slopes_refused)) return CommandCost();
234 return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
235 }
236 if (its->grf_prop.grffile->grf_version < 7) {
237 if (callback_res != 0) return CommandCost();
238 return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
239 }
240
241 return GetErrorMessageFromLocationCallbackResult(callback_res, its->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE);
242 }
243
244 /* Simple wrapper for GetHouseCallback to keep the animation unified. */
245 uint16 GetSimpleIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, const IndustryTileSpec *spec, Industry *ind, TileIndex tile, int extra_data)
246 {
247 return GetIndustryTileCallback(callback, param1, param2, spec - GetIndustryTileSpec(0), ind, tile);
248 }
249
251 struct IndustryAnimationBase : public AnimationBase<IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback> {
252 static const CallbackID cb_animation_speed = CBID_INDTILE_ANIMATION_SPEED;
253 static const CallbackID cb_animation_next_frame = CBID_INDTILE_ANIM_NEXT_FRAME;
254
255 static const IndustryTileCallbackMask cbm_animation_speed = CBM_INDT_ANIM_SPEED;
256 static const IndustryTileCallbackMask cbm_animation_next_frame = CBM_INDT_ANIM_NEXT_FRAME;
257 };
258
259 void AnimateNewIndustryTile(TileIndex tile)
260 {
261 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
262 if (itspec == NULL) return;
263
264 IndustryAnimationBase::AnimateTile(itspec, Industry::GetByTile(tile), tile, (itspec->special_flags & INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS) != 0);
265 }
266
267 bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random)
268 {
269 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
270
271 if (!HasBit(itspec->animation.triggers, iat)) return false;
272
273 IndustryAnimationBase::ChangeAnimationFrame(CBID_INDTILE_ANIM_START_STOP, itspec, Industry::GetByTile(tile), tile, random, iat);
274 return true;
275 }
276
277 bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
278 {
279 bool ret = true;
280 uint32 random = Random();
281 TILE_AREA_LOOP(tile, ind->location) {
282 if (ind->TileBelongsToIndustry(tile)) {
283 if (StartStopIndustryTileAnimation(tile, iat, random)) {
284 SB(random, 0, 16, Random());
285 } else {
286 ret = false;
287 }
288 }
289 }
290
291 return ret;
292 }
293
301 static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind, uint32 &reseed_industry)
302 {
303 assert(IsValidTile(tile) && IsTileType(tile, MP_INDUSTRY));
304
305 IndustryGfx gfx = GetIndustryGfx(tile);
306 const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
307
308 if (itspec->grf_prop.spritegroup[0] == NULL) return;
309
310 IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
311 object.waiting_triggers = GetIndustryTriggers(tile) | trigger;
312 SetIndustryTriggers(tile, object.waiting_triggers); // store now for var 5F
313
314 const SpriteGroup *group = object.Resolve();
315 if (group == NULL) return;
316
317 /* Store remaining triggers. */
318 SetIndustryTriggers(tile, object.GetRemainingTriggers());
319
320 /* Rerandomise tile bits */
321 byte new_random_bits = Random();
322 byte random_bits = GetIndustryRandomBits(tile);
323 random_bits &= ~object.reseed[VSG_SCOPE_SELF];
324 random_bits |= new_random_bits & object.reseed[VSG_SCOPE_SELF];
325 SetIndustryRandomBits(tile, random_bits);
326 MarkTileDirtyByTile(tile);
327
328 reseed_industry |= object.reseed[VSG_SCOPE_PARENT];
329 }
330
336 static void DoReseedIndustry(Industry *ind, uint32 reseed)
337 {
338 if (reseed == 0 || ind == NULL) return;
339
340 uint16 random_bits = Random();
341 ind->random &= reseed;
342 ind->random |= random_bits & reseed;
343 }
344
350 void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
351 {
352 uint32 reseed_industry = 0;
353 Industry *ind = Industry::GetByTile(tile);
354 DoTriggerIndustryTile(tile, trigger, ind, reseed_industry);
355 DoReseedIndustry(ind, reseed_industry);
356 }
357
363 void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
364 {
365 uint32 reseed_industry = 0;
366 TILE_AREA_LOOP(tile, ind->location) {
367 if (ind->TileBelongsToIndustry(tile)) {
368 DoTriggerIndustryTile(tile, trigger, ind, reseed_industry);
369 }
370 }
371 DoReseedIndustry(ind, reseed_industry);
372 }
373
IndustryTileResolverObject::IndustryTileResolverObject
IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus, CallbackID callback=CBID_NO_CALLBACK, uint32 callback_param1=0, uint32 callback_param2=0)
Constructor of the industry tiles scope resolver.
Definition: newgrf_industrytiles.cpp:140
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:406
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
IndustryAnimationTrigger
IndustryAnimationTrigger
Animation triggers of the industries.
Definition: newgrf_animation_type.h:39
GetRelativePosition
uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
This is the position of the tile relative to the northernmost tile of the industry.
Definition: newgrf_industrytiles.cpp:55
AnimationInfo::triggers
uint16 triggers
The triggers that trigger animation.
Definition: newgrf_animation_type.h:24
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:292
MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:51
Industry::founder
OwnerByte founder
Founder of the industry.
Definition: industry.h:63
GetAnimationFrame
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Definition: tile_map.h:243
debug.h
Functions related to debugging.
CBID_INDTILE_SHAPE_CHECK
Called to determine if the given industry tile can be built on specific tile.
Definition: newgrf_callbacks.h:134
DrawNewGRFTileSeq
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition: sprite.h:126
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:310
GetTerrainType
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
Definition: newgrf_commons.cpp:350
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:47
GetIndustryGfx
static IndustryGfx GetIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile.
Definition: industry_map.h:139
DoTriggerIndustryTile
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind, uint32 &reseed_industry)
Trigger random triggers for an industry tile and reseed its random bits.
Definition: newgrf_industrytiles.cpp:301
CBID_INDTILE_ANIM_START_STOP
Called for periodically starting or stopping the animation.
Definition: newgrf_callbacks.h:101
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
PerformIndustryTileSlopeCheck
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check the slope of a tile of a new industry.
Definition: newgrf_industrytiles.cpp:221
Industry
Defines the internal data of a functional industry.
Definition: industry.h:39
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Industry::random
uint16 random
Random value used for randomisation of all kinds of things.
Definition: industry.h:69
CommandCost
Common return value for all commands.
Definition: command_type.h:25
CBID_INDTILE_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition: newgrf_callbacks.h:107
ResolverObject::reseed
uint32 reseed[VSG_END]
Collects bits to rerandomise while triggering triggers.
Definition: newgrf_spritegroup.h:336
AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::ChangeAnimationFrame
static void ChangeAnimationFrame(CallbackID cb, const IndustryTileSpec *spec, Industry *obj, TileIndex tile, uint32 random_bits, uint32 trigger, int extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
Definition: newgrf_animation_base.h:120
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:20
SLOPE_FLAT
a flat tile
Definition: slope_type.h:51
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition: newgrf_commons.cpp:482
Industry::random_colour
byte random_colour
randomized colour of the industry, for display purpose
Definition: industry.h:57
AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::AnimateTile
static void AnimateTile(const IndustryTileSpec *spec, Industry *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
Definition: newgrf_animation_base.h:41
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:390
SetIndustryRandomBits
static void SetIndustryRandomBits(TileIndex tile, byte bits)
Set the random bits for this tile.
Definition: industry_map.h:239
SB
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:60
IndustryTileSpec::special_flags
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
Definition: industrytype.h:162
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition: newgrf_spritegroup.h:339
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:115
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:154
IndustryTileSpec::slopes_refused
Slope slopes_refused
slope pattern on which this tile cannot be built
Definition: industrytype.h:151
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
Definition: town_cmd.cpp:3239
IndustryTileResolverObject
Resolver for industry tiles.
Definition: newgrf_industrytiles.h:41
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
Definition: newgrf_spritegroup.h:62
GetNearbyTile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition: newgrf_commons.cpp:425
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
TileLayoutSpriteGroup::ProcessRegisters
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
Definition: newgrf_spritegroup.cpp:314
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:48
FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
Definition: slope_type.h:97
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:60
IndustryTileTrigger
IndustryTileTrigger
Available industry tile triggers.
Definition: newgrf_industrytiles.h:68
GetIndustryConstructionStage
static byte GetIndustryConstructionStage(TileIndex tile)
Returns the industry construction stage of the specified tile.
Definition: industry_map.h:102
CBM_INDT_DRAW_FOUNDATIONS
decides if default foundations need to be drawn
Definition: newgrf_callbacks.h:376
ConvertBooleanCallback
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Definition: newgrf_commons.cpp:552
CBID_INDTILE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for industry tile.
Definition: newgrf_callbacks.h:137
IndustryTileCallbackMask
IndustryTileCallbackMask
Callback masks for industry tiles.
Definition: newgrf_callbacks.h:370
GetNearbyIndustryTileInformation
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
Based on newhouses equivalent, but adapted for newindustries.
Definition: newgrf_industrytiles.cpp:36
TILE_AREA_LOOP
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition: tilearea_type.h:232
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
newgrf_animation_base.h
Function implementations related to NewGRF animation.
TriggerIndustryTile
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
Trigger a random trigger for a single industry tile.
Definition: newgrf_industrytiles.cpp:350
safeguards.h
A number of safeguards to prevent using unsafe methods.
SpriteGroup
Definition: newgrf_spritegroup.h:58
Industry::type
IndustryType type
type of industry.
Definition: industry.h:55
ResolverObject::waiting_triggers
uint32 waiting_triggers
Waiting triggers to be used by any rerandomisation. (scope independent)
Definition: newgrf_spritegroup.h:334
GroundSpritePaletteTransform
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition: sprite.h:170
IndustryTileScopeResolver::GetRandomBits
uint32 GetRandomBits() const
Get a few random bits.
Definition: newgrf_industrytiles.cpp:104
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:40
DoReseedIndustry
static void DoReseedIndustry(Industry *ind, uint32 reseed)
Reseeds the random bits of an industry.
Definition: newgrf_industrytiles.cpp:336
SPRITE_MODIFIER_CUSTOM_SPRITE
Set when a sprite originates from an Action 1.
Definition: sprites.h:1506
GetIndustryIDAtOffset
uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32 cur_grfid)
Make an analysis of a tile and check for its belonging to the same industry, and/or the same grf file...
Definition: newgrf_industries.cpp:57
IndustryTileScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Definition: newgrf_industrytiles.cpp:63
IndustryTileSpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:164
GetIndustryTileSpec
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
Definition: industry_cmd.cpp:130
CBM_INDT_ANIM_SPEED
decides animation speed
Definition: newgrf_callbacks.h:372
IndustryAvailabilityCallType
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
Definition: newgrf_industries.h:81
IndustryTileScopeResolver::industry
Industry * industry
Industry owning the tiles.
Definition: newgrf_industrytiles.h:21
SPRITE_WIDTH
number of bits for the sprite number
Definition: sprites.h:1494
GetTownRadiusGroup
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition: town_cmd.cpp:1998
VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:103
newgrf_industrytiles.h
NewGRF handling of industry tiles.
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:321
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:35
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:39
IndustryTileSpec::callback_mask
uint8 callback_mask
Bitmask of industry tile callbacks that have to be called.
Definition: industrytype.h:160
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1904
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition: newgrf_spritegroup.h:338
TriggerIndustry
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
Trigger a random trigger for all industry tiles.
Definition: newgrf_industrytiles.cpp:363
IndustryAnimationBase
Helper class for animation control.
Definition: newgrf_industrytiles.cpp:251
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:61
IndustryTileScopeResolver::tile
TileIndex tile
Tile being resolved.
Definition: newgrf_industrytiles.h:22
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
GetNearbyTileInformation
uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
Definition: newgrf_commons.cpp:448
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition: newgrf_animation_base.h:31
IndustryTileSpec::animation
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
Definition: industrytype.h:161
CBID_INDTILE_ANIM_NEXT_FRAME
Called to determine industry tile next animation frame.
Definition: newgrf_callbacks.h:104
ResolverObject::GetRemainingTriggers
uint32 GetRemainingTriggers() const
Returns the waiting triggers that did not trigger any rerandomisation.
Definition: newgrf_spritegroup.h:367
GetIndustryIndex
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:65
VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:104
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
CBM_INDT_ANIM_NEXT_FRAME
decides next animation frame
Definition: newgrf_callbacks.h:371
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:328
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:34
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
GetIndustryRandomBits
static byte GetIndustryRandomBits(TileIndex tile)
Get the random bits for this tile.
Definition: industry_map.h:226
landscape.h
Functions related to OTTD&#39;s landscape.
command_func.h
Functions related to commands.
INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS
Callback 0x26 needs random bits.
Definition: industrytype.h:89
SetIndustryTriggers
static void SetIndustryTriggers(TileIndex tile, byte triggers)
Set the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:266
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:604
GetIndTileGrffile
static const GRFFile * GetIndTileGrffile(IndustryGfx gfx)
Get the associated NewGRF file from the industry graphics.
Definition: newgrf_industrytiles.cpp:125
industry.h
Base of all industries.
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:320
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:22
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
newgrf_sound.h
Functions related to NewGRF provided sounds.
CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
Definition: newgrf_callbacks.h:27
town.h
Base of the town class.
Industry::TileBelongsToIndustry
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition: industry.h:83
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition: industrytype.h:148
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:94
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
GetIndustryTriggers
static byte GetIndustryTriggers(TileIndex tile)
Get the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:252
water.h
Functions related to water (management)
IsTileOnWater
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:130
PalSpriteID::sprite
SpriteID sprite
The &#39;real&#39; sprite.
Definition: gfx_type.h:25
TO_INDUSTRIES
industries
Definition: transparency.h:28
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition: newgrf_spritegroup.h:267
IndustryTileScopeResolver::GetTriggers
uint32 GetTriggers() const
Get the triggers.
Definition: newgrf_industrytiles.cpp:112
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:104
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:26