45 #include "table/strings.h" 54 void ShowIndustryViewWindow(
int industry);
57 static byte _industry_sound_ctr;
74 memset(&_industry_specs, 0,
sizeof(_industry_specs));
75 memcpy(&_industry_specs, &_origin_industry_specs,
sizeof(_origin_industry_specs));
83 memset(&_industry_tile_specs, 0,
sizeof(_industry_tile_specs));
84 memcpy(&_industry_tile_specs, &_origin_industry_tile_specs,
sizeof(_origin_industry_tile_specs));
119 return &_industry_specs[thistype];
133 return &_industry_tile_specs[gfx];
136 Industry::~Industry()
154 DeleteOilRig(tile_cur);
223 static void IndustryDrawSugarMine(
const TileInfo *ti)
237 _drawtile_proc1[d->
image_3 - 1].x, _drawtile_proc1[d->
image_3 - 1].y);
241 static void IndustryDrawToffeeQuarry(
const TileInfo *ti)
256 static void IndustryDrawBubbleGenerator(
const TileInfo *ti)
264 static void IndustryDrawToyFactory(
const TileInfo *ti)
280 static void IndustryDrawCoalPlantSparks(
const TileInfo *ti)
285 if (image != 0 && image < 7) {
295 typedef void IndustryDrawTileProc(
const TileInfo *ti);
296 static IndustryDrawTileProc *
const _industry_draw_tile_procs[5] = {
297 IndustryDrawSugarMine,
298 IndustryDrawToffeeQuarry,
299 IndustryDrawBubbleGenerator,
300 IndustryDrawToyFactory,
301 IndustryDrawCoalPlantSparks,
304 static void DrawTile_Industry(
TileInfo *ti)
341 DrawWaterClassGround(ti);
350 image = dits->building.
sprite;
353 ti->
x + dits->subtile_x,
354 ti->
y + dits->subtile_y,
365 int proc = dits->draw_proc - 1;
366 if (proc >= 0) _industry_draw_tile_procs[proc](ti);
370 static int GetSlopePixelZ_Industry(
TileIndex tile, uint x, uint y)
393 static void AddAcceptedCargo_Industry(
TileIndex tile,
CargoArray &acceptance, CargoTypes *always_accepted)
409 if (pos ==
endof(accepts_cargo)) {
412 if (pos ==
endof(accepts_cargo))
continue;
433 for (uint i = 0; i < 3; i++) cargo_acceptance[i] =
GB(res, i * 4, 4);
439 if (a ==
CT_INVALID || cargo_acceptance[i] <= 0)
continue;
442 acceptance[a] += cargo_acceptance[i];
445 if (
HasBit(*always_accepted, a))
continue;
447 bool accepts =
false;
456 if (accepts)
continue;
459 SetBit(*always_accepted, a);
472 td->
str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
517 bool moved_cargo =
false;
534 moved_cargo |= (am != 0);
542 static void AnimateTile_Industry(
TileIndex tile)
547 AnimateNewIndustryTile(tile);
552 case GFX_SUGAR_MINE_SIEVE:
558 case 2: SndPlayTileFx(SND_2D_RIP_2, tile);
break;
559 case 6: SndPlayTileFx(SND_29_RIP, tile);
break;
573 case GFX_TOFFEE_QUARY:
578 SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
591 case GFX_BUBBLE_CATCHER:
606 case GFX_POWERPLANT_SPARKS:
619 case GFX_TOY_FACTORY:
644 case GFX_PLASTIC_FOUNTAIN_ANIMATED_1:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
645 case GFX_PLASTIC_FOUNTAIN_ANIMATED_3:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
646 case GFX_PLASTIC_FOUNTAIN_ANIMATED_5:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
647 case GFX_PLASTIC_FOUNTAIN_ANIMATED_7:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
651 gfx = (gfx < 155) ? gfx + 1 : 148;
657 case GFX_OILWELL_ANIMATED_1:
658 case GFX_OILWELL_ANIMATED_2:
659 case GFX_OILWELL_ANIMATED_3:
665 if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
677 case GFX_COAL_MINE_TOWER_ANIMATED:
678 case GFX_COPPER_MINE_TOWER_ANIMATED:
679 case GFX_GOLD_MINE_TOWER_ANIMATED: {
682 if ((state -= 0x400) < 0)
return;
685 if (state < 0x20 || state >= 0x180) {
691 if (state & 7)
return;
693 if (state & 3)
return;
696 if (m > 0xC2) m = 0xC0;
699 }
else if (state >= 0x200 && state < 0x3A0) {
700 int i = (state < 0x220 || state >= 0x380) ? 7 : 3;
701 if (state & i)
return;
704 if (m < 0x80) m = 0x82;
713 static void CreateChimneySmoke(
TileIndex tile)
722 static void MakeIndustryTileBigger(
TileIndex tile)
747 case GFX_POWERPLANT_CHIMNEY:
748 CreateChimneySmoke(tile);
766 case GFX_TOY_FACTORY:
767 case GFX_BUBBLE_CATCHER:
768 case GFX_TOFFEE_QUARY:
773 case GFX_PLASTIC_FOUNTAIN_ANIMATED_1:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
774 case GFX_PLASTIC_FOUNTAIN_ANIMATED_3:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
775 case GFX_PLASTIC_FOUNTAIN_ANIMATED_5:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
776 case GFX_PLASTIC_FOUNTAIN_ANIMATED_7:
case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
782 static void TileLoopIndustry_BubbleGenerator(
TileIndex tile)
784 static const int8 _bubble_spawn_location[3][4] = {
792 int dir = Random() & 3;
797 _bubble_spawn_location[2][dir],
804 static void TileLoop_Industry(
TileIndex tile)
817 MakeIndustryTileBigger(tile);
821 if (_game_mode == GM_EDITOR)
return;
835 if (StartStopIndustryTileAnimation(tile,
IAT_TILELOOP))
return;
847 case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
848 case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
849 case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
852 case GFX_COAL_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COAL_MINE_TOWER_ANIMATED;
break;
853 case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED;
break;
854 case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_ANIMATED;
break;
862 case GFX_OILWELL_NOT_ANIMATED:
870 case GFX_COAL_MINE_TOWER_ANIMATED:
871 case GFX_COPPER_MINE_TOWER_ANIMATED:
872 case GFX_GOLD_MINE_TOWER_ANIMATED:
875 case GFX_COAL_MINE_TOWER_ANIMATED: gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED;
break;
876 case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED;
break;
877 case GFX_GOLD_MINE_TOWER_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED;
break;
886 case GFX_POWERPLANT_SPARKS:
893 case GFX_COPPER_MINE_CHIMNEY:
898 case GFX_TOY_FACTORY: {
908 case GFX_BUBBLE_GENERATOR:
909 TileLoopIndustry_BubbleGenerator(tile);
912 case GFX_TOFFEE_QUARY:
916 case GFX_SUGAR_MINE_SIEVE:
922 static bool ClickTile_Industry(
TileIndex tile)
964 static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
978 default:
return false;
999 if (or_ == 1 &&
Chance16(1, 7)) or_ = 2;
1008 static void PlantFarmField(
TileIndex tile, IndustryID industry)
1015 uint32 r = (Random() & 0x303) + 0x404;
1017 uint size_x =
GB(r, 0, 8);
1018 uint size_y =
GB(r, 8, 8);
1023 if (ta.
w == 0 || ta.
h == 0)
return;
1031 if (count * 2 < ta.
w * ta.
h)
return;
1036 uint field_type =
GB(r, 8, 8) * 9 >> 8;
1042 MakeField(cur_tile, field_type, industry);
1050 type = _plantfarmfield_type[Random() & 0xF];
1059 void PlantRandomFarmField(
const Industry *i)
1061 int x = i->
location.
w / 2 + Random() % 31 - 16;
1062 int y = i->
location.
h / 2 + Random() % 31 - 16;
1082 _industry_sound_ctr = 1;
1083 _industry_sound_tile = tile;
1113 static void ProduceIndustryGoods(
Industry *i)
1118 if ((i->
counter & 0x3F) == 0) {
1152 if (plant) PlantRandomFarmField(i);
1175 void OnTick_Industry()
1177 if (_industry_sound_ctr != 0) {
1178 _industry_sound_ctr++;
1180 if (_industry_sound_ctr == 75) {
1182 }
else if (_industry_sound_ctr == 160) {
1183 _industry_sound_ctr = 0;
1188 if (_game_mode == GM_EDITOR)
return;
1191 FOR_ALL_INDUSTRIES(i) {
1192 ProduceIndustryGoods(i);
1228 if (_game_mode == GM_EDITOR)
return CommandCost();
1234 extern bool _ignore_restrictions;
1243 if (_game_mode == GM_EDITOR && _ignore_restrictions)
return CommandCost();
1354 FOR_ALL_INDUSTRIES(i) {
1355 if (i->
type == (byte)type && i->
town == *t) {
1364 bool IsSlopeRefused(
Slope current,
Slope refused)
1395 bool refused_slope =
false;
1396 bool custom_shape =
false;
1413 if (ret.
Failed())
return ret;
1424 custom_shape =
true;
1426 if (ret.
Failed())
return ret;
1443 if (ret.
Failed())
return ret;
1448 if (ret.
Failed())
return ret;
1451 }
while ((++it)->ti.x != -0x80);
1453 if (custom_shape_check != NULL) *custom_shape_check = custom_shape;
1474 return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200);
1484 static bool CheckCanTerraformSurroundingTiles(
TileIndex tile, uint height,
int internal)
1496 if (
internal != 0 &&
Delta(curh, height) > 1)
return false;
1501 if (
internal == 0 && curh != height) {
1502 if (
TileX(tile_walk) == 0 ||
TileY(tile_walk) == 0 || !CheckCanTerraformSurroundingTiles(tile_walk +
TileDiffXY(-1, -1), height,
internal + 1)) {
1517 const int MKEND = -0x80;
1523 if (it->gfx == 0xFF)
continue;
1524 if (it->ti.
x > max_x) max_x = it->ti.
x;
1525 if (it->ti.
y > max_y) max_y = it->ti.
y;
1526 }
while ((++it)->ti.
x != MKEND);
1549 if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
1571 curh += (curh > h) ? -1 : 1;
1593 static const int dmax = 14;
1595 const int tx =
TileX(tile);
1596 const int ty =
TileY(tile);
1601 if (i == i2)
continue;
1614 FOR_ALL_INDUSTRIES(i) {
1688 uint16 r = Random();
1691 i->
random = initial_random_bits;
1748 for (uint j = 0; j < maxcargoes; j++) {
1775 for (uint j = 0; j < maxcargoes; j++) {
1783 if (std::find(indspec->produced_cargo,
endof(indspec->produced_cargo), cargo) ==
endof(indspec->produced_cargo)) {
1821 }
while ((++it)->ti.
x != -0x80);
1824 for (uint j = 0; j != 50; j++) PlantRandomFarmField(i);
1849 assert(itspec_index < indspec->num_table);
1851 bool custom_shape_check =
false;
1857 _cleared_object_areas = object_areas;
1858 if (ret.
Failed())
return ret;
1865 if (ret.
Failed())
return ret;
1873 if (ret.
Failed())
return ret;
1877 if (ret.
Failed())
return ret;
1881 if (ret.
Failed())
return ret;
1908 IndustryType it =
GB(p1, 0, 8);
1928 uint16 random_initial_bits =
GB(p2, 0, 16);
1929 uint32 random_var8f = randomizer.
Next();
1943 for (
int i = 0; i < 5000; i++) {
1951 for (
int j = 0; j < num_layouts; j++) {
1952 layout = (layout + 1) % num_layouts;
1962 int layout =
GB(p1, 8, 8);
1963 if (layout >= num_layouts)
return CMD_ERROR;
1966 for (
int i = 0; i < num_layouts; i++) {
1967 layout = (layout + 1) % num_layouts;
1973 if (ret.
Failed())
return ret;
1976 if ((flags &
DC_EXEC) && ind != NULL && _game_mode != GM_EDITOR) {
1995 uint32 seed = Random();
1996 uint32 seed2 = Random();
1998 CommandCost ret =
CreateNewIndustryHelper(tile, type,
DC_EXEC, indspec,
RandomRange(indspec->
num_table), seed,
GB(seed2, 0, 16),
OWNER_NONE, creation_type, &i);
1999 assert(i != NULL || ret.
Failed());
2016 *force_at_least_one =
false;
2061 static const uint16 numof_industry_table[] = {
2085 uint tries = try_hard ? 10000u : 2000u;
2086 for (; tries > 0; tries--) {
2088 if (ind != NULL)
return ind;
2123 this->probability = 0;
2124 this->min_number = 0;
2125 this->target_count = 0;
2127 this->wait_count = 0;
2136 this->builddata[it].Reset();
2143 static const int NEWINDS_PER_MONTH = 0x38000 / (10 * 12);
2164 uint32 total_prob = 0;
2165 uint num_forced = 0;
2169 total_prob += industry_probs[it];
2170 if (force_at_least_one[it]) num_forced++;
2174 if (total_prob == 0 || total_amount < num_forced) {
2176 total_amount = num_forced;
2183 if (force_at_least_one[it]) {
2184 assert(total_amount > 0);
2191 for (uint i = 0; i < total_amount; i++) {
2193 IndustryType it = 0;
2194 while (r >= industry_probs[it]) {
2195 r -= industry_probs[it];
2197 assert(it < NUM_INDUSTRYTYPES);
2199 assert(industry_probs[it] > 0);
2202 _industry_builder.
Reset();
2254 bool changed = min_number != this->min_number || probability != this->probability;
2255 this->min_number = min_number;
2256 this->probability = probability;
2263 bool changed =
false;
2264 uint num_planned = 0;
2266 changed |= this->builddata[it].GetIndustryTypeData(it);
2267 num_planned += this->builddata[it].target_count;
2269 uint total_amount = this->wanted_inds >> 16;
2270 changed |= num_planned != total_amount;
2271 if (!changed)
return;
2274 uint force_build = 0;
2275 uint32 total_prob = 0;
2283 if (total_prob == 0)
return;
2286 total_amount = (total_amount <= force_build) ? 0 : total_amount - force_build;
2289 while (total_amount > 0) {
2291 IndustryType it = 0;
2292 while (r >= this->builddata[it].probability) {
2293 r -= this->builddata[it].probability;
2295 assert(it < NUM_INDUSTRYTYPES);
2297 assert(this->builddata[it].probability > 0);
2298 this->builddata[it].target_count++;
2308 this->SetupTargetCount();
2312 uint32 total_prob = 0;
2316 missing += difference;
2317 if (this->builddata[it].wait_count > 0)
continue;
2318 if (difference > 0) {
2321 if (forced_build == NUM_INDUSTRYTYPES ||
2326 total_prob += difference;
2331 if (
EconomyIsInRecession() || (forced_build == NUM_INDUSTRYTYPES && (missing <= 0 || total_prob == 0))) count = 0;
2337 if (forced_build != NUM_INDUSTRYTYPES) {
2344 if (this->builddata[it].wait_count > 0)
continue;
2346 if (difference <= 0)
continue;
2347 if (count == 1)
break;
2348 if (r < (uint)difference)
break;
2357 this->builddata[it].wait_count = this->builddata[it].max_wait + 1;
2358 this->builddata[it].max_wait =
min(1000, this->builddata[it].max_wait + 2);
2361 this->builddata[it].max_wait =
max(this->builddata[it].max_wait / 2, 1);
2367 if (this->builddata[it].wait_count > 0) this->builddata[it].wait_count--;
2437 if (stations.
Length() == 0)
return 0;
2446 bool c_accepts =
false;
2447 bool c_produces =
false;
2449 for (
const Vehicle *u = v; u != NULL; u = u->
Next()) {
2457 if (!c_accepts && !c_produces)
continue;
2464 FOR_VEHICLE_ORDERS(v, o) {
2498 default: NOT_REACHED();
2503 AddIndustryNewsItem(
2504 percent >= 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH,
2510 static const uint PERCENT_TRANSPORTED_60 = 153;
2511 static const uint PERCENT_TRANSPORTED_80 = 204;
2521 bool closeit =
false;
2523 bool standard =
false;
2524 bool suppress_message =
false;
2525 bool recalculate_multipliers =
false;
2533 if (callback_enabled) {
2536 suppress_message =
HasBit(res, 7);
2539 res =
GB(res, 0, 4);
2541 default: NOT_REACHED();
2543 case 0x1: div = 1;
break;
2544 case 0x2: mul = 1;
break;
2545 case 0x3: closeit =
true;
break;
2546 case 0x4: standard =
true;
break;
2547 case 0x5:
case 0x6:
case 0x7:
2548 case 0x8: div = res - 0x3;
break;
2549 case 0x9:
case 0xA:
case 0xB:
2550 case 0xC: mul = res - 0x7;
break;
2553 increment = res == 0x0D ? -1 : 1;
2557 recalculate_multipliers =
true;
2562 if (monthly != smooth_economy)
return;
2570 if (smooth_economy) {
2574 uint32 r = Random();
2575 int old_prod, new_prod, percent;
2583 if (only_decrease) {
2594 new_prod += mult * (
max(((
RandomRange(50) + 10) * old_prod) >> 8, 1U));
2598 new_prod =
Clamp(new_prod, 1, 255);
2601 new_prod =
Clamp(new_prod, 0, 16);
2605 if (new_prod == old_prod && old_prod > 1) {
2610 percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
2614 if (new_prod > 1) closeit =
false;
2616 if (
abs(percent) >= 10) {
2621 if (only_decrease ||
Chance16(1, 3)) {
2641 recalculate_multipliers =
true;
2646 while (div-- != 0 && !closeit) {
2651 recalculate_multipliers =
true;
2657 if (increment != 0) {
2662 recalculate_multipliers =
true;
2677 if (!suppress_message && str != STR_NULL) {
2689 default: NOT_REACHED();
2693 if (str > STR_LAST_STRINGID) {
2697 }
else if (closeit) {
2708 AddIndustryNewsItem(str, nt, i->
index);
2732 if (change_loop == 0) {
2744 for (uint16 j = 0; j < change_loop; j++) {
2762 void IndustryMonthlyLoop()
2769 FOR_ALL_INDUSTRIES(i) {
2786 void InitializeIndustries()
2789 _industry_sound_tile = 0;
2791 _industry_builder.
Reset();
2801 bool force_at_least_one;
2803 if (chance == 0 || !force_at_least_one)
continue;
2807 ShowErrorMessage(STR_ERROR_NO_SUITABLE_PLACES_FOR_INDUSTRIES, STR_ERROR_NO_SUITABLE_PLACES_FOR_INDUSTRIES_EXPLANATION,
WL_WARNING);
2810 if (count >= 3)
break;
2842 PR_BUILD_INDUSTRY_RAW : PR_BUILD_INDUSTRY] * this->cost_multiplier) >> 8;
2853 return (_price[PR_CLEAR_INDUSTRY] * this->removal_cost_multiplier) >> 8;
2898 GetSlopePixelZ_Industry,
2900 AddAcceptedCargo_Industry,
2901 GetTileDesc_Industry,
2902 GetTileTrackStatus_Industry,
2904 AnimateTile_Industry,
2906 ChangeTileOwner_Industry,
2909 GetFoundation_Industry,
2910 TerraformTile_Industry,
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
static void ResetIndustryCounts()
Resets industry counts.
customize the cargoes the industry produces
Functions related to OTTD's strings.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
Set the industry graphics ID for the given industry tile.
don't allow building on structures
initialise production level on construction
Functions/types related to NewGRF debugging.
the north corner of the tile is raised
do not change town rating
static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile)
Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest). ...
#define RandomTile()
Get a valid random tile.
void ClampToMap()
Clamp the tile area to map borders.
byte image_2
image offset 2
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Trigger whenever the construction state changes.
bool enabled
entity still available (by default true).newgrf can disable it, though
byte production_rate[INDUSTRY_NUM_OUTPUTS]
production rate for each cargo
void SetupTargetCount()
Decide how many industries of each type are needed.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
Tile information, used while rendering the tile.
south and east corner are raised
static const int INDUSTRY_CUT_TREE_TICKS
cycle duration for lumber mill's extra action
uint8 raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
static CommandCost CheckNewIndustry_Farm(TileIndex tile)
Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).
Trigger when cargo is distributed.
the west corner of the tile is raised
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
byte landscape
the landscape we're currently in
static bool Chance16I(const uint a, const uint b, const uint32 r)
Checks if a given randomize-number is below a given probability.
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet)...
byte land_generator
the landscape generator
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, const IndustryTileTable *it, int type)
This function tries to flatten out the land below an industry, without damaging the surroundings too ...
Money GetRemovalCost() const
Get the cost for removing this industry Take note that the cost will always be zero for non-grf indus...
EconomySettings economy
settings to change the economy
byte image_3
image offset 3
byte image_1
image offset 1
uint16 counter
used for animation and/or production (if available cargo)
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
below this level, the industry is set to be closing
void DeleteIndustryNews(IndustryID iid)
Remove news regarding given industry.
int32 TileIndexDiff
An offset value between to tiles.
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.
Trigger in the periodic tile loop.
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
const char * grf
newGRF used for the tile contents
OwnerByte founder
Founder of the industry.
static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields)
Check whether the tile can be replaced by a farm field.
static CommandCost CheckNewIndustry_BubbleGen(TileIndex tile)
Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).
uint32 prospecting_chance
Chance prospecting succeeds.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
from the Fund/build using prospecting
Industries at sea should be positioned near edge of the map.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
Number of industry density settings.
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Customize the input cargo types of a newly build industry.
Slope tileh
Slope of the tile.
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
static IndustryGfx GetIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile.
byte selected_layout
Which tile layout was used when creating the industry.
static uint ScaleByMapSize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map...
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check that the industry callback allows creation of the industry.
uint8 construction_type
Way the industry was constructed (.
from the Fund/build window
default level set when the industry is created
Other industry production changes.
IndustryLifeType life_type
This is also known as Industry production flag, in newgrf specs.
periodically plants fields around itself (temp and arctic farms)
Called monthly on production changes, so it can be adjusted more frequently.
do not increase production (oil wells) in the temperate climate
Functions related to vehicles.
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
static uint TileX(TileIndex tile)
Get the X component of a tile.
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check the slope of a tile of a new industry.
static CommandCost CheckNewIndustry_Water(TileIndex tile)
Check the conditions of CHECK_WATER (Industry should be in the desert).
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height) ...
byte animation_substate
Sub state to time the change of the graphics/behaviour.
signal set to actually close the industry
Defines the internal data of a functional industry.
during random map creation
Tile description for the 'land area information' tool.
DifficultySettings difficulty
settings related to the difficulty
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
bool ambient
Play ambient, industry and town sounds.
Tindex index
Index of this pool item.
the east corner of the tile is raised
int8 acceptance[INDUSTRY_NUM_INPUTS]
Level of acceptance per cargo type (signed, may be negative!)
void IndustryProductionCallback(Industry *ind, int reason)
Get the industry production callback and apply it to the industry.
Northeast, upper right on your monitor.
A special vehicle is one of the following:
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, const IndustryTileTable *it, byte layout, Town *t, Owner founder, uint16 initial_random_bits)
Put an industry on the map.
Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]
Last day each cargo type was accepted by this industry.
static byte GetIndustryAnimationLoop(TileIndex tile)
Get the animation loop number.
check industry construction on given area
Simple vector template class.
Map accessors for tree tiles.
Functions related to world/map generation.
byte was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station...
const IndustryTileTable *const * table
List of the tiles composing the industry.
static void ResetIndustryConstructionStage(TileIndex tile)
Reset the construction stage counter of the industry, as well as the completion bit.
uint16 random
Random value used for randomisation of all kinds of things.
south and west corner are raised
Common return value for all commands.
static Industry * GetRandom()
Return a random valid industry.
static CommandCost CheckNewIndustry_Plantation(TileIndex tile)
Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).
static const int INDUSTRY_COMPLETED
final stage of industry construction.
static T max(const T a, const T b)
Returns the maximum of two values.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
uint8 status
Status; 0: no looping, 1: looping, 0xFF: no animation.
is always built near towns (toy shop)
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
the industry is running at full speed
uint32 population
Current population of people.
Year _cur_year
Current year, starting at 0.
uint16 w
The width of the area.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
static IndustryID GetIndustryIndexOfField(TileIndex t)
Get the industry (farm) that made the field.
static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, uint itspec_index, uint32 random_var8f, uint16 random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip)
Helper function for Build/Fund an industry.
void DeleteSubsidyWith(SourceType type, SourceID index)
Delete the subsidies associated with a given cargo source type and id.
Tables with default industry layouts and behaviours.
static const uint TILE_SIZE
Tile size in world coordinates.
StringID production_down_text
Message appearing when the industry's production is decreasing.
uint32 industry_daily_increment
The value which will increment industry_daily_change_counter. Computed value. NOSAVE.
byte random_colour
randomized colour of the industry, for display purpose
Industry directory; Window numbers:
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Owner owner[4]
Name of the owner(s)
StringID name
Displayed name of the industry.
IndustryBuildData _industry_builder
In-game manager of industries.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
can only be built in towns (arctic/tropic banks, water tower)
north and east corner are raised
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Do not force one instance of this type to appear on map generation.
not really a tile, but rather a very special check
static bool IsIndustryCompleted(TileIndex t)
Is this industry tile fully built?
static uint GetTreeGrowth(TileIndex t)
Returns the tree growth status.
Class to backup a specific variable and restore it later.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Date construction_date
Date of the construction of the industry.
Functions related to (drawing on) viewports.
void ResetIndustries()
This function initialize the spec arrays of both industry and industry tiles.
Bubble of bubble generator (industry).
The object is owned by a superuser / goal script.
static IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
Do industry gfx ID translation for NewGRFs.
Data for managing the number and type of industries in the game.
int16 y
The y value of the coordinate.
decides allowance of autosloping
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static const size_t MAX_SIZE
Make template parameter accessible from outside.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Slope slopes_refused
slope pattern on which this tile cannot be built
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
const uint8 * random_sounds
array of random sounds.
uint8 industry_platform
the amount of flat land around an industry
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
uint16 this_month_production[INDUSTRY_NUM_OUTPUTS]
stats of this month's production per cargo
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
void IndustryDailyLoop()
Daily handler for the industry changes Taking the original map size of 256*256, the number of random ...
Some methods of Pool are placed here in order to reduce compilation time and binary size...
uint x
X position of the tile in unit coordinates.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Foundation
Enumeration for Foundations.
Types related to cheating.
TileIndex xy
town center tile
Customize the output cargo types of a newly build industry.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
static void MakeField(TileIndex t, uint field_type, IndustryID industry)
Make a (farm) field tile.
can only be built after 1960 (oil rigs)
TileIndex tile
Tile index.
Functions related to errors.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
uint Length() const
Get the number of items in the list.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
during random map generation
PersistentStorage * psa
Persistent storage for NewGRF industries.
The tile is leveled up to a flat slope.
static size_t GetPoolSize()
Returns first unused index.
SoundSettings sound
sound effect settings
bool Contains(const T &item) const
Tests whether a item is present in the vector.
Like power plants and banks.
static void ChangeIndustryProduction(Industry *i, bool monthly)
Change industry production or do closure.
uint16 this_month_transported[INDUSTRY_NUM_OUTPUTS]
stats of this month's transport per cargo
controls random production change
either by user or random creation process
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, DiagDirection side)
Build farm field fence.
void TryBuildNewIndustry()
Try to create a random industry, during gameplay.
bool IsProcessingIndustry() const
Is an industry with the spec a processing industry?
static byte GetIndustryConstructionStage(TileIndex tile)
Returns the industry construction stage of the specified tile.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Year last_prod_year
last year of production
bool multiple_industry_per_town
allow many industries of the same type per town
bool IsType(OrderType type) const
Check whether this order is of the given type.
decides if default foundations need to be drawn
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
static void SetIndustryConstructionCounter(TileIndex tile, byte value)
Sets this industry tile's construction counter value.
Called to determine if industry can alter the ground below industry tile.
DoCommandFlag
List of flags for a command.
Called to determine the type (if any) of foundation to draw for industry tile.
ClientSettings _settings_client
The current settings for this game.
bool Succeeded() const
Did this command succeed?
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
Tile always accepts all cargoes the associated industry accepts.
static void SetIndustryAnimationLoop(TileIndex tile, byte count)
Set the animation loop number.
static void AdvertiseIndustryOpening(const Industry *ind)
Advertise about a new industry opening.
bool UsesSmoothEconomy() const
Determines whether this industrytype uses smooth economy or whether it uses standard/newgrf productio...
CommandCost CheckNewIndustryProc(TileIndex tile)
Industrytype check function signature.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
Trigger a random trigger for a single industry tile.
A number of safeguards to prevent using unsafe methods.
bool value
tells if the bool cheat is active or not
int16 x
The x value of the coordinate.
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.
IndustryType GetIndustryType(TileIndex tile)
Retrieve the type for this industry.
IndustryType type
type of industry.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
StringID new_industry_text
Message appearing when the industry is built.
uint y
Y position of the tile in unit coordinates.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
#define MKEND()
Macro for end of list marker in arrays of LegendAndColour.
End marker of the industry check procedures.
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 CommandCost CheckNewIndustry_OilRig(TileIndex tile)
Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map)...
byte anim_production
Animation frame to start when goods are produced.
decides amount of cargo acceptance
CargoLabel label
Unique label of the cargo type.
TileArea location
Location of the industry.
static int WhoCanServiceIndustry(Industry *ind)
Compute who can service the industry.
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
CargoID cargo_type
type of cargo this vehicle is carrying
const T & GetOriginalValue() const
Returns the backupped value.
Represents the covered area of e.g.
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
bool IsFrontEngine() const
Check if the vehicle is a front engine.
don't allow building on water
Defines the data structure for constructing industry.
TerraGenesis Perlin landscape generator.
This structure is the same for both Industries and Houses.
static uint16 GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
The tile has no ownership.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
GRFFileProps grf_prop
properties related to the grf file
Industry should be positioned near edge of the map.
void CheckIndustries()
Verify whether the generated industries are complete, and warn the user if not.
customize the cargoes the industry requires
Money GetConstructionCost() const
Get the cost for constructing this industry.
Base class for all effect vehicles.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
void SetSeed(uint32 seed)
(Re)set the state of the random number generator.
static const DrawBuildingsTileStruct _industry_draw_tile_data[NEW_INDUSTRYTILEOFFSET *4]
Structure for industry tiles drawing.
static const uint8 ANIM_STATUS_NO_ANIMATION
There is no animation.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
static void PlaceInitialIndustry(IndustryType type, bool try_hard)
Try to build a industry on the map.
Industry view; Window numbers:
DiagDirection
Enumeration for diagonal directions.
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]
incoming cargo waiting to be processed
static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int type)
Check that the new industry is far enough from conflicting industries.
#define lengthof(x)
Return the length of an fixed size array.
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
byte prod_level
general production level
byte appear_ingame[NUM_LANDSCAPE]
Probability of appearance in game.
GRFFileProps grf_prop
properties related to the grf file
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
static T min(const T a, const T b)
Returns the minimum of two values.
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
static bool EconomyIsInRecession()
Is the economy in recession?
cuts trees and produce first output cargo from them (lumber mill)
Data for managing the number of industries of a single industry type.
bool GetIndustryTypeData(IndustryType it)
Set the probability and min_number fields for the industry type it for a running game.
Functions related to autoslope.
Functions related to sound.
The game does not build industries.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
NewGRF handling of industry tiles.
bool Failed() const
Did this command fail?
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
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.
Called to determine the colour of an industry.
CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build/Fund an industry.
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.
Transfer all cargo onto the platform.
static uint GetNumberOfIndustries()
Get wanted number of industries on the map.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
controls monthly random production change
static void IncIndustryTypeCount(IndustryType type)
Increment the count of industries for this type.
Base class for all pools.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void Reset()
Reset the entry.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
OrderUnloadFlags GetUnloadType() const
How must the consist be unloaded?
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. ...
Called to determine which cargoes an industry should accept.
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
uint8 callback_mask
Bitmask of industry tile callbacks that have to be called.
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
TileIndex tile
The base tile of the area.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
uint64 dparam[2]
Parameters of the str string.
static uint ScaleByMapSize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map...
EffectVehicle * CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle at a particular location.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
static uint16 GetIndustryGamePlayProbability(IndustryType it, byte *min_number)
Compute the probability for constructing a new industry during game play.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
byte num_table
Number of elements in the table.
execute the given command
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
Cargo accepted by this tile.
void GenerateIndustries()
This function will create random industries during game creation.
static const DrawIndustryCoordinates _coal_plant_sparks[]
Movement of the sparks , only used for Power Station.
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
Trigger a random trigger for all industry tiles.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
static uint MapSize()
Get the size of the map.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Class for storing amounts of cargo.
bool _generating_world
Whether we are generating the map or not.
uint16 produced_cargo_waiting[INDUSTRY_NUM_OUTPUTS]
amount of cargo produced per cargo
byte oil_refinery_limit
distance oil refineries allowed from map edge
DestinationID GetDestination() const
Gets the destination of this order.
during creation of random ingame industry
is built on water (oil rig)
byte minimal_cargo
minimum amount of cargo transported to the stations.
Invisible tiles at the SW and SE border.
byte appear_creation[NUM_LANDSCAPE]
Probability of appearance during map creation.
Production changes of industry serviced by local company.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
CompanyByte _current_company
Company currently doing an action.
Set of callback functions for performing tile operations of a given tile type.
uint32 TileIndex
The index/ID of a Tile.
Map accessors for 'clear' tiles.
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
Cargo support for NewGRFs.
void ReleaseDisastersTargetingIndustry(IndustryID i)
Marks all disasters targeting this industry in such a way they won't call Industry::Get(v->dest_tile)...
static size_t GetNumItems()
Returns number of valid items in the pool.
static Industry * CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
Create a new industry of random layout.
A town owns the tile, or a town is expanding.
Vehicle * Next() const
Get the next vehicle of this vehicle.
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
north and west corner are raised
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
Source/destination is an industry.
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
StringID closure_text
Message appearing when the industry closes.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Cheat magic_bulldozer
dynamite industries, objects
static void SetIndustryCompleted(TileIndex tile)
Set if the industry that owns the tile as under construction or not.
OwnerByte owner
Which company owns the vehicle?
byte anim_next
Next frame in an animation.
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 T abs(const T a)
Returns the absolute value of (scalar) variable.
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
The tile has no foundation, the slope remains unchanged.
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
int x
coordinate x of the first image offset
static bool IsOilRig(TileIndex t)
Is tile t part of an oilrig?
Slope
Enumeration for the slope-type.
uint32 Next()
Generate the next pseudo random number.
Called to query the cargo acceptance of the industry tile.
TownCache cache
Container for all cacheable data.
static Industry * PlaceIndustry(IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
Try to place the industry in the game.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
#define endof(x)
Get the end element of an fixed size array.
static void DecIndustryTypeCount(IndustryType type)
Decrement the count of industries for this type.
call production callback when cargo arrives at the industry
uint32 industry_daily_change_counter
Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily.
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile)
Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map)...
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
This is used to gather some data about animation drawing in the industry code Image_1-2-3 are in fact...
static uint GetCurrentTotalNumberOfIndustries()
Get total number of industries existing in the game.
Functions related to OTTD's landscape.
static void RecomputeIndustriesNearForAll()
Recomputes Station::industries_near for all stations.
Base functions for all Games.
static uint32 GetScaledIndustryGenerationProbability(IndustryType it, bool *force_at_least_one)
Compute the appearance probability for an industry during map creation.
Functions related to commands.
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
uint32 probability
Relative probability of building this industry.
static void SetIndustryIndexOfField(TileIndex t, IndustryID i)
Set the industry (farm) that made the field.
static uint16 counts[NUM_INDUSTRYTYPES]
Number of industries per type ingame.
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.
IndustryType conflicting[3]
Industries this industry cannot be close to.
byte GetSnowLine()
Get the current snow line, either variable or static.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
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 uint TileHeight(TileIndex tile)
Returns the height of a tile.
static CommandCost CheckNewIndustry_Forest(TileIndex tile)
Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate)...
uint32 wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
Fields are planted around when built (all farms)
Smoke of power plant (industry).
uint16 last_month_transported[INDUSTRY_NUM_OUTPUTS]
total units transported per cargo in the last full month
Allow closing down the last instance of this type.
ConstructionSettings construction
construction of things in-game
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
const char * GetName() const
Get the name of this grf.
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.
static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
Is the industry allowed to be built at this place for the town?
void ResetOverride()
Resets the override, which is used while initializing game.
const struct GRFFile * grffile
grf file that introduced this entity
uint8 number_of_sounds
Number of sounds available in the sounds array.
void MonthlyLoop()
Monthly update of industry build data.
StringID str
Description of the tile.
byte min_number
Smallest number of industries that should exist (either 0 or 1).
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
StringID production_up_text
Message appearing when the industry's production is increasing.
static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
Search callback function for ChopLumberMillTrees.
void Restore()
Restore the variable.
Base functions for all AIs.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static void SetClearCounter(TileIndex t, uint c)
Sets the counter used to advance to the next clear density/field type.
byte check_proc
Index to a procedure to check for conflicting circumstances.
static void SetFence(TileIndex t, DiagDirection side, uint h)
Sets the type of fence (and whether there is one) for the given border.
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
GameCreationSettings game_creation
settings used during the creation of a game (map)
A tile without any structures, i.e. grass, rocks, farm fields etc.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Defines the data structure of each individual tile of an industry.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
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...
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Very few industries at game start.
uint16 target_count
Desired number of industries of this type.
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
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 smooth_economy
smooth economy
Functions related to water (management)
Force unloading all cargo onto the platform, possibly not getting paid.
Structure to encapsulate the pseudo random number generators.
town rating does not disallow you from building
byte industry_density
The industry density.
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Production changes of industry serviced by competitor(s)
can only be built in towns larger than 1200 inhabitants (temperate bank)
static void ChopLumberMillTrees(Industry *i)
Perform a circular search around the Lumber Mill in order to find trees to cut.
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
static CheckNewIndustryProc *const _check_new_industry_procs[CHECK_END]
Check functions for different types of industry.
SpriteID sprite
The 'real' sprite.
OwnerByte owner
owner of the industry. Which SHOULD always be (imho) OWNER_NONE
Called to determine industry special effects.
static void SetDParamX(uint64 *s, uint n, uint64 v)
Set a string parameter v at index n in a given array s.
Functions related to news.
The tile of the industry has been triggered during the tileloop.
Structure contains cached list of stations nearby.
void FindStationsAroundTiles(const TileArea &location, StationList *stations)
Find all stations around a rectangular producer (industry, house, headquarter, ...)
Base classes/functions for stations.
call production callback every 256 ticks
Called when industry is built to set initial production level.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
uint16 h
The height of the area.
static void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
Make the given tile an industry tile.
static const int INDUSTRY_PRODUCE_TICKS
cycle duration for industry production
can only be built before 1950 (oil wells)
the south corner of the tile is raised
static const IndustryGfx INDUSTRYTILE_NOANIM
flag to mark industry tiles as having no animation
The tile/execution is done by "water".
static bool TransportIndustryGoods(TileIndex tile)
Move produced cargo from industry to nearby stations.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
static void UpdateIndustryStatistics(Industry *i)
Monthly update of industry statistics.
VehicleTypeByte type
Type of vehicle.
SoundFx
Sound effects from baseset.
Class for backupping variables and making sure they are restored later.
Functions related to effect vehicles.
static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check=NULL)
Are the tiles of the industry free?
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...
#define TILE_MASK(x)
'Wraps' the given tile to it is within the map.
Functions related to subsidies.
Used for industry tiles on land (also for oilrig if newgrf says so).
static bool CheckIndustryCloseDownProtection(IndustryType type)
Protects an industry from closure if the appropriate flags and conditions are met INDUSTRYBEH_CANCLOS...
static void SetIndustryConstructionStage(TileIndex tile, byte value)
Sets the industry construction stage of the specified tile.
Called on production changes, so it can be adjusted.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static byte GetIndustryConstructionCounter(TileIndex tile)
Returns this industry tile's construction counter value.
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-...
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
The industry has been triggered via its tick.
static CommandCost CheckNewIndustry_NULL(TileIndex tile)
Check the conditions of CHECK_NOTHING (Always succeeds).
bool anim_state
When true, the tile has to be drawn using the animation state instead of the construction state...
give a custom colour to newly build industries
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Cheats _cheats
All the cheats.
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
void Reset()
Completely reset the industry build data.
decides slope suitability
Information about the behaviour of the default industry tiles.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
PaletteID pal
The palette (use PAL_NONE) if not needed)