OpenTTD Source: src/newgrf_industrytiles.cpp Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "debug.h"
12#include "landscape.h"
13#include "newgrf_badge.h"
14#include "newgrf_industrytiles.h"
15#include "newgrf_sound.h"
16#include "industry.h"
17#include "town.h"
18#include "command_func.h"
19#include "water.h"
20#include "newgrf_animation_base.h"
21
22#include "table/strings.h"
23
24#include "safeguards.h"
25
35uint32_t GetNearbyIndustryTileInformation(uint8_t parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
36{
37 if (parameter != 0) tile = GetNearbyTile(parameter, tile, signed_offsets); // only perform if it is required
38 bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
39
40 return GetNearbyTileInformation(tile, grf_version8) | (is_same_industry ? 1 : 0) << 8;
41}
42
54uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
55{
56 uint8_t x = TileX(tile) - TileX(ind_tile);
57 uint8_t y = TileY(tile) - TileY(ind_tile);
58
59 return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x;
60}
61
62/* virtual */ uint32_t IndustryTileScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
63{
64 switch (variable) {
65 /* Construction state of the tile: a value between 0 and 3 */
66 case 0x40: return (IsTileType(this->tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(this->tile) : 0;
67
68 /* Terrain type */
69 case 0x41: return GetTerrainType(this->tile);
70
71 /* Current town zone of the tile in the nearest town */
72 case 0x42: return to_underlying(GetTownRadiusGroup(ClosestTownFromTile(this->tile, UINT_MAX), this->tile));
73
74 /* Relative position */
75 case 0x43: return GetRelativePosition(this->tile, this->industry->location.tile);
76
77 /* Animation frame. Like house variable 46 but can contain anything 0..FF. */
78 case 0x44: return IsTileType(this->tile, MP_INDUSTRY) ? GetAnimationFrame(this->tile) : 0;
79
80 /* Land info of nearby tiles */
81 case 0x60: return GetNearbyIndustryTileInformation(parameter, this->tile,
82 this->industry == nullptr ? (IndustryID)IndustryID::Invalid() : this->industry->index, true, this->ro.grffile->grf_version >= 8);
83
84 /* Animation stage of nearby tiles */
85 case 0x61: {
86 TileIndex tile = GetNearbyTile(parameter, this->tile);
87 if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == this->industry) {
88 return GetAnimationFrame(tile);
89 }
90 return UINT_MAX;
91 }
92
93 /* Get industry tile ID at offset */
94 case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid);
95
96 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustryTileSpec(GetIndustryGfx(this->tile))->badges, parameter);
97 }
98
99 Debug(grf, 1, "Unhandled industry tile variable 0x{:X}", variable);
100
101 available = false;
102 return UINT_MAX;
103}
104
105/* virtual */ uint32_t IndustryTileScopeResolver::GetRandomBits() const
106{
107 assert(this->industry != nullptr && IsValidTile(this->tile));
108 assert(this->industry->index == IndustryID::Invalid() || IsTileType(this->tile, MP_INDUSTRY));
109
110 return (this->industry->index != IndustryID::Invalid()) ? GetIndustryRandomBits(this->tile) : 0;
111}
112
113/* virtual */ uint32_t IndustryTileScopeResolver::GetRandomTriggers() const
114{
115 assert(this->industry != nullptr && IsValidTile(this->tile));
116 assert(this->industry->index == IndustryID::Invalid() || IsTileType(this->tile, MP_INDUSTRY));
117 if (this->industry->index == IndustryID::Invalid()) return 0;
118 return GetIndustryRandomTriggers(this->tile).base();
119}
120
126 static const GRFFile *GetIndTileGrffile(IndustryGfx gfx)
127{
128 const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
129 return (its != nullptr) ? its->grf_prop.grffile : nullptr;
130}
131
141IndustryTileResolverObject::IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus,
142 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
143 : SpecializedResolverObject<IndustryRandomTriggers>(GetIndTileGrffile(gfx), callback, callback_param1, callback_param2),
144 indtile_scope(*this, indus, tile),
145 ind_scope(*this, tile, indus, indus->type),
146 gfx(gfx)
147{
148 this->root_spritegroup = GetIndustryTileSpec(gfx)->grf_prop.GetSpriteGroup(indus->index != IndustryID::Invalid());
149}
150
151 GrfSpecFeature IndustryTileResolverObject::GetFeature() const
152{
153 return GSF_INDUSTRYTILES;
154}
155
156uint32_t IndustryTileResolverObject::GetDebugID() const
157{
158 return GetIndustryTileSpec(gfx)->grf_prop.local_id;
159}
160
161static void IndustryDrawTileLayout(const TileInfo *ti, const DrawTileSpriteSpan &dts, Colours rnd_colour, uint8_t stage)
162{
163 SpriteID image = dts.ground.sprite;
164 PaletteID pal = dts.ground.pal;
165
166 if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
167 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
168
169 if (GB(image, 0, SPRITE_WIDTH) != 0) {
170 /* If the ground sprite is the default flat water sprite, draw also canal/river borders
171 * Do not do this if the tile's WaterClass is 'land'. */
172 if (image == SPR_FLAT_WATER_TILE && IsTileOnWater(ti->tile)) {
173 DrawWaterClassGround(ti);
174 } else {
175 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, GetColourPalette(rnd_colour)));
176 }
177 }
178
179 DrawNewGRFTileSeq(ti, &dts, TO_INDUSTRIES, stage, GetColourPalette(rnd_colour));
180}
181
182uint16_t GetIndustryTileCallback(CallbackID callback, uint32_t param1, uint32_t param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile, std::span<int32_t> regs100)
183{
184 assert(industry != nullptr && IsValidTile(tile));
185 assert(industry->index == IndustryID::Invalid() || IsTileType(tile, MP_INDUSTRY));
186
187 IndustryTileResolverObject object(gfx_id, tile, industry, callback, param1, param2);
188 return object.ResolveCallback(regs100);
189}
190
191bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
192{
193 if (ti->tileh != SLOPE_FLAT) {
194 bool draw_old_one = true;
195 if (inds->callback_mask.Test(IndustryTileCallbackMask::DrawFoundations)) {
196 /* Called to determine the type (if any) of foundation to draw for industry tile */
197 uint32_t callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile);
198 if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(inds->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res);
199 }
200
201 if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
202 }
203
204 IndustryTileResolverObject object(gfx, ti->tile, i);
205
206 const auto *group = object.Resolve<TileLayoutSpriteGroup>();
207 if (group == nullptr) return false;
208
209 /* Limit the building stage to the number of stages supplied. */
210 uint8_t stage = GetIndustryConstructionStage(ti->tile);
211 auto processor = group->ProcessRegisters(object, &stage);
212 auto dts = processor.GetLayout();
213 IndustryDrawTileLayout(ti, dts, i->random_colour, stage);
214 return true;
215}
216
217extern bool IsSlopeRefused(Slope current, Slope refused);
218
232 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)
233{
234 Industry ind;
235 ind.index = IndustryID::Invalid();
236 ind.location.tile = ind_base_tile;
237 ind.location.w = 0;
238 ind.type = type;
239 ind.random = initial_random_bits;
240 ind.founder = founder;
241
242 std::array<int32_t, 16> regs100;
243 uint16_t callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, creation_type << 8 | static_cast<uint32_t>(layout_index), gfx, &ind, ind_tile, regs100);
244 if (callback_res == CALLBACK_FAILED) {
245 if (!IsSlopeRefused(GetTileSlope(ind_tile), its->slopes_refused)) return CommandCost();
246 return CommandCost(STR_ERROR_SITE_UNSUITABLE);
247 }
248 if (its->grf_prop.grffile->grf_version < 7) {
249 if (callback_res != 0) return CommandCost();
250 return CommandCost(STR_ERROR_SITE_UNSUITABLE);
251 }
252
253 return GetErrorMessageFromLocationCallbackResult(callback_res, regs100, its->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE);
254}
255
256/* Simple wrapper for GetHouseCallback to keep the animation unified. */
257uint16_t GetSimpleIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, const IndustryTileSpec *spec, Industry *ind, TileIndex tile, int)
258{
259 return GetIndustryTileCallback(callback, param1, param2, spec - GetIndustryTileSpec(0), ind, tile);
260}
261
263 struct IndustryAnimationBase : public AnimationBase<IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback, TileAnimationFrameAnimationHelper<Industry> > {
264 static constexpr CallbackID cb_animation_speed = CBID_INDTILE_ANIMATION_SPEED;
265 static constexpr CallbackID cb_animation_next_frame = CBID_INDTILE_ANIMATION_NEXT_FRAME;
266
267 static constexpr IndustryTileCallbackMask cbm_animation_speed = IndustryTileCallbackMask::AnimationSpeed;
268 static constexpr IndustryTileCallbackMask cbm_animation_next_frame = IndustryTileCallbackMask::AnimationNextFrame;
269};
270
271void AnimateNewIndustryTile(TileIndex tile)
272{
273 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
274 if (itspec == nullptr) return;
275
276 IndustryAnimationBase::AnimateTile(itspec, Industry::GetByTile(tile), tile, itspec->special_flags.Test(IndustryTileSpecialFlag::NextFrameRandomBits));
277}
278
279static bool DoTriggerIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32_t random, uint32_t var18_extra = 0)
280{
281 const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
282 if (!itspec->animation.triggers.Test(iat)) return false;
283
284 IndustryAnimationBase::ChangeAnimationFrame(CBID_INDTILE_ANIMATION_TRIGGER, itspec, Industry::GetByTile(tile), tile, random, to_underlying(iat) | var18_extra);
285 return true;
286}
287
288bool TriggerIndustryTileAnimation_ConstructionStageChanged(TileIndex tile, bool first_call)
289{
290 auto iat = IndustryAnimationTrigger::ConstructionStageChanged;
291 return DoTriggerIndustryTileAnimation(tile, iat, Random(), first_call ? 0x100 : 0);
292}
293
294bool TriggerIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat)
295{
296 assert(iat != IndustryAnimationTrigger::ConstructionStageChanged);
297 return DoTriggerIndustryTileAnimation(tile, iat, Random());
298}
299
300bool TriggerIndustryAnimation(const Industry *ind, IndustryAnimationTrigger iat)
301{
302 bool ret = true;
303 uint32_t random = Random();
304 for (TileIndex tile : ind->location) {
305 if (ind->TileBelongsToIndustry(tile)) {
306 if (DoTriggerIndustryTileAnimation(tile, iat, random)) {
307 SB(random, 0, 16, Random());
308 } else {
309 ret = false;
310 }
311 }
312 }
313
314 return ret;
315}
316
324 static void DoTriggerIndustryTileRandomisation(TileIndex tile, IndustryRandomTrigger trigger, Industry *ind, uint32_t &reseed_industry)
325{
326 assert(IsValidTile(tile) && IsTileType(tile, MP_INDUSTRY));
327
328 IndustryGfx gfx = GetIndustryGfx(tile);
329 const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
330
331 if (!itspec->grf_prop.HasSpriteGroups()) return;
332
333 IndustryTileResolverObject object(gfx, tile, ind, CBID_RANDOM_TRIGGER);
334 auto waiting_random_triggers = GetIndustryRandomTriggers(tile);
335 waiting_random_triggers.Set(trigger);
336 SetIndustryRandomTriggers(tile, waiting_random_triggers); // store now for var 5F
337 object.SetWaitingRandomTriggers(waiting_random_triggers);
338
339 object.ResolveRerandomisation();
340
341 /* Store remaining triggers. */
342 waiting_random_triggers.Reset(object.GetUsedRandomTriggers());
343 SetIndustryRandomTriggers(tile, waiting_random_triggers);
344
345 /* Rerandomise tile bits */
346 uint8_t new_random_bits = Random();
347 uint8_t random_bits = GetIndustryRandomBits(tile);
348 random_bits &= ~object.reseed[VSG_SCOPE_SELF];
349 random_bits |= new_random_bits & object.reseed[VSG_SCOPE_SELF];
350 SetIndustryRandomBits(tile, random_bits);
351 MarkTileDirtyByTile(tile);
352
353 reseed_industry |= object.reseed[VSG_SCOPE_PARENT];
354}
355
361 static void DoReseedIndustry(Industry *ind, uint32_t reseed)
362{
363 if (reseed == 0 || ind == nullptr) return;
364
365 uint16_t random_bits = Random();
366 ind->random &= reseed;
367 ind->random |= random_bits & reseed;
368}
369
375 void TriggerIndustryTileRandomisation(TileIndex tile, IndustryRandomTrigger trigger)
376{
377 uint32_t reseed_industry = 0;
378 Industry *ind = Industry::GetByTile(tile);
379 DoTriggerIndustryTileRandomisation(tile, trigger, ind, reseed_industry);
380 DoReseedIndustry(ind, reseed_industry);
381}
382
388 void TriggerIndustryRandomisation(Industry *ind, IndustryRandomTrigger trigger)
389{
390 uint32_t reseed_industry = 0;
391 for (TileIndex tile : ind->location) {
392 if (ind->TileBelongsToIndustry(tile)) {
393 DoTriggerIndustryTileRandomisation(tile, trigger, ind, reseed_industry);
394 }
395 }
396 DoReseedIndustry(ind, reseed_industry);
397}
398
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
GB
static constexpr 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
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::base
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
Definition base_bitset_type.hpp:219
CommandCost
Common return value for all commands.
Definition command_type.h:24
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
command_func.h
Functions related to commands.
debug.h
Functions related to debugging.
Debug
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
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:2128
industry.h
Base of all industries.
GetIndustryTileSpec
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
Definition industry_cmd.cpp:140
GetIndustryRandomBits
uint8_t GetIndustryRandomBits(Tile tile)
Get the random bits for this tile.
Definition industry_map.h:224
GetIndustryGfx
IndustryGfx GetIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile.
Definition industry_map.h:137
GetIndustryIndex
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
Definition industry_map.h:63
SetIndustryRandomBits
void SetIndustryRandomBits(Tile tile, uint8_t bits)
Set the random bits for this tile.
Definition industry_map.h:237
SetIndustryRandomTriggers
void SetIndustryRandomTriggers(Tile tile, IndustryRandomTriggers triggers)
Set the activated triggers bits for this industry tile Used for grf callbacks.
Definition industry_map.h:264
GetIndustryRandomTriggers
IndustryRandomTriggers GetIndustryRandomTriggers(Tile tile)
Get the activated triggers bits for this industry tile Used for grf callbacks.
Definition industry_map.h:250
GetIndustryConstructionStage
uint8_t GetIndustryConstructionStage(Tile tile)
Returns the industry construction stage of the specified tile.
Definition industry_map.h:100
IndustryRandomTrigger
IndustryRandomTrigger
Available industry random triggers.
Definition industry_type.h:25
IndustryAnimationTrigger
IndustryAnimationTrigger
Animation triggers of the industries.
Definition industry_type.h:33
IndustryAnimationTrigger::ConstructionStageChanged
@ ConstructionStageChanged
Trigger whenever the construction stage changes.
IndustryTileSpecialFlag::NextFrameRandomBits
@ NextFrameRandomBits
Callback 0x26 needs random bits.
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition landscape.cpp:428
landscape.h
Functions related to OTTD's landscape.
BorderFlag::Random
@ Random
Randomise borders.
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
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:54
newgrf_animation_base.h
Function implementations related to NewGRF animation.
GetBadgeVariableResult
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Definition newgrf_badge.cpp:225
newgrf_badge.h
Functions related to NewGRF badges.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:22
CBID_INDTILE_ANIMATION_SPEED
@ CBID_INDTILE_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition newgrf_callbacks.h:107
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:134
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:137
CBID_RANDOM_TRIGGER
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
Definition newgrf_callbacks.h:27
CBID_INDTILE_ANIMATION_TRIGGER
@ CBID_INDTILE_ANIMATION_TRIGGER
Called for periodically starting or stopping the animation.
Definition newgrf_callbacks.h:101
CBID_INDTILE_ANIMATION_NEXT_FRAME
@ CBID_INDTILE_ANIMATION_NEXT_FRAME
Called to determine industry tile next animation frame.
Definition newgrf_callbacks.h:104
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
IndustryTileCallbackMask
IndustryTileCallbackMask
Callback masks for industry tiles.
Definition newgrf_callbacks.h:400
IndustryTileCallbackMask::DrawFoundations
@ DrawFoundations
decides if default foundations need to be drawn
IndustryTileCallbackMask::AnimationNextFrame
@ AnimationNextFrame
decides next animation frame
IndustryTileCallbackMask::AnimationSpeed
@ AnimationSpeed
decides animation speed
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span< const int32_t > textstack, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition newgrf_commons.cpp:471
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:434
ConvertBooleanCallback
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition newgrf_commons.cpp:543
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:336
GetNearbyTile
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition newgrf_commons.cpp:411
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:57
IndustryAvailabilityCallType
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
Definition newgrf_industries.h:81
GetNearbyIndustryTileInformation
uint32_t GetNearbyIndustryTileInformation(uint8_t parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
Based on newhouses equivalent, but adapted for newindustries.
Definition newgrf_industrytiles.cpp:35
TriggerIndustryTileRandomisation
void TriggerIndustryTileRandomisation(TileIndex tile, IndustryRandomTrigger trigger)
Trigger a random trigger for a single industry tile.
Definition newgrf_industrytiles.cpp:375
DoTriggerIndustryTileRandomisation
static void DoTriggerIndustryTileRandomisation(TileIndex tile, IndustryRandomTrigger trigger, Industry *ind, uint32_t &reseed_industry)
Trigger random triggers for an industry tile and reseed its random bits.
Definition newgrf_industrytiles.cpp:324
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:54
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:232
GetIndTileGrffile
static const GRFFile * GetIndTileGrffile(IndustryGfx gfx)
Get the associated NewGRF file from the industry graphics.
Definition newgrf_industrytiles.cpp:126
TriggerIndustryRandomisation
void TriggerIndustryRandomisation(Industry *ind, IndustryRandomTrigger trigger)
Trigger a random trigger for all industry tiles.
Definition newgrf_industrytiles.cpp:388
DoReseedIndustry
static void DoReseedIndustry(Industry *ind, uint32_t reseed)
Reseeds the random bits of an industry.
Definition newgrf_industrytiles.cpp:361
GetNearbyIndustryTileInformation
uint32_t GetNearbyIndustryTileInformation(uint8_t parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
Based on newhouses equivalent, but adapted for newindustries.
Definition newgrf_industrytiles.cpp:35
newgrf_industrytiles.h
NewGRF handling of industry tiles.
newgrf_sound.h
Functions related to NewGRF provided sounds.
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition newgrf_spritegroup.h:85
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition newgrf_spritegroup.h:86
safeguards.h
A number of safeguards to prevent using unsafe methods.
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:49
FOUNDATION_LEVELED
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
Definition slope_type.h:95
GetColourPalette
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:188
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:130
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:174
SPRITE_MODIFIER_CUSTOM_SPRITE
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
Definition sprites.h:1559
SPRITE_WIDTH
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Definition sprites.h:1549
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition newgrf_animation_base.h:43
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:52
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:131
DrawTileSpriteSpan
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:318
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:316
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
IndustryAnimationBase
Helper class for animation control.
Definition newgrf_industrytiles.cpp:263
IndustryTileResolverObject
Resolver for industry tiles.
Definition newgrf_industrytiles.h:38
IndustryTileResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_industrytiles.cpp:151
IndustryTileResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_industrytiles.cpp:156
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:141
IndustryTileScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_industrytiles.cpp:105
IndustryTileScopeResolver::industry
Industry * industry
Industry owning the tiles.
Definition newgrf_industrytiles.h:18
IndustryTileScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
Definition newgrf_industrytiles.cpp:62
IndustryTileScopeResolver::tile
TileIndex tile
Tile being resolved.
Definition newgrf_industrytiles.h:19
IndustryTileScopeResolver::GetRandomTriggers
uint32_t GetRandomTriggers() const override
Get the triggers.
Definition newgrf_industrytiles.cpp:113
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition industrytype.h:152
IndustryTileSpec::special_flags
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
Definition industrytype.h:166
IndustryTileSpec::slopes_refused
Slope slopes_refused
slope pattern on which this tile cannot be built
Definition industrytype.h:155
IndustryTileSpec::animation
AnimationInfo< IndustryAnimationTriggers > animation
Information about the animation (is it looping, how many loops etc)
Definition industrytype.h:165
IndustryTileSpec::grf_prop
SubstituteGRFFileProps grf_prop
properties related to the grf file
Definition industrytype.h:168
IndustryTileSpec::callback_mask
IndustryTileCallbackMasks callback_mask
Bitmask of industry tile callbacks that have to be called.
Definition industrytype.h:164
Industry
Defines the internal data of a functional industry.
Definition industry.h:62
Industry::type
IndustryType type
type of industry.
Definition industry.h:115
Industry::random_colour
Colours random_colour
randomized colour of the industry, for display purpose
Definition industry.h:117
Industry::random
uint16_t random
Random value used for randomisation of all kinds of things.
Definition industry.h:134
Industry::founder
Owner founder
Founder of the industry.
Definition industry.h:126
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition industry.h:251
Industry::location
TileArea location
Location of the industry.
Definition industry.h:106
Industry::TileBelongsToIndustry
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition industry.h:148
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition tilearea_type.h:20
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition tilearea_type.h:19
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
PoolID
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition newgrf_spritegroup.h:352
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition newgrf_spritegroup.h:353
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:270
SpecializedResolverObject
Specialization of ResolverObject with type-safe access to RandomTriggers.
Definition newgrf_spritegroup.h:450
StandardGRFFileProps::GetSpriteGroup
const struct SpriteGroup * GetSpriteGroup(bool entity_exists) const
Get the standard sprite group.
Definition newgrf_commons.h:394
StandardGRFFileProps::HasSpriteGroups
bool HasSpriteGroups() const
Check whether the entity has sprite groups.
Definition newgrf_commons.h:385
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition tile_cmd.h:31
TileInfo::tile
TileIndex tile
Tile index.
Definition tile_cmd.h:32
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition newgrf_spritegroup.h:236
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetAnimationFrame
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
GetTileSlope
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition tile_type.h:56
town.h
Base of the town class.
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:3952
GetTownRadiusGroup
HouseZone GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition town_cmd.cpp:2507
TO_INDUSTRIES
@ TO_INDUSTRIES
industries
Definition transparency.h:27
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:579
water.h
Functions related to water (management)
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition water_map.h:138