OpenTTD Source: src/newgrf_industries.cpp Source File

OpenTTD Source 15.0-RC2

newgrf_industries.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 "industry.h"
13#include "newgrf_badge.h"
14#include "newgrf_industries.h"
15#include "newgrf_town.h"
16#include "newgrf_cargo.h"
17#include "window_func.h"
18#include "town.h"
19#include "company_base.h"
20#include "error.h"
21#include "strings_func.h"
22#include "core/random_func.hpp"
23#include "timer/timer_game_calendar.h"
24
25#include "table/strings.h"
26
27#include "safeguards.h"
28
29/* Since the industry IDs defined by the GRF file don't necessarily correlate
30 * to those used by the game, the IDs used for overriding old industries must be
31 * translated when the idustry spec is set. */
32 IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, IT_INVALID);
33 IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
34
41IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32_t grf_id)
42{
43 if (grf_type == IT_INVALID) return IT_INVALID;
44 if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 7);
45
46 return _industry_mngr.GetID(GB(grf_type, 0, 7), grf_id);
47}
48
57uint32_t GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32_t cur_grfid)
58{
59 if (!i->TileBelongsToIndustry(tile)) {
60 /* No industry and/or the tile does not have the same industry as the one we match it with */
61 return 0xFFFF;
62 }
63
64 IndustryGfx gfx = GetCleanIndustryGfx(tile);
65 const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
66
67 if (gfx < NEW_INDUSTRYTILEOFFSET) { // Does it belongs to an old type?
68 /* It is an old tile. We have to see if it's been overridden */
69 if (indtsp->grf_prop.override_id == INVALID_INDUSTRYTILE) { // has it been overridden?
70 return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
71 }
72 /* Overridden */
73 const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override_id);
74
75 if (tile_ovr->grf_prop.grfid == cur_grfid) {
76 return tile_ovr->grf_prop.local_id; // same grf file
77 } else {
78 return 0xFFFE; // not the same grf file
79 }
80 }
81 /* Not an 'old type' tile */
82 if (indtsp->grf_prop.HasSpriteGroups()) {
83 if (indtsp->grf_prop.grfid == cur_grfid) { // same industry, same grf ?
84 return indtsp->grf_prop.local_id;
85 } else {
86 return 0xFFFE; // Defined in another grf file
87 }
88 }
89 /* The tile has no spritegroup */
90 return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give it the substitute
91}
92
93static uint32_t GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current)
94{
95 uint32_t best_dist = UINT32_MAX;
96
97 for (const IndustryID &industry : Industry::industries[type]) {
98 if (industry == current->index) continue;
99
100 best_dist = std::min(best_dist, DistanceManhattan(tile, Industry::Get(industry)->location.tile));
101 }
102
103 return best_dist;
104}
105
117 static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &object, uint8_t param_set_id, uint8_t layout_filter, bool town_filter, const Industry *current)
118{
119 uint32_t grf_id = static_cast<uint32_t>(object.GetRegister(0x100));
120 IndustryType industry_type;
121 uint32_t closest_dist = UINT32_MAX;
122 uint8_t count = 0;
123
124 /* Determine what will be the industry type to look for */
125 switch (grf_id) {
126 case 0: // this is a default industry type
127 industry_type = param_set_id;
128 break;
129
130 case 0xFFFFFFFF: // current grf
131 grf_id = GetIndustrySpec(current->type)->grf_prop.grfid;
132 [[fallthrough]];
133
134 default: // use the grfid specified in register 100h
135 SetBit(param_set_id, 7); // bit 7 means it is not an old type
136 industry_type = MapNewGRFIndustryType(param_set_id, grf_id);
137 break;
138 }
139
140 /* If the industry type is invalid, there is none and the closest is far away. */
141 if (industry_type >= NUM_INDUSTRYTYPES) return 0 | 0xFFFF;
142
143 if (layout_filter == 0 && !town_filter) {
144 /* If the filter is 0, it could be because none was specified as well as being really a 0.
145 * In either case, just do the regular var67 */
146 closest_dist = GetClosestIndustry(current->location.tile, industry_type, current);
147 count = ClampTo<uint8_t>(Industry::GetIndustryTypeCount(industry_type));
148 } else {
149 /* Count only those who match the same industry type and layout filter
150 * Unfortunately, we have to do it manually */
151 for (const IndustryID &industry : Industry::industries[industry_type]) {
152 if (industry == current->index) continue;
153
154 const Industry *i = Industry::Get(industry);
155 if ((layout_filter == 0 || i->selected_layout == layout_filter) && (!town_filter || i->town == current->town)) {
156 closest_dist = std::min(closest_dist, DistanceManhattan(current->location.tile, i->location.tile));
157 count++;
158 }
159 }
160 }
161
162 return count << 16 | GB(closest_dist, 0, 16);
163}
164
165/* virtual */ uint32_t IndustriesScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
166{
167 if (this->ro.callback == CBID_INDUSTRY_LOCATION) {
168 /* Variables available during construction check. */
169
170 switch (variable) {
171 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
172
173 case 0x80: return this->tile.base();
174 case 0x81: return GB(this->tile.base(), 8, 8);
175
176 /* Pointer to the town the industry is associated with */
177 case 0x82: return this->industry->town->index.base();
178 case 0x83:
179 case 0x84:
180 case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
181
182 /* Number of the layout */
183 case 0x86: return this->industry->selected_layout;
184
185 /* Ground type */
186 case 0x87: return GetTerrainType(this->tile);
187
188 /* Town zone */
189 case 0x88: return to_underlying(GetTownRadiusGroup(this->industry->town, this->tile));
190
191 /* Manhattan distance of the closest town */
192 case 0x89: return ClampTo<uint8_t>(DistanceManhattan(this->industry->town->xy, this->tile));
193
194 /* Lowest height of the tile */
195 case 0x8A: return ClampTo<uint8_t>(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT));
196
197 /* Distance to the nearest water/land tile */
198 case 0x8B: return GetClosestWaterDistance(this->tile, !GetIndustrySpec(this->industry->type)->behaviour.Test(IndustryBehaviour::BuiltOnWater));
199
200 /* Square of Euclidean distance from town */
201 case 0x8D: return ClampTo<uint16_t>(DistanceSquare(this->industry->town->xy, this->tile));
202
203 /* 32 random bits */
204 case 0x8F: return this->random_bits;
205 }
206 }
207
208 const IndustrySpec *indspec = GetIndustrySpec(this->type);
209
210 if (this->industry == nullptr) {
211 Debug(grf, 1, "Unhandled variable 0x{:X} (no available industry) in callback 0x{:x}", variable, this->ro.callback);
212
213 available = false;
214 return UINT_MAX;
215 }
216
217 switch (variable) {
218 case 0x40:
219 case 0x41:
220 case 0x42: { // waiting cargo, but only if those two callback flags are set
221 IndustryCallbackMasks callback = indspec->callback_mask;
222 if (callback.Any({IndustryCallbackMask::ProductionCargoArrival, IndustryCallbackMask::Production256Ticks})) {
223 if (indspec->behaviour.Test(IndustryBehaviour::ProdMultiHandling)) {
224 if (this->industry->prod_level == 0) return 0;
225 return ClampTo<uint16_t>(this->industry->GetAccepted(variable - 0x40).waiting / this->industry->prod_level);
226 } else {
227 return ClampTo<uint16_t>(this->industry->GetAccepted(variable - 0x40).waiting);
228 }
229 } else {
230 return 0;
231 }
232 }
233
234 /* Manhattan distance of closes dry/water tile */
235 case 0x43:
236 if (this->tile == INVALID_TILE) break;
237 return GetClosestWaterDistance(this->tile, !indspec->behaviour.Test(IndustryBehaviour::BuiltOnWater));
238
239 /* Layout number */
240 case 0x44: return this->industry->selected_layout;
241
242 /* Company info */
243 case 0x45: {
244 uint8_t colours = 0;
245 bool is_ai = false;
246
247 const Company *c = Company::GetIfValid(this->industry->founder);
248 if (c != nullptr) {
249 is_ai = c->is_ai;
250 colours = c->GetCompanyRecolourOffset(LS_DEFAULT);
251 }
252
253 return this->industry->founder.base() | (is_ai ? 0x10000 : 0) | (colours << 24);
254 }
255
256 case 0x46: return this->industry->construction_date.base(); // Date when built - long format - (in days)
257
258 /* Override flags from GS */
259 case 0x47: return this->industry->ctlflags.base();
260
261 /* Get industry ID at offset param */
262 case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->industry->location.tile, false), this->industry, this->ro.grffile->grfid);
263
264 /* Get random tile bits at offset param */
265 case 0x61: {
266 if (this->tile == INVALID_TILE) break;
267 TileIndex tile = GetNearbyTile(parameter, this->tile, false);
268 return this->industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0;
269 }
270
271 /* Land info of nearby tiles */
272 case 0x62:
273 if (this->tile == INVALID_TILE) break;
274 return GetNearbyIndustryTileInformation(parameter, this->tile, IndustryID::Invalid(), false, this->ro.grffile->grf_version >= 8);
275
276 /* Animation stage of nearby tiles */
277 case 0x63: {
278 if (this->tile == INVALID_TILE) break;
279 TileIndex tile = GetNearbyTile(parameter, this->tile, false);
280 if (this->industry->TileBelongsToIndustry(tile)) {
281 return GetAnimationFrame(tile);
282 }
283 return 0xFFFFFFFF;
284 }
285
286 /* Distance of nearest industry of given type */
287 case 0x64: {
288 if (this->tile == INVALID_TILE) break;
289 IndustryType type = MapNewGRFIndustryType(parameter, indspec->grf_prop.grfid);
290 if (type >= NUM_INDUSTRYTYPES) return UINT32_MAX;
291 return GetClosestIndustry(this->tile, type, this->industry);
292 }
293 /* Get town zone and Manhattan distance of closest town */
294 case 0x65: {
295 if (this->tile == INVALID_TILE) break;
296 TileIndex tile = GetNearbyTile(parameter, this->tile, true);
297 return to_underlying(GetTownRadiusGroup(this->industry->town, tile)) << 16 | ClampTo<uint16_t>(DistanceManhattan(tile, this->industry->town->xy));
298 }
299 /* Get square of Euclidean distance of closest town */
300 case 0x66: {
301 if (this->tile == INVALID_TILE) break;
302 TileIndex tile = GetNearbyTile(parameter, this->tile, true);
303 return DistanceSquare(tile, this->industry->town->xy);
304 }
305
306 /* Count of industry, distance of closest instance
307 * 68 is the same as 67, but with a filtering on selected layout */
308 case 0x67:
309 case 0x68: {
310 uint8_t layout_filter = 0;
311 bool town_filter = false;
312 if (variable == 0x68) {
313 int32_t reg = this->ro.GetRegister(0x101);
314 layout_filter = GB(reg, 0, 8);
315 town_filter = HasBit(reg, 8);
316 }
317 return GetCountAndDistanceOfClosestInstance(this->ro, parameter, layout_filter, town_filter, this->industry);
318 }
319
320 case 0x69:
321 case 0x6A:
322 case 0x6B:
323 case 0x6C:
324 case 0x6D:
325 case 0x70:
326 case 0x71: {
327 CargoType cargo = GetCargoTranslation(parameter, this->ro.grffile);
328 if (!IsValidCargoType(cargo)) return 0;
329 auto it = this->industry->GetCargoProduced(cargo);
330 if (it == std::end(this->industry->produced)) return 0; // invalid cargo
331 switch (variable) {
332 case 0x69: return it->waiting;
333 case 0x6A: return it->history[THIS_MONTH].production;
334 case 0x6B: return it->history[THIS_MONTH].transported;
335 case 0x6C: return it->history[LAST_MONTH].production;
336 case 0x6D: return it->history[LAST_MONTH].transported;
337 case 0x70: return it->rate;
338 case 0x71: return it->history[LAST_MONTH].PctTransported();
339 default: NOT_REACHED();
340 }
341 }
342
343
344 case 0x6E:
345 case 0x6F: {
346 CargoType cargo = GetCargoTranslation(parameter, this->ro.grffile);
347 if (!IsValidCargoType(cargo)) return 0;
348 auto it = this->industry->GetCargoAccepted(cargo);
349 if (it == std::end(this->industry->accepted)) return 0; // invalid cargo
350 if (variable == 0x6E) return it->last_accepted.base();
351 if (variable == 0x6F) return it->waiting;
352 NOT_REACHED();
353 }
354
355 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
356
357 /* Get a variable from the persistent storage */
358 case 0x7C: return (this->industry->psa != nullptr) ? this->industry->psa->GetValue(parameter) : 0;
359
360 /* Industry structure access*/
361 case 0x80: return this->industry->location.tile.base();
362 case 0x81: return GB(this->industry->location.tile.base(), 8, 8);
363 /* Pointer to the town the industry is associated with */
364 case 0x82: return this->industry->town->index.base();
365 case 0x83:
366 case 0x84:
367 case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
368 case 0x86: return this->industry->location.w;
369 case 0x87: return this->industry->location.h;// xy dimensions
370
371 case 0x88:
372 case 0x89: return this->industry->GetProduced(variable - 0x88).cargo;
373 case 0x8A: return this->industry->GetProduced(0).waiting;
374 case 0x8B: return GB(this->industry->GetProduced(0).waiting, 8, 8);
375 case 0x8C: return this->industry->GetProduced(1).waiting;
376 case 0x8D: return GB(this->industry->GetProduced(1).waiting, 8, 8);
377 case 0x8E:
378 case 0x8F: return this->industry->GetProduced(variable - 0x8E).rate;
379 case 0x90:
380 case 0x91:
381 case 0x92: return this->industry->GetAccepted(variable - 0x90).cargo;
382 case 0x93: return this->industry->prod_level;
383 /* amount of cargo produced so far THIS month. */
384 case 0x94: return this->industry->GetProduced(0).history[THIS_MONTH].production;
385 case 0x95: return GB(this->industry->GetProduced(0).history[THIS_MONTH].production, 8, 8);
386 case 0x96: return this->industry->GetProduced(1).history[THIS_MONTH].production;
387 case 0x97: return GB(this->industry->GetProduced(1).history[THIS_MONTH].production, 8, 8);
388 /* amount of cargo transported so far THIS month. */
389 case 0x98: return this->industry->GetProduced(0).history[THIS_MONTH].transported;
390 case 0x99: return GB(this->industry->GetProduced(0).history[THIS_MONTH].transported, 8, 8);
391 case 0x9A: return this->industry->GetProduced(1).history[THIS_MONTH].transported;
392 case 0x9B: return GB(this->industry->GetProduced(1).history[THIS_MONTH].transported, 8, 8);
393 /* fraction of cargo transported LAST month. */
394 case 0x9C:
395 case 0x9D: return this->industry->GetProduced(variable - 0x9C).history[LAST_MONTH].PctTransported();
396 /* amount of cargo produced LAST month. */
397 case 0x9E: return this->industry->GetProduced(0).history[LAST_MONTH].production;
398 case 0x9F: return GB(this->industry->GetProduced(0).history[LAST_MONTH].production, 8, 8);
399 case 0xA0: return this->industry->GetProduced(1).history[LAST_MONTH].production;
400 case 0xA1: return GB(this->industry->GetProduced(1).history[LAST_MONTH].production, 8, 8);
401 /* amount of cargo transported last month. */
402 case 0xA2: return this->industry->GetProduced(0).history[LAST_MONTH].transported;
403 case 0xA3: return GB(this->industry->GetProduced(0).history[LAST_MONTH].transported, 8, 8);
404 case 0xA4: return this->industry->GetProduced(1).history[LAST_MONTH].transported;
405 case 0xA5: return GB(this->industry->GetProduced(1).history[LAST_MONTH].transported, 8, 8);
406
407 case 0xA6: return indspec->grf_prop.local_id;
408 case 0xA7: return this->industry->founder.base();
409 case 0xA8: return this->industry->random_colour;
410 case 0xA9: return ClampTo<uint8_t>(this->industry->last_prod_year - EconomyTime::ORIGINAL_BASE_YEAR);
411 case 0xAA: return this->industry->counter;
412 case 0xAB: return GB(this->industry->counter, 8, 8);
413 case 0xAC: return this->industry->was_cargo_delivered;
414
415 case 0xB0: return ClampTo<uint16_t>(this->industry->construction_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date when built since 1920 (in days)
416 case 0xB3: return this->industry->construction_type; // Construction type
417 case 0xB4: {
418 if (this->industry->accepted.empty()) return 0;
419 auto it = std::max_element(std::begin(this->industry->accepted), std::end(this->industry->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; });
420 return ClampTo<uint16_t>(it->last_accepted - EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days)
421 }
422 }
423
424 Debug(grf, 1, "Unhandled industry variable 0x{:X}", variable);
425
426 available = false;
427 return UINT_MAX;
428}
429
430/* virtual */ uint32_t IndustriesScopeResolver::GetRandomBits() const
431{
432 return this->industry != nullptr ? this->industry->random : 0;
433}
434
435/* virtual */ uint32_t IndustriesScopeResolver::GetRandomTriggers() const
436{
437 return 0;
438}
439
440/* virtual */ void IndustriesScopeResolver::StorePSA(uint pos, int32_t value)
441{
442 if (this->industry->index == IndustryID::Invalid()) return;
443
444 if (this->industry->psa == nullptr) {
445 /* There is no need to create a storage if the value is zero. */
446 if (value == 0) return;
447
448 /* Create storage on first modification. */
449 const IndustrySpec *indsp = GetIndustrySpec(this->industry->type);
450 assert(PersistentStorage::CanAllocateItem());
451 this->industry->psa = new PersistentStorage(indsp->grf_prop.grfid, GSF_INDUSTRIES, this->industry->location.tile);
452 }
453
454 this->industry->psa->StoreValue(pos, value);
455}
456
462 static const GRFFile *GetGrffile(IndustryType type)
463{
464 const IndustrySpec *indspec = GetIndustrySpec(type);
465 return (indspec != nullptr) ? indspec->grf_prop.grffile : nullptr;
466}
467
478IndustriesResolverObject::IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32_t random_bits,
479 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
480 : ResolverObject(GetGrffile(type), callback, callback_param1, callback_param2),
481 industries_scope(*this, tile, indus, type, random_bits)
482{
483 this->root_spritegroup = GetIndustrySpec(type)->grf_prop.GetSpriteGroup(indus != nullptr && indus->index != IndustryID::Invalid());
484}
485
490 TownScopeResolver *IndustriesResolverObject::GetTown()
491{
492 if (!this->town_scope.has_value()) {
493 Town *t = nullptr;
494 bool readonly = true;
495 if (this->industries_scope.industry != nullptr) {
496 t = this->industries_scope.industry->town;
497 readonly = this->industries_scope.industry->index == IndustryID::Invalid();
498 } else if (this->industries_scope.tile != INVALID_TILE) {
499 t = ClosestTownFromTile(this->industries_scope.tile, UINT_MAX);
500 }
501 if (t == nullptr) return nullptr;
502 this->town_scope.emplace(*this, t, readonly);
503 }
504 return &*this->town_scope;
505}
506
507 GrfSpecFeature IndustriesResolverObject::GetFeature() const
508{
509 return GSF_INDUSTRIES;
510}
511
512uint32_t IndustriesResolverObject::GetDebugID() const
513{
514 return GetIndustrySpec(this->industries_scope.type)->grf_prop.local_id;
515}
516
528uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile, std::span<int32_t> regs100)
529{
530 IndustriesResolverObject object(tile, industry, type, 0, callback, param1, param2);
531 return object.ResolveCallback(regs100);
532}
533
545 CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, size_t layout, uint32_t seed, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
546{
547 const IndustrySpec *indspec = GetIndustrySpec(type);
548
549 Industry ind;
550 ind.index = IndustryID::Invalid();
551 ind.location.tile = tile;
552 ind.location.w = 0; // important to mark the industry invalid
553 ind.type = type;
554 ind.selected_layout = (uint8_t)layout;
555 ind.town = ClosestTownFromTile(tile, UINT_MAX);
556 ind.random = initial_random_bits;
557 ind.founder = founder;
558 ind.psa = nullptr;
559
560 IndustriesResolverObject object(tile, &ind, type, seed, CBID_INDUSTRY_LOCATION, 0, creation_type);
561 std::array<int32_t, 16> regs100;
562 uint16_t result = object.ResolveCallback(regs100);
563
564 /* Unlike the "normal" cases, not having a valid result means we allow
565 * the building of the industry, as that's how it's done in TTDP. */
566 if (result == CALLBACK_FAILED) return CommandCost();
567
568 return GetErrorMessageFromLocationCallbackResult(result, regs100, indspec->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE);
569}
570
577uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
578{
579 const IndustrySpec *indspec = GetIndustrySpec(type);
580
581 if (indspec->callback_mask.Test(IndustryCallbackMask::Probability)) {
582 uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, creation_type, nullptr, type, INVALID_TILE);
583 if (res != CALLBACK_FAILED) {
584 if (indspec->grf_prop.grffile->grf_version < 8) {
585 /* Disallow if result != 0 */
586 if (res != 0) default_prob = 0;
587 } else {
588 /* Use returned probability. 0x100 to use default */
589 if (res < 0x100) {
590 default_prob = res;
591 } else if (res > 0x100) {
592 ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_PROBABILITY, res);
593 }
594 }
595 }
596 }
597 return default_prob;
598}
599
605 void IndustryProductionCallback(Industry *ind, int reason)
606{
607 const IndustrySpec *spec = GetIndustrySpec(ind->type);
608 IndustriesResolverObject object(ind->location.tile, ind, ind->type);
609 if (spec->behaviour.Test(IndustryBehaviour::ProdCallbackRandom)) object.callback_param1 = Random();
610 int multiplier = 1;
611 if (spec->behaviour.Test(IndustryBehaviour::ProdMultiHandling)) multiplier = ind->prod_level;
612 object.callback_param2 = reason;
613
614 auto deref_ind_prod = [&object](int field, bool use_register) -> int32_t {
615 return use_register ? object.GetRegister(field) : field;
616 };
617
618 for (uint loop = 0;; loop++) {
619 /* limit the number of calls to break infinite loops.
620 * 'loop' is provided as 16 bits to the newgrf, so abort when those are exceeded. */
621 if (loop >= 0x10000) {
622 /* display error message */
623 ShowErrorMessage(GetEncodedString(STR_NEWGRF_BUGGY, spec->grf_prop.grffile->filename),
624 GetEncodedString(STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK, std::monostate{}, spec->name),
625 WL_WARNING);
626
627 /* abort the function early, this error isn't critical and will allow the game to continue to run */
628 break;
629 }
630
631 SB(object.callback_param2, 8, 16, loop);
632 const auto *group = object.Resolve<IndustryProductionSpriteGroup>();
633 if (group == nullptr) break;
634
635 if (group->version == 0xFF) {
636 /* Result was marked invalid on load, display error message */
637 ShowErrorMessage(GetEncodedString(STR_NEWGRF_BUGGY, spec->grf_prop.grffile->filename),
638 GetEncodedString(STR_NEWGRF_BUGGY_INVALID_CARGO_PRODUCTION_CALLBACK, std::monostate{}, spec->name, ind->location.tile),
639 WL_WARNING);
640
641 /* abort the function early, this error isn't critical and will allow the game to continue to run */
642 break;
643 }
644
645 bool deref = (group->version >= 1);
646
647 if (group->version < 2) {
648 /* Callback parameters map directly to industry cargo slot indices */
649 for (uint i = 0; i < group->num_input && i < ind->accepted.size(); i++) {
650 if (!IsValidCargoType(ind->accepted[i].cargo)) continue;
651 ind->accepted[i].waiting = ClampTo<uint16_t>(ind->accepted[i].waiting - deref_ind_prod(group->subtract_input[i], deref) * multiplier);
652 }
653 for (uint i = 0; i < group->num_output && i < ind->produced.size(); i++) {
654 if (!IsValidCargoType(ind->produced[i].cargo)) continue;
655 ind->produced[i].waiting = ClampTo<uint16_t>(ind->produced[i].waiting + std::max(deref_ind_prod(group->add_output[i], deref), 0) * multiplier);
656 }
657 } else {
658 /* Callback receives list of cargos to apply for, which need to have their cargo slots in industry looked up */
659 for (uint i = 0; i < group->num_input; i++) {
660 auto it = ind->GetCargoAccepted(group->cargo_input[i]);
661 if (it == std::end(ind->accepted)) continue;
662 it->waiting = ClampTo<uint16_t>(it->waiting - deref_ind_prod(group->subtract_input[i], deref) * multiplier);
663 }
664 for (uint i = 0; i < group->num_output; i++) {
665 auto it = ind->GetCargoProduced(group->cargo_output[i]);
666 if (it == std::end(ind->produced)) continue;
667 it->waiting = ClampTo<uint16_t>(it->waiting + std::max(deref_ind_prod(group->add_output[i], deref), 0) * multiplier);
668 }
669 }
670
671 int32_t again = deref_ind_prod(group->again, deref);
672 if (again == 0) break;
673
674 SB(object.callback_param2, 24, 8, again);
675 }
676
677 SetWindowDirty(WC_INDUSTRY_VIEW, ind->index);
678}
679
687 bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoType cargo_type)
688{
689 assert(ind->IsCargoAccepted(cargo_type));
690
691 const IndustrySpec *indspec = GetIndustrySpec(ind->type);
692 if (indspec->callback_mask.Test(IndustryCallbackMask::RefuseCargo)) {
693 uint16_t res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
694 0, indspec->grf_prop.grffile->cargo_map[cargo_type],
695 ind, ind->type, ind->location.tile);
696 if (res != CALLBACK_FAILED) return !ConvertBooleanCallback(indspec->grf_prop.grffile, CBID_INDUSTRY_REFUSE_CARGO, res);
697 }
698 return false;
699}
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
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
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
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
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
BaseBitSet::Any
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Definition base_bitset_type.hpp:170
CommandCost
Common return value for all commands.
Definition command_type.h:24
EnumBitSet< IndustryCallbackMask, uint16_t >
IndustryOverrideManager
Definition newgrf_commons.h:241
IndustryOverrideManager::GetID
uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const override
Return the ID (if ever available) of a previously inserted entity.
Definition newgrf_commons.cpp:193
IndustryTileOverrideManager
Definition newgrf_commons.h:254
TimerGameConst< struct Economy >::ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Economy >::Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Definition timer_game_common.h:163
TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
Definition timer_game_common.h:184
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
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
error.h
Functions related to errors.
WL_WARNING
@ WL_WARNING
Other information.
Definition error.h:25
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:290
industry.h
Base of all industries.
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition industry_cmd.cpp:126
GetIndustryTileSpec
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
Definition industry_cmd.cpp:140
GetCleanIndustryGfx
IndustryGfx GetCleanIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile as stored in the without translation.
Definition industry_map.h:125
GetIndustryRandomBits
uint8_t GetIndustryRandomBits(Tile tile)
Get the random bits for this tile.
Definition industry_map.h:224
NEW_INDUSTRYTILEOFFSET
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
Definition industry_type.h:51
NEW_INDUSTRYOFFSET
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
Definition industry_type.h:44
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like IT_...
Definition industry_type.h:45
INVALID_INDUSTRYTILE
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
Definition industry_type.h:53
NUM_INDUSTRYTILES
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
Definition industry_type.h:52
IndustryBehaviour::ProdCallbackRandom
@ ProdCallbackRandom
Production callback needs random bits in var 10.
IndustryBehaviour::BuiltOnWater
@ BuiltOnWater
is built on water (oil rig)
IndustryBehaviour::ProdMultiHandling
@ ProdMultiHandling
Automatic production multiplier handling.
BorderFlag::Random
@ Random
Randomise borders.
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition map.cpp:175
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition map.cpp:158
GetClosestWaterDistance
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
Definition map.cpp:252
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
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.
IndustryCallbackMask::Probability
@ Probability
industry availability/probability callback
IndustryCallbackMask::RefuseCargo
@ RefuseCargo
option out of accepting cargo
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:22
CBID_INDUSTRY_PROBABILITY
@ CBID_INDUSTRY_PROBABILITY
Called to determine if the given industry type is available.
Definition newgrf_callbacks.h:89
CBID_INDUSTRY_REFUSE_CARGO
@ CBID_INDUSTRY_REFUSE_CARGO
Called to determine if the industry can still accept or refuse more cargo arrival.
Definition newgrf_callbacks.h:182
CBID_INDUSTRY_LOCATION
@ CBID_INDUSTRY_LOCATION
Called to determine if the given industry can be built on specific area.
Definition newgrf_callbacks.h:110
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
GetCargoTranslation
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
Definition newgrf_cargo.cpp:80
newgrf_cargo.h
Cargo support for NewGRFs.
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition newgrf_commons.cpp:517
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
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
MapNewGRFIndustryType
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32_t grf_id)
Map the GRF local type to an industry type.
Definition newgrf_industries.cpp:41
GetCountAndDistanceOfClosestInstance
static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &object, uint8_t param_set_id, uint8_t layout_filter, bool town_filter, const Industry *current)
Implementation of both var 67 and 68 since the mechanism is almost the same, it is easier to regroup ...
Definition newgrf_industries.cpp:117
CheckIfCallBackAllowsCreation
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, size_t layout, uint32_t seed, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check that the industry callback allows creation of the industry.
Definition newgrf_industries.cpp:545
GetIndustryCallback
uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile, std::span< int32_t > regs100)
Perform an industry callback.
Definition newgrf_industries.cpp:528
IndustryProductionCallback
void IndustryProductionCallback(Industry *ind, int reason)
Get the industry production callback and apply it to the industry.
Definition newgrf_industries.cpp:605
GetIndustryProbabilityCallback
uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
Definition newgrf_industries.cpp:577
IndustryTemporarilyRefusesCargo
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoType cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
Definition newgrf_industries.cpp:687
GetGrffile
static const GRFFile * GetGrffile(IndustryType type)
Get the grf file associated with the given industry type.
Definition newgrf_industries.cpp:462
newgrf_industries.h
Functions for NewGRF industries.
GetIndustryIDAtOffset
uint32_t GetIndustryIDAtOffset(TileIndex new_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
MapNewGRFIndustryType
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32_t grf_id)
Map the GRF local type to an industry type.
Definition newgrf_industries.cpp:41
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
newgrf_town.h
Functions to handle the town part of NewGRF towns.
random_func.hpp
Pseudo random number generator.
safeguards.h
A number of safeguards to prevent using unsafe methods.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
strings_func.h
Functions related to OTTD's strings.
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition company_base.h:114
Company
Definition company_base.h:127
Company::GetCompanyRecolourOffset
uint8_t GetCompanyRecolourOffset(LiveryScheme livery_scheme, bool use_secondary=true) const
Get offset for recolour palette of specific company.
Definition company_base.h:189
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
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
GRFFile::cargo_map
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoType -> local ID)
Definition newgrf.h:136
IndustriesResolverObject
Resolver for industries.
Definition newgrf_industries.h:42
IndustriesResolverObject::IndustriesResolverObject
IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32_t random_bits=0, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Constructor of the industries resolver.
Definition newgrf_industries.cpp:478
IndustriesResolverObject::town_scope
std::optional< TownScopeResolver > town_scope
Scope resolver for the associated town (if needed and available, else std::nullopt).
Definition newgrf_industries.h:44
IndustriesResolverObject::GetTown
TownScopeResolver * GetTown()
Get or create the town scope object associated with the industry.
Definition newgrf_industries.cpp:490
IndustriesResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_industries.cpp:507
IndustriesResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_industries.cpp:512
IndustriesResolverObject::industries_scope
IndustriesScopeResolver industries_scope
Scope resolver for the industry.
Definition newgrf_industries.h:43
IndustriesScopeResolver::GetRandomTriggers
uint32_t GetRandomTriggers() const override
Get the triggers.
Definition newgrf_industries.cpp:435
IndustriesScopeResolver::type
IndustryType type
Type of the industry.
Definition newgrf_industries.h:19
IndustriesScopeResolver::random_bits
uint32_t random_bits
Random bits of the new industry.
Definition newgrf_industries.h:20
IndustriesScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
Definition newgrf_industries.cpp:165
IndustriesScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_industries.cpp:430
IndustriesScopeResolver::StorePSA
void StorePSA(uint pos, int32_t value) override
Store a value into the persistent storage area (PSA).
Definition newgrf_industries.cpp:440
IndustriesScopeResolver::tile
TileIndex tile
Tile owned by the industry.
Definition newgrf_industries.h:17
IndustriesScopeResolver::industry
Industry * industry
Industry being resolved.
Definition newgrf_industries.h:18
IndustryProductionSpriteGroup
Definition newgrf_spritegroup.h:247
IndustrySpec
Defines the data structure for constructing industry.
Definition industrytype.h:103
IndustrySpec::callback_mask
IndustryCallbackMasks callback_mask
Bitmask of industry callbacks that have to be called.
Definition industrytype.h:132
IndustrySpec::grf_prop
SubstituteGRFFileProps grf_prop
properties related to the grf file
Definition industrytype.h:134
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition industrytype.h:123
IndustrySpec::behaviour
IndustryBehaviours behaviour
How this industry will behave, and how others entities can use it.
Definition industrytype.h:121
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition industrytype.h:152
IndustryTileSpec::grf_prop
SubstituteGRFFileProps grf_prop
properties related to the grf file
Definition industrytype.h:168
Industry::AcceptedCargo::cargo
CargoType cargo
Cargo type.
Definition industry.h:86
Industry::AcceptedCargo::waiting
uint16_t waiting
Amount of cargo waiting to processed.
Definition industry.h:87
Industry::ProducedCargo::waiting
uint16_t waiting
Amount of cargo produced.
Definition industry.h:75
Industry::ProducedCargo::cargo
CargoType cargo
Cargo type.
Definition industry.h:74
Industry::ProducedCargo::history
HistoryData< ProducedHistory > history
History of cargo produced and transported for this month and 24 previous months.
Definition industry.h:77
Industry::ProducedCargo::rate
uint8_t rate
Production rate.
Definition industry.h:76
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::construction_date
TimerGameCalendar::Date construction_date
Date of the construction of the industry.
Definition industry.h:127
Industry::ctlflags
IndustryControlFlags ctlflags
flags overriding standard behaviours
Definition industry.h:120
Industry::IsCargoAccepted
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
Definition industry.h:223
Industry::psa
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition industry.h:136
Industry::prod_level
uint8_t prod_level
general production level
Definition industry.h:112
Industry::random_colour
Colours random_colour
randomized colour of the industry, for display purpose
Definition industry.h:117
Industry::GetCargoProduced
ProducedCargoes::iterator GetCargoProduced(CargoType cargo)
Get produced cargo slot for a specific cargo type.
Definition industry.h:180
Industry::construction_type
uint8_t construction_type
Way the industry was constructed (.
Definition industry.h:128
Industry::GetProduced
const ProducedCargo & GetProduced(size_t slot) const
Safely get a produced cargo slot, or an empty data if the slot does not exist.
Definition industry.h:158
Industry::last_prod_year
TimerGameEconomy::Year last_prod_year
last economy year of production
Definition industry.h:118
Industry::produced
ProducedCargoes produced
produced cargo slots
Definition industry.h:110
Industry::random
uint16_t random
Random value used for randomisation of all kinds of things.
Definition industry.h:134
Industry::town
Town * town
Nearest town.
Definition industry.h:107
Industry::founder
Owner founder
Founder of the industry.
Definition industry.h:126
Industry::selected_layout
uint8_t selected_layout
Which tile layout was used when creating the industry.
Definition industry.h:129
Industry::accepted
AcceptedCargoes accepted
accepted cargo slots
Definition industry.h:111
Industry::GetIndustryTypeCount
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition industry.h:264
Industry::GetAccepted
const AcceptedCargo & GetAccepted(size_t slot) const
Safely get an accepted cargo slot, or an empty data if the slot does not exist.
Definition industry.h:169
Industry::location
TileArea location
Location of the industry.
Definition industry.h:106
Industry::counter
uint16_t counter
used for animation and/or production (if available cargo)
Definition industry.h:113
Industry::was_cargo_delivered
uint8_t was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station....
Definition industry.h:119
Industry::TileBelongsToIndustry
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition industry.h:148
Industry::GetCargoAccepted
AcceptedCargoes::iterator GetCargoAccepted(CargoType cargo)
Get accepted cargo slot for a specific cargo type.
Definition industry.h:202
Industry::industries
static std::array< FlatSet< IndustryID >, NUM_INDUSTRYTYPES > industries
List of industries of each type.
Definition industry.h:276
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
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition tilearea_type.h:21
PersistentStorageArray::GetValue
TYPE GetValue(uint pos) const
Gets the value from a given position.
Definition newgrf_storage.h:108
PersistentStorageArray::StoreValue
void StoreValue(uint pos, int32_t value)
Stores some value at a given position.
Definition newgrf_storage.h:80
PersistentStorage
Class for pooled persistent storage of data.
Definition newgrf_storage.h:199
PoolID
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_persistent_storage_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition pool_type.hpp:357
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Definition pool_type.hpp:398
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition newgrf_spritegroup.h:352
ResolverObject::GetRegister
int32_t GetRegister(uint i) const
Gets the value of a so-called newgrf "register".
Definition newgrf_spritegroup.h:324
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition newgrf_spritegroup.h:340
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
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 > >
SubstituteGRFFileProps::override_id
uint16_t override_id
id of the entity been replaced by
Definition newgrf_commons.h:469
TownScopeResolver
Scope resolver for a town.
Definition newgrf_town.h:22
Town
Town data structure.
Definition town.h:63
Town::xy
TileIndex xy
town center tile
Definition town.h:64
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition tile_map.cpp:116
GetAnimationFrame
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
TILE_HEIGHT
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18
timer_game_calendar.h
Definition of the game-calendar-timer.
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
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3176
window_func.h
Window functions not directly related to making/drawing windows.
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition window_type.h:368