OpenTTD Source: src/newgrf_industrytiles.cpp Source File

OpenTTD Source 14.0-beta3

newgrf_industrytiles.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "stdafx.h"
11 #include "debug.h"
12 #include "landscape.h"
13 #include "newgrf_industrytiles.h"
14 #include "newgrf_sound.h"
15 #include "industry.h"
16 #include "town.h"
17 #include "command_func.h"
18 #include "water.h"
19 #include "newgrf_animation_base.h"
20
21 #include "table/strings.h"
22
23 #include "safeguards.h"
24
34 uint32_t GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
35 {
36 if (parameter != 0) tile = GetNearbyTile(parameter, tile, signed_offsets); // only perform if it is required
37 bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
38
39 return GetNearbyTileInformation(tile, grf_version8) | (is_same_industry ? 1 : 0) << 8;
40 }
41
53 uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
54 {
55 byte x = TileX(tile) - TileX(ind_tile);
56 byte y = TileY(tile) - TileY(ind_tile);
57
58 return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x;
59 }
60
61 /* virtual */ uint32_t IndustryTileScopeResolver::GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const
62 {
63 switch (variable) {
64 /* Construction state of the tile: a value between 0 and 3 */
65 case 0x40: return (IsTileType(this->tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(this->tile) : 0;
66
67 /* Terrain type */
68 case 0x41: return GetTerrainType(this->tile);
69
70 /* Current town zone of the tile in the nearest town */
71 case 0x42: return GetTownRadiusGroup(ClosestTownFromTile(this->tile, UINT_MAX), this->tile);
72
73 /* Relative position */
74 case 0x43: return GetRelativePosition(this->tile, this->industry->location.tile);
75
76 /* Animation frame. Like house variable 46 but can contain anything 0..FF. */
77 case 0x44: return IsTileType(this->tile, MP_INDUSTRY) ? GetAnimationFrame(this->tile) : 0;
78
79 /* Land info of nearby tiles */
80 case 0x60: return GetNearbyIndustryTileInformation(parameter, this->tile,
81 this->industry == nullptr ? (IndustryID)INVALID_INDUSTRY : this->industry->index, true, this->ro.grffile->grf_version >= 8);
82
83 /* Animation stage of nearby tiles */
84 case 0x61: {
85 TileIndex tile = GetNearbyTile(parameter, this->tile);
86 if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == this->industry) {
87 return GetAnimationFrame(tile);
88 }
89 return UINT_MAX;
90 }
91
92 /* Get industry tile ID at offset */
93 case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid);
94 }
95
96 Debug(grf, 1, "Unhandled industry tile variable 0x{:X}", variable);
97
98 *available = false;
99 return UINT_MAX;
100 }
101
102 /* virtual */ uint32_t IndustryTileScopeResolver::GetRandomBits() const
103 {
104 assert(this->industry != nullptr && IsValidTile(this->tile));
105 assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY));
106
107 return (this->industry->index != INVALID_INDUSTRY) ? GetIndustryRandomBits(this->tile) : 0;
108 }
109
110 /* virtual */ uint32_t IndustryTileScopeResolver::GetTriggers() const
111 {
112 assert(this->industry != nullptr && IsValidTile(this->tile));
113 assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY));
114 if (this->industry->index == INVALID_INDUSTRY) return 0;
115 return GetIndustryTriggers(this->tile);
116 }
117
123 static const GRFFile *GetIndTileGrffile(IndustryGfx gfx)
124 {
125 const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
126 return (its != nullptr) ? its->grf_prop.grffile : nullptr;
127 }
128
138 IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus,
139 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
140 : ResolverObject(GetIndTileGrffile(gfx), callback, callback_param1, callback_param2),
141 indtile_scope(*this, indus, tile),
142 ind_scope(*this, tile, indus, indus->type),
143 gfx(gfx)
144 {
145 this->root_spritegroup = GetIndustryTileSpec(gfx)->grf_prop.spritegroup[0];
146 }
147
148 GrfSpecFeature IndustryTileResolverObject::GetFeature() const
149 {
150 return GSF_INDUSTRYTILES;
151 }
152
153 uint32_t IndustryTileResolverObject::GetDebugID() const
154 {
155 return GetIndustryTileSpec(gfx)->grf_prop.local_id;
156 }
157
158 static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage)
159 {
160 const DrawTileSprites *dts = group->ProcessRegisters(&stage);
161
162 SpriteID image = dts->ground.sprite;
163 PaletteID pal = dts->ground.pal;
164
165 if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
166 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
167
168 if (GB(image, 0, SPRITE_WIDTH) != 0) {
169 /* If the ground sprite is the default flat water sprite, draw also canal/river borders
170 * Do not do this if the tile's WaterClass is 'land'. */
171 if (image == SPR_FLAT_WATER_TILE && IsTileOnWater(ti->tile)) {
172 DrawWaterClassGround(ti);
173 } else {
174 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, GENERAL_SPRITE_COLOUR(rnd_colour)));
175 }
176 }
177
178 DrawNewGRFTileSeq(ti, dts, TO_INDUSTRIES, stage, GENERAL_SPRITE_COLOUR(rnd_colour));
179 }
180
181 uint16_t GetIndustryTileCallback(CallbackID callback, uint32_t param1, uint32_t param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
182 {
183 assert(industry != nullptr && IsValidTile(tile));
184 assert(industry->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY));
185
186 IndustryTileResolverObject object(gfx_id, tile, industry, callback, param1, param2);
187 return object.ResolveCallback();
188 }
189
190 bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
191 {
192 if (ti->tileh != SLOPE_FLAT) {
193 bool draw_old_one = true;
194 if (HasBit(inds->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) {
195 /* Called to determine the type (if any) of foundation to draw for industry tile */
196 uint32_t callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile);
197 if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(inds->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res);
198 }
199
200 if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
201 }
202
203 IndustryTileResolverObject object(gfx, ti->tile, i);
204
205 const SpriteGroup *group = object.Resolve();
206 if (group == nullptr || group->type != SGT_TILELAYOUT) return false;
207
208 /* Limit the building stage to the number of stages supplied. */
209 const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
210 byte stage = GetIndustryConstructionStage(ti->tile);
211 IndustryDrawTileLayout(ti, tlgroup, i->random_colour, stage);
212 return true;
213 }
214
215 extern bool IsSlopeRefused(Slope current, Slope refused);
216
230 CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, size_t layout_index, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
231 {
232 Industry ind;
233 ind.index = INVALID_INDUSTRY;
234 ind.location.tile = ind_base_tile;
235 ind.location.w = 0;
236 ind.type = type;
237 ind.random = initial_random_bits;
238 ind.founder = founder;
239
240 uint16_t callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, creation_type << 8 | (uint32_t)layout_index, gfx, &ind, ind_tile);
241 if (callback_res == CALLBACK_FAILED) {
242 if (!IsSlopeRefused(GetTileSlope(ind_tile), its->slopes_refused)) return CommandCost();
243 return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
244 }
245 if (its->grf_prop.grffile->grf_version < 7) {
246 if (callback_res != 0) return CommandCost();
247 return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
248 }
249
250 return GetErrorMessageFromLocationCallbackResult(callback_res, its->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE);
251 }
252
253 /* Simple wrapper for GetHouseCallback to keep the animation unified. */
254 uint16_t GetSimpleIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, const IndustryTileSpec *spec, Industry *ind, TileIndex tile, int)
255 {
256 return GetIndustryTileCallback(callback, param1, param2, spec - GetIndustryTileSpec(0), ind, tile);
257 }
258
260 struct IndustryAnimationBase : public AnimationBase<IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback, TileAnimationFrameAnimationHelper<Industry> > {
261 static const CallbackID cb_animation_speed = CBID_INDTILE_ANIMATION_SPEED;
262 static const CallbackID cb_animation_next_frame = CBID_INDTILE_ANIM_NEXT_FRAME;
263
264 static const IndustryTileCallbackMask cbm_animation_speed = CBM_INDT_ANIM_SPEED;
265 static const IndustryTileCallbackMask cbm_animation_next_frame = CBM_INDT_ANIM_NEXT_FRAME;
266 };
267
268 void AnimateNewIndustryTile(TileIndex tile)
269 {
270 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
271 if (itspec == nullptr) return;
272
273 IndustryAnimationBase::AnimateTile(itspec, Industry::GetByTile(tile), tile, (itspec->special_flags & INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS) != 0);
274 }
275
276 bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32_t random)
277 {
278 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
279
280 if (!HasBit(itspec->animation.triggers, iat)) return false;
281
282 IndustryAnimationBase::ChangeAnimationFrame(CBID_INDTILE_ANIM_START_STOP, itspec, Industry::GetByTile(tile), tile, random, iat);
283 return true;
284 }
285
286 bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
287 {
288 bool ret = true;
289 uint32_t random = Random();
290 for (TileIndex tile : ind->location) {
291 if (ind->TileBelongsToIndustry(tile)) {
292 if (StartStopIndustryTileAnimation(tile, iat, random)) {
293 SB(random, 0, 16, Random());
294 } else {
295 ret = false;
296 }
297 }
298 }
299
300 return ret;
301 }
302
310 static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind, uint32_t &reseed_industry)
311 {
312 assert(IsValidTile(tile) && IsTileType(tile, MP_INDUSTRY));
313
314 IndustryGfx gfx = GetIndustryGfx(tile);
315 const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
316
317 if (itspec->grf_prop.spritegroup[0] == nullptr) return;
318
319 IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
320 object.waiting_triggers = GetIndustryTriggers(tile) | trigger;
321 SetIndustryTriggers(tile, object.waiting_triggers); // store now for var 5F
322
323 const SpriteGroup *group = object.Resolve();
324 if (group == nullptr) return;
325
326 /* Store remaining triggers. */
327 SetIndustryTriggers(tile, object.GetRemainingTriggers());
328
329 /* Rerandomise tile bits */
330 byte new_random_bits = Random();
331 byte random_bits = GetIndustryRandomBits(tile);
332 random_bits &= ~object.reseed[VSG_SCOPE_SELF];
333 random_bits |= new_random_bits & object.reseed[VSG_SCOPE_SELF];
334 SetIndustryRandomBits(tile, random_bits);
335 MarkTileDirtyByTile(tile);
336
337 reseed_industry |= object.reseed[VSG_SCOPE_PARENT];
338 }
339
345 static void DoReseedIndustry(Industry *ind, uint32_t reseed)
346 {
347 if (reseed == 0 || ind == nullptr) return;
348
349 uint16_t random_bits = Random();
350 ind->random &= reseed;
351 ind->random |= random_bits & reseed;
352 }
353
359 void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
360 {
361 uint32_t reseed_industry = 0;
362 Industry *ind = Industry::GetByTile(tile);
363 DoTriggerIndustryTile(tile, trigger, ind, reseed_industry);
364 DoReseedIndustry(ind, reseed_industry);
365 }
366
372 void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
373 {
374 uint32_t reseed_industry = 0;
375 for (TileIndex tile : ind->location) {
376 if (ind->TileBelongsToIndustry(tile)) {
377 DoTriggerIndustryTile(tile, trigger, ind, reseed_industry);
378 }
379 }
380 DoReseedIndustry(ind, reseed_industry);
381 }
382
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
IndustryTileScopeResolver::industry
Industry * industry
Industry owning the tiles.
Definition: newgrf_industrytiles.h:19
DoTriggerIndustryTile
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind, uint32_t &reseed_industry)
Trigger random triggers for an industry tile and reseed its random bits.
Definition: newgrf_industrytiles.cpp:310
ResolverObject::reseed
uint32_t reseed[VSG_END]
Collects bits to rerandomise while triggering triggers.
Definition: newgrf_spritegroup.h:333
GroundSpritePaletteTransform
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition: sprite.h:168
SetIndustryTriggers
void SetIndustryTriggers(Tile tile, byte triggers)
Set the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:264
water.h
GetIndustryIDAtOffset
uint32_t GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32_t 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:56
command_func.h
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:3744
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
SPRITE_WIDTH
@ SPRITE_WIDTH
number of bits for the sprite number
Definition: sprites.h:1527
GetIndustryConstructionStage
byte GetIndustryConstructionStage(Tile tile)
Returns the industry construction stage of the specified tile.
Definition: industry_map.h:100
AnimationInfo::triggers
uint16_t triggers
The triggers that trigger animation.
Definition: newgrf_animation_type.h:22
PerformIndustryTileSlopeCheck
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, size_t layout_index, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check the slope of a tile of a new industry.
Definition: newgrf_industrytiles.cpp:230
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
GetIndustryGfx
IndustryGfx GetIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile.
Definition: industry_map.h:137
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition: newgrf_spritegroup.h:335
newgrf_animation_base.h
IndustryTileResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_industrytiles.cpp:153
IndustryTileSpec::callback_mask
uint8_t callback_mask
Bitmask of industry tile callbacks that have to be called.
Definition: industrytype.h:169
GetIndTileGrffile
static const GRFFile * GetIndTileGrffile(IndustryGfx gfx)
Get the associated NewGRF file from the industry graphics.
Definition: newgrf_industrytiles.cpp:123
IndustryAnimationTrigger
IndustryAnimationTrigger
Animation triggers of the industries.
Definition: newgrf_animation_type.h:37
INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS
@ INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS
Callback 0x26 needs random bits.
Definition: industrytype.h:88
CBID_INDTILE_ANIM_START_STOP
@ CBID_INDTILE_ANIM_START_STOP
Called for periodically starting or stopping the animation.
Definition: newgrf_callbacks.h:99
CBID_INDTILE_DRAW_FOUNDATIONS
@ CBID_INDTILE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for industry tile.
Definition: newgrf_callbacks.h:135
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
town.h
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetTerrainType
uint32_t 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:331
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:101
Industry
Defines the internal data of a functional industry.
Definition: industry.h:68
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
IndustryTileResolverObject::IndustryTileResolverObject
IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Constructor of the industry tiles scope resolver.
Definition: newgrf_industrytiles.cpp:138
TriggerIndustry
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
Trigger a random trigger for all industry tiles.
Definition: newgrf_industrytiles.cpp:372
IndustryTileScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition: newgrf_industrytiles.cpp:102
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:100
GetTownRadiusGroup
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition: town_cmd.cpp:2386
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:46
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
IndustryTileSpec::special_flags
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
Definition: industrytype.h:171
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
CommandCost
Common return value for all commands.
Definition: command_type.h:23
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:96
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:207
Industry::type
IndustryType type
type of industry.
Definition: industry.h:104
IndustryTileResolverObject
Resolver for industry tiles.
Definition: newgrf_industrytiles.h:39
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition: newgrf_spritegroup.h:336
CBM_INDT_DRAW_FOUNDATIONS
@ CBM_INDT_DRAW_FOUNDATIONS
decides if default foundations need to be drawn
Definition: newgrf_callbacks.h:390
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition: water_map.h:139
GetNearbyTileInformation
uint32_t 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:429
GetIndustryIndex
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
industry.h
safeguards.h
IndustryTileResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_industrytiles.cpp:148
IndustryTileSpec::slopes_refused
Slope slopes_refused
slope pattern on which this tile cannot be built
Definition: industrytype.h:160
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
SPRITE_MODIFIER_CUSTOM_SPRITE
@ SPRITE_MODIFIER_CUSTOM_SPRITE
Set when a sprite originates from an Action 1.
Definition: sprites.h:1539
IndustryTileScopeResolver::GetTriggers
uint32_t GetTriggers() const override
Get the triggers.
Definition: newgrf_industrytiles.cpp:110
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback, TileAnimationFrameAnimationHelper< Industry > >::ChangeAnimationFrame
static void ChangeAnimationFrame(CallbackID cb, const IndustryTileSpec *spec, Industry *obj, TileIndex tile, uint32_t random_bits, uint32_t 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:124
IndustryAvailabilityCallType
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
Definition: newgrf_industries.h:82
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition: newgrf_commons.cpp:463
stdafx.h
landscape.h
DoReseedIndustry
static void DoReseedIndustry(Industry *ind, uint32_t reseed)
Reseeds the random bits of an industry.
Definition: newgrf_industrytiles.cpp:345
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
IndustryTileSpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:173
CBM_INDT_ANIM_NEXT_FRAME
@ CBM_INDT_ANIM_NEXT_FRAME
decides next animation frame
Definition: newgrf_callbacks.h:385
TO_INDUSTRIES
@ TO_INDUSTRIES
industries
Definition: transparency.h:26
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:318
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Industry::random_colour
Colours random_colour
randomized colour of the industry, for display purpose
Definition: industry.h:106
ConvertBooleanCallback
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition: newgrf_commons.cpp:529
IndustryAnimationBase
Helper class for animation control.
Definition: newgrf_industrytiles.cpp:260
CBM_INDT_ANIM_SPEED
@ CBM_INDT_ANIM_SPEED
decides animation speed
Definition: newgrf_callbacks.h:386
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:427
DrawNewGRFTileSeq
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition: sprite.h:124
CBID_INDTILE_ANIM_NEXT_FRAME
@ CBID_INDTILE_ANIM_NEXT_FRAME
Called to determine industry tile next animation frame.
Definition: newgrf_callbacks.h:102
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
newgrf_sound.h
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:320
GetNearbyIndustryTileInformation
uint32_t 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:34
newgrf_industrytiles.h
IndustryTileSpec::animation
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
Definition: industrytype.h:170
Industry::founder
Owner founder
Founder of the industry.
Definition: industry.h:115
GetIndustryTileSpec
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
Definition: industry_cmd.cpp:137
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
IndustryTileCallbackMask
IndustryTileCallbackMask
Callback masks for industry tiles.
Definition: newgrf_callbacks.h:384
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:2051
FOUNDATION_LEVELED
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
Definition: slope_type.h:95
GetRelativePosition
uint32_t 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:53
IndustryTileScopeResolver::GetVariable
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override
Get a variable value.
Definition: newgrf_industrytiles.cpp:61
TriggerIndustryTile
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
Trigger a random trigger for a single industry tile.
Definition: newgrf_industrytiles.cpp:359
AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback, TileAnimationFrameAnimationHelper< Industry > >::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:45
SetIndustryRandomBits
void SetIndustryRandomBits(Tile tile, byte bits)
Set the random bits for this tile.
Definition: industry_map.h:237
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition: tilearea_type.h:20
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition: newgrf_animation_base.h:36
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve([[maybe_unused]] ResolverObject &object) const
Base sprite group resolver.
Definition: newgrf_spritegroup.h:61
GetAnimationFrame
byte GetAnimationFrame(Tile t)
Get the current animation frame.
Definition: tile_map.h:250
GetNearbyTile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition: newgrf_commons.cpp:406
GetIndustryTriggers
byte GetIndustryTriggers(Tile tile)
Get the activated triggers bits for this industry tile Used for grf callbacks.
Definition: industry_map.h:250
GetIndustryRandomBits
byte GetIndustryRandomBits(Tile tile)
Get the random bits for this tile.
Definition: industry_map.h:224
IndustryTileScopeResolver::tile
TileIndex tile
Tile being resolved.
Definition: newgrf_industrytiles.h:20
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:47
CBID_RANDOM_TRIGGER
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
Definition: newgrf_callbacks.h:25
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:319
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
CBID_INDTILE_ANIMATION_SPEED
@ CBID_INDTILE_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition: newgrf_callbacks.h:105
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition: industrytype.h:156
TileLayoutSpriteGroup::ProcessRegisters
const DrawTileSprites * ProcessRegisters(uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
Definition: newgrf_spritegroup.cpp:289
IndustryTileTrigger
IndustryTileTrigger
Available industry tile triggers.
Definition: newgrf_industrytiles.h:70
SpriteGroup
Definition: newgrf_spritegroup.h:57
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:589
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
debug.h
CBID_INDTILE_SHAPE_CHECK
@ CBID_INDTILE_SHAPE_CHECK
Called to determine if the given industry tile can be built on specific tile.
Definition: newgrf_callbacks.h:132
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition: newgrf_spritegroup.h:259
Industry::random
uint16_t random
Random value used for randomisation of all kinds of things.
Definition: industry.h:123
Industry::TileBelongsToIndustry
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition: industry.h:137
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103