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