51#include "script/api/script_event_types.hpp"
57#include "table/strings.h"
63IndustryPool _industry_pool(
"Industry");
66void ShowIndustryViewWindow(IndustryID industry);
69static uint8_t _industry_sound_ctr;
89 std::fill(industry_insert, std::end(_industry_specs),
IndustrySpec{});
92 for (
auto it = std::begin(_industry_specs); it != industry_insert; ++it) {
93 it->enabled = it->climate_availability.Test(
_settings_game.game_creation.landscape);
96 auto industry_tile_insert = std::copy(std::begin(_origin_industry_tile_specs), std::end(_origin_industry_tile_specs), std::begin(_industry_tile_specs));
97 std::fill(industry_tile_insert, std::end(_industry_tile_specs),
IndustryTileSpec{});
100 _industile_mngr.ResetOverride();
101 _industry_mngr.ResetOverride();
117 assert(ind !=
nullptr);
132 return &_industry_specs[thistype];
146 return &_industry_tile_specs[gfx];
170 DeleteOilRig(tile_cur);
174 if (has_neutral_station) {
176 for (
TileIndex tile_cur : this->location) {
212 st->RemoveIndustryToDeliver(
this);
235 size_t index = std::numeric_limits<size_t>::max();
252static void IndustryDrawSugarMine(
const TileInfo *ti)
270static void IndustryDrawToffeeQuarry(
const TileInfo *ti)
285static void IndustryDrawBubbleGenerator(
const TileInfo *ti)
293static void IndustryDrawToyFactory(
const TileInfo *ti)
309static void IndustryDrawCoalPlantSparks(
const TileInfo *ti)
314 if (image != 0 && image < 7) {
324typedef void IndustryDrawTileProc(
const TileInfo *ti);
325static IndustryDrawTileProc *
const _industry_draw_tile_procs[5] = {
326 IndustryDrawSugarMine,
327 IndustryDrawToffeeQuarry,
328 IndustryDrawBubbleGenerator,
329 IndustryDrawToyFactory,
330 IndustryDrawCoalPlantSparks,
371 DrawWaterClassGround(ti);
380 image = dits->building.
sprite;
390 if (proc >= 0) _industry_draw_tile_procs[proc](ti);
426 for (
const auto &a : ind->
accepted) {
427 auto pos = std::ranges::find(accepts_cargo, a.cargo);
428 if (pos == std::end(accepts_cargo)) {
431 if (pos == std::end(accepts_cargo))
continue;
434 cargo_acceptance[std::distance(std::begin(accepts_cargo), pos)] += 8;
451 cargo_acceptance.fill(0);
456 for (
size_t i = 0; i < std::size(itspec->
accepts_cargo); i++) {
461 acceptance[cargo] += cargo_acceptance[i];
464 if (always_accepted.
Test(cargo))
continue;
470 always_accepted.
Set(cargo);
484 td.
str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
504 !
_cheats.magic_bulldozer.value) ||
533 bool moved_cargo =
false;
543 p.history[THIS_MONTH].production += cw;
546 p.history[THIS_MONTH].transported += am;
548 moved_cargo |= (am != 0);
555static void AnimateSugarSieve(
TileIndex tile)
575static void AnimateToffeeQuarry(
TileIndex tile)
592static void AnimateBubbleCatcher(
TileIndex tile)
605static void AnimatePowerPlantSparks(
TileIndex tile)
617static void AnimateToyFactory(
TileIndex tile)
641static void AnimatePlasticFountain(
TileIndex tile, IndustryGfx gfx)
648static void AnimateOilWell(
TileIndex tile, IndustryGfx gfx)
663static void AnimateMineTower(
TileIndex tile)
667 if ((state -= 0x400) < 0)
return;
670 if (state < 0x20 || state >= 0x180) {
676 if (state & 7)
return;
678 if (state & 3)
return;
681 if (m > 0xC2) m = 0xC0;
684 }
else if (state >= 0x200 && state < 0x3A0) {
685 int i = (state < 0x220 || state >= 0x380) ? 7 : 3;
686 if (state & i)
return;
689 if (m < 0x80) m = 0x82;
701 AnimateNewIndustryTile(tile);
742 AnimateMineTower(tile);
747static void CreateChimneySmoke(
TileIndex tile)
756static void MakeIndustryTileBigger(
TileIndex tile)
767 TriggerIndustryTileAnimation_ConstructionStageChanged(tile,
false);
782 CreateChimneySmoke(tile);
816static void TileLoopIndustry_BubbleGenerator(
TileIndex tile)
818 static const int8_t _bubble_spawn_location[3][4] = {
826 int dir = Random() & 3;
831 _bubble_spawn_location[2][dir],
852 MakeIndustryTileBigger(tile);
945 TileLoopIndustry_BubbleGenerator(tile);
992 return std::any_of(std::begin(ind->
produced), std::end(ind->
produced), [](
const auto &p) { return IsValidCargoType(p.cargo) && CargoSpec::Get(p.cargo)->label == CT_WOOD; });
995static const uint8_t _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
1013 default:
return true;
1016 default:
return false;
1036 TileIndex neighbour = tile + neighbour_diff;
1041 if (or_ == 1 &&
Chance16(1, 7)) or_ = 2;
1051static void PlantFarmField(
TileIndex tile, IndustryID industry)
1058 uint32_t r = (Random() & 0x303) + 0x404;
1060 uint size_x =
GB(r, 0, 8);
1061 uint size_y =
GB(r, 8, 8);
1066 if (ta.w == 0 || ta.h == 0)
return;
1074 if (count * 2 < ta.w * ta.h)
return;
1078 uint counter =
GB(r, 5, 3);
1079 uint field_type =
GB(r, 8, 8) * 9 >> 8;
1085 MakeField(cur_tile, field_type, industry);
1093 type = _plantfarmfield_type[Random() & 0xF];
1102void PlantRandomFarmField(
const Industry *i)
1104 int x = i->
location.
w / 2 + Random() % 31 - 16;
1105 int y = i->
location.
h / 2 + Random() % 31 - 16;
1109 if (tile !=
INVALID_TILE) PlantFarmField(tile, i->index);
1119 auto itp = std::begin(i->
produced);
1133 _industry_sound_ctr = 1;
1134 _industry_sound_tile = tile;
1156 uint16_t amount = p.rate;
1163static void ProduceIndustryGoods(
Industry *i)
1168 if ((i->
counter & 0x3F) == 0) {
1171 if (std::any_of(std::begin(i->
produced), std::end(i->
produced), [](
const auto &p) { return p.history[LAST_MONTH].production > 0; })) {
1213 if (plant) PlantRandomFarmField(i);
1236void OnTick_Industry()
1238 if (_industry_sound_ctr != 0) {
1239 _industry_sound_ctr++;
1241 if (_industry_sound_ctr == 75) {
1243 }
else if (_industry_sound_ctr == 160) {
1244 _industry_sound_ctr = 0;
1252 ProduceIndustryGoods(i);
1255 for (
auto &a : i->
accepted) a.accumulated_waiting += a.waiting;
1278 return CommandCost(STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED);
1293 uint maxdist_x = maxdist;
1294 uint maxdist_y = maxdist;
1318 return CommandCost(STR_ERROR_CAN_ONLY_BE_POSITIONED);
1321extern bool _ignore_industry_restrictions;
1335 return CommandCost(STR_ERROR_CAN_ONLY_BE_POSITIONED);
1374 return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT);
1387 return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST);
1400 return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_LOW_AREAS);
1444 return CommandCost(STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN);
1451bool IsSlopeRefused(
Slope current,
Slope refused)
1494 if (ret.
Failed())
return ret;
1502 if (ind_behav.
Any({IndustryBehaviour::OnlyInTown, IndustryBehaviour::Town1200More}) ||
1505 return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS);
1510 ret = Command<Commands::LandscapeClear>::Do({}, cur_tile);
1512 if (ret.
Failed())
return ret;
1516 if (ret.
Failed())
return ret;
1538 bool refused_slope =
false;
1539 bool custom_shape =
false;
1550 custom_shape =
true;
1552 if (ret.
Failed())
return ret;
1560 if (custom_shape_check !=
nullptr) *custom_shape_check = custom_shape;
1581 return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200);
1585 return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_NEAR_TOWN_CENTER);
1591static bool CheckCanTerraformSurroundingTiles(
TileIndex tile, uint height,
int internal)
1603 if (internal != 0 &&
Delta(curh, height) > 1)
return false;
1608 if (internal == 0 && curh != height) {
1609 if (
TileX(tile_walk) == 0 ||
TileY(tile_walk) == 0 || !CheckCanTerraformSurroundingTiles(tile_walk +
TileDiffXY(-1, -1), height, internal + 1)) {
1634 if (it.ti.x > max_x) max_x = it.ti.x;
1635 if (it.ti.y > max_y) max_y = it.ti.y;
1661 if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
1680 Command<Commands::TerraformLand>::Do(flags, tile_walk,
SLOPE_N, curh <= h);
1681 curh += (curh > h) ? -1 : 1;
1700 for (IndustryType conflicting_type : indspec->
conflicting) {
1701 if (conflicting_type == IT_INVALID)
continue;
1747 if (!IsTileType(tile, TileType::Industry) || GetIndustryIndex(tile) != ind->index) return false;
1748 ind->stations_near.insert(st);
1749 st->AddIndustryToDeliver(ind, tile);
1773 industries.insert(i->index);
1775 size_t produced_count = 0;
1776 for (
size_t index = 0; index < std::size(indspec->produced_cargo); ++index) {
1778 produced_count = index + 1;
1781 for (
size_t index = 0; index < produced_count; ++index) {
1783 p.
cargo = indspec->produced_cargo[index];
1784 p.
rate = indspec->production_rate[index];
1787 size_t accepted_count = 0;
1788 for (
size_t index = 0; index < std::size(indspec->
accepts_cargo); ++index) {
1790 accepted_count = index + 1;
1793 for (
size_t index = 0; index < accepted_count; ++index) {
1808 uint16_t r = Random();
1811 i->
random = initial_random_bits;
1874 for (uint j = 0; j < maxcargoes; j++) {
1897 if (std::any_of(std::begin(i->
accepted), std::begin(i->
accepted) + j, [&cargo](
const auto &a) { return a.cargo == cargo; })) {
1912 for (uint j = 0; j < maxcargoes; j++) {
1928 if (std::ranges::find(indspec->produced_cargo, cargo) == std::end(indspec->produced_cargo)) {
1933 if (std::any_of(std::begin(i->
produced), std::begin(i->
produced) + j, [&cargo](
const auto &p) { return p.cargo == cargo; })) {
1955 MakeIndustry(cur_tile, i->index, it.gfx, Random(), wc);
1974 TriggerIndustryTileAnimation_ConstructionStageChanged(cur_tile,
true);
1979 for (uint j = 0; j != 50; j++) PlantRandomFarmField(i);
2005 assert(layout_index < indspec->layouts.size());
2012 if (ret.
Failed())
return ret;
2016 if (ret.
Failed())
return ret;
2017 assert(t !=
nullptr);
2020 if (ret.
Failed())
return ret;
2023 std::vector<ClearedObjectArea> object_areas(_cleared_object_areas);
2025 _cleared_object_areas = std::move(object_areas);
2026 if (ret.
Failed())
return ret;
2034 if (ret.
Failed())
return ret;
2037 bool custom_shape_check =
false;
2038 ret =
CheckIfIndustryTileSlopes(tile, layout, layout_index, type, random_initial_bits, founder, creation_type, &custom_shape_check);
2039 if (ret.
Failed())
return ret;
2051 DoCreateNewIndustry(*ip, tile, type, layout, layout_index, t, founder, random_initial_bits);
2088 uint16_t random_initial_bits =
GB(seed, 0, 16);
2089 uint32_t random_var8f = randomizer.
Next();
2090 size_t num_layouts = indspec->
layouts.size();
2101 if (prospect_success) {
2105 for (
int i = 0; i < 5000; i++) {
2111 size_t layout =
RandomRange((uint32_t)num_layouts);
2113 for (
size_t j = 0; j < num_layouts; j++) {
2114 layout = (layout + 1) % num_layouts;
2122 if (prospect_success) {
2130 size_t layout = first_layout;
2131 if (layout >= num_layouts)
return CMD_ERROR;
2134 for (
size_t i = 0; i < num_layouts; i++) {
2135 layout = (layout + 1) % num_layouts;
2141 if (ret.
Failed())
return ret;
2194 if (show_news && prod_level != ind->
prod_level) {
2200 default: NOT_REACHED();
2205 if (!custom_news.empty()) {
2206 headline = custom_news;
2212 if (str > STR_LAST_STRINGID) {
2219 AddIndustryNewsItem(std::move(headline), nt, ind->index);
2273 if (!text.empty()) ind->
text = text;
2291 uint32_t seed = Random();
2292 uint32_t seed2 = Random();
2295 [[maybe_unused]]
CommandCost ret =
CreateNewIndustryHelper(tile, type,
DoCommandFlag::Execute, indspec, layout_index, seed,
GB(seed2, 0, 16),
OWNER_NONE, creation_type, &i);
2296 assert(i !=
nullptr || ret.
Failed());
2317 *force_at_least_one =
false;
2368 static const uint16_t numof_industry_table[] = {
2397 uint tries = try_hard ? 10000u : 2000u;
2398 for (; tries > 0; tries--) {
2400 if (ind !=
nullptr)
return ind;
2427 total +=
static_cast<uint16_t
>(std::size(industries));
2456 static const int NEWINDS_PER_MONTH = 0x38000 / (10 * 12);
2468 std::array<uint32_t, NUM_INDUSTRYTYPES> probs{};
2469 std::array<bool, NUM_INDUSTRYTYPES> force_one{};
2471 uint num_forced = 0;
2485 p.total += p.probs[it];
2486 if (p.force_one[it]) p.num_forced++;
2506 for (
bool water =
false;; water =
true) {
2507 auto &p = water ? wprob : lprob;
2510 uint total_amount = 0;
2511 if (lprob.total + wprob.total > 0) total_amount = p.total *
GetNumberOfIndustries() / (lprob.total + wprob.total);
2517 if (p.total == 0 || total_amount < p.num_forced) {
2519 total_amount = p.num_forced;
2526 if (p.force_one[it]) {
2527 assert(total_amount > 0);
2534 for (uint i = 0; i < total_amount; i++) {
2536 IndustryType it = 0;
2537 while (r >= p.probs[it]) {
2542 assert(p.probs[it] > 0);
2555 uint32_t production = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r,
const auto &p) {
return r + p.production; });
2556 uint32_t transported = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r,
const auto &p) {
return r + p.transported; });
2557 auto count = std::size(history);
2564 uint32_t accepted = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r,
const auto &a) {
return r + a.accepted; });
2565 uint32_t waiting = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r,
const auto &a) {
return r + a.waiting; });;
2566 auto count = std::size(history);
2589 if (a.history ==
nullptr)
continue;
2611void Industry::FillCachedName()
const
2617void ClearAllIndustryCachedNames()
2620 ind->cached_name.clear();
2642 bool changed =
false;
2643 uint num_planned = 0;
2645 changed |= this->
builddata[it].GetIndustryTypeData(it);
2646 num_planned += this->
builddata[it].target_count;
2649 changed |= num_planned != total_amount;
2650 if (!changed)
return;
2653 uint force_build = 0;
2654 uint32_t total_prob = 0;
2662 if (total_prob == 0)
return;
2665 total_amount = (total_amount <= force_build) ? 0 : total_amount - force_build;
2668 while (total_amount > 0) {
2670 IndustryType it = 0;
2671 while (r >= this->
builddata[it].probability) {
2676 assert(this->
builddata[it].probability > 0);
2691 uint32_t total_prob = 0;
2695 missing += difference;
2696 if (this->
builddata[it].wait_count > 0)
continue;
2697 if (difference > 0) {
2705 total_prob += difference;
2723 if (this->
builddata[it].wait_count > 0)
continue;
2725 if (difference <= 0)
continue;
2726 if (count == 1)
break;
2727 if (r < (uint)difference)
break;
2735 if (ind ==
nullptr) {
2810 bool c_accepts =
false;
2811 bool c_produces =
false;
2813 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
2821 if (!c_accepts && !c_produces)
continue;
2827 for (
const Order &o : v->Orders()) {
2831 assert(st !=
nullptr);
2861 default: NOT_REACHED();
2863 AddIndustryNewsItem(
2864 GetEncodedString(percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH,
2872static const uint PERCENT_TRANSPORTED_60 = 153;
2873static const uint PERCENT_TRANSPORTED_80 = 204;
2883 bool closeit =
false;
2885 bool standard =
false;
2886 bool suppress_message =
false;
2887 bool recalculate_multipliers =
false;
2892 int8_t increment = 0;
2895 if (callback_enabled) {
2896 std::array<int32_t, 1> regs100;
2899 suppress_message =
HasBit(res, 7);
2902 res =
GB(res, 0, 4);
2904 default: NOT_REACHED();
2906 case 0x1: div = 1;
break;
2907 case 0x2: mul = 1;
break;
2908 case 0x3: closeit =
true;
break;
2909 case 0x4: standard =
true;
break;
2910 case 0x5:
case 0x6:
case 0x7:
2911 case 0x8: div = res - 0x3;
break;
2912 case 0x9:
case 0xA:
case 0xB:
2913 case 0xC: mul = res - 0x7;
break;
2916 increment = res == 0x0D ? -1 : 1;
2920 recalculate_multipliers =
true;
2925 if (monthly == original_economy)
return;
2930 if (standard || (!callback_enabled && indspec->
life_type.
Any({IndustryLifeType::Organic, IndustryLifeType::Extractive}))) {
2934 if (original_economy) {
2935 if (only_decrease ||
Chance16(1, 3)) {
2947 uint32_t r = Random();
2948 int old_prod, new_prod, percent;
2949 new_prod = old_prod = p.rate;
2953 int prod_change_direction;
2954 if (only_decrease) {
2955 prod_change_direction = -1;
2956 }
else if (p.history[LAST_MONTH].PctTransported() <= PERCENT_TRANSPORTED_60) {
2957 prod_change_direction =
Chance16I(1, 3, r) ? 1 : -1;
2958 }
else if (p.history[LAST_MONTH].PctTransported() <= PERCENT_TRANSPORTED_80) {
2959 prod_change_direction =
Chance16I(2, 3, r) ? 1 : -1;
2961 prod_change_direction =
Chance16I(5, 6, r) ? 1 : -1;
2963 new_prod += prod_change_direction * (std::max(((
RandomRange(50) + 10) * old_prod) >> 8, 1U));
2967 new_prod =
Clamp(new_prod, 1, 255);
2969 new_prod =
Clamp(new_prod, 0, 16);
2977 if (new_prod == old_prod && old_prod > 1) {
2982 percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
2986 if (new_prod > 1) closeit =
false;
2988 if (
abs(percent) >= 10) {
3013 recalculate_multipliers =
true;
3018 while (div-- != 0 && !closeit) {
3024 recalculate_multipliers =
true;
3030 if (increment != 0) {
3035 recalculate_multipliers =
true;
3050 if (!suppress_message && str != STR_NULL) {
3058 default: NOT_REACHED();
3068 default: NOT_REACHED();
3073 if (str > STR_LAST_STRINGID) {
3075 }
else if (closeit) {
3084 AddIndustryNewsItem(std::move(headline), nt, i->index);
3098 _economy.industry_daily_change_counter += _economy.industry_daily_increment;
3103 uint16_t change_loop = _economy.industry_daily_change_counter >> 16;
3106 _economy.industry_daily_change_counter &= 0xFFFF;
3108 if (change_loop == 0) {
3120 for (uint16_t j = 0; j < change_loop; j++) {
3158void InitializeIndustries()
3173 bool force_at_least_one;
3175 if (chance == 0 || !force_at_least_one)
continue;
3182 if (count >= 3)
break;
3213 return (
_price[(
_settings_game.construction.raw_industry_construction == 1 && this->IsRawIndustry()) ?
3270 return Command<Commands::LandscapeClear>::Do(flags, tile);
3291 return std::tie(lhs.distance, lhs.industry->index) < std::tie(rhs.distance, rhs.industry->index);
3300 auto ita = std::find_if(std::rbegin(ind->
accepted), std::rend(ind->
accepted), [](
const auto &a) { return IsValidCargoType(a.cargo); });
3304 auto itp = std::find_if(std::rbegin(ind->
produced), std::rend(ind->
produced), [](
const auto &p) { return IsValidCargoType(p.cargo); });
Base functions for all AIs.
void AddAnimatedTile(TileIndex tile, bool mark_dirty)
Add the given tile to the animated tile table (if it does not exist yet).
void DeleteAnimatedTile(TileIndex tile, bool immediate)
Stops animation on the given tile.
Functions related to autoslope.
bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Class for backupping variables and making sure they are restored later.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Map accessor functions for bridges.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Tables with default industry layouts and behaviours.
static constexpr CargoType INVALID_CARGO
Invalid marker for cargoes.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
static constexpr CargoLabel CT_PASSENGERS
Cargo label for passengers.
CargoType
Cargo slots to indicate a cargo type within a game.
CargoType GetCargoTypeByLabel(CargoLabel label)
Get cargo assigned to a label.
Cheats _cheats
All the cheats.
Types related to cheating.
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=CompanyID::Invalid())
Broadcast a new event to all active AIs.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool IsValid() const
Test that the raw value of this bit set is valid.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
Container for an encoded string, created by GetEncodedString.
static void NewEvent(class ScriptEvent *event)
Queue a new event for the game script.
An interval timer will fire every interval, and will continue to fire until it is deleted.
uint16_t w
The width of the area.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Generate TileIndices around a center tile or tile area, with increasing distance.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGameTick::Ticks INDUSTRY_CUT_TREE_TICKS
Cycle duration for lumber mill's extra action.
static constexpr TimerGameTick::Ticks INDUSTRY_PRODUCE_TICKS
Cycle duration for industry production.
Wrapper class to abstract away the way the tiles are stored.
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static Year year
Current year, starting at 0.
static Month month
Current month (0..11).
static TickCounter counter
Monotonic counter, in ticks, since start of game.
Map accessors for 'clear' tiles.
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
void SetFence(Tile t, DiagDirection side, uint h)
Sets the type of fence (and whether there is one) for the given border.
IndustryID GetIndustryIndexOfField(Tile t)
Get the industry (farm) that made the field.
@ Desert
Desert with transition (1,3).
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
void SetIndustryIndexOfField(Tile t, IndustryID i)
Set the industry (farm) that made the field.
void MakeField(Tile t, uint field_type, IndustryID industry)
Make a (farm) field tile.
void SetClearCounter(Tile t, uint c)
Sets the counter used to advance to the next clear density/field type.
uint GetFence(Tile t, DiagDirection side)
Is there a fence at the given border?
bool IsSnowTile(Tile t)
Test if a tile is covered with snow.
CommandCost CommandCostWithParam(StringID str, uint64_t value)
Return an error status, with string and parameter.
Functions related to commands.
CommandCost & ExtractCommandCost(Tret &ret)
Extract the CommandCost from a command proc result.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Auto
don't allow building on structures
@ NoModifyTownRating
do not change town rating
@ NoWater
don't allow building on water
@ Execute
execute the given command
@ NoTestTownRating
town rating does not disallow you from building
EnumBitSet< DoCommandFlag, uint16_t > DoCommandFlags
Bitset of DoCommandFlag elements.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
bool IsLocalCompany()
Is the current company the local company?
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
static constexpr Owner OWNER_NONE
The tile has no ownership.
static constexpr Owner INVALID_OWNER
An invalid owner.
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Axis OtherAxis(Axis a)
Select the other axis as provided.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
DiagDirection
Enumeration for diagonal directions.
@ NE
Northeast, upper right on your monitor.
Prices _price
Prices and also the fractional part.
static uint ScaleByInverseCargoScale(uint num, bool town)
Scale a number by the inverse of the cargo scale setting, e.g.
bool EconomyIsInRecession()
Is the economy in recession?
uint ScaleByCargoScale(uint num, bool town)
Scale a number by the cargo scale setting.
@ Original
Imitates original TTD economy.
@ Frozen
Stops production changes and industry closures.
@ Smooth
Makes production changes more often, and in smaller steps.
@ Construction
Construction costs.
@ BuildIndustryRaw
Price for funding new raw industries, e.g. coal mine, forest.
@ BuildFoundation
Price for building foundation under other constructions e.g. roads, rails, depots,...
@ BuildIndustry
Price for funding new industries.
@ ClearIndustry
Price for destroying industries.
EffectVehicle * CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle at a particular location.
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
Base class for all effect vehicles.
Functions related to effect vehicles.
@ EV_BUBBLE
Bubble of bubble generator (industry).
@ EV_CHIMNEY_SMOKE
Smoke of power plant (industry).
@ EV_COPPER_MINE_SMOKE
Smoke at copper mine.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Functions related to errors.
@ Warning
Other information.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Base functions for all Games.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
@ WaterIndustries
Generate industries.
@ LandIndustries
Generate industries.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Colours
One of 16 base colours used for companies and windows/widgets.
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
uint8_t HighestSnowLine()
Get the highest possible snow line height, either variable or static.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
void UpdateValidHistory(ValidHistoryMask &valid_history, const HistoryRange &hr, uint cur_month)
Update mask of valid records for a historical data.
Functions for storing historical data.
T GetAndResetAccumulatedAverage(Taccrued &total)
Get an average value for the previous month, as reset for the next month.
void RotateHistory(HistoryData< T > &history, ValidHistoryMask valid_history, const HistoryRange &hr, uint cur_month)
Rotate historical data.
Types for storing historical data.
static constexpr uint8_t PRODLEVEL_MAXIMUM
the industry is running at full speed
void ReleaseDisastersTargetingIndustry(IndustryID)
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile)...
static constexpr uint8_t PRODLEVEL_DEFAULT
default level set when the industry is created
static const TimerGameEconomy::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS
If a processing industry doesn't produce for this many consecutive economy years, it may close.
IndustryBuildData _industry_builder
In-game manager of industries.
EnumBitSet< IndustryControlFlag, uint8_t, IndustryControlFlag::End > IndustryControlFlags
Bitset of IndustryControlFlag elements.
static constexpr uint8_t PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
static constexpr uint8_t PRODLEVEL_CLOSURE
signal set to actually close the industry
@ ExternalProdLevel
Indicates that the production level of the industry is externally controlled.
@ NoClosure
Industry can not close regardless of production level or time since last delivery.
@ NoProductionDecrease
When industry production change is evaluated, rolls to decrease are ignored.
@ NoProductionIncrease
When industry production change is evaluated, rolls to increase are ignored.
static bool ClickTile_Industry(TileIndex tile)
Tile callback function signature for clicking a tile.
const TileTypeProcs _tile_type_industry_procs
TileTypeProcs definitions for TileType::Industry tiles.
static uint16_t GetIndustryGamePlayProbability(IndustryType it, uint8_t *min_number)
Compute the probability for constructing a new industry during game play.
static void TileLoop_Industry(TileIndex tile)
Tile callback function signature for running periodic tile updates.
static CommandCost CheckNewIndustry_Water(TileIndex tile)
Check the conditions of IndustryCheck::Water (Industry should be in the desert).
static CommandCost CheckNewIndustry_None(TileIndex)
Check the conditions of IndustryCheck::None (Always succeeds).
static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, IndustryType type, const Town *t)
Is the industry allowed to be built at this place for the town?
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
static bool TransportIndustryGoods(TileIndex tile)
Move produced cargo from industry to nearby stations.
CommandCost CmdIndustrySetExclusivity(DoCommandFlags flags, IndustryID ind_id, Owner company_id, bool consumer)
Change exclusive consumer or supplier for the industry.
static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, IndustryType type, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check=nullptr)
Check slope requirements for industry tiles.
static IndustryGenerationProbabilities GetScaledProbabilities(bool water)
Get scaled industry generation probabilities.
static uint GetCurrentTotalNumberOfIndustries()
Get total number of industries existing in the game.
static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile)
Check the conditions of IndustryCheck::Refinery (Industry should be positioned near edge of the map).
static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, IndustryType type)
Are the tiles of the industry free?
CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, uint8_t prod_level, bool show_news, const EncodedString &custom_news)
Set industry production.
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlags flags, const IndustryTileLayout &layout)
This function tries to flatten out the land below an industry, without damaging the surroundings too ...
static CommandCost CheckNewIndustry_BubbleGen(TileIndex tile)
Check the conditions of IndustryCheck::BubbleGen (Industry should be in low land).
static CommandCost CheckNewIndustry_Farm(TileIndex tile)
Check the conditions of IndustryCheck::Farm (Industry should be below snow-line in arctic).
static void AdvertiseIndustryOpening(const Industry *ind)
Advertise about a new industry opening.
static void ChopLumberMillTrees(Industry *i)
Perform a circular search around the Lumber Mill in order to find trees to cut.
static uint32_t GetScaledIndustryGenerationProbability(IndustryType it, std::optional< bool > water, bool *force_at_least_one)
Compute the appearance probability for an industry during map creation.
static bool CheckScaledDistanceFromEdge(TileIndex tile, uint maxdist)
Check if a tile is within a distance from map edges, scaled by map dimensions independently.
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoType cargo, int percent)
Report news that industry production has changed significantly.
static void GetTileDesc_Industry(TileIndex tile, TileDesc &td)
Tile callback function signature for obtaining a tile description.
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
static void CanCargoServiceIndustry(CargoType cargo, Industry *ind, bool *c_accepts, bool *c_produces)
Can given cargo type be accepted or produced by the industry?
static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
Tile callback function signature for getting the foundation of a tile.
void GenerateIndustries()
This function will create random industries during game creation.
static void ProduceIndustryGoodsHelper(Industry *i, bool scale)
Helper for ProduceIndustryGoods that scales and produces cargos.
static void ChangeTileOwner_Industry(TileIndex tile, Owner old_owner, Owner new_owner)
Tile callback function signature for changing the owner of a tile.
static Industry * PlaceIndustry(IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
Try to place the industry in the game.
static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields, bool allow_rough)
Check whether the tile can be replaced by a farm field.
static CommandCost CheckNewIndustry_Plantation(TileIndex tile)
Check the conditions of IndustryCheck::Plantation (Industry should NOT be in the desert).
void CheckIndustries()
Verify whether the generated industries are complete, and warn the user if not.
static void PopulateStationsNearby(Industry *ind)
Populate an industry's list of nearby stations, and if it accepts any cargo, also add the industry to...
static CommandCost CheckNewIndustry_Forest(TileIndex tile)
Check the conditions of IndustryCheck::Forest (Industry should be build above snow-line in arctic cli...
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.
CommandCost CheckNewIndustryProc(TileIndex tile)
Industrytype check function signature.
static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlags 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.
static int WhoCanServiceIndustry(Industry *ind)
Compute who can service the industry.
void ResetIndustries()
This function initialize the spec arrays of both industry and industry tiles.
static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, IndustryType type)
Check that the new industry is far enough from conflicting industries.
static CommandCost CheckNewIndustry_OilRig(TileIndex tile)
Check the conditions of IndustryCheck::OilRig (Industries at sea should be positioned near edge of th...
void TrimIndustryAcceptedProduced(Industry *ind)
Remove unused industry accepted/produced slots – entries after the last slot with valid cargo.
static uint GetNumberOfIndustries()
Get wanted number of industries on the map.
static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
Tile callback function signature for obtaining cargo acceptance of a tile.
CommandCost CmdBuildIndustry(DoCommandFlags flags, TileIndex tile, IndustryType it, uint32_t first_layout, bool fund, uint32_t seed)
Build/Fund an industry.
static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlags flags)
Tile callback function signature for clearing a tile.
static void PlaceInitialIndustry(IndustryType type, bool water, bool try_hard)
Try to build a industry on the map.
static bool CheckIndustryCloseDownProtection(IndustryType type)
Protects an industry from closure if the appropriate flags and conditions are met CanCloseLastInstanc...
static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
static void AnimateTile_Industry(TileIndex tile)
Tile callback function signature for animating a tile.
static void DrawTile_Industry(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
static void SetupFarmFieldFence(TileIndex tile, int size, uint8_t type, DiagDirection side)
Build farm field fence.
static constexpr EnumIndexArray< CheckNewIndustryProc *const, IndustryCheck, IndustryCheck::End > _check_new_industry_procs
Check functions for different types of industry.
static const IntervalTimer< TimerGameEconomy > _economy_industries_daily({TimerGameEconomy::Trigger::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;} AutoRestoreBackup cur_company(_current_company, OWNER_NONE);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(WindowClass::IndustryView, i->index);} } } InvalidateWindowData(WindowClass::IndustryDirectory, 0, IDIWD_PRODUCTION_CHANGE);})
Every economy day handler for the industry changes Taking the original map size of 256*256,...
CommandCost CmdIndustrySetFlags(DoCommandFlags flags, IndustryID ind_id, IndustryControlFlags ctlflags)
Set industry control flags.
IndustryType GetIndustryType(Tile tile)
Retrieve the type for this industry.
static const IntervalTimer< TimerGameEconomy > _economy_industries_monthly({TimerGameEconomy::Trigger::Month, TimerGameEconomy::Priority::Industry}, [](auto) { AutoRestoreBackup cur_company(_current_company, OWNER_NONE);_industry_builder.EconomyMonthlyLoop();for(Industry *i :Industry::Iterate()) { UpdateIndustryStatistics(i);if(i->prod_level==PRODLEVEL_CLOSURE) { delete i;} else { ChangeIndustryProduction(i, true);SetWindowDirty(WindowClass::IndustryView, i->index);} } InvalidateWindowData(WindowClass::IndustryDirectory, 0, IDIWD_PRODUCTION_CHANGE);})
Economy monthly loop for industries.
static void UpdateIndustryStatistics(Industry *i)
Monthly update of industry statistics.
static CommandCost FindTownForIndustry(TileIndex tile, IndustryType type, Town **t)
Find a town for the industry, while checking for multiple industries in the same town.
static Industry * CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
Create a new industry of random layout.
static void ChangeIndustryProduction(Industry *i, bool monthly)
Change industry production or do closure.
static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile)
Check the conditions of IndustryCheck::Lumbermill (Industry should be in the rainforest).
CommandCost CmdIndustrySetText(DoCommandFlags flags, IndustryID ind_id, const EncodedString &text)
Change additional industry text.
Command definitions related to industries.
Information about the behaviour of the default industry tiles.
static const uint8_t _industry_anim_offs_toffee[]
This is ONLY used for Toffee Quarry.
static const Coord2D< uint8_t > _drawtile_proc1[5]
This is ONLY used for Sugar Mine.
static const DrawIndustryAnimationStruct _draw_industry_spec1[96]
This is ONLY used for Sugar Mine.
static const Coord2D< uint8_t > _coal_plant_sparks[]
Movement of the sparks , only used for Power Station.
static const uint8_t _industry_anim_offs_bubbles[]
This is ONLY used for the Bubble Generator.
static const DrawBuildingsTileStruct _industry_draw_tile_data[NEW_INDUSTRYTILEOFFSET *4]
Structure for industry tiles drawing.
void SetIndustryCompleted(Tile tile)
Set if the industry that owns the tile as under construction or not.
void SetIndustryGfx(Tile t, IndustryGfx gfx)
Set the industry graphics ID for the given industry tile.
void ResetIndustryConstructionStage(Tile tile)
Reset the construction stage counter of the industry, as well as the completion bit.
void SetIndustryConstructionCounter(Tile tile, uint8_t value)
Sets this industry tile's construction counter value.
IndustryGfx GetIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile.
bool IsIndustryCompleted(Tile t)
Is this industry tile fully built?
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
uint8_t GetIndustryConstructionCounter(Tile tile)
Returns this industry tile's construction counter value.
void MakeIndustry(Tile t, IndustryID index, IndustryGfx gfx, uint8_t random, WaterClass wc)
Make the given tile an industry tile.
void SetIndustryAnimationLoop(Tile tile, uint8_t count)
Set the animation loop number.
void SetIndustryConstructionStage(Tile tile, uint8_t value)
Sets the industry construction stage of the specified tile.
uint8_t GetIndustryAnimationLoop(Tile tile)
Get the animation loop number.
uint8_t GetIndustryConstructionStage(Tile tile)
Returns the industry construction stage of the specified tile.
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
static constexpr IndustryGfx GFX_COPPER_MINE_TOWER_NOT_ANIMATED
static const IndustryGfx INDUSTRYTILE_NOANIM
Sentinel value to mark industry tiles as having no animation.
@ IndustryTick
The industry has been triggered via its tick.
@ TileLoop
The tile of the industry has been triggered during the tileloop.
static constexpr IndustryGfx GFX_GOLD_MINE_TOWER_ANIMATED
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
static constexpr IndustryGfx GFX_WATERTILE_SPECIALCHECK
Sentinel marker in industry layout to perform a water tile check.
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
static constexpr IndustryGfx GFX_TOFFEE_QUARRY
static constexpr IndustryGfx GFX_SUGAR_MINE_SIEVE
static const int INDUSTRY_NUM_INPUTS
Number of cargo types an industry can accept.
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_5
static constexpr IndustryGfx GFX_POWERPLANT_CHIMNEY
static constexpr IndustryGfx GFX_OILWELL_ANIMATED_1
static constexpr IndustryGfx GFX_POWERPLANT_SPARKS
static constexpr IndustryGfx GFX_COAL_MINE_TOWER_NOT_ANIMATED
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_4
static constexpr IndustryGfx GFX_OILWELL_ANIMATED_2
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_3
static constexpr IndustryGfx GFX_COPPER_MINE_CHIMNEY
static constexpr IndustryGfx GFX_TOY_FACTORY
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like IT_...
static constexpr IndustryGfx GFX_COPPER_MINE_TOWER_ANIMATED
static constexpr IndustryGfx GFX_BUBBLE_GENERATOR
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_8
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
static constexpr IndustryGfx GFX_COAL_MINE_TOWER_ANIMATED
static constexpr IndustryGfx GFX_OILWELL_NOT_ANIMATED
static constexpr IndustryGfx GFX_BUBBLE_CATCHER
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_6
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_1
@ CargoDistributed
Trigger when cargo is distributed.
@ IndustryTick
Trigger every tick.
@ TileLoop
Trigger in the periodic tile loop.
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_7
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
static constexpr IndustryGfx GFX_PLASTIC_FOUNTAIN_ANIMATED_2
static constexpr IndustryGfx GFX_OILRIG_1
static const int INDUSTRY_COMPLETED
final stage of industry construction.
static constexpr IndustryGfx GFX_GOLD_MINE_TOWER_NOT_ANIMATED
static constexpr IndustryGfx GFX_OILWELL_ANIMATED_3
@ NoBuildMapCreation
Do not force one instance of this type to appear on map generation.
@ CutTrees
cuts trees and produce first output cargo from them (lumber mill)
@ PlantOnBuild
Fields are planted around when built (all farms).
@ Before1950
can only be built before 1950 (oil wells)
@ BuiltOnWater
is built on water (oil rig)
@ DontIncrProd
do not increase production (oil wells) in the temperate climate
@ CargoTypesUnlimited
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
@ After1960
can only be built after 1960 (oil rigs)
@ PlantFields
periodically plants fields around itself (temp and arctic farms)
@ Town1200More
can only be built in towns larger than 1200 inhabitants (temperate bank)
@ NoPaxProdClamp
Do not clamp production of passengers. (smooth economy only).
@ CanCloseLastInstance
Allow closing down the last instance of this type.
@ OnlyNearTown
is always built near towns (toy shop)
@ AcceptsAllCargo
Tile always accepts all cargoes the associated industry accepts.
@ Processing
Like factories.
IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
std::vector< IndustryTileLayoutTile > IndustryTileLayout
A complete tile layout for an industry is a list of tiles.
EnumBitSet< IndustryBehaviour, uint32_t > IndustryBehaviours
Bitset of IndustryBehaviour elements.
@ Gameplay
either by user or random creation process
@ ScenarioEditor
while editing a scenario
@ MapGeneration
during random map creation
@ OilRig
Industries at sea should be positioned near edge of the map.
@ Refinery
Industry should be positioned near edge of the map.
static constexpr IndustryLifeTypes INDUSTRYLIFE_BLACK_HOLE
Like power plants and banks.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Functions related to OTTD's landscape.
Command definitions related to landscape (slopes etc.).
@ Arctic
Landscape with snow levels.
@ Tropic
Landscape with distinct rainforests and deserts,.
@ Temperate
Base landscape.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir)
Gets the distance to the edge of the map in given direction.
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.
Functions related to maps.
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
#define RandomTile()
Get a valid random tile.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
int32_t TileIndexDiff
An offset value between two tiles.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
StringID MapGRFStringID(GrfID grfid, GRFStringID str)
Used when setting an object's property to map to the GRF's strings while taking in consideration the ...
@ IndustryTiles
Industry tiles feature.
@ Industries
Industries feature.
const IndustrySpec _origin_industry_specs[NEW_INDUSTRYOFFSET]
Extern declaration for _origin_industry_specs in table/build_industry.h.
@ NoAnimation
There is no animation.
@ InputCargoTypes
customize the cargoes the industry requires
@ ProductionChange
controls random production change
@ DecideColour
give a custom colour to newly build industries
@ SpecialEffect
control special effects
@ ProdChangeBuild
initialise production level on construction
@ Production256Ticks
call production callback every 256 ticks
@ Location
check industry construction on given area
@ MonthlyProdChange
controls monthly random production change
@ ProductionCargoArrival
call production callback when cargo arrives at the industry
@ OutputCargoTypes
customize the cargoes the industry produces
@ CBID_INDUSTRY_OUTPUT_CARGO_TYPES
Customize the output cargo types of a newly build industry.
@ CBID_INDUSTRY_SPECIAL_EFFECT
Called to determine industry special effects.
@ CBID_INDTILE_AUTOSLOPE
Called to determine if industry can alter the ground below industry tile.
@ CBID_INDUSTRY_DECIDE_COLOUR
Called to determine the colour of an industry.
@ CBID_INDTILE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for industry tile.
@ CBID_INDUSTRY_PRODUCTION_CHANGE
Called on production changes, so it can be adjusted.
@ CBID_INDUSTRY_MONTHLYPROD_CHANGE
Called monthly on production changes, so it can be adjusted more frequently.
@ CBID_INDUSTRY_PROD_CHANGE_BUILD
Called when industry is built to set initial production level.
@ CBID_INDTILE_CARGO_ACCEPTANCE
Called to query the cargo acceptance of the industry tile.
@ CBID_INDTILE_ACCEPT_CARGO
Called to determine which cargoes an industry should accept.
@ CBID_INDUSTRY_INPUT_CARGO_TYPES
Customize the input cargo types of a newly build industry.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ ShapeCheck
decides slope suitability
@ AcceptCargo
decides accepted types
@ CargoAcceptance
decides amount of cargo acceptance
@ DrawFoundations
decides if default foundations need to be drawn
@ Autoslope
decides allowance of autosloping
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
Cargo support for NewGRFs.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
void ErrorUnknownCallbackResult(GrfID grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
GRFConfig * GetGRFConfig(GrfID grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Functions/types related to NewGRF debugging.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
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.
uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile, std::span< int32_t > regs100)
Perform an industry callback.
void IndustryProductionCallback(Industry *ind, int reason)
Get the industry production callback and apply it to the industry.
uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoType cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
@ UserCreation
from the Fund/build window
@ MapGeneration
during random map generation
@ ProspectCreation
from the Fund/build using prospecting
@ RandomCreation
during creation of random ingame industry
void TriggerIndustryTileRandomisation(TileIndex tile, IndustryRandomTrigger trigger)
Trigger a random trigger for a single industry tile.
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.
void TriggerIndustryRandomisation(Industry *ind, IndustryRandomTrigger trigger)
Trigger a random trigger for all industry tiles.
NewGRF handling of industry tiles.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
Functions related to news.
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
@ IndustryCloseCompany
Closing of industries serviced by local company.
@ IndustryCompany
Production changes of industry serviced by local company.
@ IndustryOpen
Opening of industries.
@ IndustryNobody
Other industry production changes.
@ IndustryOther
Production changes of industry serviced by competitor(s).
@ IndustryCloseNobody
Other industry closing.
@ IndustryCloseOther
Closing of industries serviced by competitor(s).
@ Editor
In the scenario editor.
@ Transfer
Transfer all cargo onto the platform.
@ Unload
Force unloading all cargo onto the platform, possibly not getting paid.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
bool Chance16I(const uint32_t a, const uint32_t b, const uint32_t r)
Checks if a given randomize-number is below a given probability.
bool Chance16(const uint32_t a, const uint32_t b, const std::source_location location=std::source_location::current())
Flips a coin with given probability.
bool Chance16R(const uint32_t a, const uint32_t b, uint32_t &r, const std::source_location location=std::source_location::current())
Flips a coin with a given probability and saves the randomize-number in a variable.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
IndustryDensity
Available industry map generation densities.
@ FundedOnly
The game does not build industries.
@ End
Number of industry density settings.
@ VeryLow
Very few industries at game start.
@ Custom
Custom number of industries.
static constexpr int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height).
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Slope ComplementSlope(Slope s)
Return the complement of a slope.
Slope
Enumeration for the slope-type.
@ SLOPE_W
the west corner of the tile is raised
@ SLOPE_E
the east corner of the tile is raised
@ SLOPE_S
the south corner of the tile is raised
@ SLOPE_N
the north corner of the tile is raised
@ SLOPE_SW
south and west corner are raised
@ SLOPE_NE
north and east corner are raised
@ SLOPE_SE
south and east corner are raised
@ SLOPE_NW
north and west corner are raised
Foundation
Enumeration for Foundations.
@ Leveled
The tile is leveled up to a flat slope.
@ None
The tile has no foundation, the slope remains unchanged.
Functions related to sound.
SoundFx
Sound effects from baseset.
@ SND_30_TOFFEE_QUARRY
48 == 0x30 Industry animation: toffee quarry: drill
@ SND_2E_BUBBLE_GENERATOR
46 == 0x2E Industry animation: bubble generator (1): generate bubble
@ SND_2D_SUGAR_MINE_1
45 == 0x2D Industry animation: sugar mine (1): shaking sieve
@ SND_2B_TOY_FACTORY_2
43 == 0x2B Industry animation: toy factory (2): stamp product
@ SND_38_LUMBER_MILL_1
56 == 0x38 Industry animation: lumber mill (1): chainsaw
@ SND_29_SUGAR_MINE_2
41 == 0x29 Industry animation: sugar mine (2): shaking sieve
@ SND_2C_TOY_FACTORY_1
44 == 0x2C Industry animation: toy factory (1): conveyor belt
@ SND_37_LUMBER_MILL_2
55 == 0x37 Industry animation: lumber mill (2): falling tree
@ SND_0C_POWER_STATION
10 == 0x0A Industry animation: power station: spark
@ SND_0B_MINE
9 == 0x09 Industry animation: coal/copper/gold mine: headgear
@ SND_36_LUMBER_MILL_3
54 == 0x36 Industry animation: lumber mill (3): crashing tree
@ SND_2A_TOY_FACTORY_3
42 == 0x2A Industry animation: toy factory (3): eject product
@ Industry
Source/destination is an industry.
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
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...
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static const SpriteID SPR_IT_TOY_FACTORY_STAMP_HOLDER
static const SpriteID SPR_IT_TOY_FACTORY_ROBOT
static const SpriteID SPR_IT_TOY_FACTORY_CLAY
static const SpriteID SPR_IT_POWER_PLANT_TRANSFORMERS
static const SpriteID SPR_IT_BUBBLE_GENERATOR_SPRING
static const SpriteID SPR_IT_SUGAR_MINE_PILE
static const SpriteID SPR_FLAT_WATER_TILE
static const SpriteID SPR_IT_BUBBLE_GENERATOR_BUBBLE
static const SpriteID SPR_IT_TOFFEE_QUARRY_TOFFEE
static const SpriteID SPR_IT_TOFFEE_QUARRY_SHOVEL
static const SpriteID SPR_IT_SUGAR_MINE_SIEVE
static const SpriteID SPR_IT_SUGAR_MINE_CLOUDS
static const SpriteID SPR_IT_TOY_FACTORY_STAMP
Base classes/functions for stations.
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
Call a function on all stations that have any part of the requested area within their catchment.
void ClearDockingTilesCheckingNeighbours(TileIndex tile)
Clear docking tile status from tiles around a removed dock, if the tile has no neighbours which would...
Functions related to stations.
bool IsOilRig(Tile t)
Is tile t part of an oilrig?
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
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.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Functions related to OTTD's strings.
auto MakeParameters(Args &&... args)
Helper to create the StringParameters with its own buffer with the given parameter values.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
static constexpr StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
const T & GetOriginalValue() const
Returns the backupped value.
VehicleType type
Type of vehicle.
Class for storing amounts of cargo.
static void InvalidateAllFrom(Source src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
This structure is the same for both Industries and Houses.
uint8_t draw_proc
This allows to specify a special drawing procedure.
This is used to gather some data about animation drawing in the industry code Image_1-2-3 are in fact...
uint8_t image_1
image offset 1
uint8_t image_3
image offset 3
uint8_t image_2
image offset 2
int x
coordinate x of the first image offset
A special vehicle is one of the following:
uint8_t animation_substate
Sub state to time the change of the graphics/behaviour.
std::string GetName() const
Get the name of this grf.
GrfID grfid
grfid that introduced this entity.
const struct GRFFile * grffile
grf file that introduced this entity
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
uint8_t grf_version
GRF version (See https://newgrf-specs.tt-wiki.net/wiki/Version_numbers#GRF_version).
Data for managing the number and type of industries in the game.
void Reset()
Completely reset the industry build data.
void EconomyMonthlyLoop()
Monthly update of industry build data.
uint32_t wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
void SetupTargetCount()
Decide how many industries of each type are needed.
void TryBuildNewIndustry()
Try to create a random industry, during gameplay.
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]
Industry build data for every industry type.
Defines the data structure for constructing industry.
IndustryCallbackMasks callback_mask
Bitmask of industry callbacks that have to be called.
bool IsProcessingIndustry() const
Is an industry with the spec a processing industry?
std::vector< uint8_t > random_sounds
Random sounds;.
Money GetRemovalCost() const
Get the cost for removing this industry Take note that the cost will always be zero for non-grf indus...
std::array< CargoType, INDUSTRY_NUM_INPUTS > accepts_cargo
16 accepted cargoes.
uint8_t appear_creation[NUM_LANDSCAPE]
Probability of appearance during map creation.
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
uint8_t minimal_cargo
minimum amount of cargo transported to the stations.
uint32_t removal_cost_multiplier
Base removal cost multiplier.
uint32_t prospecting_chance
Chance prospecting succeeds.
StringID production_up_text
Message appearing when the industry's production is increasing.
SubstituteGRFFileProps grf_prop
properties related to the grf file
StringID name
Displayed name of the industry.
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
IndustryType conflicting[3]
Industries this industry cannot be close to.
uint8_t appear_ingame[NUM_LANDSCAPE]
Probability of appearance in game.
StringID production_down_text
Message appearing when the industry's production is decreasing.
IndustryBehaviours behaviour
How this industry will behave, and how others entities can use it.
StringID closure_text
Message appearing when the industry closes.
StringID new_industry_text
Message appearing when the industry is built.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
bool enabled
entity still available (by default true).newgrf can disable it, though
Money GetConstructionCost() const
Get the cost for constructing this industry.
IndustryLifeTypes life_type
This is also known as Industry production flag, in newgrf specs.
IndustryCheck check_proc
Index to a procedure to check for conflicting circumstances.
Definition of one tile in an industry tile layout.
Defines the data structure of each individual tile of an industry.
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
IndustryGfx anim_production
Animation frame to start when goods are produced.
Slope slopes_refused
slope pattern on which this tile cannot be built
AnimationInfo< IndustryAnimationTriggers > animation
Information about the animation (is it looping, how many loops etc).
std::array< int8_t, INDUSTRY_NUM_INPUTS > acceptance
Level of acceptance per cargo type (signed, may be negative!).
SubstituteGRFFileProps grf_prop
properties related to the grf file
bool anim_state
When true, the tile has to be drawn using the animation state instead of the construction stage.
IndustryTileCallbackMasks callback_mask
Bitmask of industry tile callbacks that have to be called.
IndustryGfx anim_next
Next frame in an animation.
std::array< CargoType, INDUSTRY_NUM_INPUTS > accepts_cargo
Cargo accepted by this tile.
Data for managing the number of industries of a single industry type.
uint32_t probability
Relative probability of building this industry.
uint16_t target_count
Desired number of industries of this type.
uint8_t min_number
Smallest number of industries that should exist (either 0 or 1).
void Reset()
Reset the entry.
bool GetIndustryTypeData(IndustryType it)
Set the probability and min_number fields for the industry type it for a running game.
uint16_t wait_count
Number of turns to wait before trying to build again.
uint16_t max_wait
Starting number of turns to wait (copied to wait_count).
CargoType cargo
Cargo type.
CargoType cargo
Cargo type.
HistoryData< ProducedHistory > history
History of cargo produced and transported for this month and 24 previous months.
uint8_t rate
Production rate.
Defines the internal data of a functional industry.
static Industry * GetRandom()
Return a random valid industry.
IndustryType type
type of industry.
Owner exclusive_supplier
Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone).
TimerGameCalendar::Date construction_date
Date of the construction of the industry.
IndustryControlFlags ctlflags
flags overriding standard behaviours
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
PersistentStorage * psa
Persistent storage for NewGRF industries.
uint8_t prod_level
general production level
Colours random_colour
randomized colour of the industry, for display purpose
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
EncodedString text
General text with additional information.
std::string cached_name
NOSAVE: Cache of the resolved name of the industry.
const ProducedCargo & GetProduced(size_t slot) const
Safely get a produced cargo slot, or an empty data if the slot does not exist.
ValidHistoryMask valid_history
Mask of valid history records.
TimerGameEconomy::Year last_prod_year
last economy year of production
ProducedCargoes produced
produced cargo slots
uint16_t random
Random value used for randomisation of all kinds of things.
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
Owner founder
Founder of the industry.
uint8_t selected_layout
Which tile layout was used when creating the industry.
AcceptedCargoes accepted
accepted cargo slots
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Owner owner
owner of the industry. Which SHOULD always be (imho) OWNER_NONE
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
TileArea location
Location of the industry.
Station * neutral_station
Associated neutral station.
~Industry()
Remove any reference to this industry from the game.
IndustryConstructionType construction_type
Way the industry was constructed (.
StationList stations_near
NOSAVE: List of nearby stations.
bool IsCargoProduced() const
Test if this industry produces any cargo.
Owner exclusive_consumer
Which company has exclusive rights to take cargo (INVALID_OWNER = anyone).
uint16_t counter
used for animation and/or production (if available cargo)
uint8_t was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station....
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
static std::array< FlatSet< IndustryID >, NUM_INDUSTRYTYPES > industries
List of industries of each type.
static uint SizeX()
Get the size of the map along the X.
static TileIndex WrapToMap(TileIndex tile)
'Wraps' the given "tile" so it is within the map.
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
static uint SizeY()
Get the size of the map along the Y.
static uint ScaleByLandProportion(uint n)
Scales the given value by the number of water tiles.
static uint ScaleBySize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
static uint Size()
Get the size of the map.
If you change this, keep in mind that it is also saved in 2 other places:
SpriteID sprite
The 'real' sprite.
PaletteID pal
The palette (use PAL_NONE) if not needed).
static Pool::IterateWrapper< Industry > Iterate(size_t from=0)
static size_t GetPoolSize()
static T * Create(Targs &&... args)
static Industry * Get(auto index)
static size_t GetNumItems()
static bool CanAllocateItem(size_t n=1)
static bool IsValidID(auto index)
static bool CleaningPool()
static Industry * GetIfValid(auto index)
static constexpr size_t MAX_SIZE
Structure to encapsulate the pseudo random number generators.
void SetSeed(uint32_t seed)
(Re)set the state of the random number generator.
uint32_t Next()
Generate the next pseudo random number.
A location from where cargo can come from (or go to).
static Station * Get(auto index)
T * Next() const
Get next vehicle in the chain.
bool HasSpriteGroups() const
Check whether the entity has sprite groups.
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
uint16_t subst_id
The id of the entity to replace.
Tile description for the 'land area information' tool.
std::optional< std::string > grf
newGRF used for the tile contents
StringID str
Description of the tile.
std::array< Owner, 4 > owner
Name of the owner(s).
uint64_t dparam
Parameter of the str string.
Tile information, used while rendering the tile.
Slope tileh
Slope of the tile.
TileIndex tile
Tile index.
Set of callback functions for performing tile operations of a given tile type.
uint32_t population
Current population of people.
TileIndex xy
town center tile
TownCache cache
Container for all cacheable data.
CargoType cargo_type
type of cargo this vehicle is carrying
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Owner owner
Which company owns the vehicle?
void DeleteSubsidyWith(Source source)
Delete the subsidies associated with a given cargo source type and id.
Functions related to subsidies.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static uint TileHeight(Tile tile)
Returns the height of a tile.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
void SetAnimationFrame(Tile t, uint8_t frame)
Set a new animation frame.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
@ Rainforest
Rainforest tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static constexpr uint TILE_SIZE
Tile size in world coordinates.
@ Station
A tile of a station or airport.
@ Industry
Part of an industry.
@ Void
Invisible tiles at the SW and SE border.
@ Trees
Tile with one or more trees.
@ House
A house by a town.
@ Clear
A tile without any structures, i.e. grass, rocks, farm fields etc.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Type for iterating a sprial tile area.
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
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...
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...
Map accessors for tree tiles.
TreeGrowthStage GetTreeGrowth(Tile t)
Returns the tree growth stage.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Functions related to vehicles.
@ Aircraft
Aircraft vehicle type.
@ Train
Train vehicle type.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
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.
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.
Functions related to (drawing on) viewports.
Functions related to water management.
void TileLoop_Water(TileIndex tile)
Tile callback function signature for running periodic tile updates.
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
WaterClass
classes of water (for WaterTileType::Clear water tile type).
@ Invalid
Used for industry tiles on land (also for oilrig if newgrf says so).
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
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-...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Window functions not directly related to making/drawing windows.