OpenTTD Source  14.0-beta1
industry_cmd.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 "clear_map.h"
12 #include "industry.h"
13 #include "station_base.h"
14 #include "landscape.h"
15 #include "viewport_func.h"
16 #include "command_func.h"
17 #include "town.h"
18 #include "news_func.h"
19 #include "cheat_type.h"
20 #include "company_base.h"
21 #include "genworld.h"
22 #include "tree_map.h"
23 #include "newgrf_cargo.h"
24 #include "newgrf_debug.h"
25 #include "newgrf_industrytiles.h"
26 #include "autoslope.h"
27 #include "water.h"
28 #include "strings_internal.h"
29 #include "window_func.h"
30 #include "vehicle_func.h"
31 #include "sound_func.h"
32 #include "animated_tile_func.h"
33 #include "effectvehicle_func.h"
34 #include "effectvehicle_base.h"
35 #include "ai/ai.hpp"
36 #include "core/pool_func.hpp"
37 #include "subsidy_func.h"
38 #include "core/backup_type.hpp"
39 #include "object_base.h"
40 #include "game/game.hpp"
41 #include "error.h"
42 #include "string_func.h"
43 #include "industry_cmd.h"
44 #include "landscape_cmd.h"
45 #include "terraform_cmd.h"
46 #include "timer/timer.h"
49 #include "timer/timer_game_tick.h"
50 
51 #include "table/strings.h"
52 #include "table/industry_land.h"
53 #include "table/build_industry.h"
54 
55 #include "safeguards.h"
56 
57 IndustryPool _industry_pool("Industry");
59 
60 void ShowIndustryViewWindow(int industry);
61 void BuildOilRig(TileIndex tile);
62 
63 static byte _industry_sound_ctr;
64 static TileIndex _industry_sound_tile;
65 
67 
68 IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
69 IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
71 
72 static int WhoCanServiceIndustry(Industry *ind);
73 
81 {
82  auto industry_insert = std::copy(std::begin(_origin_industry_specs), std::end(_origin_industry_specs), std::begin(_industry_specs));
83  std::fill(industry_insert, std::end(_industry_specs), IndustrySpec{});
84 
85  for (IndustryType i = 0; i < lengthof(_origin_industry_specs); i++) {
86  /* Enable only the current climate industries */
87  _industry_specs[i].enabled = HasBit(_industry_specs[i].climate_availability, _settings_game.game_creation.landscape);
88  }
89 
90  auto industry_tile_insert = std::copy(std::begin(_origin_industry_tile_specs), std::end(_origin_industry_tile_specs), std::begin(_industry_tile_specs));
91  std::fill(industry_tile_insert, std::end(_industry_tile_specs), IndustryTileSpec{});
92 
93  /* Reset any overrides that have been set. */
94  _industile_mngr.ResetOverride();
95  _industry_mngr.ResetOverride();
96 }
97 
106 IndustryType GetIndustryType(Tile tile)
107 {
108  assert(IsTileType(tile, MP_INDUSTRY));
109 
110  const Industry *ind = Industry::GetByTile(tile);
111  assert(ind != nullptr);
112  return ind->type;
113 }
114 
123 const IndustrySpec *GetIndustrySpec(IndustryType thistype)
124 {
125  assert(thistype < NUM_INDUSTRYTYPES);
126  return &_industry_specs[thistype];
127 }
128 
137 const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx)
138 {
139  assert(gfx < INVALID_INDUSTRYTILE);
140  return &_industry_tile_specs[gfx];
141 }
142 
143 Industry::~Industry()
144 {
145  if (CleaningPool()) return;
146 
147  /* Industry can also be destroyed when not fully initialized.
148  * This means that we do not have to clear tiles either.
149  * Also we must not decrement industry counts in that case. */
150  if (this->location.w == 0) return;
151 
152  const bool has_neutral_station = this->neutral_station != nullptr;
153 
154  for (TileIndex tile_cur : this->location) {
155  if (IsTileType(tile_cur, MP_INDUSTRY)) {
156  if (GetIndustryIndex(tile_cur) == this->index) {
157  DeleteNewGRFInspectWindow(GSF_INDUSTRYTILES, tile_cur.base());
158 
159  /* MakeWaterKeepingClass() can also handle 'land' */
160  MakeWaterKeepingClass(tile_cur, OWNER_NONE);
161  }
162  } else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
163  DeleteOilRig(tile_cur);
164  }
165  }
166 
167  if (has_neutral_station) {
168  /* Remove possible docking tiles */
169  for (TileIndex tile_cur : this->location) {
171  }
172  }
173 
174  if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
175  TileArea ta = TileArea(this->location.tile, 0, 0).Expand(21);
176 
177  /* Remove the farmland and convert it to regular tiles over time. */
178  for (TileIndex tile_cur : ta) {
179  if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
180  GetIndustryIndexOfField(tile_cur) == this->index) {
181  SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
182  }
183  }
184  }
185 
186  /* don't let any disaster vehicle target invalid industry */
188 
189  /* Clear the persistent storage. */
190  delete this->psa;
191 
192  DecIndustryTypeCount(this->type);
193 
194  DeleteIndustryNews(this->index);
196  DeleteNewGRFInspectWindow(GSF_INDUSTRIES, this->index);
197 
200 
201  for (Station *st : this->stations_near) {
202  st->RemoveIndustryToDeliver(this);
203  }
204 }
205 
211 {
212  InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_FORCE_REBUILD);
214 }
215 
216 
222 {
223  if (Industry::GetNumItems() == 0) return nullptr;
224  int num = RandomRange((uint16_t)Industry::GetNumItems());
225  size_t index = MAX_UVALUE(size_t);
226 
227  while (num >= 0) {
228  num--;
229  index++;
230 
231  /* Make sure we have a valid industry */
232  while (!Industry::IsValidID(index)) {
233  index++;
234  assert(index < Industry::GetPoolSize());
235  }
236  }
237 
238  return Industry::Get(index);
239 }
240 
241 
242 static void IndustryDrawSugarMine(const TileInfo *ti)
243 {
244  if (!IsIndustryCompleted(ti->tile)) return;
245 
246  const DrawIndustryAnimationStruct *d = &_draw_industry_spec1[GetAnimationFrame(ti->tile)];
247 
248  AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0);
249 
250  if (d->image_2 != 0) {
251  AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41);
252  }
253 
254  if (d->image_3 != 0) {
255  AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE,
256  _drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y);
257  }
258 }
259 
260 static void IndustryDrawToffeeQuarry(const TileInfo *ti)
261 {
262  uint8_t x = 0;
263 
264  if (IsIndustryCompleted(ti->tile)) {
265  x = _industry_anim_offs_toffee[GetAnimationFrame(ti->tile)];
266  if (x == 0xFF) {
267  x = 0;
268  }
269  }
270 
271  AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, PAL_NONE, 22 - x, 24 + x);
272  AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, PAL_NONE, 6, 14);
273 }
274 
275 static void IndustryDrawBubbleGenerator( const TileInfo *ti)
276 {
277  if (IsIndustryCompleted(ti->tile)) {
278  AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetAnimationFrame(ti->tile)]);
279  }
280  AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67);
281 }
282 
283 static void IndustryDrawToyFactory(const TileInfo *ti)
284 {
285  const DrawIndustryAnimationStruct *d = &_industry_anim_offs_toys[GetAnimationFrame(ti->tile)];
286 
287  if (d->image_1 != 0xFF) {
288  AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1);
289  }
290 
291  if (d->image_2 != 0xFF) {
292  AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, PAL_NONE, 16 - d->image_2 * 2, 100 + d->image_2);
293  }
294 
295  AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, PAL_NONE, 7, d->image_3);
296  AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, PAL_NONE, 0, 42);
297 }
298 
299 static void IndustryDrawCoalPlantSparks(const TileInfo *ti)
300 {
301  if (IsIndustryCompleted(ti->tile)) {
302  uint8_t image = GetAnimationFrame(ti->tile);
303 
304  if (image != 0 && image < 7) {
305  AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS,
306  PAL_NONE,
307  _coal_plant_sparks[image - 1].x,
308  _coal_plant_sparks[image - 1].y
309  );
310  }
311  }
312 }
313 
314 typedef void IndustryDrawTileProc(const TileInfo *ti);
315 static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = {
316  IndustryDrawSugarMine,
317  IndustryDrawToffeeQuarry,
318  IndustryDrawBubbleGenerator,
319  IndustryDrawToyFactory,
320  IndustryDrawCoalPlantSparks,
321 };
322 
323 static void DrawTile_Industry(TileInfo *ti)
324 {
325  IndustryGfx gfx = GetIndustryGfx(ti->tile);
326  Industry *ind = Industry::GetByTile(ti->tile);
327  const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
328 
329  /* Retrieve pointer to the draw industry tile struct */
330  if (gfx >= NEW_INDUSTRYTILEOFFSET) {
331  /* Draw the tile using the specialized method of newgrf industrytile.
332  * DrawNewIndustry will return false if ever the resolver could not
333  * find any sprite to display. So in this case, we will jump on the
334  * substitute gfx instead. */
335  if (indts->grf_prop.spritegroup[0] != nullptr && DrawNewIndustryTile(ti, ind, gfx, indts)) {
336  return;
337  } else {
338  /* No sprite group (or no valid one) found, meaning no graphics associated.
339  * Use the substitute one instead */
340  if (indts->grf_prop.subst_id != INVALID_INDUSTRYTILE) {
341  gfx = indts->grf_prop.subst_id;
342  /* And point the industrytile spec accordingly */
343  indts = GetIndustryTileSpec(gfx);
344  }
345  }
346  }
347 
348  const DrawBuildingsTileStruct *dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ?
351 
352  SpriteID image = dits->ground.sprite;
353 
354  /* DrawFoundation() modifies ti->z and ti->tileh */
356 
357  /* If the ground sprite is the default flat water sprite, draw also canal/river borders.
358  * Do not do this if the tile's WaterClass is 'land'. */
359  if (image == SPR_FLAT_WATER_TILE && IsTileOnWater(ti->tile)) {
360  DrawWaterClassGround(ti);
361  } else {
362  DrawGroundSprite(image, GroundSpritePaletteTransform(image, dits->ground.pal, GENERAL_SPRITE_COLOUR(ind->random_colour)));
363  }
364 
365  /* If industries are transparent and invisible, do not draw the upper part */
366  if (IsInvisibilitySet(TO_INDUSTRIES)) return;
367 
368  /* Add industry on top of the ground? */
369  image = dits->building.sprite;
370  if (image != 0) {
371  AddSortableSpriteToDraw(image, SpriteLayoutPaletteTransform(image, dits->building.pal, GENERAL_SPRITE_COLOUR(ind->random_colour)),
372  ti->x + dits->subtile_x,
373  ti->y + dits->subtile_y,
374  dits->width,
375  dits->height,
376  dits->dz,
377  ti->z,
379 
380  if (IsTransparencySet(TO_INDUSTRIES)) return;
381  }
382 
383  {
384  int proc = dits->draw_proc - 1;
385  if (proc >= 0) _industry_draw_tile_procs[proc](ti);
386  }
387 }
388 
389 static int GetSlopePixelZ_Industry(TileIndex tile, uint, uint, bool)
390 {
391  return GetTileMaxPixelZ(tile);
392 }
393 
394 static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
395 {
396  IndustryGfx gfx = GetIndustryGfx(tile);
397 
398  /* For NewGRF industry tiles we might not be drawing a foundation. We need to
399  * account for this, as other structures should
400  * draw the wall of the foundation in this case.
401  */
402  if (gfx >= NEW_INDUSTRYTILEOFFSET) {
403  const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
404  if (indts->grf_prop.spritegroup[0] != nullptr && HasBit(indts->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) {
405  uint32_t callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, Industry::GetByTile(tile), tile);
406  if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(indts->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res)) return FOUNDATION_NONE;
407  }
408  }
409  return FlatteningFoundation(tileh);
410 }
411 
412 static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
413 {
414  IndustryGfx gfx = GetIndustryGfx(tile);
415  const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
416  const Industry *ind = Industry::GetByTile(tile);
417 
418  /* Starting point for acceptance */
419  auto accepts_cargo = itspec->accepts_cargo;
420  auto cargo_acceptance = itspec->acceptance;
421 
423  /* Copy all accepted cargoes from industry itself */
424  for (const auto &a : ind->accepted) {
425  auto pos = std::find(std::begin(accepts_cargo), std::end(accepts_cargo), a.cargo);
426  if (pos == std::end(accepts_cargo)) {
427  /* Not found, insert */
428  pos = std::find(std::begin(accepts_cargo), std::end(accepts_cargo), INVALID_CARGO);
429  if (pos == std::end(accepts_cargo)) continue; // nowhere to place, give up on this one
430  *pos = a.cargo;
431  }
432  cargo_acceptance[std::distance(std::begin(accepts_cargo), pos)] += 8;
433  }
434  }
435 
437  /* Try callback for accepts list, if success override all existing accepts */
438  uint16_t res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, Industry::GetByTile(tile), tile);
439  if (res != CALLBACK_FAILED) {
440  accepts_cargo.fill(INVALID_CARGO);
441  for (uint i = 0; i < 3; i++) accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile);
442  }
443  }
444 
446  /* Try callback for acceptance list, if success override all existing acceptance */
447  uint16_t res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, Industry::GetByTile(tile), tile);
448  if (res != CALLBACK_FAILED) {
449  cargo_acceptance.fill(0);
450  for (uint i = 0; i < 3; i++) cargo_acceptance[i] = GB(res, i * 4, 4);
451  }
452  }
453 
454  for (byte i = 0; i < std::size(itspec->accepts_cargo); i++) {
455  CargoID a = accepts_cargo[i];
456  if (!IsValidCargoID(a) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes
457 
458  /* Add accepted cargo */
459  acceptance[a] += cargo_acceptance[i];
460 
461  /* Maybe set 'always accepted' bit (if it's not set already) */
462  if (HasBit(*always_accepted, a)) continue;
463 
464  /* Test whether the industry itself accepts the cargo type */
465  if (ind->IsCargoAccepted(a)) continue;
466 
467  /* If the industry itself doesn't accept this cargo, set 'always accepted' bit */
468  SetBit(*always_accepted, a);
469  }
470 }
471 
472 static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
473 {
474  const Industry *i = Industry::GetByTile(tile);
475  const IndustrySpec *is = GetIndustrySpec(i->type);
476 
477  td->owner[0] = i->owner;
478  td->str = is->name;
479  if (!IsIndustryCompleted(tile)) {
480  td->dparam = td->str;
481  td->str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
482  }
483 
484  if (is->grf_prop.grffile != nullptr) {
485  td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->GetName();
486  }
487 }
488 
489 static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags)
490 {
491  Industry *i = Industry::GetByTile(tile);
492  const IndustrySpec *indspec = GetIndustrySpec(i->type);
493 
494  /* water can destroy industries
495  * in editor you can bulldoze industries
496  * with magic_bulldozer cheat you can destroy industries
497  * (area around OILRIG is water, so water shouldn't flood it
498  */
499  if ((_current_company != OWNER_WATER && _game_mode != GM_EDITOR &&
501  ((flags & DC_AUTO) != 0) ||
503  ((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) ||
504  HasBit(GetIndustryTileSpec(GetIndustryGfx(tile))->slopes_refused, 5)))) {
505  SetDParam(1, indspec->name);
506  return_cmd_error(flags & DC_AUTO ? STR_ERROR_GENERIC_OBJECT_IN_THE_WAY : INVALID_STRING_ID);
507  }
508 
509  if (flags & DC_EXEC) {
510  AI::BroadcastNewEvent(new ScriptEventIndustryClose(i->index));
511  Game::NewEvent(new ScriptEventIndustryClose(i->index));
512  delete i;
513  }
515 }
516 
523 {
524  Industry *i = Industry::GetByTile(tile);
525  const IndustrySpec *indspec = GetIndustrySpec(i->type);
526  bool moved_cargo = false;
527 
528  for (auto &p : i->produced) {
529  uint cw = ClampTo<uint8_t>(p.waiting);
530  if (cw > indspec->minimal_cargo && IsValidCargoID(p.cargo)) {
531  p.waiting -= cw;
532 
533  /* fluctuating economy? */
534  if (EconomyIsInRecession()) cw = (cw + 1) / 2;
535 
536  p.history[THIS_MONTH].production += cw;
537 
538  uint am = MoveGoodsToStation(p.cargo, cw, SourceType::Industry, i->index, &i->stations_near, i->exclusive_consumer);
539  p.history[THIS_MONTH].transported += am;
540 
541  moved_cargo |= (am != 0);
542  }
543  }
544 
545  return moved_cargo;
546 }
547 
548 static void AnimateSugarSieve(TileIndex tile)
549 {
550  byte m = GetAnimationFrame(tile) + 1;
551 
553  switch (m & 7) {
554  case 2: SndPlayTileFx(SND_2D_SUGAR_MINE_1, tile); break;
555  case 6: SndPlayTileFx(SND_29_SUGAR_MINE_2, tile); break;
556  }
557  }
558 
559  if (m >= 96) {
560  m = 0;
561  DeleteAnimatedTile(tile);
562  }
563  SetAnimationFrame(tile, m);
564 
565  MarkTileDirtyByTile(tile);
566 }
567 
568 static void AnimateToffeeQuarry(TileIndex tile)
569 {
570  byte m = GetAnimationFrame(tile);
571 
572  if (_industry_anim_offs_toffee[m] == 0xFF && _settings_client.sound.ambient) {
573  SndPlayTileFx(SND_30_TOFFEE_QUARRY, tile);
574  }
575 
576  if (++m >= 70) {
577  m = 0;
578  DeleteAnimatedTile(tile);
579  }
580  SetAnimationFrame(tile, m);
581 
582  MarkTileDirtyByTile(tile);
583 }
584 
585 static void AnimateBubbleCatcher(TileIndex tile)
586 {
587  byte m = GetAnimationFrame(tile);
588 
589  if (++m >= 40) {
590  m = 0;
591  DeleteAnimatedTile(tile);
592  }
593  SetAnimationFrame(tile, m);
594 
595  MarkTileDirtyByTile(tile);
596 }
597 
598 static void AnimatePowerPlantSparks(TileIndex tile)
599 {
600  byte m = GetAnimationFrame(tile);
601  if (m == 6) {
602  SetAnimationFrame(tile, 0);
603  DeleteAnimatedTile(tile);
604  } else {
605  SetAnimationFrame(tile, m + 1);
606  MarkTileDirtyByTile(tile);
607  }
608 }
609 
610 static void AnimateToyFactory(TileIndex tile)
611 {
612  byte m = GetAnimationFrame(tile) + 1;
613 
614  switch (m) {
615  case 1: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2C_TOY_FACTORY_1, tile); break;
616  case 23: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2B_TOY_FACTORY_2, tile); break;
617  case 28: if (_settings_client.sound.ambient) SndPlayTileFx(SND_2A_TOY_FACTORY_3, tile); break;
618  default:
619  if (m >= 50) {
620  int n = GetIndustryAnimationLoop(tile) + 1;
621  m = 0;
622  if (n >= 8) {
623  n = 0;
624  DeleteAnimatedTile(tile);
625  }
626  SetIndustryAnimationLoop(tile, n);
627  }
628  }
629 
630  SetAnimationFrame(tile, m);
631  MarkTileDirtyByTile(tile);
632 }
633 
634 static void AnimatePlasticFountain(TileIndex tile, IndustryGfx gfx)
635 {
636  gfx = (gfx < GFX_PLASTIC_FOUNTAIN_ANIMATED_8) ? gfx + 1 : GFX_PLASTIC_FOUNTAIN_ANIMATED_1;
637  SetIndustryGfx(tile, gfx);
638  MarkTileDirtyByTile(tile);
639 }
640 
641 static void AnimateOilWell(TileIndex tile, IndustryGfx gfx)
642 {
643  bool b = Chance16(1, 7);
644  byte m = GetAnimationFrame(tile) + 1;
645  if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
646  SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
648  DeleteAnimatedTile(tile);
649  } else {
650  SetAnimationFrame(tile, m);
651  SetIndustryGfx(tile, gfx);
652  MarkTileDirtyByTile(tile);
653  }
654 }
655 
656 static void AnimateMineTower(TileIndex tile)
657 {
658  int state = TimerGameTick::counter & 0x7FF;
659 
660  if ((state -= 0x400) < 0) return;
661 
662  if (state < 0x1A0) {
663  if (state < 0x20 || state >= 0x180) {
664  byte m = GetAnimationFrame(tile);
665  if (!(m & 0x40)) {
666  SetAnimationFrame(tile, m | 0x40);
667  if (_settings_client.sound.ambient) SndPlayTileFx(SND_0B_MINE, tile);
668  }
669  if (state & 7) return;
670  } else {
671  if (state & 3) return;
672  }
673  byte m = (GetAnimationFrame(tile) + 1) | 0x40;
674  if (m > 0xC2) m = 0xC0;
675  SetAnimationFrame(tile, m);
676  MarkTileDirtyByTile(tile);
677  } else if (state >= 0x200 && state < 0x3A0) {
678  int i = (state < 0x220 || state >= 0x380) ? 7 : 3;
679  if (state & i) return;
680 
681  byte m = (GetAnimationFrame(tile) & 0xBF) - 1;
682  if (m < 0x80) m = 0x82;
683  SetAnimationFrame(tile, m);
684  MarkTileDirtyByTile(tile);
685  }
686 }
687 
688 static void AnimateTile_Industry(TileIndex tile)
689 {
690  IndustryGfx gfx = GetIndustryGfx(tile);
691 
692  if (GetIndustryTileSpec(gfx)->animation.status != ANIM_STATUS_NO_ANIMATION) {
693  AnimateNewIndustryTile(tile);
694  return;
695  }
696 
697  switch (gfx) {
698  case GFX_SUGAR_MINE_SIEVE:
699  if ((TimerGameTick::counter & 1) == 0) AnimateSugarSieve(tile);
700  break;
701 
702  case GFX_TOFFEE_QUARY:
703  if ((TimerGameTick::counter & 3) == 0) AnimateToffeeQuarry(tile);
704  break;
705 
706  case GFX_BUBBLE_CATCHER:
707  if ((TimerGameTick::counter & 1) == 0) AnimateBubbleCatcher(tile);
708  break;
709 
710  case GFX_POWERPLANT_SPARKS:
711  if ((TimerGameTick::counter & 3) == 0) AnimatePowerPlantSparks(tile);
712  break;
713 
714  case GFX_TOY_FACTORY:
715  if ((TimerGameTick::counter & 1) == 0) AnimateToyFactory(tile);
716  break;
717 
718  case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
719  case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
720  case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
721  case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
722  if ((TimerGameTick::counter & 3) == 0) AnimatePlasticFountain(tile, gfx);
723  break;
724 
725  case GFX_OILWELL_ANIMATED_1:
726  case GFX_OILWELL_ANIMATED_2:
727  case GFX_OILWELL_ANIMATED_3:
728  if ((TimerGameTick::counter & 7) == 0) AnimateOilWell(tile, gfx);
729  break;
730 
731  case GFX_COAL_MINE_TOWER_ANIMATED:
732  case GFX_COPPER_MINE_TOWER_ANIMATED:
733  case GFX_GOLD_MINE_TOWER_ANIMATED:
734  AnimateMineTower(tile);
735  break;
736  }
737 }
738 
739 static void CreateChimneySmoke(TileIndex tile)
740 {
741  uint x = TileX(tile) * TILE_SIZE;
742  uint y = TileY(tile) * TILE_SIZE;
743  int z = GetTileMaxPixelZ(tile);
744 
745  CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE);
746 }
747 
748 static void MakeIndustryTileBigger(TileIndex tile)
749 {
750  byte cnt = GetIndustryConstructionCounter(tile) + 1;
751  if (cnt != 4) {
753  return;
754  }
755 
756  byte stage = GetIndustryConstructionStage(tile) + 1;
758  SetIndustryConstructionStage(tile, stage);
759  StartStopIndustryTileAnimation(tile, IAT_CONSTRUCTION_STATE_CHANGE);
760  if (stage == INDUSTRY_COMPLETED) SetIndustryCompleted(tile);
761 
762  MarkTileDirtyByTile(tile);
763 
764  if (!IsIndustryCompleted(tile)) return;
765 
766  IndustryGfx gfx = GetIndustryGfx(tile);
767  if (gfx >= NEW_INDUSTRYTILEOFFSET) {
768  /* New industries are already animated on construction. */
769  return;
770  }
771 
772  switch (gfx) {
773  case GFX_POWERPLANT_CHIMNEY:
774  CreateChimneySmoke(tile);
775  break;
776 
777  case GFX_OILRIG_1: {
778  /* Do not require an industry tile to be after the first two GFX_OILRIG_1
779  * tiles (like the default oil rig). Do a proper check to ensure the
780  * tiles belong to the same industry and based on that build the oil rig's
781  * station. */
782  TileIndex other = tile + TileDiffXY(0, 1);
783 
784  if (IsTileType(other, MP_INDUSTRY) &&
785  GetIndustryGfx(other) == GFX_OILRIG_1 &&
786  GetIndustryIndex(tile) == GetIndustryIndex(other)) {
787  BuildOilRig(tile);
788  }
789  break;
790  }
791 
792  case GFX_TOY_FACTORY:
793  case GFX_BUBBLE_CATCHER:
794  case GFX_TOFFEE_QUARY:
795  SetAnimationFrame(tile, 0);
796  SetIndustryAnimationLoop(tile, 0);
797  break;
798 
799  case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
800  case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
801  case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
802  case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
803  AddAnimatedTile(tile);
804  break;
805  }
806 }
807 
808 static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
809 {
810  static const int8_t _bubble_spawn_location[3][4] = {
811  { 11, 0, -4, -14 },
812  { -4, -10, -4, 1 },
813  { 49, 59, 60, 65 },
814  };
815 
816  if (_settings_client.sound.ambient) SndPlayTileFx(SND_2E_BUBBLE_GENERATOR, tile);
817 
818  int dir = Random() & 3;
819 
821  TileX(tile) * TILE_SIZE + _bubble_spawn_location[0][dir],
822  TileY(tile) * TILE_SIZE + _bubble_spawn_location[1][dir],
823  _bubble_spawn_location[2][dir],
824  EV_BUBBLE
825  );
826 
827  if (v != nullptr) v->animation_substate = dir;
828 }
829 
830 static void TileLoop_Industry(TileIndex tile)
831 {
832  if (IsTileOnWater(tile)) TileLoop_Water(tile);
833 
834  /* Normally this doesn't happen, but if an industry NewGRF is removed
835  * an industry that was previously build on water can now be flooded.
836  * If this happens the tile is no longer an industry tile after
837  * returning from TileLoop_Water. */
838  if (!IsTileType(tile, MP_INDUSTRY)) return;
839 
841 
842  if (!IsIndustryCompleted(tile)) {
843  MakeIndustryTileBigger(tile);
844  return;
845  }
846 
847  if (_game_mode == GM_EDITOR) return;
848 
849  if (TransportIndustryGoods(tile) && !StartStopIndustryTileAnimation(Industry::GetByTile(tile), IAT_INDUSTRY_DISTRIBUTES_CARGO)) {
850  uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
851 
852  if (newgfx != INDUSTRYTILE_NOANIM) {
854  SetIndustryCompleted(tile);
855  SetIndustryGfx(tile, newgfx);
856  MarkTileDirtyByTile(tile);
857  return;
858  }
859  }
860 
861  if (StartStopIndustryTileAnimation(tile, IAT_TILELOOP)) return;
862 
863  IndustryGfx newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next;
864  if (newgfx != INDUSTRYTILE_NOANIM) {
866  SetIndustryGfx(tile, newgfx);
867  MarkTileDirtyByTile(tile);
868  return;
869  }
870 
871  IndustryGfx gfx = GetIndustryGfx(tile);
872  switch (gfx) {
873  case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
874  case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
875  case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
876  if (!(TimerGameTick::counter & 0x400) && Chance16(1, 2)) {
877  switch (gfx) {
878  case GFX_COAL_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COAL_MINE_TOWER_ANIMATED; break;
879  case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break;
880  case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_ANIMATED; break;
881  }
882  SetIndustryGfx(tile, gfx);
883  SetAnimationFrame(tile, 0x80);
884  AddAnimatedTile(tile);
885  }
886  break;
887 
888  case GFX_OILWELL_NOT_ANIMATED:
889  if (Chance16(1, 6)) {
890  SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1);
891  SetAnimationFrame(tile, 0);
892  AddAnimatedTile(tile);
893  }
894  break;
895 
896  case GFX_COAL_MINE_TOWER_ANIMATED:
897  case GFX_COPPER_MINE_TOWER_ANIMATED:
898  case GFX_GOLD_MINE_TOWER_ANIMATED:
899  if (!(TimerGameTick::counter & 0x400)) {
900  switch (gfx) {
901  case GFX_COAL_MINE_TOWER_ANIMATED: gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED; break;
902  case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break;
903  case GFX_GOLD_MINE_TOWER_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED; break;
904  }
905  SetIndustryGfx(tile, gfx);
906  SetIndustryCompleted(tile);
908  DeleteAnimatedTile(tile);
909  }
910  break;
911 
912  case GFX_POWERPLANT_SPARKS:
913  if (Chance16(1, 3)) {
914  if (_settings_client.sound.ambient) SndPlayTileFx(SND_0C_POWER_STATION, tile);
915  AddAnimatedTile(tile);
916  }
917  break;
918 
919  case GFX_COPPER_MINE_CHIMNEY:
921  break;
922 
923 
924  case GFX_TOY_FACTORY: {
925  Industry *i = Industry::GetByTile(tile);
926  if (i->was_cargo_delivered) {
927  i->was_cargo_delivered = false;
928  SetIndustryAnimationLoop(tile, 0);
929  AddAnimatedTile(tile);
930  }
931  }
932  break;
933 
934  case GFX_BUBBLE_GENERATOR:
935  TileLoopIndustry_BubbleGenerator(tile);
936  break;
937 
938  case GFX_TOFFEE_QUARY:
939  AddAnimatedTile(tile);
940  break;
941 
942  case GFX_SUGAR_MINE_SIEVE:
943  if (Chance16(1, 3)) AddAnimatedTile(tile);
944  break;
945  }
946 }
947 
948 static bool ClickTile_Industry(TileIndex tile)
949 {
950  ShowIndustryViewWindow(GetIndustryIndex(tile));
951  return true;
952 }
953 
954 static TrackStatus GetTileTrackStatus_Industry(TileIndex, TransportType, uint, DiagDirection)
955 {
956  return 0;
957 }
958 
959 static void ChangeTileOwner_Industry(TileIndex tile, Owner old_owner, Owner new_owner)
960 {
961  /* If the founder merges, the industry was created by the merged company */
962  Industry *i = Industry::GetByTile(tile);
963  if (i->founder == old_owner) i->founder = (new_owner == INVALID_OWNER) ? OWNER_NONE : new_owner;
964 
965  if (i->exclusive_supplier == old_owner) i->exclusive_supplier = new_owner;
966  if (i->exclusive_consumer == old_owner) i->exclusive_consumer = new_owner;
967 }
968 
975 {
976  /* Check for industry tile */
977  if (!IsTileType(tile, MP_INDUSTRY)) return false;
978 
979  const Industry *ind = Industry::GetByTile(tile);
980 
981  /* Check for organic industry (i.e. not processing or extractive) */
982  if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
983 
984  /* Check for wood production */
985  return std::any_of(std::begin(ind->produced), std::end(ind->produced), [](const auto &p) { return IsValidCargoID(p.cargo) && CargoSpec::Get(p.cargo)->label == 'WOOD'; });
986 }
987 
988 static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
989 
997 static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields)
998 {
999  switch (GetTileType(tile)) {
1000  case MP_CLEAR: return !IsClearGround(tile, CLEAR_SNOW) && !IsClearGround(tile, CLEAR_DESERT) && (allow_fields || !IsClearGround(tile, CLEAR_FIELDS));
1001  case MP_TREES: return GetTreeGround(tile) != TREE_GROUND_SHORE;
1002  default: return false;
1003  }
1004 }
1005 
1013 static void SetupFarmFieldFence(TileIndex tile, int size, byte type, DiagDirection side)
1014 {
1015  TileIndexDiff diff = (DiagDirToAxis(side) == AXIS_Y ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
1016 
1017  do {
1018  tile = Map::WrapToMap(tile);
1019 
1020  if (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)) {
1021  byte or_ = type;
1022 
1023  if (or_ == 1 && Chance16(1, 7)) or_ = 2;
1024 
1025  SetFence(tile, side, or_);
1026  }
1027 
1028  tile += diff;
1029  } while (--size);
1030 }
1031 
1032 static void PlantFarmField(TileIndex tile, IndustryID industry)
1033 {
1034  if (_settings_game.game_creation.landscape == LT_ARCTIC) {
1035  if (GetTileZ(tile) + 2 >= GetSnowLine()) return;
1036  }
1037 
1038  /* determine field size */
1039  uint32_t r = (Random() & 0x303) + 0x404;
1040  if (_settings_game.game_creation.landscape == LT_ARCTIC) r += 0x404;
1041  uint size_x = GB(r, 0, 8);
1042  uint size_y = GB(r, 8, 8);
1043 
1044  TileArea ta(tile - TileDiffXY(std::min(TileX(tile), size_x / 2), std::min(TileY(tile), size_y / 2)), size_x, size_y);
1045  ta.ClampToMap();
1046 
1047  if (ta.w == 0 || ta.h == 0) return;
1048 
1049  /* check the amount of bad tiles */
1050  int count = 0;
1051  for (TileIndex cur_tile : ta) {
1052  assert(cur_tile < Map::Size());
1053  count += IsSuitableForFarmField(cur_tile, false);
1054  }
1055  if (count * 2 < ta.w * ta.h) return;
1056 
1057  /* determine type of field */
1058  r = Random();
1059  uint counter = GB(r, 5, 3);
1060  uint field_type = GB(r, 8, 8) * 9 >> 8;
1061 
1062  /* make field */
1063  for (TileIndex cur_tile : ta) {
1064  assert(cur_tile < Map::Size());
1065  if (IsSuitableForFarmField(cur_tile, true)) {
1066  MakeField(cur_tile, field_type, industry);
1067  SetClearCounter(cur_tile, counter);
1068  MarkTileDirtyByTile(cur_tile);
1069  }
1070  }
1071 
1072  int type = 3;
1073  if (_settings_game.game_creation.landscape != LT_ARCTIC && _settings_game.game_creation.landscape != LT_TROPIC) {
1074  type = _plantfarmfield_type[Random() & 0xF];
1075  }
1076 
1077  SetupFarmFieldFence(ta.tile, ta.h, type, DIAGDIR_NE);
1078  SetupFarmFieldFence(ta.tile, ta.w, type, DIAGDIR_NW);
1079  SetupFarmFieldFence(ta.tile + TileDiffXY(ta.w - 1, 0), ta.h, type, DIAGDIR_SW);
1080  SetupFarmFieldFence(ta.tile + TileDiffXY(0, ta.h - 1), ta.w, type, DIAGDIR_SE);
1081 }
1082 
1083 void PlantRandomFarmField(const Industry *i)
1084 {
1085  int x = i->location.w / 2 + Random() % 31 - 16;
1086  int y = i->location.h / 2 + Random() % 31 - 16;
1087 
1088  TileIndex tile = TileAddWrap(i->location.tile, x, y);
1089 
1090  if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
1091 }
1092 
1098 static bool SearchLumberMillTrees(TileIndex tile, void *)
1099 {
1100  if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) {
1101  /* found a tree */
1102 
1103  Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
1104 
1105  _industry_sound_ctr = 1;
1106  _industry_sound_tile = tile;
1107  if (_settings_client.sound.ambient) SndPlayTileFx(SND_38_LUMBER_MILL_1, tile);
1108 
1110 
1111  cur_company.Restore();
1112  return true;
1113  }
1114  return false;
1115 }
1116 
1122 {
1123  /* Skip production if cargo slot is invalid. */
1124  if (!IsValidCargoID(i->produced[0].cargo)) return;
1125 
1126  /* We only want to cut trees if all tiles are completed. */
1127  for (TileIndex tile_cur : i->location) {
1128  if (i->TileBelongsToIndustry(tile_cur)) {
1129  if (!IsIndustryCompleted(tile_cur)) return;
1130  }
1131  }
1132 
1133  TileIndex tile = i->location.tile;
1134  if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, nullptr)) { // 40x40 tiles to search.
1135  i->produced[0].waiting = ClampTo<uint16_t>(i->produced[0].waiting + ScaleByCargoScale(45, false)); // Found a tree, add according value to waiting cargo.
1136  }
1137 }
1138 
1144 static void ProduceIndustryGoodsHelper(Industry *i, bool scale)
1145 {
1146  for (auto &p : i->produced) {
1147  if (!IsValidCargoID(p.cargo)) continue;
1148 
1149  uint16_t amount = p.rate;
1150  if (scale) amount = ScaleByCargoScale(amount, false);
1151 
1152  p.waiting = ClampTo<uint16_t>(p.waiting + amount);
1153  }
1154 }
1155 
1156 static void ProduceIndustryGoods(Industry *i)
1157 {
1158  const IndustrySpec *indsp = GetIndustrySpec(i->type);
1159 
1160  /* play a sound? */
1161  if ((i->counter & 0x3F) == 0) {
1162  uint32_t r;
1163  if (Chance16R(1, 14, r) && indsp->number_of_sounds != 0 && _settings_client.sound.ambient) {
1164  if (std::any_of(std::begin(i->produced), std::end(i->produced), [](const auto &p) { return p.history[LAST_MONTH].production > 0; })) {
1165  /* Play sound since last month had production */
1166  SndPlayTileFx(
1167  (SoundFx)(indsp->random_sounds[((r >> 16) * indsp->number_of_sounds) >> 16]),
1168  i->location.tile);
1169  }
1170  }
1171  }
1172 
1173  i->counter--;
1174 
1175  /* If using an industry callback, scale the callback interval by cargo scale percentage. */
1179  ProduceIndustryGoodsHelper(i, false);
1180  }
1181  }
1182 
1183  /*
1184  * All other production and special effects happen every 256 ticks, and cargo production is just scaled by the cargo scale percentage.
1185  * This keeps a slow trickle of production to avoid confusion at low scale factors when the industry seems to be doing nothing for a long period of time.
1186  */
1187  if ((i->counter % Ticks::INDUSTRY_PRODUCE_TICKS) == 0) {
1188  /* Handle non-callback cargo production. */
1190 
1191  IndustryBehaviour indbehav = indsp->behaviour;
1192 
1193  if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
1194  uint16_t cb_res = CALLBACK_FAILED;
1196  cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->location.tile);
1197  }
1198 
1199  bool plant;
1200  if (cb_res != CALLBACK_FAILED) {
1202  } else {
1203  plant = Chance16(1, 8);
1204  }
1205 
1206  if (plant) PlantRandomFarmField(i);
1207  }
1208  if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
1209  uint16_t cb_res = CALLBACK_FAILED;
1211  cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 1, i, i->type, i->location.tile);
1212  }
1213 
1214  bool cut;
1215  if (cb_res != CALLBACK_FAILED) {
1217  } else {
1218  cut = ((i->counter % Ticks::INDUSTRY_CUT_TREE_TICKS) == 0);
1219  }
1220 
1221  if (cut) ChopLumberMillTrees(i);
1222  }
1223 
1225  StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK);
1226  }
1227 }
1228 
1229 void OnTick_Industry()
1230 {
1231  if (_industry_sound_ctr != 0) {
1232  _industry_sound_ctr++;
1233 
1234  if (_industry_sound_ctr == 75) {
1235  if (_settings_client.sound.ambient) SndPlayTileFx(SND_37_LUMBER_MILL_2, _industry_sound_tile);
1236  } else if (_industry_sound_ctr == 160) {
1237  _industry_sound_ctr = 0;
1238  if (_settings_client.sound.ambient) SndPlayTileFx(SND_36_LUMBER_MILL_3, _industry_sound_tile);
1239  }
1240  }
1241 
1242  if (_game_mode == GM_EDITOR) return;
1243 
1244  for (Industry *i : Industry::Iterate()) {
1245  ProduceIndustryGoods(i);
1246  }
1247 }
1248 
1254 {
1255  return CommandCost();
1256 }
1257 
1264 {
1265  if (_settings_game.game_creation.landscape == LT_ARCTIC) {
1266  if (GetTileZ(tile) < HighestSnowLine() + 2) {
1267  return_cmd_error(STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED);
1268  }
1269  }
1270  return CommandCost();
1271 }
1272 
1280 static bool CheckScaledDistanceFromEdge(TileIndex tile, uint maxdist)
1281 {
1282  uint maxdist_x = maxdist;
1283  uint maxdist_y = maxdist;
1284 
1285  if (Map::SizeX() > 256) maxdist_x *= Map::SizeX() / 256;
1286  if (Map::SizeY() > 256) maxdist_y *= Map::SizeY() / 256;
1287 
1288  if (DistanceFromEdgeDir(tile, DIAGDIR_NE) < maxdist_x) return true;
1289  if (DistanceFromEdgeDir(tile, DIAGDIR_NW) < maxdist_y) return true;
1290  if (DistanceFromEdgeDir(tile, DIAGDIR_SW) < maxdist_x) return true;
1291  if (DistanceFromEdgeDir(tile, DIAGDIR_SE) < maxdist_y) return true;
1292 
1293  return false;
1294 }
1295 
1302 {
1303  if (_game_mode == GM_EDITOR) return CommandCost();
1304 
1306 
1307  return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED);
1308 }
1309 
1310 extern bool _ignore_restrictions;
1311 
1318 {
1319  if (_game_mode == GM_EDITOR && _ignore_restrictions) return CommandCost();
1320 
1321  if (TileHeight(tile) == 0 &&
1323 
1324  return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED);
1325 }
1326 
1333 {
1334  if (_settings_game.game_creation.landscape == LT_ARCTIC) {
1335  if (GetTileZ(tile) + 2 >= HighestSnowLine()) {
1336  return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
1337  }
1338  }
1339  return CommandCost();
1340 }
1341 
1348 {
1349  if (GetTropicZone(tile) == TROPICZONE_DESERT) {
1350  return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
1351  }
1352  return CommandCost();
1353 }
1354 
1361 {
1362  if (GetTropicZone(tile) != TROPICZONE_DESERT) {
1363  return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
1364  }
1365  return CommandCost();
1366 }
1367 
1374 {
1375  if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
1376  return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
1377  }
1378  return CommandCost();
1379 }
1380 
1387 {
1388  if (GetTileZ(tile) > 4) {
1389  return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_LOW_AREAS);
1390  }
1391  return CommandCost();
1392 }
1393 
1400 
1412 };
1413 
1424 static CommandCost FindTownForIndustry(TileIndex tile, int type, Town **t)
1425 {
1426  *t = ClosestTownFromTile(tile, UINT_MAX);
1427 
1429 
1430  for (const Industry *i : Industry::Iterate()) {
1431  if (i->type == (byte)type && i->town == *t) {
1432  *t = nullptr;
1433  return_cmd_error(STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN);
1434  }
1435  }
1436 
1437  return CommandCost();
1438 }
1439 
1440 bool IsSlopeRefused(Slope current, Slope refused)
1441 {
1442  if (IsSteepSlope(current)) return true;
1443  if (current != SLOPE_FLAT) {
1444  if (IsSteepSlope(refused)) return true;
1445 
1446  Slope t = ComplementSlope(current);
1447 
1448  if ((refused & SLOPE_W) && (t & SLOPE_NW)) return true;
1449  if ((refused & SLOPE_S) && (t & SLOPE_NE)) return true;
1450  if ((refused & SLOPE_E) && (t & SLOPE_SW)) return true;
1451  if ((refused & SLOPE_N) && (t & SLOPE_SE)) return true;
1452  }
1453 
1454  return false;
1455 }
1456 
1464 static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, IndustryType type)
1465 {
1466  IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
1467 
1468  for (const IndustryTileLayoutTile &it : layout) {
1469  IndustryGfx gfx = GetTranslatedIndustryTileID(it.gfx);
1470  TileIndex cur_tile = TileAddWrap(tile, it.ti.x, it.ti.y);
1471 
1472  if (!IsValidTile(cur_tile)) {
1473  return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
1474  }
1475 
1476  if (gfx == GFX_WATERTILE_SPECIALCHECK) {
1477  if (!IsWaterTile(cur_tile) ||
1478  !IsTileFlat(cur_tile)) {
1479  return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
1480  }
1481  } else {
1482  CommandCost ret = EnsureNoVehicleOnGround(cur_tile);
1483  if (ret.Failed()) return ret;
1484  if (IsBridgeAbove(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
1485 
1486  const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
1487 
1488  /* Perform land/water check if not disabled */
1489  if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
1490 
1491  if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house
1492  ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house)
1493  if (!IsTileType(cur_tile, MP_HOUSE)) {
1494  return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS);
1495  }
1496 
1497  /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
1498  Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
1499  ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_NONE, cur_tile);
1500  cur_company.Restore();
1501 
1502  if (ret.Failed()) return ret;
1503  } else {
1504  /* Clear the tiles, but do not affect town ratings */
1506  if (ret.Failed()) return ret;
1507  }
1508  }
1509  }
1510 
1511  return CommandCost();
1512 }
1513 
1526 static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check = nullptr)
1527 {
1528  bool refused_slope = false;
1529  bool custom_shape = false;
1530 
1531  for (const IndustryTileLayoutTile &it : layout) {
1532  IndustryGfx gfx = GetTranslatedIndustryTileID(it.gfx);
1533  TileIndex cur_tile = TileAddWrap(tile, it.ti.x, it.ti.y);
1534  assert(IsValidTile(cur_tile)); // checked before in CheckIfIndustryTilesAreFree
1535 
1536  if (gfx != GFX_WATERTILE_SPECIALCHECK) {
1537  const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
1538 
1540  custom_shape = true;
1541  CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, layout_index, initial_random_bits, founder, creation_type);
1542  if (ret.Failed()) return ret;
1543  } else {
1544  Slope tileh = GetTileSlope(cur_tile);
1545  refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
1546  }
1547  }
1548  }
1549 
1550  if (custom_shape_check != nullptr) *custom_shape_check = custom_shape;
1551 
1552  /* It is almost impossible to have a fully flat land in TG, so what we
1553  * do is that we check if we can make the land flat later on. See
1554  * CheckIfCanLevelIndustryPlatform(). */
1555  if (!refused_slope || (_settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions)) {
1556  return CommandCost();
1557  }
1558  return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
1559 }
1560 
1568 static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
1569 {
1570  if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->cache.population < 1200) {
1571  return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200);
1572  }
1573 
1574  if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
1575  return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_NEAR_TOWN_CENTER);
1576  }
1577 
1578  return CommandCost();
1579 }
1580 
1581 static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
1582 {
1583  /* Check if we don't leave the map */
1584  if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
1585 
1586  TileArea ta(tile - TileDiffXY(1, 1), 2, 2);
1587  for (TileIndex tile_walk : ta) {
1588  uint curh = TileHeight(tile_walk);
1589  /* Is the tile clear? */
1590  if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) return false;
1591 
1592  /* Don't allow too big of a change if this is the sub-tile check */
1593  if (internal != 0 && Delta(curh, height) > 1) return false;
1594 
1595  /* Different height, so the surrounding tiles of this tile
1596  * has to be correct too (in level, or almost in level)
1597  * else you get a chain-reaction of terraforming. */
1598  if (internal == 0 && curh != height) {
1599  if (TileX(tile_walk) == 0 || TileY(tile_walk) == 0 || !CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1)) {
1600  return false;
1601  }
1602  }
1603  }
1604 
1605  return true;
1606 }
1607 
1613 {
1614  int max_x = 0;
1615  int max_y = 0;
1616 
1617  /* Finds dimensions of largest variant of this industry */
1618  for (const IndustryTileLayoutTile &it : layout) {
1619  if (it.gfx == GFX_WATERTILE_SPECIALCHECK) continue; // watercheck tiles don't count for footprint size
1620  if (it.ti.x > max_x) max_x = it.ti.x;
1621  if (it.ti.y > max_y) max_y = it.ti.y;
1622  }
1623 
1624  /* Remember level height */
1625  uint h = TileHeight(tile);
1626 
1627  if (TileX(tile) <= _settings_game.construction.industry_platform + 1U || TileY(tile) <= _settings_game.construction.industry_platform + 1U) return false;
1628  /* Check that all tiles in area and surrounding are clear
1629  * this determines that there are no obstructing items */
1630 
1631  /* TileArea::Expand is not used here as we need to abort
1632  * instead of clamping if the bounds cannot expanded. */
1635 
1636  if (TileX(ta.tile) + ta.w >= Map::MaxX() || TileY(ta.tile) + ta.h >= Map::MaxY()) return false;
1637 
1638  /* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
1639  * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */
1640  Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
1641 
1642  for (TileIndex tile_walk : ta) {
1643  uint curh = TileHeight(tile_walk);
1644  if (curh != h) {
1645  /* This tile needs terraforming. Check if we can do that without
1646  * damaging the surroundings too much. */
1647  if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
1648  cur_company.Restore();
1649  return false;
1650  }
1651  /* This is not 100% correct check, but the best we can do without modifying the map.
1652  * What is missing, is if the difference in height is more than 1.. */
1653  if (std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(flags & ~DC_EXEC, tile_walk, SLOPE_N, curh <= h)).Failed()) {
1654  cur_company.Restore();
1655  return false;
1656  }
1657  }
1658  }
1659 
1660  if (flags & DC_EXEC) {
1661  /* Terraform the land under the industry */
1662  for (TileIndex tile_walk : ta) {
1663  uint curh = TileHeight(tile_walk);
1664  while (curh != h) {
1665  /* We give the terraforming for free here, because we can't calculate
1666  * exact cost in the test-round, and as we all know, that will cause
1667  * a nice assert if they don't match ;) */
1668  Command<CMD_TERRAFORM_LAND>::Do(flags, tile_walk, SLOPE_N, curh <= h);
1669  curh += (curh > h) ? -1 : 1;
1670  }
1671  }
1672  }
1673 
1674  cur_company.Restore();
1675  return true;
1676 }
1677 
1678 
1686 {
1687  const IndustrySpec *indspec = GetIndustrySpec(type);
1688 
1689  /* On a large map with many industries, it may be faster to check an area. */
1690  static const int dmax = 14;
1691  if (Industry::GetNumItems() > (size_t) (dmax * dmax * 2)) {
1692  const Industry *i = nullptr;
1693  TileArea tile_area = TileArea(tile, 1, 1).Expand(dmax);
1694  for (TileIndex atile : tile_area) {
1695  if (GetTileType(atile) == MP_INDUSTRY) {
1696  const Industry *i2 = Industry::GetByTile(atile);
1697  if (i == i2) continue;
1698  i = i2;
1699  if (DistanceMax(tile, i->location.tile) > (uint)dmax) continue;
1700  if (i->type == indspec->conflicting[0] ||
1701  i->type == indspec->conflicting[1] ||
1702  i->type == indspec->conflicting[2]) {
1703  return_cmd_error(STR_ERROR_INDUSTRY_TOO_CLOSE);
1704  }
1705  }
1706  }
1707  return CommandCost();
1708  }
1709 
1710  for (const Industry *i : Industry::Iterate()) {
1711  /* Within 14 tiles from another industry is considered close */
1712  if (DistanceMax(tile, i->location.tile) > 14) continue;
1713 
1714  /* check if there are any conflicting industry types around */
1715  if (i->type == indspec->conflicting[0] ||
1716  i->type == indspec->conflicting[1] ||
1717  i->type == indspec->conflicting[2]) {
1718  return_cmd_error(STR_ERROR_INDUSTRY_TOO_CLOSE);
1719  }
1720  }
1721  return CommandCost();
1722 }
1723 
1728 static void AdvertiseIndustryOpening(const Industry *ind)
1729 {
1730  const IndustrySpec *ind_spc = GetIndustrySpec(ind->type);
1731  SetDParam(0, ind_spc->name);
1732  if (ind_spc->new_industry_text > STR_LAST_STRINGID) {
1733  SetDParam(1, STR_TOWN_NAME);
1734  SetDParam(2, ind->town->index);
1735  } else {
1736  SetDParam(1, ind->town->index);
1737  }
1738  AddIndustryNewsItem(ind_spc->new_industry_text, NT_INDUSTRY_OPEN, ind->index);
1739  AI::BroadcastNewEvent(new ScriptEventIndustryOpen(ind->index));
1740  Game::NewEvent(new ScriptEventIndustryOpen(ind->index));
1741 }
1742 
1749 {
1751  /* Industry has a neutral station. Use it and ignore any other nearby stations. */
1752  ind->stations_near.insert(ind->neutral_station);
1753  ind->neutral_station->industries_near.clear();
1754  ind->neutral_station->industries_near.insert(IndustryListEntry{0, ind});
1755  return;
1756  }
1757 
1758  ForAllStationsAroundTiles(ind->location, [ind](Station *st, TileIndex tile) {
1759  if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != ind->index) return false;
1760  ind->stations_near.insert(st);
1761  st->AddIndustryToDeliver(ind, tile);
1762  return false;
1763  });
1764 }
1765 
1777 static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, const IndustryTileLayout &layout, size_t layout_index, Town *t, Owner founder, uint16_t initial_random_bits)
1778 {
1779  const IndustrySpec *indspec = GetIndustrySpec(type);
1780 
1781  i->location = TileArea(tile, 1, 1);
1782  i->type = type;
1784 
1785  for (auto it = std::begin(i->produced); it != std::end(i->produced); ++it) {
1786  size_t index = it - std::begin(i->produced);
1787  it->cargo = indspec->produced_cargo[index];
1788  it->rate = indspec->production_rate[index];
1789  }
1790 
1791  for (auto it = std::begin(i->accepted); it != std::end(i->accepted); ++it) {
1792  size_t index = it - std::begin(i->accepted);
1793  it->cargo = indspec->accepts_cargo[index];
1794  }
1795 
1796  /* Randomize inital production if non-original economy is used and there are no production related callbacks. */
1797  if (!indspec->UsesOriginalEconomy()) {
1798  for (auto &p : i->produced) {
1799  p.rate = ClampTo<byte>((RandomRange(256) + 128) * p.rate >> 8);
1800  }
1801  }
1802 
1803  i->town = t;
1804  i->owner = OWNER_NONE;
1805 
1806  uint16_t r = Random();
1807  i->random_colour = static_cast<Colours>(GB(r, 0, 4));
1808  i->counter = GB(r, 4, 12);
1809  i->random = initial_random_bits;
1810  i->was_cargo_delivered = false;
1812  i->founder = founder;
1813  i->ctlflags = INDCTL_NONE;
1814 
1816  i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR :
1818 
1819  /* Adding 1 here makes it conform to specs of var44 of varaction2 for industries
1820  * 0 = created prior of newindustries
1821  * else, chosen layout + 1 */
1822  i->selected_layout = (byte)(layout_index + 1);
1823 
1826 
1828 
1829  /* Call callbacks after the regular fields got initialised. */
1830 
1832  uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROD_CHANGE_BUILD, 0, Random(), i, type, INVALID_TILE);
1833  if (res != CALLBACK_FAILED) {
1834  if (res < PRODLEVEL_MINIMUM || res > PRODLEVEL_MAXIMUM) {
1836  } else {
1837  i->prod_level = res;
1839  }
1840  }
1841  }
1842 
1843  if (_generating_world) {
1846  for (auto &p : i->produced) {
1847  p.history[LAST_MONTH].production = p.waiting * 8;
1848  p.waiting = 0;
1849  }
1850  }
1851 
1852  for (auto &p : i->produced) {
1853  p.history[LAST_MONTH].production += ScaleByCargoScale(p.rate * 8, false);
1854  }
1855  }
1856 
1857  if (HasBit(indspec->callback_mask, CBM_IND_DECIDE_COLOUR)) {
1858  uint16_t res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
1859  if (res != CALLBACK_FAILED) {
1860  if (GB(res, 4, 11) != 0) ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_DECIDE_COLOUR, res);
1861  i->random_colour = static_cast<Colours>(GB(res, 0, 4));
1862  }
1863  }
1864 
1866  /* Clear all input cargo types */
1867  for (auto &a : i->accepted) a.cargo = INVALID_CARGO;
1868  /* Query actual types */
1869  uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? static_cast<uint>(i->accepted.size()) : 3;
1870  for (uint j = 0; j < maxcargoes; j++) {
1871  uint16_t res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
1872  if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
1873  if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) {
1875  break;
1876  }
1877  CargoID cargo = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
1878  /* Industries without "unlimited" cargo types support depend on the specific order/slots of cargo types.
1879  * They need to be able to blank out specific slots without aborting the callback sequence,
1880  * and solve this by returning undefined cargo indexes. Skip these. */
1881  if (!IsValidCargoID(cargo) && !(indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED)) continue;
1882  /* Verify valid cargo */
1883  if (std::find(indspec->accepts_cargo, endof(indspec->accepts_cargo), cargo) == endof(indspec->accepts_cargo)) {
1884  /* Cargo not in spec, error in NewGRF */
1886  break;
1887  }
1888  if (std::any_of(std::begin(i->accepted), std::begin(i->accepted) + j, [&cargo](const auto &a) { return a.cargo == cargo; })) {
1889  /* Duplicate cargo */
1891  break;
1892  }
1893  i->accepted[j].cargo = cargo;
1894  }
1895  }
1896 
1898  /* Clear all output cargo types */
1899  for (auto &p : i->produced) p.cargo = INVALID_CARGO;
1900  /* Query actual types */
1901  uint maxcargoes = (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) ? static_cast<uint>(i->produced.size()) : 2;
1902  for (uint j = 0; j < maxcargoes; j++) {
1903  uint16_t res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
1904  if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
1905  if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) {
1907  break;
1908  }
1909  CargoID cargo = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
1910  /* Allow older GRFs to skip slots. */
1911  if (!IsValidCargoID(cargo) && !(indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED)) continue;
1912  /* Verify valid cargo */
1913  if (std::find(indspec->produced_cargo, endof(indspec->produced_cargo), cargo) == endof(indspec->produced_cargo)) {
1914  /* Cargo not in spec, error in NewGRF */
1916  break;
1917  }
1918  if (std::any_of(std::begin(i->produced), std::begin(i->produced) + j, [&cargo](const auto &p) { return p.cargo == cargo; })) {
1919  /* Duplicate cargo */
1921  break;
1922  }
1923  i->produced[j].cargo = cargo;
1924  }
1925  }
1926 
1927  /* Plant the tiles */
1928 
1929  for (const IndustryTileLayoutTile &it : layout) {
1930  TileIndex cur_tile = tile + ToTileIndexDiff(it.ti);
1931 
1932  if (it.gfx != GFX_WATERTILE_SPECIALCHECK) {
1933  i->location.Add(cur_tile);
1934 
1935  WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID);
1936 
1938 
1939  MakeIndustry(cur_tile, i->index, it.gfx, Random(), wc);
1940 
1941  if (_generating_world) {
1942  SetIndustryConstructionCounter(cur_tile, 3);
1943  SetIndustryConstructionStage(cur_tile, 2);
1944  }
1945 
1946  /* it->gfx is stored in the map. But the translated ID cur_gfx is the interesting one */
1947  IndustryGfx cur_gfx = GetTranslatedIndustryTileID(it.gfx);
1948  const IndustryTileSpec *its = GetIndustryTileSpec(cur_gfx);
1950  }
1951  }
1952 
1954  for (uint j = 0; j != 50; j++) PlantRandomFarmField(i);
1955  }
1956  InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_FORCE_REBUILD);
1958 
1960 }
1961 
1978 static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, size_t layout_index, uint32_t random_var8f, uint16_t random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip)
1979 {
1980  assert(layout_index < indspec->layouts.size());
1981  const IndustryTileLayout &layout = indspec->layouts[layout_index];
1982 
1983  *ip = nullptr;
1984 
1985  /* 1. Cheap: Built-in checks on industry level. */
1987  if (ret.Failed()) return ret;
1988 
1989  Town *t = nullptr;
1990  ret = FindTownForIndustry(tile, type, &t);
1991  if (ret.Failed()) return ret;
1992  assert(t != nullptr);
1993 
1994  ret = CheckIfIndustryIsAllowed(tile, type, t);
1995  if (ret.Failed()) return ret;
1996 
1997  /* 2. Built-in checks on industry tiles. */
1998  std::vector<ClearedObjectArea> object_areas(_cleared_object_areas);
1999  ret = CheckIfIndustryTilesAreFree(tile, layout, type);
2000  _cleared_object_areas = object_areas;
2001  if (ret.Failed()) return ret;
2002 
2003  /* 3. NewGRF-defined checks on industry level. */
2004  if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) {
2005  ret = CheckIfCallBackAllowsCreation(tile, type, layout_index, random_var8f, random_initial_bits, founder, creation_type);
2006  } else {
2007  ret = _check_new_industry_procs[indspec->check_proc](tile);
2008  }
2009  if (ret.Failed()) return ret;
2010 
2011  /* 4. Expensive: NewGRF-defined checks on industry tiles. */
2012  bool custom_shape_check = false;
2013  ret = CheckIfIndustryTileSlopes(tile, layout, layout_index, type, random_initial_bits, founder, creation_type, &custom_shape_check);
2014  if (ret.Failed()) return ret;
2015 
2017  !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, layout)) {
2018  return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
2019  }
2020 
2021  if (!Industry::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_INDUSTRIES);
2022 
2023  if (flags & DC_EXEC) {
2024  *ip = new Industry(tile);
2025  if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER | DC_EXEC, layout);
2026  DoCreateNewIndustry(*ip, tile, type, layout, layout_index, t, founder, random_initial_bits);
2027  }
2028 
2029  return CommandCost();
2030 }
2031 
2042 CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType it, uint32_t first_layout, bool fund, uint32_t seed)
2043 {
2044  if (it >= NUM_INDUSTRYTYPES) return CMD_ERROR;
2045 
2046  const IndustrySpec *indspec = GetIndustrySpec(it);
2047 
2048  /* Check if the to-be built/founded industry is available for this climate. */
2049  if (!indspec->enabled || indspec->layouts.empty()) return CMD_ERROR;
2050 
2051  /* If the setting for raw-material industries is not on, you cannot build raw-material industries.
2052  * Raw material industries are industries that do not accept cargo (at least for now) */
2053  if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
2054  return CMD_ERROR;
2055  }
2056 
2057  if (_game_mode != GM_EDITOR && GetIndustryProbabilityCallback(it, _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) {
2058  return CMD_ERROR;
2059  }
2060 
2061  Randomizer randomizer;
2062  randomizer.SetSeed(seed);
2063  uint16_t random_initial_bits = GB(seed, 0, 16);
2064  uint32_t random_var8f = randomizer.Next();
2065  size_t num_layouts = indspec->layouts.size();
2066  CommandCost ret = CommandCost(STR_ERROR_SITE_UNSUITABLE);
2067  const bool deity_prospect = _current_company == OWNER_DEITY && !fund;
2068 
2069  Industry *ind = nullptr;
2070  if (deity_prospect || (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry())) {
2071  if (flags & DC_EXEC) {
2072  /* Prospecting has a chance to fail, however we cannot guarantee that something can
2073  * be built on the map, so the chance gets lower when the map is fuller, but there
2074  * is nothing we can really do about that. */
2075  bool prospect_success = deity_prospect || Random() <= indspec->prospecting_chance;
2076  if (prospect_success) {
2077  /* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */
2079  Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
2080  for (int i = 0; i < 5000; i++) {
2081  /* We should not have more than one Random() in a function call
2082  * because parameter evaluation order is not guaranteed in the c++ standard
2083  */
2084  tile = RandomTile();
2085  /* Start with a random layout */
2086  size_t layout = RandomRange((uint32_t)num_layouts);
2087  /* Check now each layout, starting with the random one */
2088  for (size_t j = 0; j < num_layouts; j++) {
2089  layout = (layout + 1) % num_layouts;
2090  ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, cur_company.GetOriginalValue(), calltype, &ind);
2091  if (ret.Succeeded()) break;
2092  }
2093  if (ret.Succeeded()) break;
2094  }
2095  cur_company.Restore();
2096  }
2097  if (ret.Failed() && IsLocalCompany()) {
2098  if (prospect_success) {
2099  ShowErrorMessage(STR_ERROR_CAN_T_PROSPECT_INDUSTRY, STR_ERROR_NO_SUITABLE_PLACES_FOR_PROSPECTING, WL_INFO);
2100  } else {
2101  ShowErrorMessage(STR_ERROR_CAN_T_PROSPECT_INDUSTRY, STR_ERROR_PROSPECTING_WAS_UNLUCKY, WL_INFO);
2102  }
2103  }
2104  }
2105  } else {
2106  size_t layout = first_layout;
2107  if (layout >= num_layouts) return CMD_ERROR;
2108 
2109  /* Check subsequently each layout, starting with the given layout in p1 */
2110  for (size_t i = 0; i < num_layouts; i++) {
2111  layout = (layout + 1) % num_layouts;
2112  ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, _current_company, _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_USERCREATION, &ind);
2113  if (ret.Succeeded()) break;
2114  }
2115 
2116  /* If it still failed, there's no suitable layout to build here, return the error */
2117  if (ret.Failed()) return ret;
2118  }
2119 
2120  if ((flags & DC_EXEC) && ind != nullptr && _game_mode != GM_EDITOR) {
2122  }
2123 
2124  return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost());
2125 }
2126 
2135 {
2136  if (_current_company != OWNER_DEITY) return CMD_ERROR;
2137 
2138  Industry *ind = Industry::GetIfValid(ind_id);
2139  if (ind == nullptr) return CMD_ERROR;
2140 
2141  if (flags & DC_EXEC) ind->ctlflags = ctlflags & INDCTL_MASK;
2142 
2143  return CommandCost();
2144 }
2145 
2155 CommandCost CmdIndustrySetProduction(DoCommandFlag flags, IndustryID ind_id, byte prod_level, bool show_news, const std::string &custom_news)
2156 {
2157  if (_current_company != OWNER_DEITY) return CMD_ERROR;
2158  if (prod_level < PRODLEVEL_MINIMUM || prod_level > PRODLEVEL_MAXIMUM) return CMD_ERROR;
2159 
2160  Industry *ind = Industry::GetIfValid(ind_id);
2161  if (ind == nullptr) return CMD_ERROR;
2162 
2163  if (flags & DC_EXEC) {
2164  StringID str = STR_NULL;
2165  if (prod_level > ind->prod_level) {
2167  } else if (prod_level < ind->prod_level) {
2169  }
2170  if (prod_level != ind->prod_level && !custom_news.empty()) str = STR_NEWS_CUSTOM_ITEM;
2171 
2173  ind->prod_level = prod_level;
2175 
2176  /* Show news message if requested. */
2177  if (show_news && str != STR_NULL) {
2178  NewsType nt;
2179  switch (WhoCanServiceIndustry(ind)) {
2180  case 0: nt = NT_INDUSTRY_NOBODY; break;
2181  case 1: nt = NT_INDUSTRY_OTHER; break;
2182  case 2: nt = NT_INDUSTRY_COMPANY; break;
2183  default: NOT_REACHED();
2184  }
2185 
2186  /* Set parameters of news string */
2187  NewsAllocatedData *data = nullptr;
2188  if (str == STR_NEWS_CUSTOM_ITEM) {
2189  NewsStringData *news = new NewsStringData(custom_news);
2190  SetDParamStr(0, news->string);
2191  } else if (str > STR_LAST_STRINGID) {
2192  SetDParam(0, STR_TOWN_NAME);
2193  SetDParam(1, ind->town->index);
2194  SetDParam(2, GetIndustrySpec(ind->type)->name);
2195  } else {
2196  SetDParam(0, ind->index);
2197  }
2198  AddIndustryNewsItem(str, nt, ind->index, data);
2199  }
2200  }
2201 
2202  return CommandCost();
2203 }
2204 
2214 CommandCost CmdIndustrySetExclusivity(DoCommandFlag flags, IndustryID ind_id, Owner company_id, bool consumer)
2215 {
2216  if (_current_company != OWNER_DEITY) return CMD_ERROR;
2217 
2218  Industry *ind = Industry::GetIfValid(ind_id);
2219  if (ind == nullptr) return CMD_ERROR;
2220 
2221  if (company_id != OWNER_NONE && company_id != INVALID_OWNER && company_id != OWNER_DEITY
2222  && !Company::IsValidID(company_id)) return CMD_ERROR;
2223 
2224  if (flags & DC_EXEC) {
2225  if (consumer) {
2226  ind->exclusive_consumer = company_id;
2227  } else {
2228  ind->exclusive_supplier = company_id;
2229  }
2230  }
2231 
2232 
2233  return CommandCost();
2234 }
2235 
2243 CommandCost CmdIndustrySetText(DoCommandFlag flags, IndustryID ind_id, const std::string &text)
2244 {
2245  if (_current_company != OWNER_DEITY) return CMD_ERROR;
2246 
2247  Industry *ind = Industry::GetIfValid(ind_id);
2248  if (ind == nullptr) return CMD_ERROR;
2249 
2250  if (flags & DC_EXEC) {
2251  ind->text.clear();
2252  if (!text.empty()) ind->text = text;
2254  }
2255 
2256  return CommandCost();
2257 }
2258 
2266 static Industry *CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
2267 {
2268  const IndustrySpec *indspec = GetIndustrySpec(type);
2269 
2270  uint32_t seed = Random();
2271  uint32_t seed2 = Random();
2272  Industry *i = nullptr;
2273  size_t layout_index = RandomRange((uint32_t)indspec->layouts.size());
2274  [[maybe_unused]] CommandCost ret = CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, layout_index, seed, GB(seed2, 0, 16), OWNER_NONE, creation_type, &i);
2275  assert(i != nullptr || ret.Failed());
2276  return i;
2277 }
2278 
2285 static uint32_t GetScaledIndustryGenerationProbability(IndustryType it, bool *force_at_least_one)
2286 {
2287  const IndustrySpec *ind_spc = GetIndustrySpec(it);
2288  uint32_t chance = ind_spc->appear_creation[_settings_game.game_creation.landscape];
2289  if (!ind_spc->enabled || ind_spc->layouts.empty() ||
2290  (_game_mode != GM_EDITOR && _settings_game.difficulty.industry_density == ID_FUND_ONLY) ||
2291  (chance = GetIndustryProbabilityCallback(it, IACT_MAPGENERATION, chance)) == 0) {
2292  *force_at_least_one = false;
2293  return 0;
2294  } else {
2295  chance *= 16; // to increase precision
2296  /* We want industries appearing at coast to appear less often on bigger maps, as length of coast increases slower than map area.
2297  * For simplicity we scale in both cases, though scaling the probabilities of all industries has no effect. */
2298  chance = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? Map::ScaleBySize1D(chance) : Map::ScaleBySize(chance);
2299 
2300  *force_at_least_one = (chance > 0) && !(ind_spc->behaviour & INDUSTRYBEH_NOBUILT_MAPCREATION) && (_game_mode != GM_EDITOR);
2301  return chance;
2302  }
2303 }
2304 
2311 static uint16_t GetIndustryGamePlayProbability(IndustryType it, byte *min_number)
2312 {
2314  *min_number = 0;
2315  return 0;
2316  }
2317 
2318  const IndustrySpec *ind_spc = GetIndustrySpec(it);
2319  byte chance = ind_spc->appear_ingame[_settings_game.game_creation.landscape];
2320  if (!ind_spc->enabled || ind_spc->layouts.empty() ||
2321  ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && TimerGameCalendar::year > 1950) ||
2322  ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && TimerGameCalendar::year < 1960) ||
2323  (chance = GetIndustryProbabilityCallback(it, IACT_RANDOMCREATION, chance)) == 0) {
2324  *min_number = 0;
2325  return 0;
2326  }
2327  *min_number = (ind_spc->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) ? 1 : 0;
2328  return chance;
2329 }
2330 
2336 {
2337  /* Number of industries on a 256x256 map. */
2338  static const uint16_t numof_industry_table[] = {
2339  0, // none
2340  0, // minimal
2341  10, // very low
2342  25, // low
2343  55, // normal
2344  80, // high
2345  0, // custom
2346  };
2347 
2348  assert(lengthof(numof_industry_table) == ID_END);
2349  uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.industry_density : (uint)ID_VERY_LOW;
2350 
2351  if (difficulty == ID_CUSTOM) return std::min<uint>(IndustryPool::MAX_SIZE, _settings_game.game_creation.custom_industry_number);
2352 
2353  return std::min<uint>(IndustryPool::MAX_SIZE, Map::ScaleBySize(numof_industry_table[difficulty]));
2354 }
2355 
2364 static Industry *PlaceIndustry(IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
2365 {
2366  uint tries = try_hard ? 10000u : 2000u;
2367  for (; tries > 0; tries--) {
2368  Industry *ind = CreateNewIndustry(RandomTile(), type, creation_type);
2369  if (ind != nullptr) return ind;
2370  }
2371  return nullptr;
2372 }
2373 
2379 static void PlaceInitialIndustry(IndustryType type, bool try_hard)
2380 {
2381  Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
2382 
2384  PlaceIndustry(type, IACT_MAPGENERATION, try_hard);
2385 
2386  cur_company.Restore();
2387 }
2388 
2394 {
2395  int total = 0;
2396  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) total += Industry::GetIndustryTypeCount(it);
2397  return total;
2398 }
2399 
2400 
2403 {
2404  this->probability = 0;
2405  this->min_number = 0;
2406  this->target_count = 0;
2407  this->max_wait = 1;
2408  this->wait_count = 0;
2409 }
2410 
2413 {
2415 
2416  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2417  this->builddata[it].Reset();
2418  }
2419 }
2420 
2423 {
2424  static const int NEWINDS_PER_MONTH = 0x38000 / (10 * 12); // lower 16 bits is a float fraction, 3.5 industries per decade, divided by 10 * 12 months.
2425  if (_settings_game.difficulty.industry_density == ID_FUND_ONLY) return; // 'no industries' setting.
2426 
2427  /* To prevent running out of unused industries for the player to connect,
2428  * add a fraction of new industries each month, but only if the manager can keep up. */
2429  uint max_behind = 1 + std::min(99u, Map::ScaleBySize(3)); // At most 2 industries for small maps, and 100 at the biggest map (about 6 months industry build attempts).
2430  if (GetCurrentTotalNumberOfIndustries() + max_behind >= (this->wanted_inds >> 16)) {
2431  this->wanted_inds += Map::ScaleBySize(NEWINDS_PER_MONTH);
2432  }
2433 }
2434 
2440 {
2441  if (_game_mode != GM_EDITOR && _settings_game.difficulty.industry_density == ID_FUND_ONLY) return; // No industries in the game.
2442 
2443  uint32_t industry_probs[NUM_INDUSTRYTYPES];
2444  bool force_at_least_one[NUM_INDUSTRYTYPES];
2445  uint32_t total_prob = 0;
2446  uint num_forced = 0;
2447 
2448  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2449  industry_probs[it] = GetScaledIndustryGenerationProbability(it, force_at_least_one + it);
2450  total_prob += industry_probs[it];
2451  if (force_at_least_one[it]) num_forced++;
2452  }
2453 
2454  uint total_amount = GetNumberOfIndustries();
2455  if (total_prob == 0 || total_amount < num_forced) {
2456  /* Only place the forced ones */
2457  total_amount = num_forced;
2458  }
2459 
2461 
2462  /* Try to build one industry per type independent of any probabilities */
2463  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2464  if (force_at_least_one[it]) {
2465  assert(total_amount > 0);
2466  total_amount--;
2467  PlaceInitialIndustry(it, true);
2468  }
2469  }
2470 
2471  /* Add the remaining industries according to their probabilities */
2472  for (uint i = 0; i < total_amount; i++) {
2473  uint32_t r = RandomRange(total_prob);
2474  IndustryType it = 0;
2475  while (r >= industry_probs[it]) {
2476  r -= industry_probs[it];
2477  it++;
2478  assert(it < NUM_INDUSTRYTYPES);
2479  }
2480  assert(industry_probs[it] > 0);
2481  PlaceInitialIndustry(it, false);
2482  }
2484 }
2485 
2491 {
2492  for (auto &p : i->produced) {
2493  if (IsValidCargoID(p.cargo)) {
2494  if (p.history[THIS_MONTH].production != 0) i->last_prod_year = TimerGameEconomy::year;
2495 
2496  /* Move history from this month to last month. */
2497  std::rotate(std::rbegin(p.history), std::rbegin(p.history) + 1, std::rend(p.history));
2498  p.history[THIS_MONTH].production = 0;
2499  p.history[THIS_MONTH].transported = 0;
2500  }
2501  }
2502 }
2503 
2509 {
2510  const IndustrySpec *indspec = GetIndustrySpec(this->type);
2511  assert(indspec->UsesOriginalEconomy());
2512 
2513  /* Rates are rounded up, so e.g. oilrig always produces some passengers */
2514  for (auto &p : this->produced) {
2515  p.rate = ClampTo<uint8_t>(CeilDiv(indspec->production_rate[&p - this->produced.data()] * this->prod_level, PRODLEVEL_DEFAULT));
2516  }
2517 }
2518 
2519 void Industry::FillCachedName() const
2520 {
2521  auto tmp_params = MakeParameters(this->index);
2522  this->cached_name = GetStringWithArgs(STR_INDUSTRY_NAME, tmp_params);
2523 }
2524 
2525 void ClearAllIndustryCachedNames()
2526 {
2527  for (Industry *ind : Industry::Iterate()) {
2528  ind->cached_name.clear();
2529  }
2530 }
2531 
2538 {
2539  byte min_number;
2541  bool changed = min_number != this->min_number || probability != this->probability;
2542  this->min_number = min_number;
2543  this->probability = probability;
2544  return changed;
2545 }
2546 
2549 {
2550  bool changed = false;
2551  uint num_planned = 0; // Number of industries planned in the industry build data.
2552  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2553  changed |= this->builddata[it].GetIndustryTypeData(it);
2554  num_planned += this->builddata[it].target_count;
2555  }
2556  uint total_amount = this->wanted_inds >> 16; // Desired total number of industries.
2557  changed |= num_planned != total_amount;
2558  if (!changed) return; // All industries are still the same, no need to re-randomize.
2559 
2560  /* Initialize the target counts. */
2561  uint force_build = 0; // Number of industries that should always be available.
2562  uint32_t total_prob = 0; // Sum of probabilities.
2563  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2564  IndustryTypeBuildData *ibd = this->builddata + it;
2565  force_build += ibd->min_number;
2566  ibd->target_count = ibd->min_number;
2567  total_prob += ibd->probability;
2568  }
2569 
2570  if (total_prob == 0) return; // No buildable industries.
2571 
2572  /* Subtract forced industries from the number of industries available for construction. */
2573  total_amount = (total_amount <= force_build) ? 0 : total_amount - force_build;
2574 
2575  /* Assign number of industries that should be aimed for, by using the probability as a weight. */
2576  while (total_amount > 0) {
2577  uint32_t r = RandomRange(total_prob);
2578  IndustryType it = 0;
2579  while (r >= this->builddata[it].probability) {
2580  r -= this->builddata[it].probability;
2581  it++;
2582  assert(it < NUM_INDUSTRYTYPES);
2583  }
2584  assert(this->builddata[it].probability > 0);
2585  this->builddata[it].target_count++;
2586  total_amount--;
2587  }
2588 }
2589 
2594 {
2595  this->SetupTargetCount();
2596 
2597  int missing = 0; // Number of industries that need to be build.
2598  uint count = 0; // Number of industry types eligible for build.
2599  uint32_t total_prob = 0; // Sum of probabilities.
2600  IndustryType forced_build = NUM_INDUSTRYTYPES; // Industry type that should be forcibly build.
2601  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2602  int difference = this->builddata[it].target_count - Industry::GetIndustryTypeCount(it);
2603  missing += difference;
2604  if (this->builddata[it].wait_count > 0) continue; // This type may not be built now.
2605  if (difference > 0) {
2606  if (Industry::GetIndustryTypeCount(it) == 0 && this->builddata[it].min_number > 0) {
2607  /* An industry that should exist at least once, is not available. Force it, trying the most needed one first. */
2608  if (forced_build == NUM_INDUSTRYTYPES ||
2609  difference > this->builddata[forced_build].target_count - Industry::GetIndustryTypeCount(forced_build)) {
2610  forced_build = it;
2611  }
2612  }
2613  total_prob += difference;
2614  count++;
2615  }
2616  }
2617 
2618  if (EconomyIsInRecession() || (forced_build == NUM_INDUSTRYTYPES && (missing <= 0 || total_prob == 0))) count = 0; // Skip creation of an industry.
2619 
2620  if (count >= 1) {
2621  /* If not forced, pick a weighted random industry to build.
2622  * For the case that count == 1, there is no need to draw a random number. */
2623  IndustryType it;
2624  if (forced_build != NUM_INDUSTRYTYPES) {
2625  it = forced_build;
2626  } else {
2627  /* Non-forced, select an industry type to build (weighted random). */
2628  uint32_t r = 0; // Initialized to silence the compiler.
2629  if (count > 1) r = RandomRange(total_prob);
2630  for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
2631  if (this->builddata[it].wait_count > 0) continue; // Type may not be built now.
2632  int difference = this->builddata[it].target_count - Industry::GetIndustryTypeCount(it);
2633  if (difference <= 0) continue; // Too many of this kind.
2634  if (count == 1) break;
2635  if (r < (uint)difference) break;
2636  r -= difference;
2637  }
2638  assert(it < NUM_INDUSTRYTYPES && this->builddata[it].target_count > Industry::GetIndustryTypeCount(it));
2639  }
2640 
2641  /* Try to create the industry. */
2642  const Industry *ind = PlaceIndustry(it, IACT_RANDOMCREATION, false);
2643  if (ind == nullptr) {
2644  this->builddata[it].wait_count = this->builddata[it].max_wait + 1; // Compensate for decrementing below.
2645  this->builddata[it].max_wait = std::min(1000, this->builddata[it].max_wait + 2);
2646  } else {
2648  this->builddata[it].max_wait = std::max(this->builddata[it].max_wait / 2, 1); // Reduce waiting time of the industry type.
2649  }
2650  }
2651 
2652  /* Decrement wait counters. */
2653  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2654  if (this->builddata[it].wait_count > 0) this->builddata[it].wait_count--;
2655  }
2656 }
2657 
2666 static bool CheckIndustryCloseDownProtection(IndustryType type)
2667 {
2668  const IndustrySpec *indspec = GetIndustrySpec(type);
2669 
2670  /* oil wells (or the industries with that flag set) are always allowed to closedown */
2671  if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _settings_game.game_creation.landscape == LT_TEMPERATE) return false;
2672  return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) == 0 && Industry::GetIndustryTypeCount(type) <= 1;
2673 }
2674 
2684 static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
2685 {
2686  if (!IsValidCargoID(cargo)) return;
2687 
2688  /* Check for acceptance of cargo */
2689  if (ind->IsCargoAccepted(cargo) && !IndustryTemporarilyRefusesCargo(ind, cargo)) *c_accepts = true;
2690 
2691  /* Check for produced cargo */
2692  if (ind->IsCargoProduced(cargo)) *c_produces = true;
2693 }
2694 
2709 {
2710  if (ind->stations_near.empty()) return 0; // No stations found at all => nobody services
2711 
2712  int result = 0;
2713  for (const Vehicle *v : Vehicle::Iterate()) {
2714  /* Is it worthwhile to try this vehicle? */
2715  if (v->owner != _local_company && result != 0) continue;
2716 
2717  /* Check whether it accepts the right kind of cargo */
2718  bool c_accepts = false;
2719  bool c_produces = false;
2720  if (v->type == VEH_TRAIN && v->IsFrontEngine()) {
2721  for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
2722  CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces);
2723  }
2724  } else if (v->type == VEH_ROAD || v->type == VEH_SHIP || v->type == VEH_AIRCRAFT) {
2725  CanCargoServiceIndustry(v->cargo_type, ind, &c_accepts, &c_produces);
2726  } else {
2727  continue;
2728  }
2729  if (!c_accepts && !c_produces) continue; // Wrong cargo
2730 
2731  /* Check orders of the vehicle.
2732  * We cannot check the first of shared orders only, since the first vehicle in such a chain
2733  * may have a different cargo type.
2734  */
2735  for (const Order *o : v->Orders()) {
2736  if (o->IsType(OT_GOTO_STATION) && !(o->GetUnloadType() & OUFB_TRANSFER)) {
2737  /* Vehicle visits a station to load or unload */
2738  Station *st = Station::Get(o->GetDestination());
2739  assert(st != nullptr);
2740 
2741  /* Same cargo produced by industry is dropped here => not serviced by vehicle v */
2742  if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break;
2743 
2744  if (ind->stations_near.find(st) != ind->stations_near.end()) {
2745  if (v->owner == _local_company) return 2; // Company services industry
2746  result = 1; // Competitor services industry
2747  }
2748  }
2749  }
2750  }
2751  return result;
2752 }
2753 
2761 static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent)
2762 {
2763  NewsType nt;
2764 
2765  switch (WhoCanServiceIndustry(ind)) {
2766  case 0: nt = NT_INDUSTRY_NOBODY; break;
2767  case 1: nt = NT_INDUSTRY_OTHER; break;
2768  case 2: nt = NT_INDUSTRY_COMPANY; break;
2769  default: NOT_REACHED();
2770  }
2771  SetDParam(2, abs(percent));
2772  SetDParam(0, CargoSpec::Get(type)->name);
2773  SetDParam(1, ind->index);
2774  AddIndustryNewsItem(
2775  percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH,
2776  nt,
2777  ind->index
2778  );
2779 }
2780 
2781 static const uint PERCENT_TRANSPORTED_60 = 153;
2782 static const uint PERCENT_TRANSPORTED_80 = 204;
2783 
2789 static void ChangeIndustryProduction(Industry *i, bool monthly)
2790 {
2791  StringID str = STR_NULL;
2792  bool closeit = false;
2793  const IndustrySpec *indspec = GetIndustrySpec(i->type);
2794  bool standard = false;
2795  bool suppress_message = false;
2796  bool recalculate_multipliers = false;
2797  /* use original economy for industries using production related callbacks */
2798  bool original_economy = indspec->UsesOriginalEconomy();
2799  byte div = 0;
2800  byte mul = 0;
2801  int8_t increment = 0;
2802 
2803  bool callback_enabled = HasBit(indspec->callback_mask, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE);
2804  if (callback_enabled) {
2805  uint16_t res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->location.tile);
2806  if (res != CALLBACK_FAILED) { // failed callback means "do nothing"
2807  suppress_message = HasBit(res, 7);
2808  /* Get the custom message if any */
2809  if (HasBit(res, 8)) str = MapGRFStringID(indspec->grf_prop.grffile->grfid, GB(GetRegister(0x100), 0, 16));
2810  res = GB(res, 0, 4);
2811  switch (res) {
2812  default: NOT_REACHED();
2813  case 0x0: break; // Do nothing, but show the custom message if any
2814  case 0x1: div = 1; break; // Halve industry production. If production reaches the quarter of the default, the industry is closed instead.
2815  case 0x2: mul = 1; break; // Double industry production if it hasn't reached eight times of the original yet.
2816  case 0x3: closeit = true; break; // The industry announces imminent closure, and is physically removed from the map next month.
2817  case 0x4: standard = true; break; // Do the standard random production change as if this industry was a primary one.
2818  case 0x5: case 0x6: case 0x7: // Divide production by 4, 8, 16
2819  case 0x8: div = res - 0x3; break; // Divide production by 32
2820  case 0x9: case 0xA: case 0xB: // Multiply production by 4, 8, 16
2821  case 0xC: mul = res - 0x7; break; // Multiply production by 32
2822  case 0xD: // decrement production
2823  case 0xE: // increment production
2824  increment = res == 0x0D ? -1 : 1;
2825  break;
2826  case 0xF: // Set production to third byte of register 0x100
2828  recalculate_multipliers = true;
2829  break;
2830  }
2831  }
2832  } else {
2833  if (monthly == original_economy) return;
2834  if (!original_economy && _settings_game.economy.type == ET_FROZEN) return;
2835  if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
2836  }
2837 
2838  if (standard || (!callback_enabled && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0)) {
2839  /* decrease or increase */
2840  bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _settings_game.game_creation.landscape == LT_TEMPERATE;
2841 
2842  if (original_economy) {
2843  if (only_decrease || Chance16(1, 3)) {
2844  /* If more than 60% transported, 66% chance of increase, else 33% chance of increase */
2845  if (!only_decrease && (i->produced[0].history[LAST_MONTH].PctTransported() > PERCENT_TRANSPORTED_60) != Chance16(1, 3)) {
2846  mul = 1; // Increase production
2847  } else {
2848  div = 1; // Decrease production
2849  }
2850  }
2851  } else if (_settings_game.economy.type == ET_SMOOTH) {
2853  for (auto &p : i->produced) {
2854  if (!IsValidCargoID(p.cargo)) continue;
2855  uint32_t r = Random();
2856  int old_prod, new_prod, percent;
2857  /* If over 60% is transported, mult is 1, else mult is -1. */
2858  int mult = (p.history[LAST_MONTH].PctTransported() > PERCENT_TRANSPORTED_60) ? 1 : -1;
2859 
2860  new_prod = old_prod = p.rate;
2861 
2862  /* For industries with only_decrease flags (temperate terrain Oil Wells),
2863  * the multiplier will always be -1 so they will only decrease. */
2864  if (only_decrease) {
2865  mult = -1;
2866  /* For normal industries, if over 60% is transported, 33% chance for decrease.
2867  * Bonus for very high station ratings (over 80%): 16% chance for decrease. */
2868  } else if (Chance16I(1, ((p.history[LAST_MONTH].PctTransported() > PERCENT_TRANSPORTED_80) ? 6 : 3), r)) {
2869  mult *= -1;
2870  }
2871 
2872  /* 4.5% chance for 3-23% (or 1 unit for very low productions) production change,
2873  * determined by mult value. If mult = 1 prod. increases, else (-1) it decreases. */
2874  if (Chance16I(1, 22, r >> 16)) {
2875  new_prod += mult * (std::max(((RandomRange(50) + 10) * old_prod) >> 8, 1U));
2876  }
2877 
2878  /* Prevent production to overflow or Oil Rig passengers to be over-"produced" */
2879  new_prod = Clamp(new_prod, 1, 255);
2880  if (p.cargo == CT_PASSENGERS && !(indspec->behaviour & INDUSTRYBEH_NO_PAX_PROD_CLAMP)) {
2881  new_prod = Clamp(new_prod, 0, 16);
2882  }
2883 
2884  /* If override flags are set, prevent actually changing production if any was decided on */
2885  if ((i->ctlflags & INDCTL_NO_PRODUCTION_DECREASE) && new_prod < old_prod) continue;
2886  if ((i->ctlflags & INDCTL_NO_PRODUCTION_INCREASE) && new_prod > old_prod) continue;
2887 
2888  /* Do not stop closing the industry when it has the lowest possible production rate */
2889  if (new_prod == old_prod && old_prod > 1) {
2890  closeit = false;
2891  continue;
2892  }
2893 
2894  percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
2895  p.rate = new_prod;
2896 
2897  /* Close the industry when it has the lowest possible production rate */
2898  if (new_prod > 1) closeit = false;
2899 
2900  if (abs(percent) >= 10) {
2901  ReportNewsProductionChangeIndustry(i, p.cargo, percent);
2902  }
2903  }
2904  }
2905  }
2906 
2907  /* If override flags are set, prevent actually changing production if any was decided on */
2908  if ((i->ctlflags & INDCTL_NO_PRODUCTION_DECREASE) && (div > 0 || increment < 0)) return;
2909  if ((i->ctlflags & INDCTL_NO_PRODUCTION_INCREASE) && (mul > 0 || increment > 0)) return;
2911  div = 0;
2912  mul = 0;
2913  increment = 0;
2914  }
2915 
2916  if (!callback_enabled && (indspec->life_type & INDUSTRYLIFE_PROCESSING)) {
2917  if (TimerGameEconomy::year - i->last_prod_year >= PROCESSING_INDUSTRY_ABANDONMENT_YEARS && Chance16(1, original_economy ? 2 : 180)) {
2918  closeit = true;
2919  }
2920  }
2921 
2922  /* Increase if needed */
2923  while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
2924  i->prod_level = std::min<int>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
2925  recalculate_multipliers = true;
2926  if (str == STR_NULL) str = indspec->production_up_text;
2927  }
2928 
2929  /* Decrease if needed */
2930  while (div-- != 0 && !closeit) {
2931  if (i->prod_level == PRODLEVEL_MINIMUM) {
2932  closeit = true;
2933  break;
2934  } else {
2935  i->prod_level = std::max<int>(i->prod_level / 2, PRODLEVEL_MINIMUM);
2936  recalculate_multipliers = true;
2937  if (str == STR_NULL) str = indspec->production_down_text;
2938  }
2939  }
2940 
2941  /* Increase or Decreasing the production level if needed */
2942  if (increment != 0) {
2943  if (increment < 0 && i->prod_level == PRODLEVEL_MINIMUM) {
2944  closeit = true;
2945  } else {
2947  recalculate_multipliers = true;
2948  }
2949  }
2950 
2951  /* Recalculate production_rate
2952  * For non-smooth economy these should always be synchronized with prod_level */
2953  if (recalculate_multipliers) i->RecomputeProductionMultipliers();
2954 
2955  /* Close if needed and allowed */
2956  if (closeit && !CheckIndustryCloseDownProtection(i->type) && !(i->ctlflags & INDCTL_NO_CLOSURE)) {
2959  str = indspec->closure_text;
2960  }
2961 
2962  if (!suppress_message && str != STR_NULL) {
2963  NewsType nt;
2964  /* Compute news category */
2965  if (closeit) {
2966  nt = NT_INDUSTRY_CLOSE;
2967  AI::BroadcastNewEvent(new ScriptEventIndustryClose(i->index));
2968  Game::NewEvent(new ScriptEventIndustryClose(i->index));
2969  } else {
2970  switch (WhoCanServiceIndustry(i)) {
2971  case 0: nt = NT_INDUSTRY_NOBODY; break;
2972  case 1: nt = NT_INDUSTRY_OTHER; break;
2973  case 2: nt = NT_INDUSTRY_COMPANY; break;
2974  default: NOT_REACHED();
2975  }
2976  }
2977  /* Set parameters of news string */
2978  if (str > STR_LAST_STRINGID) {
2979  SetDParam(0, STR_TOWN_NAME);
2980  SetDParam(1, i->town->index);
2981  SetDParam(2, indspec->name);
2982  } else if (closeit) {
2983  SetDParam(0, STR_FORMAT_INDUSTRY_NAME);
2984  SetDParam(1, i->town->index);
2985  SetDParam(2, indspec->name);
2986  } else {
2987  SetDParam(0, i->index);
2988  }
2989  /* and report the news to the user */
2990  if (closeit) {
2991  AddTileNewsItem(str, nt, i->location.tile + TileDiffXY(1, 1));
2992  } else {
2993  AddIndustryNewsItem(str, nt, i->index);
2994  }
2995  }
2996 }
2997 
3005 static IntervalTimer<TimerGameEconomy> _economy_industries_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::INDUSTRY}, [](auto)
3006 {
3008 
3009  /* Bits 16-31 of industry_construction_counter contain the number of industries to change/create today,
3010  * the lower 16 bit are a fractional part that might accumulate over several days until it
3011  * is sufficient for an industry. */
3012  uint16_t change_loop = _economy.industry_daily_change_counter >> 16;
3013 
3014  /* Reset the active part of the counter, just keeping the "fractional part" */
3015  _economy.industry_daily_change_counter &= 0xFFFF;
3016 
3017  if (change_loop == 0) {
3018  return; // Nothing to do? get out
3019  }
3020 
3021  Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
3022 
3023  /* perform the required industry changes for the day */
3024 
3025  uint perc = 3; // Between 3% and 9% chance of creating a new industry.
3027  perc = std::min(9u, perc + (_industry_builder.wanted_inds >> 16) - GetCurrentTotalNumberOfIndustries());
3028  }
3029  for (uint16_t j = 0; j < change_loop; j++) {
3030  if (Chance16(perc, 100)) {
3032  } else {
3034  if (i != nullptr) {
3035  ChangeIndustryProduction(i, false);
3037  }
3038  }
3039  }
3040 
3041  cur_company.Restore();
3042 
3043  /* production-change */
3044  InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
3045 });
3046 
3047 static IntervalTimer<TimerGameEconomy> _economy_industries_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::INDUSTRY}, [](auto)
3048 {
3049  Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
3050 
3052 
3053  for (Industry *i : Industry::Iterate()) {
3055  if (i->prod_level == PRODLEVEL_CLOSURE) {
3056  delete i;
3057  } else {
3058  ChangeIndustryProduction(i, true);
3060  }
3061  }
3062 
3063  cur_company.Restore();
3064 
3065  /* production-change */
3066  InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
3067 });
3068 
3069 
3070 void InitializeIndustries()
3071 {
3073  _industry_sound_tile = 0;
3074 
3076 }
3077 
3080 {
3081  int count = 0;
3082  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
3083  if (Industry::GetIndustryTypeCount(it) > 0) continue; // Types of existing industries can be skipped.
3084 
3085  bool force_at_least_one;
3086  uint32_t chance = GetScaledIndustryGenerationProbability(it, &force_at_least_one);
3087  if (chance == 0 || !force_at_least_one) continue; // Types that are not available can be skipped.
3088 
3089  const IndustrySpec *is = GetIndustrySpec(it);
3090  SetDParam(0, is->name);
3091  ShowErrorMessage(STR_ERROR_NO_SUITABLE_PLACES_FOR_INDUSTRIES, STR_ERROR_NO_SUITABLE_PLACES_FOR_INDUSTRIES_EXPLANATION, WL_WARNING);
3092 
3093  count++;
3094  if (count >= 3) break; // Don't swamp the user with errors.
3095  }
3096 }
3097 
3103 {
3104  return (this->life_type & (INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC)) != 0;
3105 }
3106 
3112 {
3113  /* Lumber mills are neither raw nor processing */
3114  return (this->life_type & INDUSTRYLIFE_PROCESSING) != 0 &&
3115  (this->behaviour & INDUSTRYBEH_CUT_TREES) == 0;
3116 }
3117 
3123 {
3124  /* Building raw industries like secondary uses different price base */
3125  return (_price[(_settings_game.construction.raw_industry_construction == 1 && this->IsRawIndustry()) ?
3126  PR_BUILD_INDUSTRY_RAW : PR_BUILD_INDUSTRY] * this->cost_multiplier) >> 8;
3127 }
3128 
3136 {
3137  return (_price[PR_CLEAR_INDUSTRY] * this->removal_cost_multiplier) >> 8;
3138 }
3139 
3145 {
3146  return _settings_game.economy.type == ET_ORIGINAL ||
3149 }
3150 
3151 IndustrySpec::~IndustrySpec()
3152 {
3153  if (HasBit(this->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
3154  free(this->random_sounds);
3155  }
3156 }
3157 
3158 static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
3159 {
3160  if (AutoslopeEnabled()) {
3161  /* We imitate here TTDP's behaviour:
3162  * - Both new and old slope must not be steep.
3163  * - TileMaxZ must not be changed.
3164  * - Allow autoslope by default.
3165  * - Disallow autoslope if callback succeeds and returns non-zero.
3166  */
3167  Slope tileh_old = GetTileSlope(tile);
3168  /* TileMaxZ must not be changed. Slopes must not be steep. */
3169  if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
3170  const IndustryGfx gfx = GetIndustryGfx(tile);
3171  const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
3172 
3173  /* Call callback 3C 'disable autosloping for industry tiles'. */
3174  if (HasBit(itspec->callback_mask, CBM_INDT_AUTOSLOPE)) {
3175  /* If the callback fails, allow autoslope. */
3176  uint16_t res = GetIndustryTileCallback(CBID_INDTILE_AUTOSLOPE, 0, 0, gfx, Industry::GetByTile(tile), tile);
3177  if (res == CALLBACK_FAILED || !ConvertBooleanCallback(itspec->grf_prop.grffile, CBID_INDTILE_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
3178  } else {
3179  /* allow autoslope */
3180  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
3181  }
3182  }
3183  }
3184  return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
3185 }
3186 
3187 extern const TileTypeProcs _tile_type_industry_procs = {
3188  DrawTile_Industry, // draw_tile_proc
3189  GetSlopePixelZ_Industry, // get_slope_z_proc
3190  ClearTile_Industry, // clear_tile_proc
3191  AddAcceptedCargo_Industry, // add_accepted_cargo_proc
3192  GetTileDesc_Industry, // get_tile_desc_proc
3193  GetTileTrackStatus_Industry, // get_tile_track_status_proc
3194  ClickTile_Industry, // click_tile_proc
3195  AnimateTile_Industry, // animate_tile_proc
3196  TileLoop_Industry, // tile_loop_proc
3197  ChangeTileOwner_Industry, // change_tile_owner_proc
3198  nullptr, // add_produced_cargo_proc
3199  nullptr, // vehicle_enter_tile_proc
3200  GetFoundation_Industry, // get_foundation_proc
3201  TerraformTile_Industry, // terraform_tile_proc
3202 };
3203 
3204 bool IndustryCompare::operator() (const IndustryListEntry &lhs, const IndustryListEntry &rhs) const
3205 {
3206  /* Compare by distance first and use index as a tiebreaker. */
3207  return std::tie(lhs.distance, lhs.industry->index) < std::tie(rhs.distance, rhs.industry->index);
3208 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
game.hpp
INDUSTRYBEH_ONLY_INTOWN
@ INDUSTRYBEH_ONLY_INTOWN
can only be built in towns (arctic/tropic banks, water tower)
Definition: industrytype.h:65
CheckScaledDistanceFromEdge
static bool CheckScaledDistanceFromEdge(TileIndex tile, uint maxdist)
Check if a tile is within a distance from map edges, scaled by map dimensions independently.
Definition: industry_cmd.cpp:1280
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
TileInfo::z
int z
Height.
Definition: tile_cmd.h:48
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
Vehicle::IsFrontEngine
debug_inline bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:931
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:51
DeleteNewGRFInspectWindow
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Definition: newgrf_debug_gui.cpp:739
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:100
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:76
SLOPE_SE
@ SLOPE_SE
south and east corner are raised
Definition: slope_type.h:57
TileDesc::grf
const char * grf
newGRF used for the tile contents
Definition: tile_cmd.h:63
PRODLEVEL_MINIMUM
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
Definition: industry.h:35
CLEAR_SNOW
@ CLEAR_SNOW
0-3
Definition: clear_map.h:24
CreateNewIndustryHelper
static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, size_t layout_index, uint32_t random_var8f, uint16_t random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip)
Helper function for Build/Fund an industry.
Definition: industry_cmd.cpp:1978
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3200
Industry::owner
Owner owner
owner of the industry. Which SHOULD always be (imho) OWNER_NONE
Definition: industry.h:105
sound_func.h
GroundSpritePaletteTransform
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition: sprite.h:168
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:118
ID_FUND_ONLY
@ ID_FUND_ONLY
The game does not build industries.
Definition: settings_type.h:55
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
SND_30_TOFFEE_QUARRY
@ SND_30_TOFFEE_QUARRY
48 == 0x30 Industry animation: toffee quarry: drill
Definition: sound_type.h:87
IndustryBuildData::wanted_inds
uint32_t wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
Definition: industry.h:293
Cheats::magic_bulldozer
Cheat magic_bulldozer
dynamite industries, objects
Definition: cheat_type.h:27
IsClearGround
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
OUFB_UNLOAD
@ OUFB_UNLOAD
Force unloading all cargo onto the platform, possibly not getting paid.
Definition: order_type.h:54
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
CheckNewIndustryProc
CommandCost CheckNewIndustryProc(TileIndex tile)
Industrytype check function signature.
Definition: industry_cmd.cpp:1399
SND_0B_MINE
@ SND_0B_MINE
9 == 0x09 Industry animation: coal/copper/gold mine: headgear
Definition: sound_type.h:48
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
ReportNewsProductionChangeIndustry
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent)
Report news that industry production has changed significantly.
Definition: industry_cmd.cpp:2761
INDUSTRYBEH_CARGOTYPES_UNLIMITED
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
Definition: industrytype.h:80
IndustrySpec::UsesOriginalEconomy
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
Definition: industry_cmd.cpp:3144
TimerGameTick::counter
static TickCounter counter
Monotonic counter, in ticks, since start of game.
Definition: timer_game_tick.h:33
SND_2B_TOY_FACTORY_2
@ SND_2B_TOY_FACTORY_2
43 == 0x2B Industry animation: toy factory (2): stamp product
Definition: sound_type.h:82
DeleteIndustryNews
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
Definition: news_gui.cpp:955
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:630
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
AdvertiseIndustryOpening
static void AdvertiseIndustryOpening(const Industry *ind)
Advertise about a new industry opening.
Definition: industry_cmd.cpp:1728
water.h
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
ID_VERY_LOW
@ ID_VERY_LOW
Very few industries at game start.
Definition: settings_type.h:57
SpriteLayoutPaletteTransform
PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layou...
Definition: sprite.h:149
EV_BUBBLE
@ EV_BUBBLE
Bubble of bubble generator (industry).
Definition: effectvehicle_func.h:26
INDCTL_NONE
@ INDCTL_NONE
No flags in effect.
Definition: industry.h:46
Industry::counts
static uint16_t counts[NUM_INDUSTRYTYPES]
Number of industries per type ingame.
Definition: industry.h:264
command_func.h
INDUSTRYBEH_AFTER_1960
@ INDUSTRYBEH_AFTER_1960
can only be built after 1960 (oil rigs)
Definition: industrytype.h:70
EV_CHIMNEY_SMOKE
@ EV_CHIMNEY_SMOKE
Smoke of power plant (industry).
Definition: effectvehicle_func.h:17
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<&_industry_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
IAT_TILELOOP
@ IAT_TILELOOP
Trigger in the periodic tile loop.
Definition: newgrf_animation_type.h:39
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
INDCTL_NO_CLOSURE
@ INDCTL_NO_CLOSURE
Industry can not close regardless of production level or time since last delivery.
Definition: industry.h:54
GetTreeGround
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
FlatteningFoundation
Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Definition: slope_func.h:369
INDUSTRYBEH_NO_PAX_PROD_CLAMP
@ INDUSTRYBEH_NO_PAX_PROD_CLAMP
Do not clamp production of passengers. (smooth economy only)
Definition: industrytype.h:81
IndustryBuildData::builddata
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]
Industry build data for every industry type.
Definition: industry.h:292
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
CheckIndustryCloseDownProtection
static bool CheckIndustryCloseDownProtection(IndustryType type)
Protects an industry from closure if the appropriate flags and conditions are met INDUSTRYBEH_CANCLOS...
Definition: industry_cmd.cpp:2666
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:25
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition: water_map.h:115
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:356
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
ID_CUSTOM
@ ID_CUSTOM
Custom number of industries.
Definition: settings_type.h:62
Map::MaxX
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:297
terraform_cmd.h
company_base.h
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1116
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition: economy_type.h:185
IndustryTypeBuildData::max_wait
uint16_t max_wait
Starting number of turns to wait (copied to wait_count).
Definition: industry.h:280
OUFB_TRANSFER
@ OUFB_TRANSFER
Transfer all cargo onto the platform.
Definition: order_type.h:55
timer_game_calendar.h
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:55
IndustrySpec::GetRemovalCost
Money GetRemovalCost() const
Get the cost for removing this industry Take note that the cost will always be zero for non-grf indus...
Definition: industry_cmd.cpp:3135
CheckIndustries
void CheckIndustries()
Verify whether the generated industries are complete, and warn the user if not.
Definition: industry_cmd.cpp:3079
SND_2A_TOY_FACTORY_3
@ SND_2A_TOY_FACTORY_3
42 == 0x2A Industry animation: toy factory (3): eject product
Definition: sound_type.h:81
CBID_INDUSTRY_PRODUCTION_CHANGE
@ CBID_INDUSTRY_PRODUCTION_CHANGE
Called on production changes, so it can be adjusted.
Definition: newgrf_callbacks.h:111
SLOPE_NW
@ SLOPE_NW
north and west corner are raised
Definition: slope_type.h:55
Station
Station data structure.
Definition: station_base.h:442
GetIndustryConstructionStage
byte GetIndustryConstructionStage(Tile tile)
Returns the industry construction stage of the specified tile.
Definition: industry_map.h:100
NewsAllocatedData
Container for any custom data that must be deleted after the news item has reached end-of-life.
Definition: news_type.h:122
PRODLEVEL_CLOSURE
@ PRODLEVEL_CLOSURE
signal set to actually close the industry
Definition: industry.h:34
IndustrySpec::GetConstructionCost
Money GetConstructionCost() const
Get the cost for constructing this industry.
Definition: industry_cmd.cpp:3122
CargoPacket::InvalidateAllFrom
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Definition: cargopacket.cpp:137
CBID_INDTILE_CARGO_ACCEPTANCE
@ CBID_INDTILE_CARGO_ACCEPTANCE
Called to query the cargo acceptance of the industry tile.
Definition: newgrf_callbacks.h:117
ChopLumberMillTrees
static void ChopLumberMillTrees(Industry *i)
Perform a circular search around the Lumber Mill in order to find trees to cut.
Definition: industry_cmd.cpp:1121
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
IndustryBuildData::EconomyMonthlyLoop
void EconomyMonthlyLoop()
Monthly update of industry build data.
Definition: industry_cmd.cpp:2422
SetClearCounter
void SetClearCounter(Tile t, uint c)
Sets the counter used to advance to the next clear density/field type.
Definition: clear_map.h:144
IAT_INDUSTRY_TICK
@ IAT_INDUSTRY_TICK
Trigger every tick.
Definition: newgrf_animation_type.h:40
PerformIndustryTileSlopeCheck
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, size_t layout_index, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check the slope of a tile of a new industry.
Definition: newgrf_industrytiles.cpp:230
IndustryTileSpec::anim_state
bool anim_state
When true, the tile has to be drawn using the animation state instead of the construction state.
Definition: industrytype.h:164
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
SND_0C_POWER_STATION
@ SND_0C_POWER_STATION
10 == 0x0A Industry animation: power station: spark
Definition: sound_type.h:49
CBM_INDT_SHAPE_CHECK
@ CBM_INDT_SHAPE_CHECK
decides slope suitability
Definition: newgrf_callbacks.h:389
_industry_builder
IndustryBuildData _industry_builder
In-game manager of industries.
Definition: industry_cmd.cpp:70
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition: window_type.h:363
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition: timer.h:76
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
Map::ScaleBySize1D
static uint ScaleBySize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
Definition: map_func.h:341
AutoslopeEnabled
bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition: autoslope.h:44
IsTransparencySet
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:48
GetRegister
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Definition: newgrf_spritegroup.h:29
TREE_GROUND_SHORE
@ TREE_GROUND_SHORE
shore
Definition: tree_map.h:56
Pool::PoolItem<&_industry_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
NT_INDUSTRY_COMPANY
@ NT_INDUSTRY_COMPANY
Production changes of industry serviced by local company.
Definition: news_type.h:32
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:134
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
IACT_RANDOMCREATION
@ IACT_RANDOMCREATION
during creation of random ingame industry
Definition: newgrf_industries.h:84
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:97
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
TROPICZONE_RAINFOREST
@ TROPICZONE_RAINFOREST
Rainforest tile.
Definition: tile_type.h:79
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
ProduceIndustryGoodsHelper
static void ProduceIndustryGoodsHelper(Industry *i, bool scale)
Helper for ProduceIndustryGoods that scales and produces cargos.
Definition: industry_cmd.cpp:1144
GetIndustryGfx
IndustryGfx GetIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile.
Definition: industry_map.h:137
Map::WrapToMap
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
Definition: map_func.h:317
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:618
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
CheckNewIndustry_Farm
static CommandCost CheckNewIndustry_Farm(TileIndex tile)
Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).
Definition: industry_cmd.cpp:1332
IsOilRig
bool IsOilRig(Tile t)
Is tile t part of an oilrig?
Definition: station_map.h:275
INDUSTRYBEH_DONT_INCR_PROD
@ INDUSTRYBEH_DONT_INCR_PROD
do not increase production (oil wells) in the temperate climate
Definition: industrytype.h:68
CheckIfCanLevelIndustryPlatform
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, const IndustryTileLayout &layout)
This function tries to flatten out the land below an industry, without damaging the surroundings too ...
Definition: industry_cmd.cpp:1612
DrawIndustryAnimationStruct::x
int x
coordinate x of the first image offset
Definition: industry_land.h:19
IndustryTileSpec::acceptance
std::array< int8_t, INDUSTRY_NUM_INPUTS > acceptance
Level of acceptance per cargo type (signed, may be negative!)
Definition: industrytype.h:156
IndustryTileSpec::callback_mask
uint8_t callback_mask
Bitmask of industry tile callbacks that have to be called.
Definition: industrytype.h:166
IsSteepSlope
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
WC_BUILD_INDUSTRY
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
Definition: window_type.h:435
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
CBM_INDT_ACCEPT_CARGO
@ CBM_INDT_ACCEPT_CARGO
decides accepted types
Definition: newgrf_callbacks.h:388
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition: map_func.h:25
CeilDiv
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:320
build_industry.h
Industry::produced
ProducedCargoArray produced
INDUSTRY_NUM_OUTPUTS production cargo slots.
Definition: industry.h:99
Industry::RecomputeProductionMultipliers
void RecomputeProductionMultipliers()
Recompute #production_rate for current prod_level.
Definition: industry_cmd.cpp:2508
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
GWP_INDUSTRY
@ GWP_INDUSTRY
Generate industries.
Definition: genworld.h:75
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:374
CBID_INDTILE_DRAW_FOUNDATIONS
@ CBID_INDTILE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for industry tile.
Definition: newgrf_callbacks.h:135
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
newgrf_debug.h
town.h
GetGRFConfig
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Definition: newgrf_config.cpp:716
TileInfo::y
int y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:45
CBM_IND_PRODUCTION_256_TICKS
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
Definition: newgrf_callbacks.h:366
IsTileForestIndustry
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
Definition: industry_cmd.cpp:974
OrthogonalTileArea::Add
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition: tilearea.cpp:43
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
SLOPE_S
@ SLOPE_S
the south corner of the tile is raised
Definition: slope_type.h:51
effectvehicle_base.h
ClampU
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:150
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:78
IsWaterTile
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Definition: water_map.h:193
Industry::construction_type
uint8_t construction_type
Way the industry was constructed (.
Definition: industry.h:117
NT_INDUSTRY_NOBODY
@ NT_INDUSTRY_NOBODY
Other industry production changes.
Definition: news_type.h:34
Industry::exclusive_consumer
Owner exclusive_consumer
Which company has exclusive rights to take cargo (INVALID_OWNER = anyone)
Definition: industry.h:120
CmdIndustrySetProduction
CommandCost CmdIndustrySetProduction(DoCommandFlag flags, IndustryID ind_id, byte prod_level, bool show_news, const std::string &custom_news)
Set industry production.
Definition: industry_cmd.cpp:2155
SND_2C_TOY_FACTORY_1
@ SND_2C_TOY_FACTORY_1
44 == 0x2C Industry animation: toy factory (1): conveyor belt
Definition: sound_type.h:83
clear_map.h
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
PRODLEVEL_DEFAULT
@ PRODLEVEL_DEFAULT
default level set when the industry is created
Definition: industry.h:36
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Industry
Defines the internal data of a functional industry.
Definition: industry.h:68
INDUSTRY_TRIGGER_INDUSTRY_TICK
@ INDUSTRY_TRIGGER_INDUSTRY_TICK
The industry has been triggered via its tick.
Definition: newgrf_industrytiles.h:72
IndustryTileSpec::accepts_cargo
std::array< CargoID, INDUSTRY_NUM_INPUTS > accepts_cargo
Cargo accepted by this tile.
Definition: industrytype.h:155
Chance16
bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
Definition: random_func.hpp:131
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:304
Map::ScaleBySize
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
Definition: map_func.h:328
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
CmdIndustrySetText
CommandCost CmdIndustrySetText(DoCommandFlag flags, IndustryID ind_id, const std::string &text)
Change additional industry text.
Definition: industry_cmd.cpp:2243
Industry::ctlflags
IndustryControlFlags ctlflags
flags overriding standard behaviours
Definition: industry.h:109
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
CBID_INDUSTRY_OUTPUT_CARGO_TYPES
@ CBID_INDUSTRY_OUTPUT_CARGO_TYPES
Customize the output cargo types of a newly build industry.
Definition: newgrf_callbacks.h:221
GFX_WATERTILE_SPECIALCHECK
@ GFX_WATERTILE_SPECIALCHECK
not really a tile, but rather a very special check
Definition: industry_map.h:54
CBID_INDTILE_ACCEPT_CARGO
@ CBID_INDTILE_ACCEPT_CARGO
Called to determine which cargoes an industry should accept.
Definition: newgrf_callbacks.h:120
TriggerIndustry
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
Trigger a random trigger for all industry tiles.
Definition: newgrf_industrytiles.cpp:372
WATER_CLASS_INVALID
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition: water_map.h:51
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:52
CBID_INDUSTRY_SPECIAL_EFFECT
@ CBID_INDUSTRY_SPECIAL_EFFECT
Called to determine industry special effects.
Definition: newgrf_callbacks.h:174
CBM_INDT_AUTOSLOPE
@ CBM_INDT_AUTOSLOPE
decides allowance of autosloping
Definition: newgrf_callbacks.h:391
SLOPE_E
@ SLOPE_E
the east corner of the tile is raised
Definition: slope_type.h:52
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
genworld.h
NT_INDUSTRY_CLOSE
@ NT_INDUSTRY_CLOSE
Closing of industries.
Definition: news_type.h:30
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
CheckIfIndustryTileSlopes
static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check=nullptr)
Check slope requirements for industry tiles.
Definition: industry_cmd.cpp:1526
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition: tilearea_type.h:21
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:546
GameCreationSettings::custom_industry_number
uint16_t custom_industry_number
manually entered number of industries
Definition: settings_type.h:359
INDUSTRYBEH_NOBUILT_MAPCREATION
@ INDUSTRYBEH_NOBUILT_MAPCREATION
Do not force one instance of this type to appear on map generation.
Definition: industrytype.h:78
DoCreateNewIndustry
static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, const IndustryTileLayout &layout, size_t layout_index, Town *t, Owner founder, uint16_t initial_random_bits)
Put an industry on the map.
Definition: industry_cmd.cpp:1777
IncreaseGeneratingWorldProgress
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Definition: genworld_gui.cpp:1550
Industry::neutral_station
Station * neutral_station
Associated neutral station.
Definition: industry.h:98
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
object_base.h
RandomRange
static uint32_t RandomRange(uint32_t limit)
Pick a random number between 0 and limit - 1, inclusive.
Definition: random_func.hpp:81
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
_coal_plant_sparks
static const DrawIndustryCoordinates _coal_plant_sparks[]
Movement of the sparks , only used for Power Station.
Definition: industry_land.h:948
effectvehicle_func.h
IndustryTileLayout
std::vector< IndustryTileLayoutTile > IndustryTileLayout
A complete tile layout for an industry is a list of tiles.
Definition: industrytype.h:100
ai.hpp
SND_2D_SUGAR_MINE_1
@ SND_2D_SUGAR_MINE_1
45 == 0x2D Industry animation: sugar mine (1): shaking sieve
Definition: sound_type.h:84
ComplementSlope
Slope ComplementSlope(Slope s)
Return the complement of a slope.
Definition: slope_func.h:76
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:46
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
INDUSTRYBEH_PLANT_ON_BUILT
@ INDUSTRYBEH_PLANT_ON_BUILT
Fields are planted around when built (all farms)
Definition: industrytype.h:67
ClearDockingTilesCheckingNeighbours
void ClearDockingTilesCheckingNeighbours(TileIndex tile)
Clear docking tile status from tiles around a removed dock, if the tile has no neighbours which would...
Definition: station_cmd.cpp:2757
SoundSettings::ambient
bool ambient
Play ambient, industry and town sounds.
Definition: settings_type.h:244
IndustrySpec::closure_text
StringID closure_text
Message appearing when the industry closes.
Definition: industrytype.h:127
GetStringWithArgs
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
Definition: strings.cpp:261
Pool::MAX_SIZE
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:84
ScaleByCargoScale
uint ScaleByCargoScale(uint num, bool town)
Scale a number by the cargo scale setting.
Definition: economy_func.h:77
IsInvisibilitySet
bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:59
Industry::GetRandom
static Industry * GetRandom()
Return a random valid industry.
Definition: industry_cmd.cpp:221
IndustryTileSpec::special_flags
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
Definition: industrytype.h:168
SetIndustryCompleted
void SetIndustryCompleted(Tile tile)
Set if the industry that owns the tile as under construction or not.
Definition: industry_map.h:88
INDUSTRY_COMPLETED
static const int INDUSTRY_COMPLETED
final stage of industry construction.
Definition: industry_type.h:36
Pool::PoolItem<&_industry_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:356
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
Vehicle::Orders
IterateWrapper Orders() const
Returns an iterable ensemble of orders of a vehicle.
Definition: vehicle_base.h:1070
_economy_industries_daily
static IntervalTimer< TimerGameEconomy > _economy_industries_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::INDUSTRY}, [](auto) { _economy.industry_daily_change_counter+=_economy.industry_daily_increment;uint16_t change_loop=_economy.industry_daily_change_counter >> 16;_economy.industry_daily_change_counter &=0xFFFF;if(change_loop==0) { return;} Backup< CompanyID > cur_company(_current_company, OWNER_NONE, FILE_LINE);uint perc=3;if((_industry_builder.wanted_inds >> 16) > GetCurrentTotalNumberOfIndustries()) { perc=std::min(9u, perc+(_industry_builder.wanted_inds >> 16) - GetCurrentTotalNumberOfIndustries());} for(uint16_t j=0;j< change_loop;j++) { if(Chance16(perc, 100)) { _industry_builder.TryBuildNewIndustry();} else { Industry *i=Industry::GetRandom();if(i !=nullptr) { ChangeIndustryProduction(i, false);SetWindowDirty(WC_INDUSTRY_VIEW, i->index);} } } cur_company.Restore();InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);})
Every economy day handler for the industry changes Taking the original map size of 256*256,...
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:77
UpdateIndustryStatistics
static void UpdateIndustryStatistics(Industry *i)
Monthly update of industry statistics.
Definition: industry_cmd.cpp:2490
CheckIfIndustryTilesAreFree
static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, IndustryType type)
Are the tiles of the industry free?
Definition: industry_cmd.cpp:1464
Industry::PostDestructor
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
Definition: industry_cmd.cpp:210
GetTreeGrowth
uint GetTreeGrowth(Tile t)
Returns the tree growth status.
Definition: tree_map.h:181
landscape_cmd.h
CHECK_END
@ CHECK_END
End marker of the industry check procedures.
Definition: industrytype.h:47
AnimationInfo::status
uint8_t status
Status; 0: no looping, 1: looping, 0xFF: no animation.
Definition: newgrf_animation_type.h:20
SND_29_SUGAR_MINE_2
@ SND_29_SUGAR_MINE_2
41 == 0x29 Industry animation: sugar mine (2): shaking sieve
Definition: sound_type.h:80
StationSettings::serve_neutral_industries
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
Definition: settings_type.h:591
SetIndustryAnimationLoop
void SetIndustryAnimationLoop(Tile tile, byte count)
Set the animation loop number.
Definition: industry_map.h:211
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
IndustrySpec::IsRawIndustry
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
Definition: industry_cmd.cpp:3102
SearchLumberMillTrees
static bool SearchLumberMillTrees(TileIndex tile, void *)
Search callback function for ChopLumberMillTrees.
Definition: industry_cmd.cpp:1098
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
ToTileIndexDiff
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition: map_func.h:452
PlaceIndustry
static Industry * PlaceIndustry(IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
Try to place the industry in the game.
Definition: industry_cmd.cpp:2364
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:173
Industry::stations_near
StationList stations_near
NOSAVE: List of nearby stations.
Definition: industry.h:112
TileAddWrap
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
Definition: map.cpp:116
CommandCost
Common return value for all commands.
Definition: command_type.h:23
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:611
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:96
IndustryTypeBuildData::Reset
void Reset()
Reset the entry.
Definition: industry_cmd.cpp:2402
WhoCanServiceIndustry
static int WhoCanServiceIndustry(Industry *ind)
Compute who can service the industry.
Definition: industry_cmd.cpp:2708
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
CheckNewIndustry_OilRefinery
static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile)
Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map).
Definition: industry_cmd.cpp:1301
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
CircularTileSearch
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
Definition: map.cpp:260
Industry::cached_name
std::string cached_name
NOSAVE: Cache of the resolved name of the industry.
Definition: industry.h:113
Randomizer::SetSeed
void SetSeed(uint32_t seed)
(Re)set the state of the random number generator.
Definition: random_func.cpp:67
SLOPE_NE
@ SLOPE_NE
north and east corner are raised
Definition: slope_type.h:58
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:207
IndustrySpec::conflicting
IndustryType conflicting[3]
Industries this industry cannot be close to.
Definition: industrytype.h:110
Industry::exclusive_supplier
Owner exclusive_supplier
Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone)
Definition: industry.h:119
GetSlopeMaxZ
static constexpr int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition: slope_func.h:160
INDUSTRYBEH_PLANT_FIELDS
@ INDUSTRYBEH_PLANT_FIELDS
periodically plants fields around itself (temp and arctic farms)
Definition: industrytype.h:61
Industry::type
IndustryType type
type of industry.
Definition: industry.h:104
SND_36_LUMBER_MILL_3
@ SND_36_LUMBER_MILL_3
54 == 0x36 Industry animation: lumber mill (3): crashing tree
Definition: sound_type.h:93
NT_INDUSTRY_OTHER
@ NT_INDUSTRY_OTHER
Production changes of industry serviced by competitor(s)
Definition: news_type.h:33
NewsType
NewsType
Type of news.
Definition: news_type.h:23
free
void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:379
autoslope.h
CBM_IND_PRODUCTION_CHANGE
@ CBM_IND_PRODUCTION_CHANGE
controls random production change
Definition: newgrf_callbacks.h:368
SND_2E_BUBBLE_GENERATOR
@ SND_2E_BUBBLE_GENERATOR
46 == 0x2E Industry animation: bubble generator (1): generate bubble
Definition: sound_type.h:85
WC_INDUSTRY_DIRECTORY
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
Definition: window_type.h:266
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
Ticks::INDUSTRY_CUT_TREE_TICKS
static constexpr TimerGameTick::Ticks INDUSTRY_CUT_TREE_TICKS
Cycle duration for lumber mill's extra action.
Definition: timer_game_tick.h:57
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
IndustryBuildData
Data for managing the number and type of industries in the game.
Definition: industry.h:291
CBID_INDUSTRY_MONTHLYPROD_CHANGE
@ CBID_INDUSTRY_MONTHLYPROD_CHANGE
Called monthly on production changes, so it can be adjusted more frequently.
Definition: newgrf_callbacks.h:153
IndustrySpec::layouts
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
Definition: industrytype.h:106
IndustrySpec::accepts_cargo
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
Definition: industrytype.h:119
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
INDUSTRYTILE_NOANIM
static const IndustryGfx INDUSTRYTILE_NOANIM
flag to mark industry tiles as having no animation
Definition: industry_type.h:31
CBM_INDT_DRAW_FOUNDATIONS
@ CBM_INDT_DRAW_FOUNDATIONS
decides if default foundations need to be drawn
Definition: newgrf_callbacks.h:390
INVALID_INDUSTRYTILE
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
Definition: industry_type.h:34
ConstructionSettings::industry_platform
uint8_t industry_platform
the amount of flat land around an industry
Definition: settings_type.h:382
SetFence
void SetFence(Tile t, DiagDirection side, uint h)
Sets the type of fence (and whether there is one) for the given border.
Definition: clear_map.h:240
CBM_IND_LOCATION
@ CBM_IND_LOCATION
check industry construction on given area
Definition: newgrf_callbacks.h:367
CBM_IND_INPUT_CARGO_TYPES
@ CBM_IND_INPUT_CARGO_TYPES
customize the cargoes the industry requires
Definition: newgrf_callbacks.h:376
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
EV_COPPER_MINE_SMOKE
@ EV_COPPER_MINE_SMOKE
Smoke at copper mine.
Definition: effectvehicle_func.h:28
INDUSTRYBEH_BUILT_ONWATER
@ INDUSTRYBEH_BUILT_ONWATER
is built on water (oil rig)
Definition: industrytype.h:63
IndustrySpec::production_up_text
StringID production_up_text
Message appearing when the industry's production is increasing.
Definition: industrytype.h:128
SetIndustryGfx
void SetIndustryGfx(Tile t, IndustryGfx gfx)
Set the industry graphics ID for the given industry tile.
Definition: industry_map.h:149
CBID_INDUSTRY_INPUT_CARGO_TYPES
@ CBID_INDUSTRY_INPUT_CARGO_TYPES
Customize the input cargo types of a newly build industry.
Definition: newgrf_callbacks.h:218
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
CLEAR_DESERT
@ CLEAR_DESERT
1,3
Definition: clear_map.h:25
IndustrySpec::minimal_cargo
byte minimal_cargo
minimum amount of cargo transported to the stations.
Definition: industrytype.h:118
Industry::DecIndustryTypeCount
static void DecIndustryTypeCount(IndustryType type)
Decrement the count of industries for this type.
Definition: industry.h:231
DrawIndustryAnimationStruct::image_2
byte image_2
image offset 2
Definition: industry_land.h:21
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
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:401
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
NewsStringData
Container for a single string to be passed as NewsAllocatedData.
Definition: news_type.h:150
Industry::accepted
AcceptedCargoArray accepted
INDUSTRY_NUM_INPUTS input cargo slots.
Definition: industry.h:100
DeleteSubsidyWith
void DeleteSubsidyWith(SourceType type, SourceID index)
Delete the subsidies associated with a given cargo source type and id.
Definition: subsidy.cpp:152
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition: water_map.h:139
timer_game_tick.h
SetupFarmFieldFence
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, DiagDirection side)
Build farm field fence.
Definition: industry_cmd.cpp:1013
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:147
ANIM_STATUS_NO_ANIMATION
static const uint8_t ANIM_STATUS_NO_ANIMATION
There is no animation.
Definition: newgrf_animation_type.h:15
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:628
IndustryTypeBuildData::probability
uint32_t probability
Relative probability of building this industry.
Definition: industry.h:277
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
IndustryTypeBuildData::wait_count
uint16_t wait_count
Number of turns to wait before trying to build again.
Definition: industry.h:281
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
PRODLEVEL_MAXIMUM
@ PRODLEVEL_MAXIMUM
the industry is running at full speed
Definition: industry.h:37
GetIndustryIndex
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:260
industry.h
industry_land.h
safeguards.h
GetNumberOfIndustries
static uint GetNumberOfIndustries()
Get wanted number of industries on the map.
Definition: industry_cmd.cpp:2335
Randomizer::Next
uint32_t Next()
Generate the next pseudo random number.
Definition: random_func.cpp:43
timer.h
HighestSnowLine
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
Definition: landscape.cpp:624
DistanceFromEdgeDir
uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir)
Gets the distance to the edge of the map in given direction.
Definition: map.cpp:236
GetIndustryGamePlayProbability
static uint16_t GetIndustryGamePlayProbability(IndustryType it, byte *min_number)
Compute the probability for constructing a new industry during game play.
Definition: industry_cmd.cpp:2311
IndustryTileSpec::slopes_refused
Slope slopes_refused
slope pattern on which this tile cannot be built
Definition: industrytype.h:157
Industry::ResetIndustryCounts
static void ResetIndustryCounts()
Resets industry counts.
Definition: industry.h:249
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
DifficultySettings::industry_density
byte industry_density
The industry density.
Definition: settings_type.h:102
RandomTile
#define RandomTile()
Get a valid random tile.
Definition: map_func.h:657
DC_NO_TEST_TOWN_RATING
@ DC_NO_TEST_TOWN_RATING
town rating does not disallow you from building
Definition: command_type.h:376
INDUSTRYBEH_BEFORE_1950
@ INDUSTRYBEH_BEFORE_1950
can only be built before 1950 (oil wells)
Definition: industrytype.h:69
CheckNewIndustry_BubbleGen
static CommandCost CheckNewIndustry_BubbleGen(TileIndex tile)
Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).
Definition: industry_cmd.cpp:1386
IndustryBuildData::SetupTargetCount
void SetupTargetCount()
Decide how many industries of each type are needed.
Definition: industry_cmd.cpp:2548
IndustrySpec::prospecting_chance
uint32_t prospecting_chance
Chance prospecting succeeds.
Definition: industrytype.h:109
CBM_IND_SPECIAL_EFFECT
@ CBM_IND_SPECIAL_EFFECT
control special effects
Definition: newgrf_callbacks.h:373
IsSuitableForFarmField
static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields)
Check whether the tile can be replaced by a farm field.
Definition: industry_cmd.cpp:997
TileIndexDiff
int32_t TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:376
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
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition: slope_type.h:94
error.h
GameCreationSettings::oil_refinery_limit
byte oil_refinery_limit
distance oil refineries allowed from map edge
Definition: settings_type.h:346
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
SourceType::Industry
@ Industry
Source/destination is an industry.
IndustryBuildData::TryBuildNewIndustry
void TryBuildNewIndustry()
Try to create a random industry, during gameplay.
Definition: industry_cmd.cpp:2593
INDUSTRYLIFE_BLACK_HOLE
@ INDUSTRYLIFE_BLACK_HOLE
Like power plants and banks.
Definition: industrytype.h:27
PROCESSING_INDUSTRY_ABANDONMENT_YEARS
static const TimerGameEconomy::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS
If a processing industry doesn't produce for this many consecutive economy years, it may close.
Definition: industry.h:26
IndustrySpec::appear_creation
byte appear_creation[NUM_LANDSCAPE]
Probability of appearance during map creation.
Definition: industrytype.h:132
IACT_PROSPECTCREATION
@ IACT_PROSPECTCREATION
from the Fund/build using prospecting
Definition: newgrf_industries.h:86
IndustryTileSpec::anim_production
byte anim_production
Animation frame to start when goods are produced.
Definition: industrytype.h:158
DrawIndustryAnimationStruct::image_3
byte image_3
image offset 3
Definition: industry_land.h:22
stdafx.h
ScaleByInverseCargoScale
static uint ScaleByInverseCargoScale(uint num, bool town)
Scale a number by the inverse of the cargo scale setting, e.g.
Definition: economy_func.h:60
ResetIndustryConstructionStage
void ResetIndustryConstructionStage(Tile tile)
Reset the construction stage counter of the industry, as well as the completion bit.
Definition: industry_map.h:187
landscape.h
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:158
SetAnimationFrame
void SetAnimationFrame(Tile t, byte frame)
Set a new animation frame.
Definition: tile_map.h:262
SoundFx
SoundFx
Sound effects from baseset.
Definition: sound_type.h:37
SND_38_LUMBER_MILL_1
@ SND_38_LUMBER_MILL_1
56 == 0x38 Industry animation: lumber mill (1): chainsaw
Definition: sound_type.h:95
ReleaseDisastersTargetingIndustry
void ReleaseDisastersTargetingIndustry(IndustryID i)
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile)...
Definition: disaster_vehicle.cpp:958
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:105
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
IndustryTileSpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:170
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
Ticks::INDUSTRY_PRODUCE_TICKS
static constexpr TimerGameTick::Ticks INDUSTRY_PRODUCE_TICKS
Cycle duration for industry production.
Definition: timer_game_tick.h:55
CreateNewIndustry
static Industry * CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
Create a new industry of random layout.
Definition: industry_cmd.cpp:2266
viewport_func.h
Industry::text
std::string text
General text with additional information.
Definition: industry.h:121
TileLoop_Water
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
Definition: water_cmd.cpp:1230
IACT_USERCREATION
@ IACT_USERCREATION
from the Fund/build window
Definition: newgrf_industries.h:85
DrawIndustryAnimationStruct
This is used to gather some data about animation drawing in the industry code Image_1-2-3 are in fact...
Definition: industry_land.h:18
SetIndustryConstructionStage
void SetIndustryConstructionStage(Tile tile, byte value)
Sets the industry construction stage of the specified tile.
Definition: industry_map.h:112
TO_INDUSTRIES
@ TO_INDUSTRIES
industries
Definition: transparency.h:26
IndustrySpec::number_of_sounds
uint8_t number_of_sounds
Number of sounds available in the sounds array.
Definition: industrytype.h:133
Chance16I
bool Chance16I(const uint a, const uint b, const uint32_t r)
Checks if a given randomize-number is below a given probability.
Definition: random_func.hpp:112
animated_tile_func.h
HasTileWaterClass
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:104
ICT_MAP_GENERATION
@ ICT_MAP_GENERATION
during random map creation
Definition: industrytype.h:54
TownCache::population
uint32_t population
Current population of people.
Definition: town.h:42
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:673
SLOPE_W
@ SLOPE_W
the west corner of the tile is raised
Definition: slope_type.h:50
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Industry::random_colour
Colours random_colour
randomized colour of the industry, for display purpose
Definition: industry.h:106
ConvertBooleanCallback
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition: newgrf_commons.cpp:529
_industry_draw_tile_data
static const DrawBuildingsTileStruct _industry_draw_tile_data[NEW_INDUSTRYTILEOFFSET *4]
Structure for industry tiles drawing.
Definition: industry_land.h:51
IndustrySpec::callback_mask
uint16_t callback_mask
Bitmask of industry callbacks that have to be called.
Definition: industrytype.h:136
DistanceMax
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition: map.cpp:191
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:427
NT_INDUSTRY_OPEN
@ NT_INDUSTRY_OPEN
Opening of industries.
Definition: news_type.h:29
Map::SizeX
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition: map_func.h:270
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:62
CreateEffectVehicle
EffectVehicle * CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle at a particular location.
Definition: effectvehicle.cpp:594
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
INDUSTRYLIFE_PROCESSING
@ INDUSTRYLIFE_PROCESSING
Like factories.
Definition: industrytype.h:30
CBM_IND_MONTHLYPROD_CHANGE
@ CBM_IND_MONTHLYPROD_CHANGE
controls monthly random production change
Definition: newgrf_callbacks.h:369
CBID_INDUSTRY_PROD_CHANGE_BUILD
@ CBID_INDUSTRY_PROD_CHANGE_BUILD
Called when industry is built to set initial production level.
Definition: newgrf_callbacks.h:278
CheckNewIndustry_Lumbermill
static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile)
Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest).
Definition: industry_cmd.cpp:1373
string_func.h
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:138
MakeField
void MakeField(Tile t, uint field_type, IndustryID industry)
Make a (farm) field tile.
Definition: clear_map.h:280
IndustryBuildData::Reset
void Reset()
Completely reset the industry build data.
Definition: industry_cmd.cpp:2412
Economy::industry_daily_increment
uint32_t industry_daily_increment
The value which will increment industry_daily_change_counter. Computed value. NOSAVE.
Definition: economy_type.h:50
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
ConstructionSettings::raw_industry_construction
uint8_t raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
Definition: settings_type.h:381
CmdBuildIndustry
CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType it, uint32_t first_layout, bool fund, uint32_t seed)
Build/Fund an industry.
Definition: industry_cmd.cpp:2042
Station::industries_near
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
Definition: station_base.h:474
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
vehicle_func.h
IndustrySpec::IsProcessingIndustry
bool IsProcessingIndustry() const
Is an industry with the spec a processing industry?
Definition: industry_cmd.cpp:3111
station_base.h
DrawIndustryAnimationStruct::image_1
byte image_1
image offset 1
Definition: industry_land.h:20
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
CHECK_OIL_RIG
@ CHECK_OIL_RIG
Industries at sea should be positioned near edge of the map.
Definition: industrytype.h:46
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:320
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:306
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition: timer_game_economy.h:35
CLEAN_RANDOMSOUNDS
@ CLEAN_RANDOMSOUNDS
Free the dynamically allocated sounds table.
Definition: industrytype.h:22
Industry::selected_layout
byte selected_layout
Which tile layout was used when creating the industry.
Definition: industry.h:118
Pool
Base class for all pools.
Definition: pool_type.hpp:80
IndustrySpec::removal_cost_multiplier
uint32_t removal_cost_multiplier
Base removal cost multiplier.
Definition: industrytype.h:108
newgrf_industrytiles.h
EconomySettings::type
EconomyType type
economy type (original/smooth/frozen)
Definition: settings_type.h:541
PopulateStationsNearby
static void PopulateStationsNearby(Industry *ind)
Populate an industry's list of nearby stations, and if it accepts any cargo, also add the industry to...
Definition: industry_cmd.cpp:1748
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:55
subsidy_func.h
CheckNewIndustry_Plantation
static CommandCost CheckNewIndustry_Plantation(TileIndex tile)
Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).
Definition: industry_cmd.cpp:1347
INDTILE_TRIGGER_TILE_LOOP
@ INDTILE_TRIGGER_TILE_LOOP
The tile of the industry has been triggered during the tileloop.
Definition: newgrf_industrytiles.h:71
FindTownForIndustry
static CommandCost FindTownForIndustry(TileIndex tile, int type, Town **t)
Find a town for the industry, while checking for multiple industries in the same town.
Definition: industry_cmd.cpp:1424
Pool::PoolItem<&_industry_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:365
DeleteAnimatedTile
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
Definition: animated_tile.cpp:25
Industry::counter
uint16_t counter
used for animation and/or production (if available cargo)
Definition: industry.h:102
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
INDUSTRYBEH_ONLY_NEARTOWN
@ INDUSTRYBEH_ONLY_NEARTOWN
is always built near towns (toy shop)
Definition: industrytype.h:66
SLOPE_N
@ SLOPE_N
the north corner of the tile is raised
Definition: slope_type.h:53
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
Randomizer
Structure to encapsulate the pseudo random number generators.
Definition: random_func.hpp:21
IndustryTileSpec::animation
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
Definition: industrytype.h:167
GameCreationSettings::land_generator
byte land_generator
the landscape generator
Definition: settings_type.h:345
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
Industry::founder
Owner founder
Founder of the industry.
Definition: industry.h:115
TileDesc::dparam
uint64_t dparam
Parameter of the str string.
Definition: tile_cmd.h:54
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
CheckIfFarEnoughFromConflictingIndustry
static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int type)
Check that the new industry is far enough from conflicting industries.
Definition: industry_cmd.cpp:1685
ICT_SCENARIO_EDITOR
@ ICT_SCENARIO_EDITOR
while editing a scenario
Definition: industrytype.h:55
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition: genworld_gui.cpp:1536
GetIndustryTileSpec
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
Definition: industry_cmd.cpp:137
Industry::IncIndustryTypeCount
static void IncIndustryTypeCount(IndustryType type)
Increment the count of industries for this type.
Definition: industry.h:220
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:308
CBM_INDT_CARGO_ACCEPTANCE
@ CBM_INDT_CARGO_ACCEPTANCE
decides amount of cargo acceptance
Definition: newgrf_callbacks.h:387
MakeIndustry
void MakeIndustry(Tile t, IndustryID index, IndustryGfx gfx, uint8_t random, WaterClass wc)
Make the given tile an industry tile.
Definition: industry_map.h:278
IndustrySpec::random_sounds
const uint8_t * random_sounds
array of random sounds.
Definition: industrytype.h:134
INDUSTRYLIFE_ORGANIC
@ INDUSTRYLIFE_ORGANIC
Like forests.
Definition: industrytype.h:29
SLOPE_SW
@ SLOPE_SW
south and west corner are raised
Definition: slope_type.h:56
DrawBuildingsTileStruct
This structure is the same for both Industries and Houses.
Definition: sprite.h:67
cheat_type.h
CheckNewIndustry_OilRig
static CommandCost CheckNewIndustry_OilRig(TileIndex tile)
Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map).
Definition: industry_cmd.cpp:1317
Pool::PoolItem<&_industry_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:314
tree_map.h
industry_cmd.h
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:2051
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
GenerateIndustries
void GenerateIndustries()
This function will create random industries during game creation.
Definition: industry_cmd.cpp:2439
FOUNDATION_LEVELED
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
Definition: slope_type.h:95
IndustrySpec::production_down_text
StringID production_down_text
Message appearing when the industry's production is decreasing.
Definition: industrytype.h:129
LG_TERRAGENESIS
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
Definition: genworld.h:21
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
IndustrySpec::appear_ingame
byte appear_ingame[NUM_LANDSCAPE]
Probability of appearance in game.
Definition: industrytype.h:131
IndustrySpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:139
Town::cache
TownCache cache
Container for all cacheable data.
Definition: town.h:53
OverrideManagerBase::ResetOverride
void ResetOverride()
Resets the override, which is used while initializing game.
Definition: newgrf_commons.cpp:78
IACT_MAPGENERATION
@ IACT_MAPGENERATION
during random map generation
Definition: newgrf_industries.h:83
Industry::GetIndustryTypeCount
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:242
ForAllStationsAroundTiles
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
Call a function on all stations that have any part of the requested area within their catchment.
Definition: station_base.h:567
IndustrySpec::cleanup_flag
uint8_t cleanup_flag
flags indicating which data should be freed upon cleaning up
Definition: industrytype.h:137
Pool::PoolItem<&_industry_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
IndustryTileLayoutTile
Definition of one tile in an industry tile layout.
Definition: industrytype.h:94
ChangeIndustryProduction
static void ChangeIndustryProduction(Industry *i, bool monthly)
Change industry production or do closure.
Definition: industry_cmd.cpp:2789
IndustryTypeBuildData::min_number
byte min_number
Smallest number of industries that should exist (either 0 or 1).
Definition: industry.h:278
TriggerIndustryTile
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
Trigger a random trigger for a single industry tile.
Definition: newgrf_industrytiles.cpp:359
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:388
CBID_INDTILE_AUTOSLOPE
@ CBID_INDTILE_AUTOSLOPE
Called to determine if industry can alter the ground below industry tile.
Definition: newgrf_callbacks.h:177
MapGRFStringID
StringID MapGRFStringID(uint32_t grfid, StringID str)
Used when setting an object's property to map to the GRF's strings while taking in consideration the ...
Definition: newgrf.cpp:550
IndustryTypeBuildData
Data for managing the number of industries of a single industry type.
Definition: industry.h:276
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
GetIndustryAnimationLoop
byte GetIndustryAnimationLoop(Tile tile)
Get the animation loop number.
Definition: industry_map.h:199
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:53
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:372
EffectVehicle
A special vehicle is one of the following:
Definition: effectvehicle_base.h:24
DC_NO_MODIFY_TOWN_RATING
@ DC_NO_MODIFY_TOWN_RATING
do not change town rating
Definition: command_type.h:381
IndustryListEntry
Definition: station_base.h:428
CreateEffectVehicleAbove
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
Definition: effectvehicle.cpp:622
Backup::GetOriginalValue
const T & GetOriginalValue() const
Returns the backupped value.
Definition: backup_type.hpp:72
CheckNewIndustry_Forest
static CommandCost CheckNewIndustry_Forest(TileIndex tile)
Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate).
Definition: industry_cmd.cpp:1263
CanCargoServiceIndustry
static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
Can given cargo type be accepted or produced by the industry?
Definition: industry_cmd.cpp:2684
EconomySettings::multiple_industry_per_town
bool multiple_industry_per_town
allow many industries of the same type per town
Definition: settings_type.h:549
IndustrySpec::life_type
IndustryLifeType life_type
This is also known as Industry production flag, in newgrf specs.
Definition: industrytype.h:121
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:225
SetIndustryConstructionCounter
void SetIndustryConstructionCounter(Tile tile, byte value)
Sets this industry tile's construction counter value.
Definition: industry_map.h:174
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:480
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
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:102
Industry::IsCargoProduced
bool IsCargoProduced() const
Test if this industry produces any cargo.
Definition: industry.h:185
_check_new_industry_procs
static CheckNewIndustryProc *const _check_new_industry_procs[CHECK_END]
Check functions for different types of industry.
Definition: industry_cmd.cpp:1402
CommandHelper
Definition: command_func.h:93
window_func.h
IndustrySpec::behaviour
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:123
CmdIndustrySetFlags
CommandCost CmdIndustrySetFlags(DoCommandFlag flags, IndustryID ind_id, IndustryControlFlags ctlflags)
Set industry control flags.
Definition: industry_cmd.cpp:2134
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
Delta
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
Definition: math_func.hpp:234
GetAnimationFrame
byte GetAnimationFrame(Tile t)
Get the current animation frame.
Definition: tile_map.h:250
INDUSTRYBEH_CANCLOSE_LASTINSTANCE
@ INDUSTRYBEH_CANCLOSE_LASTINSTANCE
Allow closing down the last instance of this type.
Definition: industrytype.h:79
AddChildSpriteScreen
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub, bool scale, bool relative)
Add a child sprite to a parent sprite.
Definition: viewport.cpp:829
CBID_INDUSTRY_DECIDE_COLOUR
@ CBID_INDUSTRY_DECIDE_COLOUR
Called to determine the colour of an industry.
Definition: newgrf_callbacks.h:215
GetTileMaxPixelZ
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition: tile_map.h:304
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition: tile_map.h:29
OverflowSafeInt< int64_t >
TransportIndustryGoods
static bool TransportIndustryGoods(TileIndex tile)
Move produced cargo from industry to nearby stations.
Definition: industry_cmd.cpp:522
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
Economy::industry_daily_change_counter
uint32_t industry_daily_change_counter
Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily.
Definition: economy_type.h:49
INDCTL_NO_PRODUCTION_DECREASE
@ INDCTL_NO_PRODUCTION_DECREASE
When industry production change is evaluated, rolls to decrease are ignored.
Definition: industry.h:48
GetIndustryConstructionCounter
byte GetIndustryConstructionCounter(Tile tile)
Returns this industry tile's construction counter value.
Definition: industry_map.h:162
SetIndustryIndexOfField
void SetIndustryIndexOfField(Tile t, IndustryID i)
Set the industry (farm) that made the field.
Definition: clear_map.h:207
CBM_IND_DECIDE_COLOUR
@ CBM_IND_DECIDE_COLOUR
give a custom colour to newly build industries
Definition: newgrf_callbacks.h:375
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:336
NewsStringData::string
std::string string
The string to retain.
Definition: news_type.h:151
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:90
OrthogonalTileArea::Expand
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Definition: tilearea.cpp:123
GetCurrentTotalNumberOfIndustries
static uint GetCurrentTotalNumberOfIndustries()
Get total number of industries existing in the game.
Definition: industry_cmd.cpp:2393
INDUSTRYBEH_TOWN1200_MORE
@ INDUSTRYBEH_TOWN1200_MORE
can only be built in towns larger than 1200 inhabitants (temperate bank)
Definition: industrytype.h:64
GetIndustryType
IndustryType GetIndustryType(Tile tile)
Retrieve the type for this industry.
Definition: industry_cmd.cpp:106
ID_END
@ ID_END
Number of industry density settings.
Definition: settings_type.h:64
Industry::last_prod_year
TimerGameEconomy::Year last_prod_year
last economy year of production
Definition: industry.h:107
IndustrySpec::check_proc
byte check_proc
Index to a procedure to check for conflicting circumstances.
Definition: industrytype.h:111
TileInfo::x
int x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:44
NEW_INDUSTRYTILEOFFSET
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
Definition: industry_type.h:32
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:47
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:620
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
DC_NONE
@ DC_NONE
no flag is set
Definition: command_type.h:370
CBM_IND_PROD_CHANGE_BUILD
@ CBM_IND_PROD_CHANGE_BUILD
initialise production level on construction
Definition: newgrf_callbacks.h:378
IAT_CONSTRUCTION_STATE_CHANGE
@ IAT_CONSTRUCTION_STATE_CHANGE
Trigger whenever the construction state changes.
Definition: newgrf_animation_type.h:38
CheckNewIndustry_Water
static CommandCost CheckNewIndustry_Water(TileIndex tile)
Check the conditions of CHECK_WATER (Industry should be in the desert).
Definition: industry_cmd.cpp:1360
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
EconomyIsInRecession
bool EconomyIsInRecession()
Is the economy in recession?
Definition: economy_func.h:49
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition: industrytype.h:125
Pool::PoolItem<&_industry_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
IndustryBehaviour
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
Definition: industrytype.h:59
IndustrySpec::new_industry_text
StringID new_industry_text
Message appearing when the industry is built.
Definition: industrytype.h:126
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
IndustryTypeBuildData::target_count
uint16_t target_count
Desired number of industries of this type.
Definition: industry.h:279
INDCTL_MASK
@ INDCTL_MASK
Mask of all flags set.
Definition: industry.h:58
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
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
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
Industry::construction_date
TimerGameCalendar::Date construction_date
Date of the construction of the industry.
Definition: industry.h:116
Industry::psa
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition: industry.h:125
INDCTL_NO_PRODUCTION_INCREASE
@ INDCTL_NO_PRODUCTION_INCREASE
When industry production change is evaluated, rolls to increase are ignored.
Definition: industry.h:50
IAT_INDUSTRY_DISTRIBUTES_CARGO
@ IAT_INDUSTRY_DISTRIBUTES_CARGO
Trigger when cargo is distributed.
Definition: newgrf_animation_type.h:42
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
pool_func.hpp
IndustryControlFlags
IndustryControlFlags
Flags to control/override the behaviour of an industry.
Definition: industry.h:44
CheckIfIndustryIsAllowed
static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
Is the industry allowed to be built at this place for the town?
Definition: industry_cmd.cpp:1568
Chance16R
bool Chance16R(const uint a, const uint b, uint32_t &r)
Flips a coin with a given probability and saves the randomize-number in a variable.
Definition: random_func.hpp:155
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:64
INDUSTRYBEH_CUT_TREES
@ INDUSTRYBEH_CUT_TREES
cuts trees and produce first output cargo from them (lumber mill)
Definition: industrytype.h:62
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:75
ResetIndustries
void ResetIndustries()
This function initialize the spec arrays of both industry and industry tiles.
Definition: industry_cmd.cpp:80
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
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::anim_next
byte anim_next
Next frame in an animation.
Definition: industrytype.h:159
CLEAR_FIELDS
@ CLEAR_FIELDS
3
Definition: clear_map.h:23
IsLocalCompany
bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:47
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition: industrytype.h:154
INDCTL_EXTERNAL_PROD_LEVEL
@ INDCTL_EXTERNAL_PROD_LEVEL
Indicates that the production level of the industry is externally controlled.
Definition: industry.h:56
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition: tile_map.h:238
CmdIndustrySetExclusivity
CommandCost CmdIndustrySetExclusivity(DoCommandFlag flags, IndustryID ind_id, Owner company_id, bool consumer)
Change exclusive consumer or supplier for the industry.
Definition: industry_cmd.cpp:2214
GetIndustryIndexOfField
IndustryID GetIndustryIndexOfField(Tile t)
Get the industry (farm) that made the field.
Definition: clear_map.h:195
Order
Definition: order_base.h:36
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
IndustryTypeBuildData::GetIndustryTypeData
bool GetIndustryTypeData(IndustryType it)
Set the probability and min_number fields for the industry type it for a running game.
Definition: industry_cmd.cpp:2537
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
IsIndustryCompleted
bool IsIndustryCompleted(Tile t)
Is this industry tile fully built?
Definition: industry_map.h:75
CHECK_REFINERY
@ CHECK_REFINERY
Industry should be positioned near edge of the map.
Definition: industrytype.h:40
GetScaledIndustryGenerationProbability
static uint32_t GetScaledIndustryGenerationProbability(IndustryType it, bool *force_at_least_one)
Compute the appearance probability for an industry during map creation.
Definition: industry_cmd.cpp:2285
EffectVehicle::animation_substate
byte animation_substate
Sub state to time the change of the graphics/behaviour.
Definition: effectvehicle_base.h:26
GetTranslatedIndustryTileID
IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
Definition: industrytype.h:192
CBM_IND_OUTPUT_CARGO_TYPES
@ CBM_IND_OUTPUT_CARGO_TYPES
customize the cargoes the industry produces
Definition: newgrf_callbacks.h:377
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
PlaceInitialIndustry
static void PlaceInitialIndustry(IndustryType type, bool try_hard)
Try to build a industry on the map.
Definition: industry_cmd.cpp:2379
timer_game_economy.h
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:589
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition: map_func.h:279
GRFConfig::GetName
const char * GetName() const
Get the name of this grf.
Definition: newgrf_config.cpp:98
INDTILE_SPECIAL_ACCEPTS_ALL_CARGO
@ INDTILE_SPECIAL_ACCEPTS_ALL_CARGO
Tile always accepts all cargoes the associated industry accepts.
Definition: industrytype.h:89
Industry::random
uint16_t random
Random value used for randomisation of all kinds of things.
Definition: industry.h:123
ICT_NORMAL_GAMEPLAY
@ ICT_NORMAL_GAMEPLAY
either by user or random creation process
Definition: industrytype.h:53
news_func.h
AddAnimatedTile
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet).
Definition: animated_tile.cpp:40
CheckNewIndustry_NULL
static CommandCost CheckNewIndustry_NULL(TileIndex)
Check the conditions of CHECK_NOTHING (Always succeeds).
Definition: industry_cmd.cpp:1253
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition: timer_game_calendar.h:32
Industry::TileBelongsToIndustry
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition: industry.h:137
backup_type.hpp
SND_37_LUMBER_MILL_2
@ SND_37_LUMBER_MILL_2
55 == 0x37 Industry animation: lumber mill (2): falling tree
Definition: sound_type.h:94
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
INDUSTRYLIFE_EXTRACTIVE
@ INDUSTRYLIFE_EXTRACTIVE
Like mines.
Definition: industrytype.h:28