OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
46 #include "table/strings.h"
55 void ShowIndustryViewWindow(
int industry);
58 static byte _industry_sound_ctr;
77 if (i <
lengthof(_origin_industry_specs)) {
78 _industry_specs[i] = _origin_industry_specs[i];
88 memset(&_industry_tile_specs, 0,
sizeof(_industry_tile_specs));
89 memcpy(&_industry_tile_specs, &_origin_industry_tile_specs,
sizeof(_origin_industry_tile_specs));
109 assert(ind !=
nullptr);
124 return &_industry_specs[thistype];
138 return &_industry_tile_specs[gfx];
141 Industry::~Industry()
161 DeleteOilRig(tile_cur);
165 if (has_neutral_station) {
167 for (
TileIndex tile_cur : this->location) {
200 st->industries_near.erase(
this);
239 static void IndustryDrawSugarMine(
const TileInfo *ti)
253 _drawtile_proc1[d->
image_3 - 1].x, _drawtile_proc1[d->
image_3 - 1].y);
257 static void IndustryDrawToffeeQuarry(
const TileInfo *ti)
272 static void IndustryDrawBubbleGenerator(
const TileInfo *ti)
280 static void IndustryDrawToyFactory(
const TileInfo *ti)
296 static void IndustryDrawCoalPlantSparks(
const TileInfo *ti)
301 if (image != 0 && image < 7) {
311 typedef void IndustryDrawTileProc(
const TileInfo *ti);
312 static IndustryDrawTileProc *
const _industry_draw_tile_procs[5] = {
313 IndustryDrawSugarMine,
314 IndustryDrawToffeeQuarry,
315 IndustryDrawBubbleGenerator,
316 IndustryDrawToyFactory,
317 IndustryDrawCoalPlantSparks,
320 static void DrawTile_Industry(
TileInfo *ti)
332 if (indts->
grf_prop.
spritegroup[0] !=
nullptr && DrawNewIndustryTile(ti, ind, gfx, indts)) {
357 DrawWaterClassGround(ti);
366 image = dits->building.
sprite;
369 ti->
x + dits->subtile_x,
370 ti->
y + dits->subtile_y,
381 int proc = dits->draw_proc - 1;
382 if (proc >= 0) _industry_draw_tile_procs[proc](ti);
386 static int GetSlopePixelZ_Industry(
TileIndex tile, uint x, uint y)
409 static void AddAcceptedCargo_Industry(
TileIndex tile,
CargoArray &acceptance, CargoTypes *always_accepted)
425 if (pos ==
endof(accepts_cargo)) {
428 if (pos ==
endof(accepts_cargo))
continue;
431 cargo_acceptance[pos - accepts_cargo] += 8;
449 for (uint i = 0; i < 3; i++) cargo_acceptance[i] =
GB(res, i * 4, 4);
455 if (a ==
CT_INVALID || cargo_acceptance[i] <= 0)
continue;
458 acceptance[a] += cargo_acceptance[i];
461 if (
HasBit(*always_accepted, a))
continue;
463 bool accepts =
false;
472 if (accepts)
continue;
475 SetBit(*always_accepted, a);
488 td->
str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
533 bool moved_cargo =
false;
548 moved_cargo |= (am != 0);
556 static void AnimateTile_Industry(
TileIndex tile)
561 AnimateNewIndustryTile(tile);
566 case GFX_SUGAR_MINE_SIEVE:
587 case GFX_TOFFEE_QUARY:
605 case GFX_BUBBLE_CATCHER:
620 case GFX_POWERPLANT_SPARKS:
633 case GFX_TOY_FACTORY:
658 case GFX_PLASTIC_FOUNTAIN_ANIMATED_1:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
659 case GFX_PLASTIC_FOUNTAIN_ANIMATED_3:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
660 case GFX_PLASTIC_FOUNTAIN_ANIMATED_5:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
661 case GFX_PLASTIC_FOUNTAIN_ANIMATED_7:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
665 gfx = (gfx < 155) ? gfx + 1 : 148;
671 case GFX_OILWELL_ANIMATED_1:
672 case GFX_OILWELL_ANIMATED_2:
673 case GFX_OILWELL_ANIMATED_3:
679 if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
691 case GFX_COAL_MINE_TOWER_ANIMATED:
692 case GFX_COPPER_MINE_TOWER_ANIMATED:
693 case GFX_GOLD_MINE_TOWER_ANIMATED: {
696 if ((state -= 0x400) < 0)
return;
699 if (state < 0x20 || state >= 0x180) {
705 if (state & 7)
return;
707 if (state & 3)
return;
710 if (m > 0xC2) m = 0xC0;
713 }
else if (state >= 0x200 && state < 0x3A0) {
714 int i = (state < 0x220 || state >= 0x380) ? 7 : 3;
715 if (state & i)
return;
718 if (m < 0x80) m = 0x82;
727 static void CreateChimneySmoke(
TileIndex tile)
736 static void MakeIndustryTileBigger(
TileIndex tile)
761 case GFX_POWERPLANT_CHIMNEY:
762 CreateChimneySmoke(tile);
780 case GFX_TOY_FACTORY:
781 case GFX_BUBBLE_CATCHER:
782 case GFX_TOFFEE_QUARY:
787 case GFX_PLASTIC_FOUNTAIN_ANIMATED_1:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
788 case GFX_PLASTIC_FOUNTAIN_ANIMATED_3:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
789 case GFX_PLASTIC_FOUNTAIN_ANIMATED_5:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
790 case GFX_PLASTIC_FOUNTAIN_ANIMATED_7:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
796 static void TileLoopIndustry_BubbleGenerator(
TileIndex tile)
798 static const int8 _bubble_spawn_location[3][4] = {
806 int dir = Random() & 3;
811 _bubble_spawn_location[2][dir],
818 static void TileLoop_Industry(
TileIndex tile)
831 MakeIndustryTileBigger(tile);
835 if (_game_mode == GM_EDITOR)
return;
849 if (StartStopIndustryTileAnimation(tile,
IAT_TILELOOP))
return;
861 case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
862 case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
863 case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
866 case GFX_COAL_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COAL_MINE_TOWER_ANIMATED;
break;
867 case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED;
break;
868 case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_ANIMATED;
break;
876 case GFX_OILWELL_NOT_ANIMATED:
884 case GFX_COAL_MINE_TOWER_ANIMATED:
885 case GFX_COPPER_MINE_TOWER_ANIMATED:
886 case GFX_GOLD_MINE_TOWER_ANIMATED:
889 case GFX_COAL_MINE_TOWER_ANIMATED: gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED;
break;
890 case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED;
break;
891 case GFX_GOLD_MINE_TOWER_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED;
break;
900 case GFX_POWERPLANT_SPARKS:
907 case GFX_COPPER_MINE_CHIMNEY:
912 case GFX_TOY_FACTORY: {
922 case GFX_BUBBLE_GENERATOR:
923 TileLoopIndustry_BubbleGenerator(tile);
926 case GFX_TOFFEE_QUARY:
930 case GFX_SUGAR_MINE_SIEVE:
936 static bool ClickTile_Industry(
TileIndex tile)
981 static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
995 default:
return false;
1016 if (or_ == 1 &&
Chance16(1, 7)) or_ = 2;
1025 static void PlantFarmField(
TileIndex tile, IndustryID industry)
1032 uint32 r = (Random() & 0x303) + 0x404;
1034 uint size_x =
GB(r, 0, 8);
1035 uint size_y =
GB(r, 8, 8);
1040 if (ta.w == 0 || ta.h == 0)
return;
1048 if (count * 2 < ta.w * ta.h)
return;
1052 uint counter =
GB(r, 5, 3);
1053 uint field_type =
GB(r, 8, 8) * 9 >> 8;
1059 MakeField(cur_tile, field_type, industry);
1067 type = _plantfarmfield_type[Random() & 0xF];
1076 void PlantRandomFarmField(
const Industry *i)
1078 int x = i->
location.
w / 2 + Random() % 31 - 16;
1079 int y = i->
location.
h / 2 + Random() % 31 - 16;
1099 _industry_sound_ctr = 1;
1100 _industry_sound_tile = tile;
1130 static void ProduceIndustryGoods(
Industry *i)
1135 if ((i->
counter & 0x3F) == 0) {
1174 if (plant) PlantRandomFarmField(i);
1197 void OnTick_Industry()
1199 if (_industry_sound_ctr != 0) {
1200 _industry_sound_ctr++;
1202 if (_industry_sound_ctr == 75) {
1204 }
else if (_industry_sound_ctr == 160) {
1205 _industry_sound_ctr = 0;
1210 if (_game_mode == GM_EDITOR)
return;
1213 ProduceIndustryGoods(i);
1251 uint maxdist_x = maxdist;
1252 uint maxdist_y = maxdist;
1272 if (_game_mode == GM_EDITOR)
return CommandCost();
1279 extern bool _ignore_restrictions;
1288 if (_game_mode == GM_EDITOR && _ignore_restrictions)
return CommandCost();
1400 if (i->
type == (
byte)type && i->
town == *t) {
1409 bool IsSlopeRefused(
Slope current,
Slope refused)
1440 bool refused_slope =
false;
1441 bool custom_shape =
false;
1458 if (ret.
Failed())
return ret;
1469 custom_shape =
true;
1471 if (ret.
Failed())
return ret;
1488 if (ret.
Failed())
return ret;
1493 if (ret.
Failed())
return ret;
1498 if (custom_shape_check !=
nullptr) *custom_shape_check = custom_shape;
1519 return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200);
1529 static bool CheckCanTerraformSurroundingTiles(
TileIndex tile, uint height,
int internal)
1541 if (
internal != 0 &&
Delta(curh, height) > 1)
return false;
1546 if (
internal == 0 && curh != height) {
1547 if (
TileX(tile_walk) == 0 ||
TileY(tile_walk) == 0 || !CheckCanTerraformSurroundingTiles(tile_walk +
TileDiffXY(-1, -1), height,
internal + 1)) {
1568 if (it.ti.x > max_x) max_x = it.ti.x;
1569 if (it.ti.y > max_y) max_y = it.ti.y;
1595 if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
1617 curh += (curh > h) ? -1 : 1;
1638 static const int dmax = 14;
1645 if (i == i2)
continue;
1707 if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != ind->index) return false;
1708 ind->stations_near.insert(st);
1709 st->AddIndustryToDeliver(ind);
1755 uint16 r = Random();
1758 i->
random = initial_random_bits;
1819 for (uint j = 0; j < maxcargoes; j++) {
1851 for (uint j = 0; j < maxcargoes; j++) {
1862 if (std::find(indspec->produced_cargo,
endof(indspec->produced_cargo), cargo) ==
endof(indspec->produced_cargo)) {
1903 for (uint j = 0; j != 50; j++) PlantRandomFarmField(i);
1928 assert(layout_index < indspec->layouts.size());
1930 bool custom_shape_check =
false;
1934 std::vector<ClearedObjectArea> object_areas(_cleared_object_areas);
1936 _cleared_object_areas = object_areas;
1937 if (ret.
Failed())
return ret;
1944 if (ret.
Failed())
return ret;
1952 if (ret.
Failed())
return ret;
1956 if (ret.
Failed())
return ret;
1957 assert(t !=
nullptr);
1960 if (ret.
Failed())
return ret;
1967 DoCreateNewIndustry(*ip, tile, type, layout, layout_index, t, founder, random_initial_bits);
1987 IndustryType it =
GB(p1, 0, 8);
2007 uint16 random_initial_bits =
GB(p2, 0, 16);
2008 uint32 random_var8f = randomizer.
Next();
2009 size_t num_layouts = indspec->
layouts.size();
2022 for (
int i = 0; i < 5000; i++) {
2030 for (
size_t j = 0; j < num_layouts; j++) {
2031 layout = (layout + 1) % num_layouts;
2041 size_t layout =
GB(p1, 8, 8);
2042 if (layout >= num_layouts)
return CMD_ERROR;
2045 for (
size_t i = 0; i < num_layouts; i++) {
2046 layout = (layout + 1) % num_layouts;
2052 if (ret.
Failed())
return ret;
2055 if ((flags &
DC_EXEC) && ind !=
nullptr && _game_mode != GM_EDITOR) {
2115 if (!text.empty()) ind->
text = text;
2138 uint32 seed = Random();
2139 uint32 seed2 = Random();
2142 [[maybe_unused]]
CommandCost ret =
CreateNewIndustryHelper(tile, type,
DC_EXEC, indspec, layout_index, seed,
GB(seed2, 0, 16),
OWNER_NONE, creation_type, &i);
2143 assert(i !=
nullptr || ret.
Failed());
2160 *force_at_least_one =
false;
2206 static const uint16 numof_industry_table[] = {
2230 uint tries = try_hard ? 10000u : 2000u;
2231 for (; tries > 0; tries--) {
2233 if (ind !=
nullptr)
return ind;
2288 static const int NEWINDS_PER_MONTH = 0x38000 / (10 * 12);
2309 uint32 total_prob = 0;
2310 uint num_forced = 0;
2314 total_prob += industry_probs[it];
2315 if (force_at_least_one[it]) num_forced++;
2319 if (total_prob == 0 || total_amount < num_forced) {
2321 total_amount = num_forced;
2328 if (force_at_least_one[it]) {
2329 assert(total_amount > 0);
2336 for (uint i = 0; i < total_amount; i++) {
2338 IndustryType it = 0;
2339 while (r >= industry_probs[it]) {
2340 r -= industry_probs[it];
2344 assert(industry_probs[it] > 0);
2389 void Industry::FillCachedName()
const
2392 int64 args_array[] = { this->
index };
2398 void ClearAllIndustryCachedNames()
2423 bool changed =
false;
2424 uint num_planned = 0;
2430 changed |= num_planned != total_amount;
2431 if (!changed)
return;
2434 uint force_build = 0;
2435 uint32 total_prob = 0;
2443 if (total_prob == 0)
return;
2446 total_amount = (total_amount <= force_build) ? 0 : total_amount - force_build;
2449 while (total_amount > 0) {
2451 IndustryType it = 0;
2452 while (r >= this->
builddata[it].probability) {
2457 assert(this->
builddata[it].probability > 0);
2472 uint32 total_prob = 0;
2476 missing += difference;
2477 if (this->
builddata[it].wait_count > 0)
continue;
2478 if (difference > 0) {
2486 total_prob += difference;
2504 if (this->
builddata[it].wait_count > 0)
continue;
2506 if (difference <= 0)
continue;
2507 if (count == 1)
break;
2508 if (r < (uint)difference)
break;
2516 if (ind ==
nullptr) {
2601 bool c_accepts =
false;
2602 bool c_produces =
false;
2604 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
2612 if (!c_accepts && !c_produces)
continue;
2619 if (o->IsType(OT_GOTO_STATION) && !(o->GetUnloadType() &
OUFB_TRANSFER)) {
2622 assert(st !=
nullptr);
2625 if ((o->GetUnloadType() &
OUFB_UNLOAD) && !c_accepts)
break;
2652 default: NOT_REACHED();
2657 AddIndustryNewsItem(
2658 percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH,
2664 static const uint PERCENT_TRANSPORTED_60 = 153;
2665 static const uint PERCENT_TRANSPORTED_80 = 204;
2675 bool closeit =
false;
2677 bool standard =
false;
2678 bool suppress_message =
false;
2679 bool recalculate_multipliers =
false;
2687 if (callback_enabled) {
2690 suppress_message =
HasBit(res, 7);
2693 res =
GB(res, 0, 4);
2695 default: NOT_REACHED();
2697 case 0x1: div = 1;
break;
2698 case 0x2: mul = 1;
break;
2699 case 0x3: closeit =
true;
break;
2700 case 0x4: standard =
true;
break;
2701 case 0x5:
case 0x6:
case 0x7:
2702 case 0x8: div = res - 0x3;
break;
2703 case 0x9:
case 0xA:
case 0xB:
2704 case 0xC: mul = res - 0x7;
break;
2707 increment = res == 0x0D ? -1 : 1;
2711 recalculate_multipliers =
true;
2716 if (monthly == original_economy)
return;
2725 if (original_economy) {
2726 if (only_decrease ||
Chance16(1, 3)) {
2738 uint32 r = Random();
2739 int old_prod, new_prod, percent;
2747 if (only_decrease) {
2758 new_prod += mult * (std::max(((
RandomRange(50) + 10) * old_prod) >> 8, 1U));
2762 new_prod =
Clamp(new_prod, 1, 255);
2764 new_prod =
Clamp(new_prod, 0, 16);
2772 if (new_prod == old_prod && old_prod > 1) {
2777 percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
2781 if (new_prod > 1) closeit =
false;
2783 if (
abs(percent) >= 10) {
2803 recalculate_multipliers =
true;
2808 while (div-- != 0 && !closeit) {
2814 recalculate_multipliers =
true;
2820 if (increment != 0) {
2825 recalculate_multipliers =
true;
2840 if (!suppress_message && str != STR_NULL) {
2852 default: NOT_REACHED();
2856 if (str > STR_LAST_STRINGID) {
2860 }
else if (closeit) {
2871 AddIndustryNewsItem(str, nt, i->
index);
2895 if (change_loop == 0) {
2907 for (uint16 j = 0; j < change_loop; j++) {
2925 void IndustryMonthlyLoop()
2941 cur_company.Restore();
2948 void InitializeIndustries()
2951 _industry_sound_tile = 0;
2963 bool force_at_least_one;
2965 if (chance == 0 || !force_at_least_one)
continue;
2969 ShowErrorMessage(STR_ERROR_NO_SUITABLE_PLACES_FOR_INDUSTRIES, STR_ERROR_NO_SUITABLE_PLACES_FOR_INDUSTRIES_EXPLANATION,
WL_WARNING);
2972 if (count >= 3)
break;
3004 PR_BUILD_INDUSTRY_RAW : PR_BUILD_INDUSTRY] * this->cost_multiplier) >> 8;
3029 IndustrySpec::~IndustrySpec()
3067 GetSlopePixelZ_Industry,
3069 AddAcceptedCargo_Industry,
3070 GetTileDesc_Industry,
3071 GetTileTrackStatus_Industry,
3073 AnimateTile_Industry,
3075 ChangeTileOwner_Industry,
3078 GetFoundation_Industry,
3079 TerraformTile_Industry,
3082 bool IndustryCompare::operator() (
const Industry *lhs,
const Industry *rhs)
const
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ INDUSTRYBEH_ONLY_INTOWN
can only be built in towns (arctic/tropic banks, water tower)
static bool CheckScaledDistanceFromEdge(TileIndex tile, uint maxdist)
Check if a tile is within a distance from map edges, scaled by map dimensions independently.
@ NT_INDUSTRY_NOBODY
Other industry production changes.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ MP_HOUSE
A house by a town.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
const char * grf
newGRF used for the tile contents
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
uint32 TileIndex
The index/ID of a Tile.
@ TROPICZONE_DESERT
Tile is desert.
@ NT_INDUSTRY_OPEN
Opening of industries.
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-...
Owner owner
owner of the industry. Which SHOULD always be (imho) OWNER_NONE
@ ID_FUND_ONLY
The game does not build industries.
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
@ SND_30_TOFFEE_QUARRY
48 == 0x30 Industry animation: toffee quarry: drill
uint16 this_month_production[INDUSTRY_NUM_OUTPUTS]
stats of this month's production per cargo
Cheat magic_bulldozer
dynamite industries, objects
@ OUFB_UNLOAD
Force unloading all cargo onto the platform, possibly not getting paid.
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
CommandCost CheckNewIndustryProc(TileIndex tile)
Industrytype check function signature.
@ SND_0B_MINE
9 == 0x09 Industry animation: coal/copper/gold mine: headgear
static Titem * Get(size_t index)
Returns Titem with given index.
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent)
Report news that industry production has changed significantly.
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
CargoLabel label
Unique label of the cargo type.
@ SND_2B_TOY_FACTORY_2
43 == 0x2B Industry animation: toy factory (2): stamp product
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
@ NT_INDUSTRY_CLOSE
Closing of industries.
StationSettings station
settings related to station management
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static void AdvertiseIndustryOpening(const Industry *ind)
Advertise about a new industry opening.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
static void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
Set the industry graphics ID for the given industry tile.
@ ID_VERY_LOW
Very few industries at game start.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
@ EV_BUBBLE
Bubble of bubble generator (industry).
@ INDCTL_NONE
No flags in effect.
static IndustryGfx GetIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile.
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
@ INDUSTRYBEH_AFTER_1960
can only be built after 1960 (oil rigs)
uint x
X position of the tile in unit coordinates.
@ EV_CHIMNEY_SMOKE
Smoke of power plant (industry).
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
@ IAT_TILELOOP
Trigger in the periodic tile loop.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ INDCTL_NO_CLOSURE
Industry can not close regardless of production level or time since last delivery.
@ INDUSTRYBEH_NO_PAX_PROD_CLAMP
Do not clamp production of passengers. (smooth economy only)
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]
Industry build data for every industry type.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
static bool CheckIndustryCloseDownProtection(IndustryType type)
Protects an industry from closure if the appropriate flags and conditions are met INDUSTRYBEH_CANCLOS...
@ WL_WARNING
Other information.
Tile information, used while rendering the tile.
uint16 this_month_transported[INDUSTRY_NUM_OUTPUTS]
stats of this month's transport per cargo
byte landscape
the landscape we're currently in
Class to backup a specific variable and restore it later.
static 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...
static uint GetTreeGrowth(TileIndex t)
Returns the tree growth status.
static 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...
Year _cur_year
Current year, starting at 0.
T * Next() const
Get next vehicle in the chain.
@ EXPENSES_OTHER
Other expenses.
@ OUFB_TRANSFER
Transfer all cargo onto the platform.
Owner owner[4]
Name of the owner(s)
Money GetRemovalCost() const
Get the cost for removing this industry Take note that the cost will always be zero for non-grf indus...
void CheckIndustries()
Verify whether the generated industries are complete, and warn the user if not.
@ SND_2A_TOY_FACTORY_3
42 == 0x2A Industry animation: toy factory (3): eject product
@ CBID_INDUSTRY_PRODUCTION_CHANGE
Called on production changes, so it can be adjusted.
uint32 Next()
Generate the next pseudo random number.
uint32 industry_daily_change_counter
Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily.
@ PRODLEVEL_CLOSURE
signal set to actually close the industry
Money GetConstructionCost() const
Get the cost for constructing this industry.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
@ CBID_INDTILE_CARGO_ACCEPTANCE
Called to query the cargo acceptance of the industry tile.
static void ChopLumberMillTrees(Industry *i)
Perform a circular search around the Lumber Mill in order to find trees to cut.
@ SetText
Set additional text.
uint16 last_month_transported[INDUSTRY_NUM_OUTPUTS]
total units transported per cargo in the last full month
static void SetIndustryConstructionStage(TileIndex tile, byte value)
Sets the industry construction stage of the specified tile.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
@ IAT_INDUSTRY_TICK
Trigger every tick.
bool anim_state
When true, the tile has to be drawn using the animation state instead of the construction state.
IndustryType GetIndustryType(TileIndex tile)
Retrieve the type for this industry.
@ SND_0C_POWER_STATION
10 == 0x0A Industry animation: power station: spark
@ CBM_INDT_SHAPE_CHECK
decides slope suitability
IndustryBuildData _industry_builder
In-game manager of industries.
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
uint32 removal_cost_multiplier
Base removal cost multiplier.
static bool IsIndustryCompleted(TileIndex t)
Is this industry tile fully built?
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
@ IACT_RANDOMCREATION
during creation of random ingame industry
Class for storing amounts of cargo.
byte was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station....
@ TROPICZONE_RAINFOREST
Rainforest tile.
SpriteID sprite
The 'real' sprite.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
uint16 produced_cargo_waiting[INDUSTRY_NUM_OUTPUTS]
amount of cargo produced per cargo
DifficultySettings difficulty
settings related to the difficulty
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
static CommandCost CheckNewIndustry_Farm(TileIndex tile)
Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
@ INDUSTRYBEH_DONT_INCR_PROD
do not increase production (oil wells) in the temperate climate
int x
coordinate x of the first image offset
CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Build/Fund an industry.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
static void SetDParamX(uint64 *s, uint n, uint64 v)
Set a string parameter v at index n in a given array s.
static const uint TILE_SIZE
Tile size in world coordinates.
@ SetExclusiveConsumer
Set exclusive consumer.
@ CBM_INDT_ACCEPT_CARGO
decides accepted types
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
static Station * Get(size_t index)
Gets station with given index.
uint8 construction_type
Way the industry was constructed (.
uint y
Y position of the tile in unit coordinates.
ClientSettings _settings_client
The current settings for this game.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
TileIndex xy
town center tile
@ GWP_INDUSTRY
Generate industries.
@ DC_NO_WATER
don't allow building on water
@ CBID_INDTILE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for industry tile.
@ MP_INDUSTRY
Part of an industry.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
static bool Chance16I(const uint a, const uint b, const uint32 r)
Checks if a given randomize-number is below a given probability.
Date construction_date
Date of the construction of the industry.
Owner exclusive_consumer
Which company has exclusive rights to take cargo (INVALID_OWNER = anyone)
TransportType
Available types of transport.
@ SND_2C_TOY_FACTORY_1
44 == 0x2C Industry animation: toy factory (1): conveyor belt
@ VEH_ROAD
Road vehicle type.
@ PRODLEVEL_DEFAULT
default level set when the industry is created
Defines the internal data of a functional industry.
@ INDUSTRY_TRIGGER_INDUSTRY_TICK
The industry has been triggered via its tick.
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Owner owner
Which company owns the vehicle?
Owner
Enum for all companies/owners.
IndustryControlFlags ctlflags
flags overriding standard behaviours
@ DC_EXEC
execute the given command
@ CBID_INDUSTRY_OUTPUT_CARGO_TYPES
Customize the output cargo types of a newly build industry.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
@ GFX_WATERTILE_SPECIALCHECK
not really a tile, but rather a very special check
@ CBID_INDTILE_ACCEPT_CARGO
Called to determine which cargoes an industry should accept.
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
Trigger a random trigger for all industry tiles.
Tile description for the 'land area information' tool.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
@ CBID_INDUSTRY_SPECIAL_EFFECT
Called to determine industry special effects.
@ CBM_INDT_AUTOSLOPE
decides allowance of autosloping
DoCommandFlag
List of flags for a command.
static void SetFence(TileIndex t, DiagDirection side, uint h)
Sets the type of fence (and whether there is one) for the given border.
Foundation
Enumeration for Foundations.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
@ INDUSTRYBEH_NOBUILT_MAPCREATION
Do not force one instance of this type to appear on map generation.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Station * neutral_station
Associated neutral station.
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
bool Succeeded() const
Did this command succeed?
static void ResetIndustryConstructionStage(TileIndex tile)
Reset the construction stage counter of the industry, as well as the completion bit.
static uint TileX(TileIndex tile)
Get the X component of a tile.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
void IndustryDailyLoop()
Daily handler for the industry changes Taking the original map size of 256*256, the number of random ...
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const DrawIndustryCoordinates _coal_plant_sparks[]
Movement of the sparks , only used for Power Station.
std::vector< IndustryTileLayoutTile > IndustryTileLayout
A complete tile layout for an industry is a list of tiles.
@ SND_2D_SUGAR_MINE_1
45 == 0x2D Industry animation: sugar mine (1): shaking sieve
@ SLOPE_NW
north and west corner are raised
Slope tileh
Slope of the tile.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
static uint MapSizeX()
Get the size of the map along the X.
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
@ INDUSTRYBEH_PLANT_ON_BUILT
Fields are planted around when built (all farms)
void ClearDockingTilesCheckingNeighbours(TileIndex tile)
Clear docking tile status from tiles around a removed dock, if the tile has no neighbours which would...
char * GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
bool ambient
Play ambient, industry and town sounds.
StringID closure_text
Message appearing when the industry closes.
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
static Industry * GetRandom()
Return a random valid industry.
@ SetExclusiveSupplier
Set exclusive supplier.
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
static const int INDUSTRY_COMPLETED
final stage of industry construction.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
static size_t GetPoolSize()
Returns first unused index.
IterateWrapper Orders() const
Returns an iterable ensemble of orders of a vehicle.
uint32 industry_daily_increment
The value which will increment industry_daily_change_counter. Computed value. NOSAVE.
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
static void UpdateIndustryStatistics(Industry *i)
Monthly update of industry statistics.
uint32 population
Current population of people.
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
@ CHECK_END
End marker of the industry check procedures.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
@ SND_29_SUGAR_MINE_2
41 == 0x29 Industry animation: sugar mine (2): shaking sieve
int8 acceptance[INDUSTRY_NUM_INPUTS]
Level of acceptance per cargo type (signed, may be negative!)
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, const IndustryTileLayout &layout, int type)
This function tries to flatten out the land below an industry, without damaging the surroundings too ...
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
uint16 wait_count
Number of turns to wait before trying to build again.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
static uint MapSize()
Get the size of the map.
static int WhoCanServiceIndustry(Industry *ind)
Compute who can service the industry.
static void SetIndustryConstructionCounter(TileIndex tile, byte value)
Sets this industry tile's construction counter value.
static Industry * PlaceIndustry(IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
Try to place the industry in the game.
@ EXPENSES_CONSTRUCTION
Construction costs.
StationList stations_near
NOSAVE: List of nearby stations.
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.
static byte GetIndustryAnimationLoop(TileIndex tile)
Get the animation loop number.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Common return value for all commands.
uint16 random
Random value used for randomisation of all kinds of things.
byte GetSnowLine()
Get the current snow line, either variable or static.
TileArea location
Location of the industry.
@ SetControlFlags
Set IndustryControlFlags.
void Reset()
Reset the entry.
static void SetClearCounter(TileIndex t, uint c)
Sets the counter used to advance to the next clear density/field type.
Date _date
Current date in days (day counter)
static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile)
Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map).
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
SoundSettings sound
sound effect settings
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.
@ CMD_TERRAFORM_LAND
terraform a tile
std::string cached_name
NOSAVE: Cache of the resolved name of the industry.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
IndustryType conflicting[3]
Industries this industry cannot be close to.
Owner exclusive_supplier
Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone)
@ INDUSTRYBEH_PLANT_FIELDS
periodically plants fields around itself (temp and arctic farms)
static uint32 GetScaledIndustryGenerationProbability(IndustryType it, bool *force_at_least_one)
Compute the appearance probability for an industry during map creation.
IndustryType type
type of industry.
@ SND_36_LUMBER_MILL_3
54 == 0x36 Industry animation: lumber mill (3): crashing tree
uint16 max_wait
Starting number of turns to wait (copied to wait_count).
int32 TileIndexDiff
An offset value between to tiles.
@ CBM_IND_PRODUCTION_CHANGE
controls random production change
@ SND_2E_BUBBLE_GENERATOR
46 == 0x2E Industry animation: bubble generator (1): generate bubble
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
Cheats _cheats
All the cheats.
Data for managing the number and type of industries in the game.
@ CBID_INDUSTRY_MONTHLYPROD_CHANGE
Called monthly on production changes, so it can be adjusted more frequently.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
@ INVALID_OWNER
An invalid owner.
uint16 w
The width of the area.
static const IndustryGfx INDUSTRYTILE_NOANIM
flag to mark industry tiles as having no animation
@ CBM_INDT_DRAW_FOUNDATIONS
decides if default foundations need to be drawn
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
uint8 number_of_sounds
Number of sounds available in the sounds array.
@ CBM_IND_LOCATION
check industry construction on given area
@ CBM_IND_INPUT_CARGO_TYPES
customize the cargoes the industry requires
bool Failed() const
Did this command fail?
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]
incoming cargo waiting to be processed
@ EV_COPPER_MINE_SMOKE
Smoke at copper mine.
@ INDUSTRYBEH_BUILT_ONWATER
is built on water (oil rig)
StringID production_up_text
Message appearing when the industry's production is increasing.
static 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...
@ ST_INDUSTRY
Source/destination is an industry.
@ CBID_INDUSTRY_INPUT_CARGO_TYPES
Customize the input cargo types of a newly build industry.
Represents the covered area of e.g.
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, size_t layout_index, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check the slope of a tile of a new industry.
uint8 raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
byte minimal_cargo
minimum amount of cargo transported to the stations.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
static void DecIndustryTypeCount(IndustryType type)
Decrement the count of industries for this type.
byte image_2
image offset 2
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static const uint8 ANIM_STATUS_NO_ANIMATION
There is no animation.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
void DeleteSubsidyWith(SourceType type, SourceID index)
Delete the subsidies associated with a given cargo source type and id.
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, DiagDirection side)
Build farm field fence.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
EconomySettings economy
settings to change the economy
void MonthlyLoop()
Monthly update of industry build data.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ PRODLEVEL_MAXIMUM
the industry is running at full speed
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
static uint GetNumberOfIndustries()
Get wanted number of industries on the map.
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
static void SetIndustryIndexOfField(TileIndex t, IndustryID i)
Set the industry (farm) that made the field.
uint DistanceFromEdgeDir(TileIndex tile, DiagDirection dir)
Gets the distance to the edge of the map in given direction.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Slope slopes_refused
slope pattern on which this tile cannot be built
static void ResetIndustryCounts()
Resets industry counts.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
byte industry_density
The industry density.
#define RandomTile()
Get a valid random tile.
@ DC_NO_TEST_TOWN_RATING
town rating does not disallow you from building
@ INDUSTRYBEH_BEFORE_1950
can only be built before 1950 (oil wells)
static CommandCost CheckNewIndustry_BubbleGen(TileIndex tile)
Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
void SetupTargetCount()
Decide how many industries of each type are needed.
@ CBM_IND_SPECIAL_EFFECT
control special effects
static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields)
Check whether the tile can be replaced by a farm field.
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
static void SetIndustryAnimationLoop(TileIndex tile, byte count)
Set the animation loop number.
@ SLOPE_SW
south and west corner are raised
byte oil_refinery_limit
distance oil refineries allowed from map edge
Slope
Enumeration for the slope-type.
DiagDirection
Enumeration for diagonal directions.
void TryBuildNewIndustry()
Try to create a random industry, during gameplay.
@ INDUSTRYLIFE_BLACK_HOLE
Like power plants and banks.
static uint MapSizeY()
Get the size of the map along the Y.
byte appear_creation[NUM_LANDSCAPE]
Probability of appearance during map creation.
@ IACT_PROSPECTCREATION
from the Fund/build using prospecting
byte anim_production
Animation frame to start when goods are produced.
byte image_3
image offset 3
uint64 dparam[2]
Parameters of the str string.
static IndustryID GetIndustryIndexOfField(TileIndex t)
Get the industry (farm) that made the field.
Set of callback functions for performing tile operations of a given tile type.
SoundFx
Sound effects from baseset.
@ SND_38_LUMBER_MILL_1
56 == 0x38 Industry animation: lumber mill (1): chainsaw
void ReleaseDisastersTargetingIndustry(IndustryID i)
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile)...
Defines the data structure for constructing industry.
static byte GetIndustryConstructionStage(TileIndex tile)
Returns the industry construction stage of the specified tile.
GRFFileProps grf_prop
properties related to the grf file
bool value
tells if the bool cheat is active or not
static Industry * CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
Create a new industry of random layout.
std::string text
General text with additional information.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
@ IACT_USERCREATION
from the Fund/build window
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
This is used to gather some data about animation drawing in the industry code Image_1-2-3 are in fact...
@ TO_INDUSTRIES
industries
@ ICT_MAP_GENERATION
during random map creation
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.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
uint16 h
The height of the area.
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
static const DrawBuildingsTileStruct _industry_draw_tile_data[NEW_INDUSTRYTILEOFFSET *4]
Structure for industry tiles drawing.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
@ MP_TREES
Tile got trees.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Change industry properties.
bool _generating_world
Whether we are generating the map or not.
EffectVehicle * CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle at a particular location.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
@ INDUSTRYLIFE_PROCESSING
Like factories.
@ CBM_IND_MONTHLYPROD_CHANGE
controls monthly random production change
@ CBID_INDUSTRY_PROD_CHANGE_BUILD
Called when industry is built to set initial production level.
static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile)
Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest).
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
Cargo accepted by this tile.
bool enabled
entity still available (by default true).newgrf can disable it, though
void Reset()
Completely reset the industry build data.
static bool EconomyIsInRecession()
Is the economy in recession?
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
CompanyID _current_company
Company currently doing an action.
uint32 wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
@ SLOPE_N
the north corner of the tile is raised
bool IsProcessingIndustry() const
Is an industry with the spec a processing industry?
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
byte image_1
image offset 1
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
@ CHECK_OIL_RIG
Industries at sea should be positioned near edge of the map.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
@ CLEAN_RANDOMSOUNDS
Free the dynamically allocated sounds table.
byte selected_layout
Which tile layout was used when creating the industry.
@ NT_INDUSTRY_COMPANY
Production changes of industry serviced by local company.
Base class for all pools.
static uint16 GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
static uint ScaleByMapSize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
EconomyType type
economy type (original/smooth/frozen)
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static void PopulateStationsNearby(Industry *ind)
Populate an industry's list of nearby stations, and if it accepts any cargo, also add the industry to...
@ MP_VOID
Invisible tiles at the SW and SE border.
static CommandCost CheckNewIndustry_Plantation(TileIndex tile)
Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).
@ INDTILE_TRIGGER_TILE_LOOP
The tile of the industry has been triggered during the tileloop.
static CommandCost FindTownForIndustry(TileIndex tile, int type, Town **t)
Find a town for the industry, while checking for multiple industries in the same town.
static size_t GetNumItems()
Returns number of valid items in the pool.
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
void Restore()
Restore the variable.
static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check=nullptr)
Are the tiles of the industry free?
@ INDUSTRYBEH_ONLY_NEARTOWN
is always built near towns (toy shop)
Structure to encapsulate the pseudo random number generators.
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
byte land_generator
the landscape generator
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Owner founder
Founder of the industry.
static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int type)
Check that the new industry is far enough from conflicting industries.
@ ICT_SCENARIO_EDITOR
while editing a scenario
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, size_t layout_index, uint32 random_var8f, uint16 random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip)
Helper function for Build/Fund an industry.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
static void IncIndustryTypeCount(IndustryType type)
Increment the count of industries for this type.
TileIndex tile
The base tile of the area.
#define endof(x)
Get the end element of an fixed size array.
@ CBM_INDT_CARGO_ACCEPTANCE
decides amount of cargo acceptance
static uint16 GetIndustryGamePlayProbability(IndustryType it, byte *min_number)
Compute the probability for constructing a new industry during game play.
@ INDUSTRYLIFE_ORGANIC
Like forests.
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
This structure is the same for both Industries and Houses.
static CommandCost CheckNewIndustry_OilRig(TileIndex tile)
Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map).
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
@ OWNER_NONE
The tile has no ownership.
void GenerateIndustries()
This function will create random industries during game creation.
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
StringID production_down_text
Message appearing when the industry's production is decreasing.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]
Last day each cargo type was accepted by this industry.
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
uint8 cleanup_flag
flags indicating which data should be freed upon cleaning up
@ MP_STATION
A tile of a station.
byte appear_ingame[NUM_LANDSCAPE]
Probability of appearance in game.
GRFFileProps grf_prop
properties related to the grf file
TownCache cache
Container for all cacheable data.
void ResetOverride()
Resets the override, which is used while initializing game.
@ IACT_MAPGENERATION
during random map generation
static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
Search callback function for ChopLumberMillTrees.
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
uint32 prospecting_chance
Chance prospecting succeeds.
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
Call a function on all stations that have any part of the requested area within their catchment.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition of one tile in an industry tile layout.
static void ChangeIndustryProduction(Industry *i, bool monthly)
Change industry production or do closure.
Year last_prod_year
last year of production
byte min_number
Smallest number of industries that should exist (either 0 or 1).
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
Trigger a random trigger for a single industry tile.
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
@ CBID_INDTILE_AUTOSLOPE
Called to determine if industry can alter the ground below industry tile.
Data for managing the number of industries of a single industry type.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
StringID str
Description of the tile.
@ DC_AUTO
don't allow building on structures
@ SLOPE_S
the south corner of the tile is raised
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
static uint ScaleByMapSize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
A special vehicle is one of the following:
@ DC_NO_MODIFY_TOWN_RATING
do not change town rating
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
const T & GetOriginalValue() const
Returns the backupped value.
static CommandCost CheckNewIndustry_Forest(TileIndex tile)
Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate).
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
const uint8 * random_sounds
array of random sounds.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
Can given cargo type be accepted or produced by the industry?
bool multiple_industry_per_town
allow many industries of the same type per town
IndustryLifeType life_type
This is also known as Industry production flag, in newgrf specs.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, size_t layout, uint32 seed, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check that the industry callback allows creation of the industry.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
uint8 callback_mask
Bitmask of industry tile callbacks that have to be called.
static CheckNewIndustryProc *const _check_new_industry_procs[CHECK_END]
Check functions for different types of industry.
@ SLOPE_W
the west corner of the tile is raised
byte random_colour
randomized colour of the industry, for display purpose
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
uint8 status
Status; 0: no looping, 1: looping, 0xFF: no animation.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
#define lengthof(x)
Return the length of an fixed size array.
static void SetIndustryCompleted(TileIndex tile)
Set if the industry that owns the tile as under construction or not.
@ INDUSTRYBEH_CANCLOSE_LASTINSTANCE
Allow closing down the last instance of this type.
@ CBID_INDUSTRY_DECIDE_COLOUR
Called to determine the colour of an industry.
static bool TransportIndustryGoods(TileIndex tile)
Move produced cargo from industry to nearby stations.
static bool IsOilRig(TileIndex t)
Is tile t part of an oilrig?
static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, const IndustryTileLayout &layout, size_t layout_index, Town *t, Owner founder, uint16 initial_random_bits)
Put an industry on the map.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static const int INDUSTRY_CUT_TREE_TICKS
cycle duration for lumber mill's extra action
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool Chance16R(const uint a, const uint b, uint32 &r)
Flips a coin with a given probability and saves the randomize-number in a variable.
static void MakeField(TileIndex t, uint field_type, IndustryID industry)
Make a (farm) field tile.
@ INDCTL_NO_PRODUCTION_DECREASE
When industry production change is evaluated, rolls to decrease are ignored.
@ CBM_IND_DECIDE_COLOUR
give a custom colour to newly build industries
static byte GetIndustryConstructionCounter(TileIndex tile)
Returns this industry tile's construction counter value.
CargoID cargo_type
type of cargo this vehicle is carrying
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
static uint GetCurrentTotalNumberOfIndustries()
Get total number of industries existing in the game.
static CommandCost CheckNewIndustry_NULL(TileIndex tile)
Check the conditions of CHECK_NOTHING (Always succeeds).
@ INDUSTRYBEH_TOWN1200_MORE
can only be built in towns larger than 1200 inhabitants (temperate bank)
@ ID_END
Number of industry density settings.
uint32 probability
Relative probability of building this industry.
byte check_proc
Index to a procedure to check for conflicting circumstances.
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
PaletteID pal
The palette (use PAL_NONE) if not needed)
@ NT_INDUSTRY_OTHER
Production changes of industry serviced by competitor(s)
TileIndex tile
Tile index.
ConstructionSettings construction
construction of things in-game
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
@ CBM_IND_PROD_CHANGE_BUILD
initialise production level on construction
@ IAT_CONSTRUCTION_STATE_CHANGE
Trigger whenever the construction state changes.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static CommandCost CheckNewIndustry_Water(TileIndex tile)
Check the conditions of CHECK_WATER (Industry should be in the desert).
@ VEH_TRAIN
Train vehicle type.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
StringID name
Displayed name of the industry.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
StringID new_industry_text
Message appearing when the industry is built.
VehicleType type
Type of vehicle.
@ INDCTL_MASK
Mask of all flags set.
const struct GRFFile * grffile
grf file that introduced this entity
byte prod_level
general production level
static uint16 counts[NUM_INDUSTRYTYPES]
Number of industries per type ingame.
void SetSeed(uint32 seed)
(Re)set the state of the random number generator.
static void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
Make the given tile an industry tile.
PersistentStorage * psa
Persistent storage for NewGRF industries.
@ INDCTL_NO_PRODUCTION_INCREASE
When industry production change is evaluated, rolls to increase are ignored.
@ IAT_INDUSTRY_DISTRIBUTES_CARGO
Trigger when cargo is distributed.
IndustryControlFlags
Flags to control/override the behaviour of an industry.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
Is the industry allowed to be built at this place for the town?
@ CT_INVALID
Invalid cargo type.
StringID MapGRFStringID(uint32 grfid, StringID str)
Used when setting an object's property to map to the GRF's strings while taking in consideration the ...
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
@ INDUSTRYBEH_CUT_TREES
cuts trees and produce first output cargo from them (lumber mill)
@ DIAGDIR_NE
Northeast, upper right on your monitor.
void ResetIndustries()
This function initialize the spec arrays of both industry and industry tiles.
@ VEH_SHIP
Ship vehicle type.
byte anim_next
Next frame in an animation.
Defines the data structure of each individual tile of an industry.
@ SLOPE_SE
south and east corner are raised
byte production_rate[INDUSTRY_NUM_OUTPUTS]
production rate for each cargo
@ OWNER_WATER
The tile/execution is done by "water".
#define lastof(x)
Get the last element of an fixed size array.
uint16 target_count
Desired number of industries of this type.
bool GetIndustryTypeData(IndustryType it)
Set the probability and min_number fields for the industry type it for a running game.
void IndustryProductionCallback(Industry *ind, int reason)
Get the industry production callback and apply it to the industry.
@ CHECK_REFINERY
Industry should be positioned near edge of the map.
@ SLOPE_NE
north and east corner are raised
byte animation_substate
Sub state to time the change of the graphics/behaviour.
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
@ SLOPE_E
the east corner of the tile is raised
@ CMD_LANDSCAPE_CLEAR
demolish a tile
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
@ CBM_IND_OUTPUT_CARGO_TYPES
customize the cargoes the industry produces
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
static void PlaceInitialIndustry(IndustryType type, bool try_hard)
Try to build a industry on the map.
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.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
uint16 counter
used for animation and/or production (if available cargo)
uint8 industry_platform
the amount of flat land around an industry
const char * GetName() const
Get the name of this grf.
@ INDTILE_SPECIAL_ACCEPTS_ALL_CARGO
Tile always accepts all cargoes the associated industry accepts.
static IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
@ ICT_NORMAL_GAMEPLAY
either by user or random creation process
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet).
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
static const int INDUSTRY_PRODUCE_TICKS
cycle duration for industry production
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub, bool scale)
Add a child sprite to a parent sprite.
@ SND_37_LUMBER_MILL_2
55 == 0x37 Industry animation: lumber mill (2): falling tree
@ INDUSTRYLIFE_EXTRACTIVE
Like mines.