OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
16 #include "viewport_kdtree.h"
52 #include "table/strings.h"
66 void RebuildTownKdtree()
68 std::vector<TownID> townids;
70 townids.push_back(town->index);
72 _town_kdtree.
Build(townids.begin(), townids.end());
136 this->psa_list.clear();
198 void Town::FillCachedName()
const
211 return (_price[PR_CLEAR_HOUSE] * this->
removal_cost) >> 8;
215 static int _grow_town_result;
218 enum TownGrowthResult {
220 GROWTH_SEARCH_STOPPED = 0
225 static Town *CreateRandomTown(uint attempts, uint32 townnameparts,
TownSize size,
bool city,
TownLayout layout);
227 static void TownDrawHouseLift(
const TileInfo *ti)
232 typedef void TownDrawTileProc(
const TileInfo *ti);
233 static TownDrawTileProc *
const _town_draw_tile_procs[1] = {
260 if (HouseSpec::Get(house_id)->grf_prop.spritegroup[0] !=
nullptr) {
261 DrawNewHouseTile(ti, house_id);
264 house_id = HouseSpec::Get(house_id)->
grf_prop.subst_id;
282 ti->
x + dcts->subtile_x,
283 ti->
y + dcts->subtile_y,
295 int proc = dcts->draw_proc - 1;
297 if (proc >= 0) _town_draw_tile_procs[proc](ti);
301 static int GetSlopePixelZ_Town(
TileIndex tile, uint x, uint y)
316 const HouseSpec *hs = HouseSpec::Get(hid);
334 AnimateNewHouseTile(tile);
344 if (!(HouseSpec::Get(
GetHouseType(tile))->building_flags & BUILDING_IS_ANIMATED)) {
365 pos += (pos < dest) ? 1 : -1;
384 if (_town_kdtree.
Count() == 0)
return false;
405 _viewport_sign_kdtree.
Insert(ViewportSignKdtreeItem::MakeTown(this->
index));
414 t->UpdateVirtCoord();
418 void ClearAllTownCachedNames()
421 t->cached_name.clear();
463 bool covers_area = st->TileIsInCatchment(tile);
464 if (flags & BUILDING_2_TILES_Y) covers_area |= st->TileIsInCatchment(tile +
TileDiffXY(0, 1));
465 if (flags & BUILDING_2_TILES_X) covers_area |= st->TileIsInCatchment(tile +
TileDiffXY(1, 0));
466 if (flags & BUILDING_HAS_4_TILES) covers_area |= st->TileIsInCatchment(tile +
TileDiffXY(1, 1));
488 AnimateNewHouseConstruction(tile);
532 const HouseSpec *hs = HouseSpec::Get(house_id);
542 Town *t = Town::GetByTile(tile);
548 for (uint i = 0; i < 256; i++) {
556 uint amt =
GB(callback, 0, 8);
557 if (amt == 0)
continue;
570 uint amt =
GB(r, 0, 8) / 8 + 1;
578 uint amt =
GB(r, 8, 8) / 8 + 1;
593 uint32 genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
604 genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
621 CanDeleteHouse(tile) &&
626 ClearTownHouse(t, tile);
629 if (
GB(r, 24, 8) >= 12) {
637 int x =
Clamp(grid_pos.
x, 0, 1);
638 int y =
Clamp(grid_pos.
y, 0, 1);
659 if (!CanDeleteHouse(tile))
return CMD_ERROR;
667 Town *t = Town::GetByTile(tile);
678 ClearTownHouse(t, tile);
687 const HouseSpec *hs = HouseSpec::Get(house_id);
688 Town *t = Town::GetByTile(tile);
691 for (uint i = 0; i < 256; i++) {
703 produced[CT_PASSENGERS]++;
711 static inline void AddAcceptedCargoSetMask(
CargoID cargo, uint amount,
CargoArray &acceptance, CargoTypes *always_accepted)
713 if (cargo ==
CT_INVALID || amount == 0)
return;
714 acceptance[cargo] += amount;
715 SetBit(*always_accepted, cargo);
718 static void AddAcceptedCargo_Town(
TileIndex tile,
CargoArray &acceptance, CargoTypes *always_accepted)
724 for (uint8 i = 0; i <
lengthof(accepts); i++) {
743 AddAcceptedCargoSetMask(accepts[0],
GB(callback, 0, 4), acceptance, always_accepted);
744 AddAcceptedCargoSetMask(accepts[1],
GB(callback, 4, 4), acceptance, always_accepted);
747 AddAcceptedCargoSetMask(CT_FOOD,
GB(callback, 8, 4), acceptance, always_accepted);
749 AddAcceptedCargoSetMask(accepts[2],
GB(callback, 8, 4), acceptance, always_accepted);
756 for (uint8 i = 0; i <
lengthof(accepts); i++) {
757 AddAcceptedCargoSetMask(accepts[i], hs->
cargo_acceptance[i], acceptance, always_accepted);
764 const HouseSpec *hs = HouseSpec::Get(house);
769 uint16 callback_res = GetHouseCallback(
CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, Town::GetByTile(tile), tile);
771 if (callback_res > 0x400) {
775 if (new_name != STR_NULL && new_name != STR_UNDEFINED) {
781 if (!house_completed) {
783 td->
str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
807 static void TownTickHandler(
Town *t)
825 if (_game_mode == GM_EDITOR)
return;
851 const uint16 assume_max_speed = 50;
854 if (RoadTypeIsTram(rt))
continue;
859 if (rti->
label == 0)
continue;
867 if (best !=
nullptr) {
899 dist_multi = (dist_multi + 1) * 4;
900 for (uint pos = 4; pos < dist_multi; pos++) {
905 if (pos & 2) cur += tid_lt[2];
948 if (desired_slope != cur_slope &&
ComplementSlope(desired_slope) != cur_slope) {
966 static bool TerraformTownTile(
TileIndex tile,
int edges,
int dir)
971 if (r.
Failed() || r.
GetCost() >= (_price[PR_TERRAFORM] + 2) * 8)
return false;
976 static void LevelTownLand(
TileIndex tile)
1007 default: NOT_REACHED();
1010 if ((grid_pos.
x % 3) == 0) rcmd |=
ROAD_Y;
1011 if ((grid_pos.
y % 3) == 0) rcmd |=
ROAD_X;
1015 if ((grid_pos.
x % 4) == 0) rcmd |=
ROAD_Y;
1016 if ((grid_pos.
y % 4) == 0) rcmd |=
ROAD_X;
1026 default: rb_template =
ROAD_ALL;
break;
1084 _grow_town_result = GROWTH_SUCCEED;
1105 _grow_town_result = GROWTH_SUCCEED;
1179 uint8 bridge_length = 0;
1186 int base_bridge_length = 5;
1187 int max_bridge_length = t->
cache.
population / 1000 + base_bridge_length;
1192 if (bridge_length++ >= base_bridge_length) {
1196 bridge_tile += delta;
1200 if (bridge_length++ >= max_bridge_length) {
1204 bridge_tile += delta;
1209 if (bridge_length == 1)
return false;
1214 for (uint8 times = 0; times <= 22; times++) {
1221 _grow_town_result = GROWTH_SUCCEED;
1252 int max_tunnel_length = 0;
1258 for (uint8 tiles = 0; tiles < 4; tiles++) {
1262 slope_tile += delta;
1269 max_tunnel_length = 5;
1272 uint8 tunnel_length = 0;
1277 if (tunnel_length++ >= max_tunnel_length)
return false;
1278 tunnel_tile += delta;
1283 if (tunnel_length == 1)
return false;
1292 _grow_town_result = GROWTH_SUCCEED;
1307 static const TileIndexDiffC tiles[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} };
1317 RoadType road_rt = GetRoadTypeRoad(cur_tile);
1318 RoadType tram_rt = GetRoadTypeTram(cur_tile);
1356 _grow_town_result = GROWTH_SEARCH_STOPPED;
1366 default: NOT_REACHED();
1382 do target_dir =
RandomDiagDir();
while (target_dir == source_dir);
1408 _grow_town_result = GROWTH_SEARCH_STOPPED;
1413 default: NOT_REACHED();
1426 bool allow_house =
true;
1443 if (cur_rb & target_rb) {
1451 if ((cur_rb &
ROAD_X) != target_rb)
return;
1483 default: NOT_REACHED();
1491 allow_house = (rcmd & target_rb) ==
ROAD_NONE;
1513 if (
Chance16(1, 6)) LevelTownLand(house_tile);
1518 _grow_town_result = GROWTH_SUCCEED;
1524 _grow_town_result = GROWTH_SEARCH_STOPPED;
1582 return (target_rb & back_rb) != 0 && (target_rb & ~back_rb) != 0;
1624 if (_grow_town_result == GROWTH_SUCCEED)
return true;
1643 }
while (!(cur_rb & target_bits));
1644 cur_rb &= ~target_bits;
1662 }
while (--_grow_town_result >= 0);
1676 uint32 r = Random();
1677 uint a =
GB(r, 0, 2);
1678 uint b =
GB(r, 8, 2);
1713 for (ptr = _town_coord_mod; ptr !=
endof(_town_coord_mod); ++ptr) {
1726 for (ptr = _town_coord_mod; ptr !=
endof(_town_coord_mod); ++ptr) {
1744 void UpdateTownRadius(
Town *t)
1746 static const uint32 _town_squared_town_zone_radius_data[23][5] = {
1759 { 81, 36, 25, 0, 9},
1760 { 81, 36, 25, 16, 9},
1761 { 81, 49, 0, 25, 9},
1762 { 81, 64, 0, 25, 9},
1763 { 81, 64, 0, 36, 9},
1764 { 81, 64, 0, 36, 16},
1765 {100, 81, 0, 49, 16},
1766 {100, 81, 0, 49, 25},
1767 {121, 81, 0, 49, 25},
1768 {121, 81, 0, 49, 25},
1769 {121, 81, 0, 49, 36},
1787 void UpdateTownMaxPass(
Town *t)
1812 UpdateTownRadius(t);
1846 t->townnamegrfid = tnp.grfid;
1847 t->townnametype = tnp.type;
1849 t->townnameparts = townnameparts;
1858 int x = (int)size * 16 + 3;
1859 if (size ==
TSZ_RANDOM) x = (Random() & 0xF) + 8;
1864 UpdateTownRadius(t);
1872 UpdateTownRadius(t);
1874 UpdateTownMaxPass(t);
1911 if (!t->
name.empty() && t->
name == name)
return false;
1931 TownSize size = Extract<TownSize, 0, 2>(p1);
1932 bool city =
HasBit(p1, 2);
1933 TownLayout layout = Extract<TownLayout, 3, 3>(p1);
1935 bool random =
HasBit(p1, 6);
1936 uint32 townnameparts = p2;
1968 if (ret.
Failed())
return ret;
1971 static const byte price_mult[][
TSZ_RANDOM + 1] = {{ 15, 25, 40, 25 }, { 20, 35, 55, 35 }};
1973 static_assert(
lengthof(price_mult[0]) == 4);
1976 byte mult = price_mult[city][size];
1983 _additional_cash_required = cost.
GetCost();
1991 t = CreateRandomTown(20, townnameparts, size, city, layout);
1995 _new_town_id = t->
index;
1999 DoCreateTown(t, tile, townnameparts, size, city, layout,
true);
2002 old_generating_world.
Restore();
2004 if (t !=
nullptr && !
StrEmpty(text)) {
2009 if (_game_mode != GM_EDITOR) {
2019 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
2021 char *cn =
stredup(company_name);
2048 default:
return tile;
2066 default:
return true;
2148 static Town *CreateRandomTown(uint attempts, uint32 townnameparts,
TownSize size,
bool city,
TownLayout layout)
2171 DoCreateTown(t, tile, townnameparts, size, city, layout,
false);
2179 cur_company.Restore();
2187 }
while (--attempts != 0);
2192 static const byte _num_initial_towns[4] = {5, 11, 23, 46};
2203 uint current_number = 0;
2207 uint32 townnameparts;
2208 TownNames town_names;
2221 if (CreateRandomTown(20, townnameparts,
TSZ_RANDOM, city, layout) !=
nullptr) current_number++;
2227 RebuildTownKdtree();
2229 if (current_number != 0)
return true;
2259 HouseZonesBits smallest = HZB_TOWN_EDGE;
2260 for (HouseZonesBits i = HZB_BEGIN; i < HZB_END; i++) {
2261 if (dist < t->cache.squared_town_zone_radius[i]) smallest = i;
2285 if (HouseSpec::Get(type)->building_flags & BUILDING_IS_ANIMATED)
AddAnimatedTile(tile);
2400 if ((grid_pos.
x % 3) == 0 || (grid_pos.
y % 3) == 0)
return false;
2404 if ((grid_pos.
x % 4) == 0 || (grid_pos.
y % 4) == 0)
return false;
2434 if ((grid_pos.
x != 2 && grid_pos.
x != -1) ||
2435 (grid_pos.
y != 2 && grid_pos.
y != -1))
return false;
2439 if ((grid_pos.
x & 3) < 2 || (grid_pos.
y & 3) < 2)
return false;
2526 uint bitmask = (1 << rad) + (1 << (land + 12));
2534 uint probability_max = 0;
2538 const HouseSpec *hs = HouseSpec::Get(i);
2544 if (hs->
class_id != HOUSE_NO_CLASS) {
2553 probability_max += cur_prob;
2554 probs[num] = cur_prob;
2560 while (probability_max > 0) {
2570 for (i = 0; i < num; i++) {
2571 if (probs[i] > r)
break;
2576 probability_max -= probs[i];
2580 houses[i] = houses[num];
2581 probs[i] = probs[num];
2583 const HouseSpec *hs = HouseSpec::Get(house);
2600 if (t->
flags & oneof)
continue;
2604 if (noslope && slope !=
SLOPE_FLAT)
continue;
2616 byte random_bits = Random();
2629 byte construction_counter = 0;
2630 byte construction_stage = 0;
2633 uint32 r = Random();
2636 if (
Chance16(1, 7)) construction_stage =
GB(r, 0, 2);
2641 construction_counter =
GB(r, 2, 2);
2645 MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits);
2646 UpdateTownRadius(t);
2665 DoClearSquare(tile);
2681 if (HouseSpec::Get(house - 1)->building_flags & TILE_SIZE_2x1) {
2684 }
else if (HouseSpec::Get(house - 1)->building_flags & BUILDING_2_TILES_Y) {
2687 }
else if (HouseSpec::Get(house - 2)->building_flags & BUILDING_HAS_4_TILES) {
2690 }
else if (HouseSpec::Get(house - 3)->building_flags & BUILDING_HAS_4_TILES) {
2707 const HouseSpec *hs = HouseSpec::Get(house);
2731 UpdateTownRadius(t);
2765 ClearAllStationCachedNames();
2766 ClearAllIndustryCachedNames();
2780 FOR_ALL_CARGOSPECS(cs) {
2804 uint16 index =
GB(p1, 0, 16);
2898 TownID town_id = (TownID)
GB(p1, 0, 16);
2905 int16 new_rating =
Clamp((int16)
GB(p2, 0, 16), RATING_MINIMUM, RATING_MAXIMUM);
2907 t->
ratings[company_id] = new_rating;
2934 UpdateTownRadius(t);
2936 uint n = amount * 10;
2941 for (; p2 > 0; p2--) {
2943 for (uint i = 0; i < 25; i++)
if (
GrowTown(t))
break;
2946 UpdateTownRadius(t);
2948 UpdateTownMaxPass(t);
2971 if (st->town == t) {
2976 if (ret.
Failed())
return ret;
2992 if (ret.
Failed())
return ret;
2998 bool try_clear =
false;
3035 if (ret.
Failed())
return ret;
3054 2, 4, 9, 35, 48, 53, 117, 175
3091 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
3093 char *cn =
stredup(company_name);
3133 static const int STATUE_NUMBER_INNER_TILES = 25;
3152 if (statue_data->
tile_count <= STATUE_NUMBER_INNER_TILES) {
3236 SetDParam(0, STR_NEWS_EXCLUSIVE_RIGHTS_TITLE);
3237 SetDParam(1, STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION);
3281 static TownActionProc *
const _town_action_proc[] = {
3282 TownActionAdvertiseSmall,
3283 TownActionAdvertiseMedium,
3284 TownActionAdvertiseLarge,
3285 TownActionRoadRebuild,
3287 TownActionFundBuildings,
3288 TownActionBuyRights,
3337 if (nump !=
nullptr) *nump = num;
3361 CommandCost ret = _town_action_proc[p2](t, flags);
3362 if (ret.
Failed())
return ret;
3371 template <
typename Func>
3372 static void ForAllStationsNearTown(
Town *t, Func func)
3380 if (DistanceSquare(st->xy, t->xy) <= t->cache.squared_town_zone_radius[0]) {
3386 static void UpdateTownRating(
Town *t)
3395 ForAllStationsNearTown(t, [&](
const Station *st) {
3396 if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
3397 if (Company::IsValidID(st->owner)) {
3398 int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP;
3399 t->ratings[st->owner] = std::min<int>(new_rating, INT16_MAX);
3403 int new_rating = t->ratings[st->owner] + RATING_STATION_DOWN_STEP;
3404 t->ratings[st->owner] = std::max(new_rating, INT16_MIN);
3442 ForAllStationsNearTown(t, [&](
const Station * st) {
3443 if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
3463 static const uint16 _grow_count_values[2][6] = {
3464 { 120, 120, 120, 100, 80, 60 },
3465 { 320, 420, 300, 220, 160, 100 }
3473 m >>= growth_multiplier;
3507 for (
int i = TE_BEGIN; i <
TE_END; i++) {
3508 switch (t->
goal[i]) {
3534 static void UpdateTownAmounts(
Town *t)
3543 static void UpdateTownUnwanted(
Town *t)
3604 if (tid == INVALID_TOWN) {
3621 return Town::GetByTile(tile);
3638 static int ref_count = 0;
3640 if (ref_count == 0) {
3645 assert(ref_count > 0);
3687 if (rating < max) rating = max;
3692 if (rating > max) rating = max;
3741 void TownsMonthlyLoop()
3750 UpdateTownAmounts(t);
3752 UpdateTownRating(t);
3753 UpdateTownUnwanted(t);
3758 void TownsYearlyLoop()
3772 const HouseSpec *hs = HouseSpec::Get(house);
3777 bool allow_terraform =
true;
3781 hs = HouseSpec::Get(house);
3798 GetSlopePixelZ_Town,
3800 AddAcceptedCargo_Town,
3802 GetTileTrackStatus_Town,
3806 ChangeTileOwner_Town,
3807 AddProducedCargo_Town,
3818 memset(&_house_specs, 0,
sizeof(_house_specs));
static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1)
Grows the given town.
RoadTypeFlags flags
Bit mask of road type flags.
@ TE_WATER
Cargo behaves water-like.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ MP_HOUSE
A house by a town.
byte removal_cost
cost multiplier for removing it
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.
@ TACT_BRIBE
Try to bribe the council.
static bool HasTownOwnedRoad(TileIndex t)
Checks if given tile has town owned road.
const char * grf
newGRF used for the tile contents
CompanyMask have_ratings
which companies have a rating
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
uint32 TileIndex
The index/ID of a Tile.
@ TROPICZONE_DESERT
Tile is desert.
@ TACT_BUILD_STATUE
Build a statue.
@ NT_INDUSTRY_OPEN
Opening of industries.
#define TILE_ADD(x, y)
Adds to tiles together.
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-...
Structure for storing data while searching the best place to build a statue.
static void TileLoop_Town(TileIndex tile)
Tile callback function.
static bool TryClearTile(TileIndex tile)
Check whether the land can be cleared.
uint16 override
id of the entity been replaced by
@ ROAD_N
Road at the two northern edges.
static bool IsSea(TileIndex t)
Is it a sea water tile?
Cheat magic_bulldozer
dynamite industries, objects
@ RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE
"Hostile"
Structure contains cached list of stations nearby.
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest to the given tile within threshold.
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.
static Titem * Get(size_t index)
Returns Titem with given index.
@ TO_HOUSES
town buildings
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static bool IsRoadStop(TileIndex t)
Is the station at t a road station?
static Year GetHouseAge(TileIndex t)
Get the age of the house.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
static int GetRating(const Town *t)
Get the rating of a town for the _current_company.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
@ CBM_HOUSE_CARGO_ACCEPTANCE
decides amount of cargo acceptance
static void DoClearTownHouseHelper(TileIndex tile, Town *t, HouseID house)
Update data structures when a house is removed.
void InitializeLayout(TownLayout layout)
Assigns town layout.
byte road_build_months
fund road reconstruction in action?
static Slope InclinedSlope(DiagDirection dir)
Returns the slope that is inclined in a specific direction.
TownLayout town_layout
select town layout,
uint x
X position of the tile in unit coordinates.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags)
Perform a 9x9 tiles circular search from the center of the town in order to find a free tile to place...
K-dimensional tree, specialised for 2-dimensional space.
Tile information, used while rendering the tile.
uint8 unwanted[MAX_COMPANIES]
how many months companies aren't wanted by towns (bribe)
byte landscape
the landscape we're currently in
Class to backup a specific variable and restore it later.
CompanyMask statues
which companies have a statue?
@ ROTF_TOWN_BUILD
Bit number for allowing towns to build this roadtype.
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.
@ EXPENSES_OTHER
Other expenses.
static void RemoveNearbyStations(Town *t, TileIndex tile, BuildingFlags flags)
Remove stations from nearby station list if a town is no longer in the catchment area of each.
void MultiplyCost(int factor)
Multiplies the cost of the command by the given factor.
CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
Owner owner[4]
Name of the owner(s)
TownEffect town_effect
The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
static bool IsHouseCompleted(TileIndex t)
Get the completion of this house.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
bool VerifyTownName(uint32 r, const TownNameParams *par, TownNames *town_names)
Verifies the town name is valid and unique.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
@ INVALID_ROADTYPE
flag for invalid roadtype
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
@ ROAD_SW
South-west part.
byte town_council_tolerance
minimum required town ratings to be allowed to demolish stuff
@ TE_FOOD
Cargo behaves food/fizzy-drinks-like.
static bool _town_rating_test
If true, town rating is in test-mode.
CommandCost CmdTownRating(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the rating of a company in a town.
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
static TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
@ TL_RANDOM
Random town layout.
@ DIAGDIR_END
Used for iterations.
uint32 squared_town_zone_radius[HZB_END]
UpdateTownRadius updates this given the house count.
static const int TOWN_GROWTH_TICKS
cycle duration for towns trying to grow. (this originates from the size of the town array in TTD
Tindex index
Index of this pool item.
@ TACT_FUND_BUILDINGS
Fund new buildings.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
uint8 larger_towns
the number of cities to build. These start off larger and grow twice as fast
static bool GrowTownAtRoad(Town *t, TileIndex tile)
Returns "growth" if a house was built, or no if the build failed.
static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
Check if a Road is allowed on a given tile.
Class for storing amounts of cargo.
SpriteID sprite
The 'real' sprite.
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
TownSize
Supported initial town sizes.
uint32 GetWorldPopulation()
Determines the world population Basically, count population of all towns, one by one.
static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, int maxz, bool noslope)
Checks if 2x2 building is allowed here, also takes into account current town layout Also,...
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.
uint32 goal[NUM_TE]
Amount of cargo required for the town to grow.
@ ROAD_X
Full road along the x-axis (south-west + north-east)
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
@ DIAGDIRDIFF_90LEFT
90 degrees left
const TileTypeProcs _tile_type_town_procs
Tile callback functions for a town.
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road 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 ObjectType OBJECT_STATUE
Statue in towns.
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
static void ResetHouseAge(TileIndex t)
Sets the age of the house to zero.
byte town_name
the town name generator used for town names
static const uint TILE_SIZE
Tile size in world coordinates.
@ ROADTYPE_END
Used for iterations.
@ CBID_HOUSE_CUSTOM_NAME
Called on the Get Tile Description for an house tile.
@ CMD_BUILD_BRIDGE
build a bridge
StringID building_name
building name
uint y
Y position of the tile in unit coordinates.
ClientSettings _settings_client
The current settings for this game.
TileIndex xy
town center tile
@ TCGM_ORIGINAL
Original algorithm (quadratic cargo by population)
Specification of a cargo type.
@ DC_NO_WATER
don't allow building on water
uint8 initial_city_size
multiplier for the initial size of the cities compared to towns
@ MP_INDUSTRY
Part of an industry.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
@ WC_STATION_VIEW
Station view; Window numbers:
Year max_year
last year it can be built
@ SLOPE_STEEP_S
a steep slope falling to north (from south)
TransportType
Available types of transport.
#define MAX_DAY
The number of days till the last day.
Defines the internal data of a functional industry.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Date introduction_date
Introduction date.
@ ROADTYPE_ROAD
Basic road type.
bool CatchmentCoversTown(TownID t) const
Test if the given town ID is covered by our catchment area.
@ CBID_HOUSE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for house tile.
Owner
Enum for all companies/owners.
byte fund_buildings_months
fund buildings program in action?
@ DC_EXEC
execute the given command
void Build(It begin, It end)
Clear and rebuild the tree from a new sequence of elements,.
static RoadBits GetTownRoadBits(TileIndex tile)
Return the RoadBits of a tile.
Owner owner
The owner of this station.
@ MP_ROAD
A tile with road (or tram tracks)
static bool IsLocalCompany()
Is the current company the local company?
Tile description for the 'land area information' tool.
@ NT_GENERAL
General news (from towns)
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
@ TOWN_HAS_STADIUM
There can be only one stadium by town.
static TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
@ CBM_HOUSE_PRODUCE_CARGO
custom cargo production
DoCommandFlag
List of flags for a command.
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
void UpdateVirtCoord()
Resize the sign(label) of the town after changes in population (creation or growth or else)
Foundation
Enumeration for Foundations.
bool GenerateTowns(TownLayout layout)
This function will generate a certain amount of towns, with a certain layout It can be called from th...
@ CMD_BUILD_TUNNEL
build a tunnel
size_t Count() const
Get number of elements stored in tree.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Used as the user_data for FindFurthestFromWater.
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
static void IncHouseConstructionTick(TileIndex t)
Sets the increment stage of a house It is working with the whole counter + stage 5 bits,...
static Town * GetRandom()
Return a random valid town.
bool Succeeded() const
Did this command succeed?
@ RATING_GROWTH_UP_STEP
when a town grows, all companies have rating increased a bit ...
bool bribe
enable bribing the local authority
@ ST_TOWN
Source/destination is a town.
static uint TileX(TileIndex tile)
Get the X component of a tile.
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Implementation of simple mapping class.
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
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.
static uint CountBits(T value)
Counts the number of set bits in a variable.
void NewMonth()
Update stats for a new month.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
@ SLOPE_NW
north and west corner are raised
@ RATING_INITIAL
initial rating
@ TF_CUSTOM_LAYOUT
Allowed, with custom town layout.
Slope tileh
Slope of the tile.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static bool TestTownOwnsBridge(TileIndex tile, const Town *t)
Check if a town 'owns' a bridge.
BuildingCounts< uint16 > building_counts
The number of each type of building in the town.
static HouseID GetHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array.
@ TRANSPORT_ROAD
Transport by road vehicle.
RoadBits
Enumeration for the road parts on a tile.
HouseExtraFlags extra_flags
some more flags
@ ROAD_NONE
No road-part is build.
byte probability
Relative probability of appearing (16 is the standard value)
static bool GrowTown(Town *t)
Grow the town.
static byte GetLiftPosition(TileIndex t)
Get the position of the lift on this animated house.
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
static size_t GetPoolSize()
Returns first unused index.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
bool fund_buildings
allow funding new buildings
int16 y
The y value of the coordinate.
uint32 population
Current population of people.
CargoID Index() const
Determines index of this cargospec.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
@ TOWN_RATING_CHECK_TYPE_COUNT
Number of town checking action types.
static DiagDirection RandomDiagDir()
Return a random direction.
static uint MapSize()
Get the size of the map.
@ TL_BETTER_ROADS
Extended original algorithm (min. 2 distance between roads)
uint16 time_until_rebuild
time until we rebuild a house
@ EXPENSES_CONSTRUCTION
Construction costs.
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Common return value for all commands.
byte GetSnowLine()
Get the current snow line, either variable or static.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Date _date
Current date in days (day counter)
char * GetTownName(char *buff, const TownNameParams *par, uint32 townnameparts, const char *last)
Fills buffer with specified town name.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
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
Information about GRF, used in the game and (part of it) in savegames.
static const HouseID NUM_HOUSES
Total number of houses.
@ CMD_BUILD_ROAD
build a "half" road
@ SLOPE_ELEVATED
bit mask containing all 'simple' slopes
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
TileIndex tile
holds the tile that was found
static DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
RoadBits GetAnyRoadBits(TileIndex tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
@ GSF_FAKE_TOWNS
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
static const size_t MAX_SIZE
Make template parameter accessible from outside.
static bool IsUniqueTownName(const char *name)
Verifies this custom name is unique.
@ DRD_NONE
None of the directions are disallowed.
static const HouseSpec _original_house_specs[]
House specifications from original data.
int32 TileIndexDiff
An offset value between to tiles.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
static CommandCost TownCanBePlacedHere(TileIndex tile)
Checks if it's possible to place a town at given tile.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
uint16 custom_town_number
manually entered number of towns
uint max_dist
holds the distance that tile is from the water
TownRatingCheckType
Action types that a company must ask permission for to a town authority.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
static int CountActiveStations(Town *t)
Calculates amount of active stations in the range of town (HZB_TOWN_EDGE).
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
void Insert(const T &element)
Insert a single element in the tree.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
@ CBID_HOUSE_ALLOW_CONSTRUCTION
Determine whether the house can be built on the specified tile.
Cheats _cheats
All the cheats.
bool population_in_label
show the population of a town in his label?
@ CBM_HOUSE_ACCEPT_CARGO
decides accepted types
@ TE_END
End of town effects.
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
@ ROAD_E
Road at the two eastern edges.
StationList stations_near
NOSAVE: List of nearby stations.
static bool IsRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Check if a specific road type is owned by an owner.
bool Failed() const
Did this command fail?
static void MakeSingleHouseBigger(TileIndex tile)
Helper function for house completion stages progression.
static TileIndex AlignTileToGrid(TileIndex tile, TownLayout layout)
Towns must all be placed on the same grid or when they eventually interpenetrate their road networks ...
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...
An object, such as transmitter, on the map.
static bool GrowTownWithTunnel(const Town *t, const TileIndex tile, const DiagDirection tunnel_dir)
Grows the town with a tunnel.
static byte GetLiftDestination(TileIndex t)
Get the current destination for this lift.
CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Do a town action.
static void HaltLift(TileIndex t)
Stop the lift of this animated house from moving.
@ TACT_ROAD_REBUILD
Rebuild the roads.
static bool TownLayoutAllowsHouseHere(Town *t, TileIndex tile)
Checks if current town layout allows building here.
static bool HasTileRoadType(TileIndex t, RoadTramType rtt)
Check if a tile has a road or a tram road type.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
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 const uint CALLBACK_HOUSEPRODCARGO_END
Sentinel indicating that the loop for CBID_HOUSE_PRODUCE_CARGO has ended.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner=OWNER_NONE, struct Town *town=nullptr, uint8 view=0)
Actually build the object.
EconomySettings economy
settings to change the economy
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ DIAGDIRDIFF_90RIGHT
90 degrees right
ObjectType type
Type of the object.
@ MAX_COMPANIES
Maximum number of companies.
@ ROAD_NE
North-east part.
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.
@ ROAD_SE
South-east part.
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
static void ChangePopulation(Town *t, int mod)
Change the towns population.
@ RATING_ROAD_NEEDED_HOSTILE
"Hostile"
@ ROTF_NO_HOUSES
Bit number for setting this roadtype as not house friendly.
uint16 callback_mask
Bitmask of house callbacks that have to be called.
@ ROAD_S
Road at the two southern edges.
static bool SearchTileForStatue(TileIndex tile, void *user_data)
Search callback function for TownActionBuildStatue.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Money GetCost() const
The costs as made up to this moment.
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static void SetLiftPosition(TileIndex t, byte pos)
Set the position of the lift on this animated house.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
int tile_count
Number of tiles tried.
static bool IsCloseToTown(TileIndex tile, uint dist)
Determines if a town is close to a tile.
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh)
Tile callback routine.
#define RandomTile()
Get a valid random tile.
static bool RoadTypesAllowHouseHere(TileIndex t)
Checks whether at least one surrounding roads allows to build a house here.
@ TSZ_END
Number of available town sizes.
static TileIndex FindNearestGoodCoastalTownSpot(TileIndex tile, TownLayout layout)
Given a spot on the map (presumed to be a water tile), find a good coastal spot to build a city.
@ DC_NO_TEST_TOWN_RATING
town rating does not disallow you from building
byte minimum_life
The minimum number of years this house will survive before the town rebuilds it.
static uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
Clean up unnecessary RoadBits of a planned tile.
bool exclusive_rights
allow buying exclusive rights
uint16 growth_rate
town growth rate
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
@ ROAD_ALL
Full 4-way crossing.
static bool TownLayoutAllows2x2HouseHere(Town *t, TileIndex tile)
Checks if current town layout allows 2x2 building here.
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Money GetAvailableMoneyForCommand()
Coordinates of a point in 2D.
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
TownFounding found_town
town founding.
@ SLOPE_SW
south and west corner are raised
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
@ SLOPE_STEEP_E
a steep slope falling to west (from east)
Slope
Enumeration for the slope-type.
DiagDirection
Enumeration for diagonal directions.
void SetTownRatingTestMode(bool mode)
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings...
Slope GetFoundationSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
@ TL_3X3_GRID
Geometric 3x3 grid algorithm.
CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Delete a town (scenario editor or worldgen only).
@ ROADTYPE_BEGIN
Used for iterations.
static RoadBits GetTownRoadGridElement(Town *t, TileIndex tile, DiagDirection dir)
Generate the RoadBits of a grid tile.
uint64 dparam[2]
Parameters of the str string.
@ CBID_HOUSE_CARGO_ACCEPTANCE
Called to decide how much cargo a town building can accept.
@ NR_NONE
Empty reference.
static void UpdateTownGrowth(Town *t)
Updates town growth state (whether it is growing or not).
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
RoadType
The different roadtypes we support.
static byte GetHouseConstructionTick(TileIndex t)
Gets the construction stage of a house.
Set of callback functions for performing tile operations of a given tile type.
CommandFlags GetCommandFlags(uint32 cmd)
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
@ TSZ_RANDOM
Random size, bigger than small, smaller than large.
bool value
tells if the bool cheat is active or not
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
byte mail_generation
mail generation multiplier (tile based, as the acceptances below)
@ NF_NORMAL
Normal news item. (Newspaper with text only)
@ RATING_ROAD_NEEDED_NEUTRAL
"Neutral"
byte population
population (Zero on other tiles in multi tile house.)
int16 ratings[MAX_COMPANIES]
ratings of each company for this town
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
@ ROAD_NW
North-west part.
TownEffect
Town growth effect when delivering cargo.
TownCargoGenMode town_cargogen_mode
algorithm for generating cargo from houses,
@ WC_TOWN_DIRECTORY
Town directory; Window numbers:
byte cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
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 void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
Does the actual town creation.
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
@ RATING_ROAD_NEEDED_PERMISSIVE
rating needed, "Permissive" difficulty settings
@ MP_TREES
Tile got trees.
Tstorage new_max
Maximum amount this month.
A pair-construct of a TileIndexDiff.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
bool _generating_world
Whether we are generating the map or not.
byte dist_local_authority
distance for town local authority, default 20
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Tstorage old_max
Maximum amount last month.
void ForAllStationsRadius(TileIndex center, uint radius, Func func)
Call a function on all stations whose sign is within a radius of a center tile.
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
static void PostDestructor(size_t index)
Invalidating of the "nearest town cache" has to be done after removing item from the pool.
@ NR_TOWN
Reference town. Scroll to town when clicking on the news.
static bool EconomyIsInRecession()
Is the economy in recession?
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
Get a list of available actions to do at a town.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
bool allow_town_level_crossings
towns are allowed to build level crossings
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static void SetLiftDestination(TileIndex t, byte dest)
Set the new destination of the lift for this animated house, and activate the LiftHasDestination bit.
std::string text
General text with additional information.
@ TCGM_BITCOUNT
Bit-counted algorithm (normal distribution from individual house population)
static DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
Gets the disallowed directions.
uint16 HouseID
OpenTTD ID of house types.
CompanyID _current_company
Company currently doing an action.
Tstorage new_act
Actually transported this month.
@ SLOPE_N
the north corner of the tile is raised
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi)
Check for parallel road inside a given distance.
static bool LiftHasDestination(TileIndex t)
Check if the lift of this animated house has a destination.
Base class for all pools.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
@ RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE
rating needed, "Permissive" difficulty settings
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 CmdTownCargoGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the cargo goal of a town.
@ TACT_COUNT
Number of available town actions.
static bool CanFollowRoad(TileIndex tile, DiagDirection dir)
Checks whether a road can be followed or is a dead end, that can not be extended to the next tile.
@ MP_VOID
Invisible tiles at the SW and SE border.
static byte GetHouseBuildingStage(TileIndex t)
House Construction Scheme.
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.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
RoadTypeLabel label
Unique 32 bit road type identifier.
void Restore()
Restore the variable.
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, HouseID type, byte random_bits)
Write house information into the map.
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
@ NF_COMPANY
Company news item. (Newspaper with face)
static bool FindNearestEmptyLand(TileIndex tile, void *user_data)
CircularTileSearch callback; finds the nearest land tile.
@ COMPANY_SPECTATOR
The client is spectating.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
@ RATING_GROWTH_MAXIMUM
... up to RATING_MEDIOCRE
#define endof(x)
Get the end element of an fixed size array.
bool build_on_slopes
allow building on slopes
This structure is the same for both Industries and Houses.
static void SetTownIndex(TileIndex t, TownID index)
Set the town index for a road or house tile.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
static bool BuildTownHouse(Town *t, TileIndex tile)
Tries to build a house at this tile.
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.
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
T FindNearest(CoordT x, CoordT y) const
Find the element closest to given coordinate, in Manhattan distance.
CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a town (server-only).
Tstorage old_act
Actually transported last month.
@ MP_STATION
A tile of a station.
@ NUM_CARGO
Maximal number of cargo types in a game.
TownCache cache
Container for all cacheable data.
void ResetOverride()
Resets the override, which is used while initializing game.
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
Call a function on all stations that have any part of the requested area within their catchment.
CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the growth rate of the town.
HouseClassID class_id
defines the class this house has (not grf file based)
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
uint8 town_growth_rate
town growth rate
Struct holding parameters used to generate town name.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new town.
@ DIAGDIR_BEGIN
Used for iterations.
HouseZones building_availability
where can it be built (climates, zones)
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type)
Does the town authority allow the (destructive) action of the current company?
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
@ TOWN_IS_GROWING
Conditions for town growth are met. Grow according to Town::growth_rate.
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
static uint TileHash2Bit(uint x, uint y)
Get the last two bits of the TileHash from a tile position.
@ OWNER_DEITY
The object is owned by a superuser / goal script.
StringID str
Description of the tile.
bool fund_roads
allow funding local road reconstruction
@ 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.
@ DC_NO_MODIFY_TOWN_RATING
do not change town rating
const byte _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
static bool CanRoadContinueIntoNextTile(const Town *t, const TileIndex tile, const DiagDirection road_dir)
Checks if a town road can be continued into the next tile.
TileIndex best_position
Best position found so far.
static void UpdateTownGrowCounter(Town *t, uint16 prev_growth_rate)
Updates town grow counter after growth rate change.
@ TACT_NONE
Empty action set.
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
static SmallMap< const Town *, int > _town_test_ratings
Map of towns to modified ratings, while in town rating test-mode.
@ SLOPE_W
the west corner of the tile is raised
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, void *free_data=nullptr)
Add a new newsitem to be shown.
@ CBID_HOUSE_PRODUCE_CARGO
Called to determine how much cargo a town building produces.
static void AnimateTile_Town(TileIndex tile)
Animate a tile for a town Only certain houses can be animated The newhouses animation supersedes regu...
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
Grows the town with an extra house.
#define lengthof(x)
Return the length of an fixed size array.
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
static bool CheckBuildHouseSameZ(TileIndex tile, int z, bool noslope)
Checks if a house can be built at this tile, must have the same max z as parameter.
static RoadBits GenRandomRoadBits()
Generate a random road block.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDirection bridge_dir)
Grows the town with a bridge.
uint32 num_houses
Amount of houses.
static uint16 ClampToU16(const uint64 a)
Reduce an unsigned 64-bit int to an unsigned 16-bit one.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
@ CBM_HOUSE_AUTOSLOPE
decides allowance of autosloping
@ INVALID_COMPANY
An invalid company.
@ SLOPE_STEEP_W
a steep slope falling to east (from west)
@ WC_TOWN_VIEW
Town view; Window numbers:
TownLayout layout
town specific road layout
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
PaletteID pal
The palette (use PAL_NONE) if not needed)
@ TL_ORIGINAL
Original algorithm (min. 1 distance between roads)
TileIndex tile
Tile index.
ConstructionSettings construction
construction of things in-game
static void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
Clears tile and builds a house or house part.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
@ NUM_TLS
Number of town layouts.
static const DrawBuildingsTileStruct _town_draw_tile_data[]
structure of houses graphics
@ ROAD_W
Road at the two western edges.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ CBM_HOUSE_DRAW_FOUNDATIONS
decides if default foundations need to be drawn
CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
Checks whether the local authority allows construction of a new station (rail, road,...
static bool FindFurthestFromWater(TileIndex tile, void *user_data)
CircularTileSearch callback; finds the tile furthest from any water.
static void MakeTownHouseBigger(TileIndex tile)
Make the house advance in its construction stages until completion.
const struct GRFFile * grffile
grf file that introduced this entity
@ FACIL_AIRPORT
Station with an airport.
bool larger_town
if this is a larger town and should grow more quickly
static void DrawTile_Town(TileInfo *ti)
House Tile drawing handler.
static const uint MAX_LENGTH_TOWN_NAME_CHARS
The maximum length of a town name in characters including '\0'.
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
@ BUILDING_IS_HISTORICAL
this house will only appear during town generation in random games, thus the historical
@ CT_INVALID
Invalid cargo type.
@ CMD_DELETE_TOWN
delete a town
@ TL_2X2_GRID
Geometric 2x2 grid algorithm.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
static const byte TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
static Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
@ CBM_HOUSE_ALLOW_CONSTRUCTION
decide whether the house can be built on a given tile
std::string name
Custom town name. If empty, the town was not renamed and uses the generated name.
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Expand a town (scenario editor only).
byte number_towns
the amount of towns
TransportedCargoStat< uint32 > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
CompanyID exclusivity
which company has exclusivity
CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set a custom text in the Town window.
uint16 remove_rating_decrease
rating decrease if removed
@ SLOPE_SE
south and east corner are raised
uint16 grow_counter
counter to count when to grow, value is smaller than or equal to growth_rate
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
void UpdateAllStationVirtCoords()
Update the virtual coords needed to draw the station sign for all stations.
Money GetRemovalCost() const
Get the cost for removing this house.
@ TOWN_CUSTOM_GROWTH
Growth rate is controlled by GS.
uint8 exclusive_counter
months till the exclusivity expires
#define lastof(x)
Get the last element of an fixed size array.
bool allow_town_roads
towns are allowed to build roads (always allowed when generating world / in SE)
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
Grows the town with a road piece.
@ GWP_TOWN
Generate towns.
@ CBID_HOUSE_ACCEPT_CARGO
Called to determine which cargoes a town building should accept.
static bool CheckTownBuild2House(TileIndex *tile, Town *t, int maxz, bool noslope, DiagDirection second)
Checks if 1x2 or 2x1 building is allowed here, also takes into account current town layout Also,...
Town * town
Town the object is built in.
static void IncrementHouseAge(TileIndex t)
Increments the age of the house.
@ TOWN_HAS_CHURCH
There can be only one church by town.
@ SLOPE_NE
north and east corner are raised
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
static const uint16 TOWN_GROWTH_RATE_NONE
Special value for Town::growth_rate to disable town growth.
GRFFileProps grf_prop
Properties related the the grf file.
@ SLOPE_E
the east corner of the tile is raised
std::string cached_name
NOSAVE: Cache of the resolved name of the town, if not using a custom town name.
TownActions
Town actions of a company.
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY
value for custom town number in difficulty settings
@ CMD_LANDSCAPE_CLEAR
demolish a tile
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
@ CBID_HOUSE_AUTOSLOPE
Called to determine if one can alter the ground below a house tile.
static void UpdateTownGrowthRate(Town *t)
Updates town growth rate.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
bool GenerateTownName(uint32 *townnameparts, TownNames *town_names)
Generates valid town name.
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.
@ AT_OILRIG
Oilrig airport.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
Make the tile a house.
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
TrackedViewportSign sign
Location of name sign, UpdateVirtCoord updates this.
@ RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL
"Neutral"
TransportedCargoStat< uint16 > received[NUM_TE]
Cargo statistics about received cargotypes.
const char * GetName() const
Get the name of this grf.
static bool CheckFree2x2Area(TileIndex tile, int z, bool noslope)
Checks if a house of size 2x2 can be built at this tile.
@ SLOPE_STEEP_N
a steep slope falling to south (from north)
const CargoSpec * FindFirstCargoWithTownEffect(TownEffect effect)
Determines the first cargo with a certain town effect.
@ TACT_BUY_RIGHTS
Buy exclusive transport rights.
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).
TownLayout layout
tells us what kind of town we're building
static uint GetNormalGrowthRate(Town *t)
Calculates town growth rate in normal conditions (custom growth rate not set).
static bool IsTileAlignedToGrid(TileIndex tile, TownLayout layout)
Towns must all be placed on the same grid or when they eventually interpenetrate their road networks ...
static bool CanBuildHouseHere(TileIndex tile, bool noslope)
Checks if a house can be built here.
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.
int16 x
The x value of the coordinate.