OpenTTD Source: src/newgrf_industries.cpp Source File

OpenTTD Source 14.0-beta3

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 <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "debug.h"
12 #include "industry.h"
13 #include "newgrf_industries.h"
14 #include "newgrf_town.h"
15 #include "newgrf_cargo.h"
16 #include "window_func.h"
17 #include "town.h"
18 #include "company_base.h"
19 #include "error.h"
20 #include "strings_func.h"
21 #include "core/random_func.hpp"
22 #include "timer/timer_game_calendar.h"
23
24 #include "table/strings.h"
25
26 #include "safeguards.h"
27
28 /* Since the industry IDs defined by the GRF file don't necessarily correlate
29 * to those used by the game, the IDs used for overriding old industries must be
30 * translated when the idustry spec is set. */
31 IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
32 IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
33
40 IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32_t grf_id)
41 {
42 if (grf_type == IT_INVALID) return IT_INVALID;
43 if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 7);
44
45 return _industry_mngr.GetID(GB(grf_type, 0, 7), grf_id);
46 }
47
56 uint32_t GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32_t cur_grfid)
57 {
58 if (!i->TileBelongsToIndustry(tile)) {
59 /* No industry and/or the tile does not have the same industry as the one we match it with */
60 return 0xFFFF;
61 }
62
63 IndustryGfx gfx = GetCleanIndustryGfx(tile);
64 const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
65
66 if (gfx < NEW_INDUSTRYTILEOFFSET) { // Does it belongs to an old type?
67 /* It is an old tile. We have to see if it's been overridden */
68 if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden?
69 return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
70 }
71 /* Overridden */
72 const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override);
73
74 if (tile_ovr->grf_prop.grffile->grfid == cur_grfid) {
75 return tile_ovr->grf_prop.local_id; // same grf file
76 } else {
77 return 0xFFFE; // not the same grf file
78 }
79 }
80 /* Not an 'old type' tile */
81 if (indtsp->grf_prop.spritegroup[0] != nullptr) { // tile has a spritegroup ?
82 if (indtsp->grf_prop.grffile->grfid == cur_grfid) { // same industry, same grf ?
83 return indtsp->grf_prop.local_id;
84 } else {
85 return 0xFFFE; // Defined in another grf file
86 }
87 }
88 /* The tile has no spritegroup */
89 return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give it the substitute
90 }
91
92 static uint32_t GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current)
93 {
94 uint32_t best_dist = UINT32_MAX;
95 for (const Industry *i : Industry::Iterate()) {
96 if (i->type != type || i == current) continue;
97
98 best_dist = std::min(best_dist, DistanceManhattan(tile, i->location.tile));
99 }
100
101 return best_dist;
102 }
103
114 static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, bool town_filter, const Industry *current)
115 {
116 uint32_t GrfID = GetRegister(0x100);
117 IndustryType ind_index;
118 uint32_t closest_dist = UINT32_MAX;
119 byte count = 0;
120
121 /* Determine what will be the industry type to look for */
122 switch (GrfID) {
123 case 0: // this is a default industry type
124 ind_index = param_setID;
125 break;
126
127 case 0xFFFFFFFF: // current grf
128 GrfID = GetIndustrySpec(current->type)->grf_prop.grffile->grfid;
129 [[fallthrough]];
130
131 default: // use the grfid specified in register 100h
132 SetBit(param_setID, 7); // bit 7 means it is not an old type
133 ind_index = MapNewGRFIndustryType(param_setID, GrfID);
134 break;
135 }
136
137 /* If the industry type is invalid, there is none and the closest is far away. */
138 if (ind_index >= NUM_INDUSTRYTYPES) return 0 | 0xFFFF;
139
140 if (layout_filter == 0 && !town_filter) {
141 /* If the filter is 0, it could be because none was specified as well as being really a 0.
142 * In either case, just do the regular var67 */
143 closest_dist = GetClosestIndustry(current->location.tile, ind_index, current);
144 count = ClampTo<byte>(Industry::GetIndustryTypeCount(ind_index));
145 } else {
146 /* Count only those who match the same industry type and layout filter
147 * Unfortunately, we have to do it manually */
148 for (const Industry *i : Industry::Iterate()) {
149 if (i->type == ind_index && i != current && (i->selected_layout == layout_filter || layout_filter == 0) && (!town_filter || i->town == current->town)) {
150 closest_dist = std::min(closest_dist, DistanceManhattan(current->location.tile, i->location.tile));
151 count++;
152 }
153 }
154 }
155
156 return count << 16 | GB(closest_dist, 0, 16);
157 }
158
159 /* virtual */ uint32_t IndustriesScopeResolver::GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const
160 {
161 if (this->ro.callback == CBID_INDUSTRY_LOCATION) {
162 /* Variables available during construction check. */
163
164 switch (variable) {
165 case 0x80: return this->tile.base();
166 case 0x81: return GB(this->tile.base(), 8, 8);
167
168 /* Pointer to the town the industry is associated with */
169 case 0x82: return this->industry->town->index;
170 case 0x83:
171 case 0x84:
172 case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
173
174 /* Number of the layout */
175 case 0x86: return this->industry->selected_layout;
176
177 /* Ground type */
178 case 0x87: return GetTerrainType(this->tile);
179
180 /* Town zone */
181 case 0x88: return GetTownRadiusGroup(this->industry->town, this->tile);
182
183 /* Manhattan distance of the closest town */
184 case 0x89: return ClampTo<uint8_t>(DistanceManhattan(this->industry->town->xy, this->tile));
185
186 /* Lowest height of the tile */
187 case 0x8A: return ClampTo<uint8_t>(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT));
188
189 /* Distance to the nearest water/land tile */
190 case 0x8B: return GetClosestWaterDistance(this->tile, (GetIndustrySpec(this->industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
191
192 /* Square of Euclidian distance from town */
193 case 0x8D: return ClampTo<uint16_t>(DistanceSquare(this->industry->town->xy, this->tile));
194
195 /* 32 random bits */
196 case 0x8F: return this->random_bits;
197 }
198 }
199
200 const IndustrySpec *indspec = GetIndustrySpec(this->type);
201
202 if (this->industry == nullptr) {
203 Debug(grf, 1, "Unhandled variable 0x{:X} (no available industry) in callback 0x{:x}", variable, this->ro.callback);
204
205 *available = false;
206 return UINT_MAX;
207 }
208
209 switch (variable) {
210 case 0x40:
211 case 0x41:
212 case 0x42: { // waiting cargo, but only if those two callback flags are set
213 uint16_t callback = indspec->callback_mask;
214 if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
215 if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) {
216 if (this->industry->prod_level == 0) return 0;
217 return ClampTo<uint16_t>(this->industry->accepted[variable - 0x40].waiting / this->industry->prod_level);
218 } else {
219 return ClampTo<uint16_t>(this->industry->accepted[variable - 0x40].waiting);
220 }
221 } else {
222 return 0;
223 }
224 }
225
226 /* Manhattan distance of closes dry/water tile */
227 case 0x43:
228 if (this->tile == INVALID_TILE) break;
229 return GetClosestWaterDistance(this->tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
230
231 /* Layout number */
232 case 0x44: return this->industry->selected_layout;
233
234 /* Company info */
235 case 0x45: {
236 byte colours = 0;
237 bool is_ai = false;
238
239 const Company *c = Company::GetIfValid(this->industry->founder);
240 if (c != nullptr) {
241 const Livery *l = &c->livery[LS_DEFAULT];
242
243 is_ai = c->is_ai;
244 colours = l->colour1 + l->colour2 * 16;
245 }
246
247 return this->industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
248 }
249
250 case 0x46: return this->industry->construction_date.base(); // Date when built - long format - (in days)
251
252 /* Override flags from GS */
253 case 0x47: return this->industry->ctlflags;
254
255 /* Get industry ID at offset param */
256 case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->industry->location.tile, false), this->industry, this->ro.grffile->grfid);
257
258 /* Get random tile bits at offset param */
259 case 0x61: {
260 if (this->tile == INVALID_TILE) break;
261 TileIndex tile = GetNearbyTile(parameter, this->tile, false);
262 return this->industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0;
263 }
264
265 /* Land info of nearby tiles */
266 case 0x62:
267 if (this->tile == INVALID_TILE) break;
268 return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro.grffile->grf_version >= 8);
269
270 /* Animation stage of nearby tiles */
271 case 0x63: {
272 if (this->tile == INVALID_TILE) break;
273 TileIndex tile = GetNearbyTile(parameter, this->tile, false);
274 if (this->industry->TileBelongsToIndustry(tile)) {
275 return GetAnimationFrame(tile);
276 }
277 return 0xFFFFFFFF;
278 }
279
280 /* Distance of nearest industry of given type */
281 case 0x64:
282 if (this->tile == INVALID_TILE) break;
283 return GetClosestIndustry(this->tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), this->industry);
284 /* Get town zone and Manhattan distance of closest town */
285 case 0x65: {
286 if (this->tile == INVALID_TILE) break;
287 TileIndex tile = GetNearbyTile(parameter, this->tile, true);
288 return GetTownRadiusGroup(this->industry->town, tile) << 16 | ClampTo<uint16_t>(DistanceManhattan(tile, this->industry->town->xy));
289 }
290 /* Get square of Euclidian distance of closest town */
291 case 0x66: {
292 if (this->tile == INVALID_TILE) break;
293 TileIndex tile = GetNearbyTile(parameter, this->tile, true);
294 return DistanceSquare(tile, this->industry->town->xy);
295 }
296
297 /* Count of industry, distance of closest instance
298 * 68 is the same as 67, but with a filtering on selected layout */
299 case 0x67:
300 case 0x68: {
301 byte layout_filter = 0;
302 bool town_filter = false;
303 if (variable == 0x68) {
304 uint32_t reg = GetRegister(0x101);
305 layout_filter = GB(reg, 0, 8);
306 town_filter = HasBit(reg, 8);
307 }
308 return GetCountAndDistanceOfClosestInstance(parameter, layout_filter, town_filter, this->industry);
309 }
310
311 case 0x69:
312 case 0x6A:
313 case 0x6B:
314 case 0x6C:
315 case 0x6D:
316 case 0x70:
317 case 0x71: {
318 CargoID cargo = GetCargoTranslation(parameter, this->ro.grffile);
319 if (!IsValidCargoID(cargo)) return 0;
320 auto it = this->industry->GetCargoProduced(cargo);
321 if (it == std::end(this->industry->produced)) return 0; // invalid cargo
322 switch (variable) {
323 case 0x69: return it->waiting;
324 case 0x6A: return it->history[THIS_MONTH].production;
325 case 0x6B: return it->history[THIS_MONTH].transported;
326 case 0x6C: return it->history[LAST_MONTH].production;
327 case 0x6D: return it->history[LAST_MONTH].transported;
328 case 0x70: return it->rate;
329 case 0x71: return it->history[LAST_MONTH].PctTransported();
330 default: NOT_REACHED();
331 }
332 }
333
334
335 case 0x6E:
336 case 0x6F: {
337 CargoID cargo = GetCargoTranslation(parameter, this->ro.grffile);
338 if (!IsValidCargoID(cargo)) return 0;
339 auto it = this->industry->GetCargoAccepted(cargo);
340 if (it == std::end(this->industry->accepted)) return 0; // invalid cargo
341 if (variable == 0x6E) return it->last_accepted.base();
342 if (variable == 0x6F) return it->waiting;
343 NOT_REACHED();
344 }
345
346 /* Get a variable from the persistent storage */
347 case 0x7C: return (this->industry->psa != nullptr) ? this->industry->psa->GetValue(parameter) : 0;
348
349 /* Industry structure access*/
350 case 0x80: return this->industry->location.tile.base();
351 case 0x81: return GB(this->industry->location.tile.base(), 8, 8);
352 /* Pointer to the town the industry is associated with */
353 case 0x82: return this->industry->town->index;
354 case 0x83:
355 case 0x84:
356 case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
357 case 0x86: return this->industry->location.w;
358 case 0x87: return this->industry->location.h;// xy dimensions
359
360 case 0x88:
361 case 0x89: return this->industry->produced[variable - 0x88].cargo;
362 case 0x8A: return this->industry->produced[0].waiting;
363 case 0x8B: return GB(this->industry->produced[0].waiting, 8, 8);
364 case 0x8C: return this->industry->produced[1].waiting;
365 case 0x8D: return GB(this->industry->produced[1].waiting, 8, 8);
366 case 0x8E:
367 case 0x8F: return this->industry->produced[variable - 0x8E].rate;
368 case 0x90:
369 case 0x91:
370 case 0x92: return this->industry->accepted[variable - 0x90].cargo;
371 case 0x93: return this->industry->prod_level;
372 /* amount of cargo produced so far THIS month. */
373 case 0x94: return this->industry->produced[0].history[THIS_MONTH].production;
374 case 0x95: return GB(this->industry->produced[0].history[THIS_MONTH].production, 8, 8);
375 case 0x96: return this->industry->produced[1].history[THIS_MONTH].production;
376 case 0x97: return GB(this->industry->produced[1].history[THIS_MONTH].production, 8, 8);
377 /* amount of cargo transported so far THIS month. */
378 case 0x98: return this->industry->produced[0].history[THIS_MONTH].transported;
379 case 0x99: return GB(this->industry->produced[0].history[THIS_MONTH].transported, 8, 8);
380 case 0x9A: return this->industry->produced[1].history[THIS_MONTH].transported;
381 case 0x9B: return GB(this->industry->produced[1].history[THIS_MONTH].transported, 8, 8);
382 /* fraction of cargo transported LAST month. */
383 case 0x9C:
384 case 0x9D: return this->industry->produced[variable - 0x9C].history[LAST_MONTH].PctTransported();
385 /* amount of cargo produced LAST month. */
386 case 0x9E: return this->industry->produced[0].history[LAST_MONTH].production;
387 case 0x9F: return GB(this->industry->produced[0].history[LAST_MONTH].production, 8, 8);
388 case 0xA0: return this->industry->produced[1].history[LAST_MONTH].production;
389 case 0xA1: return GB(this->industry->produced[1].history[LAST_MONTH].production, 8, 8);
390 /* amount of cargo transported last month. */
391 case 0xA2: return this->industry->produced[0].history[LAST_MONTH].transported;
392 case 0xA3: return GB(this->industry->produced[0].history[LAST_MONTH].transported, 8, 8);
393 case 0xA4: return this->industry->produced[1].history[LAST_MONTH].transported;
394 case 0xA5: return GB(this->industry->produced[1].history[LAST_MONTH].transported, 8, 8);
395
396 case 0xA6: return indspec->grf_prop.local_id;
397 case 0xA7: return this->industry->founder;
398 case 0xA8: return this->industry->random_colour;
399 case 0xA9: return ClampTo<uint8_t>(this->industry->last_prod_year - EconomyTime::ORIGINAL_BASE_YEAR);
400 case 0xAA: return this->industry->counter;
401 case 0xAB: return GB(this->industry->counter, 8, 8);
402 case 0xAC: return this->industry->was_cargo_delivered;
403
404 case 0xB0: return ClampTo<uint16_t>(this->industry->construction_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date when built since 1920 (in days)
405 case 0xB3: return this->industry->construction_type; // Construction type
406 case 0xB4: {
407 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; });
408 return ClampTo<uint16_t>(it->last_accepted - EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days)
409 }
410 }
411
412 Debug(grf, 1, "Unhandled industry variable 0x{:X}", variable);
413
414 *available = false;
415 return UINT_MAX;
416 }
417
418 /* virtual */ uint32_t IndustriesScopeResolver::GetRandomBits() const
419 {
420 return this->industry != nullptr ? this->industry->random : 0;
421 }
422
423 /* virtual */ uint32_t IndustriesScopeResolver::GetTriggers() const
424 {
425 return 0;
426 }
427
428 /* virtual */ void IndustriesScopeResolver::StorePSA(uint pos, int32_t value)
429 {
430 if (this->industry->index == INVALID_INDUSTRY) return;
431
432 if (this->industry->psa == nullptr) {
433 /* There is no need to create a storage if the value is zero. */
434 if (value == 0) return;
435
436 /* Create storage on first modification. */
437 const IndustrySpec *indsp = GetIndustrySpec(this->industry->type);
438 uint32_t grfid = (indsp->grf_prop.grffile != nullptr) ? indsp->grf_prop.grffile->grfid : 0;
439 assert(PersistentStorage::CanAllocateItem());
440 this->industry->psa = new PersistentStorage(grfid, GSF_INDUSTRIES, this->industry->location.tile);
441 }
442
443 this->industry->psa->StoreValue(pos, value);
444 }
445
451 static const GRFFile *GetGrffile(IndustryType type)
452 {
453 const IndustrySpec *indspec = GetIndustrySpec(type);
454 return (indspec != nullptr) ? indspec->grf_prop.grffile : nullptr;
455 }
456
467 IndustriesResolverObject::IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32_t random_bits,
468 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
469 : ResolverObject(GetGrffile(type), callback, callback_param1, callback_param2),
470 industries_scope(*this, tile, indus, type, random_bits),
471 town_scope(nullptr)
472 {
473 this->root_spritegroup = GetIndustrySpec(type)->grf_prop.spritegroup[0];
474 }
475
476 IndustriesResolverObject::~IndustriesResolverObject()
477 {
478 delete this->town_scope;
479 }
480
485 TownScopeResolver *IndustriesResolverObject::GetTown()
486 {
487 if (this->town_scope == nullptr) {
488 Town *t = nullptr;
489 bool readonly = true;
490 if (this->industries_scope.industry != nullptr) {
491 t = this->industries_scope.industry->town;
492 readonly = this->industries_scope.industry->index == INVALID_INDUSTRY;
493 } else if (this->industries_scope.tile != INVALID_TILE) {
494 t = ClosestTownFromTile(this->industries_scope.tile, UINT_MAX);
495 }
496 if (t == nullptr) return nullptr;
497 this->town_scope = new TownScopeResolver(*this, t, readonly);
498 }
499 return this->town_scope;
500 }
501
502 GrfSpecFeature IndustriesResolverObject::GetFeature() const
503 {
504 return GSF_INDUSTRIES;
505 }
506
507 uint32_t IndustriesResolverObject::GetDebugID() const
508 {
509 return GetIndustrySpec(this->industries_scope.type)->grf_prop.local_id;
510 }
511
522 uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile)
523 {
524 IndustriesResolverObject object(tile, industry, type, 0, callback, param1, param2);
525 return object.ResolveCallback();
526 }
527
539 CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, size_t layout, uint32_t seed, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
540 {
541 const IndustrySpec *indspec = GetIndustrySpec(type);
542
543 Industry ind;
544 ind.index = INVALID_INDUSTRY;
545 ind.location.tile = tile;
546 ind.location.w = 0; // important to mark the industry invalid
547 ind.type = type;
548 ind.selected_layout = (byte)layout;
549 ind.town = ClosestTownFromTile(tile, UINT_MAX);
550 ind.random = initial_random_bits;
551 ind.founder = founder;
552 ind.psa = nullptr;
553
554 IndustriesResolverObject object(tile, &ind, type, seed, CBID_INDUSTRY_LOCATION, 0, creation_type);
555 uint16_t result = object.ResolveCallback();
556
557 /* Unlike the "normal" cases, not having a valid result means we allow
558 * the building of the industry, as that's how it's done in TTDP. */
559 if (result == CALLBACK_FAILED) return CommandCost();
560
561 return GetErrorMessageFromLocationCallbackResult(result, indspec->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE);
562 }
563
570 uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
571 {
572 const IndustrySpec *indspec = GetIndustrySpec(type);
573
574 if (HasBit(indspec->callback_mask, CBM_IND_PROBABILITY)) {
575 uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, creation_type, nullptr, type, INVALID_TILE);
576 if (res != CALLBACK_FAILED) {
577 if (indspec->grf_prop.grffile->grf_version < 8) {
578 /* Disallow if result != 0 */
579 if (res != 0) default_prob = 0;
580 } else {
581 /* Use returned probability. 0x100 to use default */
582 if (res < 0x100) {
583 default_prob = res;
584 } else if (res > 0x100) {
585 ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_PROBABILITY, res);
586 }
587 }
588 }
589 }
590 return default_prob;
591 }
592
593 static int32_t DerefIndProd(int field, bool use_register)
594 {
595 return use_register ? (int32_t)GetRegister(field) : field;
596 }
597
603 void IndustryProductionCallback(Industry *ind, int reason)
604 {
605 const IndustrySpec *spec = GetIndustrySpec(ind->type);
606 IndustriesResolverObject object(ind->location.tile, ind, ind->type);
607 if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random();
608 int multiplier = 1;
609 if ((spec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) multiplier = ind->prod_level;
610 object.callback_param2 = reason;
611
612 for (uint loop = 0;; loop++) {
613 /* limit the number of calls to break infinite loops.
614 * 'loop' is provided as 16 bits to the newgrf, so abort when those are exceeded. */
615 if (loop >= 0x10000) {
616 /* display error message */
617 SetDParamStr(0, spec->grf_prop.grffile->filename);
618 SetDParam(1, spec->name);
619 ShowErrorMessage(STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_ENDLESS_PRODUCTION_CALLBACK, WL_WARNING);
620
621 /* abort the function early, this error isn't critical and will allow the game to continue to run */
622 break;
623 }
624
625 SB(object.callback_param2, 8, 16, loop);
626 const SpriteGroup *tgroup = object.Resolve();
627 if (tgroup == nullptr || tgroup->type != SGT_INDUSTRY_PRODUCTION) break;
628 const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup;
629
630 if (group->version == 0xFF) {
631 /* Result was marked invalid on load, display error message */
632 SetDParamStr(0, spec->grf_prop.grffile->filename);
633 SetDParam(1, spec->name);
634 SetDParam(2, ind->location.tile);
635 ShowErrorMessage(STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_INVALID_CARGO_PRODUCTION_CALLBACK, WL_WARNING);
636
637 /* abort the function early, this error isn't critical and will allow the game to continue to run */
638 break;
639 }
640
641 bool deref = (group->version >= 1);
642
643 if (group->version < 2) {
644 /* Callback parameters map directly to industry cargo slot indices */
645 for (uint i = 0; i < group->num_input; i++) {
646 if (!IsValidCargoID(ind->accepted[i].cargo)) continue;
647 ind->accepted[i].waiting = ClampTo<uint16_t>(ind->accepted[i].waiting - DerefIndProd(group->subtract_input[i], deref) * multiplier);
648 }
649 for (uint i = 0; i < group->num_output; i++) {
650 if (!IsValidCargoID(ind->produced[i].cargo)) continue;
651 ind->produced[i].waiting = ClampTo<uint16_t>(ind->produced[i].waiting + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier);
652 }
653 } else {
654 /* Callback receives list of cargos to apply for, which need to have their cargo slots in industry looked up */
655 for (uint i = 0; i < group->num_input; i++) {
656 auto it = ind->GetCargoAccepted(group->cargo_input[i]);
657 if (it == std::end(ind->accepted)) continue;
658 it->waiting = ClampTo<uint16_t>(it->waiting - DerefIndProd(group->subtract_input[i], deref) * multiplier);
659 }
660 for (uint i = 0; i < group->num_output; i++) {
661 auto it = ind->GetCargoProduced(group->cargo_output[i]);
662 if (it == std::end(ind->produced)) continue;
663 it->waiting = ClampTo<uint16_t>(it->waiting + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier);
664 }
665 }
666
667 int32_t again = DerefIndProd(group->again, deref);
668 if (again == 0) break;
669
670 SB(object.callback_param2, 24, 8, again);
671 }
672
673 SetWindowDirty(WC_INDUSTRY_VIEW, ind->index);
674 }
675
683 bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
684 {
685 assert(ind->IsCargoAccepted(cargo_type));
686
687 const IndustrySpec *indspec = GetIndustrySpec(ind->type);
688 if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
689 uint16_t res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
690 0, indspec->grf_prop.grffile->cargo_map[cargo_type],
691 ind, ind->type, ind->location.tile);
692 if (res != CALLBACK_FAILED) return !ConvertBooleanCallback(indspec->grf_prop.grffile, CBID_INDUSTRY_REFUSE_CARGO, res);
693 }
694 return false;
695 }
IndustriesScopeResolver::StorePSA
void StorePSA(uint pos, int32_t value) override
Store a value into the persistent storage area (PSA).
Definition: newgrf_industries.cpp:428
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:95
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:467
CBM_IND_PRODUCTION_CARGO_ARRIVAL
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
Definition: newgrf_callbacks.h:365
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 INV...
Definition: industry_type.h:26
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
IndustriesScopeResolver::tile
TileIndex tile
Tile owned by the industry.
Definition: newgrf_industries.h:17
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
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
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
IndustryProductionSpriteGroup::num_output
uint8_t num_output
How many add_output values are valid.
Definition: newgrf_spritegroup.h:275
IndustriesScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition: newgrf_industries.cpp:418
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
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
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:25
IndustriesResolverObject::GetTown
TownScopeResolver * GetTown()
Get or create the town scope object associated with the industry.
Definition: newgrf_industries.cpp:485
company_base.h
timer_game_calendar.h
GetClosestWaterDistance
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
Definition: map.cpp:342
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition: window_type.h:363
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
IndustryOverrideManager
Definition: newgrf_commons.h:234
GetRegister
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Definition: newgrf_spritegroup.h:29
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
IndustriesScopeResolver::GetTriggers
uint32_t GetTriggers() const override
Get the triggers.
Definition: newgrf_industries.cpp:423
Industry::was_cargo_delivered
byte was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station....
Definition: industry.h:108
IndustryProductionSpriteGroup::add_output
uint16_t add_output[INDUSTRY_NUM_OUTPUTS]
Add this much output cargo when successful (unsigned, is indirect in cb version 1+)
Definition: newgrf_spritegroup.h:276
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
IndustriesScopeResolver::industry
Industry * industry
Industry being resolved.
Definition: newgrf_industries.h:18
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition: newgrf_spritegroup.h:335
CBID_INDUSTRY_PROBABILITY
@ CBID_INDUSTRY_PROBABILITY
Called to determine if the given industry type is available.
Definition: newgrf_callbacks.h:87
IndustriesResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_industries.cpp:502
IndustriesScopeResolver::random_bits
uint32_t random_bits
Random bits of the new industry.
Definition: newgrf_industries.h:20
IndustriesResolverObject::town_scope
TownScopeResolver * town_scope
Scope resolver for the associated town (if needed and available, else nullptr).
Definition: newgrf_industries.h:44
Industry::produced
ProducedCargoArray produced
INDUSTRY_NUM_OUTPUTS production cargo slots.
Definition: industry.h:99
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
Industry::GetCargoProduced
ProducedCargoArray::iterator GetCargoProduced(CargoID cargo)
Get produced cargo slot for a specific cargo type.
Definition: industry.h:147
town.h
CBM_IND_PRODUCTION_256_TICKS
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
Definition: newgrf_callbacks.h:366
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
Industry::construction_type
uint8_t construction_type
Way the industry was constructed (.
Definition: industry.h:117
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
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
Industry::ctlflags
IndustryControlFlags ctlflags
flags overriding standard behaviours
Definition: industry.h:109
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition: tilearea_type.h:21
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
CBM_IND_PROBABILITY
@ CBM_IND_PROBABILITY
industry availability/probability callback
Definition: newgrf_callbacks.h:364
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
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
CBID_INDUSTRY_LOCATION
@ CBID_INDUSTRY_LOCATION
Called to determine if the given industry can be built on specific area.
Definition: newgrf_callbacks.h:108
GRFFileProps::override
uint16_t override
id of the entity been replaced by
Definition: newgrf_commons.h:332
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
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:539
CommandCost
Common return value for all commands.
Definition: command_type.h:23
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:96
NEW_INDUSTRYOFFSET
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
Definition: industry_type.h:25
MapNewGRFIndustryType
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32_t grf_id)
Map the GRF local type to an industry type.
Definition: newgrf_industries.cpp:40
Industry::type
IndustryType type
type of industry.
Definition: industry.h:104
IndustriesResolverObject
Resolver for industries.
Definition: newgrf_industries.h:42
IndustryProductionSpriteGroup::version
uint8_t version
Production callback version used, or 0xFF if marked invalid.
Definition: newgrf_spritegroup.h:271
PersistentStorageArray::GetValue
TYPE GetValue(uint pos) const
Gets the value from a given position.
Definition: newgrf_storage.h:108
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition: newgrf_spritegroup.h:336
IndustryProductionSpriteGroup
Definition: newgrf_spritegroup.h:268
PersistentStorage
Class for pooled persistent storage of data.
Definition: newgrf_storage.h:199
INVALID_INDUSTRYTILE
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
Definition: industry_type.h:34
INDUSTRYBEH_BUILT_ONWATER
@ INDUSTRYBEH_BUILT_ONWATER
is built on water (oil rig)
Definition: industrytype.h:63
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:570
Industry::accepted
AcceptedCargoArray accepted
INDUSTRY_NUM_INPUTS input cargo slots.
Definition: industry.h:100
industry.h
safeguards.h
IndustryProductionSpriteGroup::subtract_input
int16_t subtract_input[INDUSTRY_NUM_INPUTS]
Take this much of the input cargo (can be negative, is indirect in cb version 1+)
Definition: newgrf_spritegroup.h:273
INDUSTRYBEH_PRODCALLBACK_RANDOM
@ INDUSTRYBEH_PRODCALLBACK_RANDOM
Production callback needs random bits in var 10.
Definition: industrytype.h:77
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
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
NUM_INDUSTRYTILES
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
Definition: industry_type.h:33
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
IndustryAvailabilityCallType
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
Definition: newgrf_industries.h:82
error.h
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
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:188
stdafx.h
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:105
IndustryTileSpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:173
GetCountAndDistanceOfClosestInstance
static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte 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:114
IndustryProductionSpriteGroup::num_input
uint8_t num_input
How many subtract_input values are valid.
Definition: newgrf_spritegroup.h:272
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:318
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
IndustrySpec::callback_mask
uint16_t callback_mask
Bitmask of industry callbacks that have to be called.
Definition: industrytype.h:138
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:176
IndustryTemporarilyRefusesCargo
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
Definition: newgrf_industries.cpp:683
Industry::town
Town * town
Nearest town.
Definition: industry.h:97
newgrf_town.h
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
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:180
Pool::PoolItem<&_industry_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:320
strings_func.h
Industry::selected_layout
byte selected_layout
Which tile layout was used when creating the industry.
Definition: industry.h:118
Industry::counter
uint16_t counter
used for animation and/or production (if available cargo)
Definition: industry.h:102
GetGrffile
static const GRFFile * GetGrffile(IndustryType type)
Get the grf file associated with the given industry type.
Definition: newgrf_industries.cpp:451
INVALID_INDUSTRYTYPE
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
Definition: industry_type.h:27
INDUSTRYBEH_PROD_MULTI_HNDLING
@ INDUSTRYBEH_PROD_MULTI_HNDLING
Automatic production multiplier handling.
Definition: industrytype.h:76
Industry::founder
Owner founder
Founder of the industry.
Definition: industry.h:115
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
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
Industry::GetCargoAccepted
AcceptedCargoArray::iterator GetCargoAccepted(CargoID cargo)
Get accepted cargo slot for a specific cargo type.
Definition: industry.h:169
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition: livery.h:80
CBM_IND_REFUSE_CARGO
@ CBM_IND_REFUSE_CARGO
option out of accepting cargo
Definition: newgrf_callbacks.h:374
IndustrySpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:141
Industry::GetIndustryTypeCount
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:242
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:305
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:325
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
IndustriesScopeResolver::type
IndustryType type
Type of the industry.
Definition: newgrf_industries.h:19
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition: tilearea_type.h:20
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:499
IndustryTileOverrideManager
Definition: newgrf_commons.h:247
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve([[maybe_unused]] ResolverObject &object) const
Base sprite group resolver.
Definition: newgrf_spritegroup.h:61
window_func.h
IndustrySpec::behaviour
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:125
Town
Town data structure.
Definition: town.h:50
GetAnimationFrame
byte GetAnimationFrame(Tile t)
Get the current animation frame.
Definition: tile_map.h:250
IndustriesScopeResolver::GetVariable
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override
Get a variable value.
Definition: newgrf_industries.cpp:159
random_func.hpp
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
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:18
GetNearbyTile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition: newgrf_commons.cpp:406
GetIndustryRandomBits
byte GetIndustryRandomBits(Tile tile)
Get the random bits for this tile.
Definition: industry_map.h:224
IndustryProductionSpriteGroup::cargo_output
CargoID cargo_output[INDUSTRY_NUM_OUTPUTS]
Which output cargoes to add to (only cb version 2)
Definition: newgrf_spritegroup.h:277
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:103
Industry::last_prod_year
TimerGameEconomy::Year last_prod_year
last economy year of production
Definition: industry.h:107
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
NEW_INDUSTRYTILEOFFSET
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
Definition: industry_type.h:32
newgrf_industries.h
Industry::IsCargoAccepted
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
Definition: industry.h:179
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition: industry_cmd.cpp:123
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition: industrytype.h:127
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
IndustryProductionSpriteGroup::cargo_input
CargoID cargo_input[INDUSTRY_NUM_INPUTS]
Which input cargoes to take from (only cb version 2)
Definition: newgrf_spritegroup.h:274
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:319
Industry::prod_level
byte prod_level
general production level
Definition: industry.h:101
Industry::construction_date
TimerGameCalendar::Date construction_date
Date of the construction of the industry.
Definition: industry.h:116
IndustriesResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_industries.cpp:507
Industry::psa
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition: industry.h:125
Company
Definition: company_base.h:116
GetCargoTranslation
CargoID GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
Definition: newgrf_cargo.cpp:79
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition: industrytype.h:156
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
GRFFile::cargo_map
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:130
GetIndustryCallback
uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
Definition: newgrf_industries.cpp:522
Livery
Information about a particular livery.
Definition: livery.h:78
newgrf_cargo.h
IndustryProductionCallback
void IndustryProductionCallback(Industry *ind, int reason)
Get the industry production callback and apply it to the industry.
Definition: newgrf_industries.cpp:603
SpriteGroup
Definition: newgrf_spritegroup.h:57
PersistentStorageArray::StoreValue
void StoreValue(uint pos, int32_t value)
Stores some value at a given position.
Definition: newgrf_storage.h:80
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
debug.h
IndustriesResolverObject::industries_scope
IndustriesScopeResolver industries_scope
Scope resolver for the industry.
Definition: newgrf_industries.h:43
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