50 #include "table/strings.h" 67 if (CleaningPool())
return;
75 FOR_ALL_INDUSTRIES(i) assert(i->
town !=
this);
79 FOR_ALL_OBJECTS(o) assert(o->
town !=
this);
102 this->psa_list.clear();
171 return (_price[PR_CLEAR_HOUSE] * this->removal_cost) >> 8;
175 static int _grow_town_result;
178 enum TownGrowthResult {
180 GROWTH_SEARCH_STOPPED = 0
187 static void TownDrawHouseLift(
const TileInfo *ti)
192 typedef void TownDrawTileProc(
const TileInfo *ti);
193 static TownDrawTileProc *
const _town_draw_tile_procs[1] = {
220 if (HouseSpec::Get(house_id)->grf_prop.spritegroup[0] != NULL) {
221 DrawNewHouseTile(ti, house_id);
224 house_id = HouseSpec::Get(house_id)->
grf_prop.subst_id;
242 ti->
x + dcts->subtile_x,
243 ti->
y + dcts->subtile_y,
255 int proc = dcts->draw_proc - 1;
257 if (proc >= 0) _town_draw_tile_procs[proc](ti);
261 static int GetSlopePixelZ_Town(
TileIndex tile, uint x, uint y)
276 const HouseSpec *hs = HouseSpec::Get(hid);
294 AnimateNewHouseTile(tile);
304 if (!(HouseSpec::Get(
GetHouseType(tile))->building_flags & BUILDING_IS_ANIMATED)) {
325 pos += (pos < dest) ? 1 : -1;
347 const int tx =
TileX(tile);
348 const int ty =
TileY(tile);
350 TileXY(
max(0, tx - (
int) dist),
max(0, ty - (
int) dist)),
355 Town *t = Town::GetByTile(atile);
436 AnimateNewHouseConstruction(tile);
480 const HouseSpec *hs = HouseSpec::Get(house_id);
490 Town *t = Town::GetByTile(tile);
496 for (uint i = 0; i < 256; i++) {
504 uint amt =
GB(callback, 0, 8);
505 if (amt == 0)
continue;
515 uint amt =
GB(r, 0, 8) / 8 + 1;
523 uint amt =
GB(r, 8, 8) / 8 + 1;
535 CanDeleteHouse(tile) &&
540 ClearTownHouse(t, tile);
546 cur_company.Restore();
552 if (!CanDeleteHouse(tile))
return CMD_ERROR;
560 Town *t = Town::GetByTile(tile);
571 ClearTownHouse(t, tile);
580 const HouseSpec *hs = HouseSpec::Get(house_id);
581 Town *t = Town::GetByTile(tile);
584 for (uint i = 0; i < 256; i++) {
596 produced[CT_PASSENGERS]++;
604 static inline void AddAcceptedCargoSetMask(
CargoID cargo, uint amount,
CargoArray &acceptance, uint32 *always_accepted)
606 if (cargo ==
CT_INVALID || amount == 0)
return;
607 acceptance[cargo] += amount;
608 SetBit(*always_accepted, cargo);
611 static void AddAcceptedCargo_Town(
TileIndex tile,
CargoArray &acceptance, uint32 *always_accepted)
617 for (uint8 i = 0; i <
lengthof(accepts); i++) {
636 AddAcceptedCargoSetMask(accepts[0],
GB(callback, 0, 4), acceptance, always_accepted);
637 AddAcceptedCargoSetMask(accepts[1],
GB(callback, 4, 4), acceptance, always_accepted);
640 AddAcceptedCargoSetMask(CT_FOOD,
GB(callback, 8, 4), acceptance, always_accepted);
642 AddAcceptedCargoSetMask(accepts[2],
GB(callback, 8, 4), acceptance, always_accepted);
649 for (uint8 i = 0; i <
lengthof(accepts); i++) {
650 AddAcceptedCargoSetMask(accepts[i], hs->
cargo_acceptance[i], acceptance, always_accepted);
657 const HouseSpec *hs = HouseSpec::Get(house);
662 uint16 callback_res = GetHouseCallback(
CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, Town::GetByTile(tile), tile);
664 if (callback_res > 0x400) {
668 if (new_name != STR_NULL && new_name != STR_UNDEFINED) {
674 if (!house_completed) {
676 td->
str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
707 if (
TileX(tile) % AcceptanceMatrix::GRID == 0 &&
TileY(tile) % AcceptanceMatrix::GRID == 0) {
731 AddAcceptedCargo_Town(tile, accepted, &dummy);
732 AddProducedCargo_Town(tile, produced);
737 for (uint cid = 0; cid <
NUM_CARGO; cid++) {
738 if (accepted[cid] >= 8)
SetBit(acc, cid);
758 if (
TileX(tile) % AcceptanceMatrix::GRID == 0 &&
TileY(tile) % AcceptanceMatrix::GRID == 0) {
773 FOR_ALL_TOWNS(town) {
780 static void TownTickHandler(
Town *t)
797 if (_game_mode == GM_EDITOR)
return;
844 dist_multi = (dist_multi + 1) * 4;
845 for (uint pos = 4; pos < dist_multi; pos++) {
850 if (pos & 2) cur += tid_lt[2];
892 if (desired_slope != cur_slope &&
ComplementSlope(desired_slope) != cur_slope) {
910 static bool TerraformTownTile(
TileIndex tile,
int edges,
int dir)
915 if (r.
Failed() || r.
GetCost() >= (_price[PR_TERRAFORM] + 2) * 8)
return false;
920 static void LevelTownLand(
TileIndex tile)
931 TerraformTownTile(tile, tileh & SLOPE_ELEVATED, 0);
951 default: NOT_REACHED();
954 if ((grid_pos.
x % 3) == 0) rcmd |=
ROAD_Y;
955 if ((grid_pos.
y % 3) == 0) rcmd |=
ROAD_X;
959 if ((grid_pos.
x % 4) == 0) rcmd |=
ROAD_Y;
960 if ((grid_pos.
y % 4) == 0) rcmd |=
ROAD_X;
970 default: rb_template =
ROAD_ALL;
break;
1028 _grow_town_result = GROWTH_SUCCEED;
1048 _grow_town_result = GROWTH_SUCCEED;
1079 uint8 bridge_length = 0;
1087 if (bridge_length++ >= 4) {
1091 bridge_tile += delta;
1095 if (bridge_length++ >= 11) {
1099 bridge_tile += delta;
1104 if (bridge_length == 1)
return false;
1106 for (uint8 times = 0; times <= 22; times++) {
1112 _grow_town_result = GROWTH_SUCCEED;
1147 _grow_town_result = GROWTH_SEARCH_STOPPED;
1157 default: NOT_REACHED();
1173 do target_dir =
RandomDiagDir();
while (target_dir == source_dir);
1199 _grow_town_result = GROWTH_SEARCH_STOPPED;
1204 default: NOT_REACHED();
1217 bool allow_house =
true;
1243 default: NOT_REACHED();
1271 if (
Chance16(1, 6)) LevelTownLand(house_tile);
1276 _grow_town_result = GROWTH_SUCCEED;
1282 _grow_town_result = GROWTH_SEARCH_STOPPED;
1339 return (target_rb & back_rb) != 0 && (target_rb & ~back_rb) != 0;
1381 if (_grow_town_result == GROWTH_SUCCEED)
return true;
1400 }
while (!(cur_rb & target_bits));
1401 cur_rb &= ~target_bits;
1419 }
while (--_grow_town_result >= 0);
1433 uint32 r = Random();
1434 uint a =
GB(r, 0, 2);
1435 uint b =
GB(r, 8, 2);
1470 for (ptr = _town_coord_mod; ptr !=
endof(_town_coord_mod); ++ptr) {
1483 for (ptr = _town_coord_mod; ptr !=
endof(_town_coord_mod); ++ptr) {
1500 void UpdateTownRadius(
Town *t)
1502 static const uint32 _town_squared_town_zone_radius_data[23][5] = {
1515 { 81, 36, 25, 0, 9},
1516 { 81, 36, 25, 16, 9},
1517 { 81, 49, 0, 25, 9},
1518 { 81, 64, 0, 25, 9},
1519 { 81, 64, 0, 36, 9},
1520 { 81, 64, 0, 36, 16},
1521 {100, 81, 0, 49, 16},
1522 {100, 81, 0, 49, 25},
1523 {121, 81, 0, 49, 25},
1524 {121, 81, 0, 49, 25},
1525 {121, 81, 0, 49, 36},
1543 void UpdateTownMaxPass(
Town *t)
1565 UpdateTownRadius(t);
1595 t->townnamegrfid = 0;
1602 t->townnameparts = townnameparts;
1611 int x = (int)size * 16 + 3;
1612 if (size ==
TSZ_RANDOM) x = (Random() & 0xF) + 8;
1617 UpdateTownRadius(t);
1625 UpdateTownRadius(t);
1626 UpdateTownMaxPass(t);
1665 if (t->
name != NULL && strcmp(t->
name, name) == 0)
return false;
1685 TownSize size = Extract<TownSize, 0, 2>(p1);
1686 bool city =
HasBit(p1, 2);
1689 bool random =
HasBit(p1, 6);
1690 uint32 townnameparts = p2;
1722 if (ret.
Failed())
return ret;
1725 static const byte price_mult[][
TSZ_RANDOM + 1] = {{ 15, 25, 40, 25 }, { 20, 35, 55, 35 }};
1727 assert_compile(
lengthof(price_mult[0]) == 4);
1730 byte mult = price_mult[city][size];
1737 _additional_cash_required = cost.
GetCost();
1745 t = CreateRandomTown(20, townnameparts, size, city, layout);
1749 _new_town_id = t->
index;
1753 DoCreateTown(t, tile, townnameparts, size, city, layout,
true);
1756 old_generating_world.
Restore();
1758 if (t != NULL && !
StrEmpty(text)) {
1763 if (_game_mode != GM_EDITOR) {
1768 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
1770 char *cn =
stredup(company_name);
1796 default:
return tile;
1814 default:
return true;
1919 DoCreateTown(t, tile, townnameparts, size, city, layout,
false);
1935 }
while (--attempts != 0);
1940 static const byte _num_initial_towns[4] = {5, 11, 23, 46};
1951 uint current_number = 0;
1955 uint32 townnameparts;
1956 TownNames town_names;
1969 if (CreateRandomTown(20, townnameparts,
TSZ_RANDOM, city, layout) != NULL) current_number++;
1974 if (current_number != 0)
return true;
2004 HouseZonesBits smallest = HZB_TOWN_EDGE;
2005 for (HouseZonesBits i = HZB_BEGIN; i < HZB_END; i++) {
2030 if (HouseSpec::Get(type)->building_flags & BUILDING_IS_ANIMATED)
AddAnimatedTile(tile);
2135 if ((grid_pos.
x % 3) == 0 || (grid_pos.
y % 3) == 0)
return false;
2139 if ((grid_pos.
x % 4) == 0 || (grid_pos.
y % 4) == 0)
return false;
2169 if ((grid_pos.
x != 2 && grid_pos.
x != -1) ||
2170 (grid_pos.
y != 2 && grid_pos.
y != -1))
return false;
2174 if ((grid_pos.
x & 3) < 2 || (grid_pos.
y & 3) < 2)
return false;
2261 uint bitmask = (1 << rad) + (1 << (land + 12));
2269 uint probability_max = 0;
2273 const HouseSpec *hs = HouseSpec::Get(i);
2279 if (hs->
class_id != HOUSE_NO_CLASS) {
2289 probability_max += cur_prob;
2290 probs[num] = cur_prob;
2296 while (probability_max > 0) {
2306 for (i = 0; i < num; i++) {
2307 if (probs[i] > r)
break;
2312 probability_max -= probs[i];
2316 houses[i] = houses[num];
2317 probs[i] = probs[num];
2319 const HouseSpec *hs = HouseSpec::Get(house);
2337 if (t->
flags & oneof)
continue;
2341 if (noslope && slope !=
SLOPE_FLAT)
continue;
2353 byte random_bits = Random();
2366 byte construction_counter = 0;
2367 byte construction_stage = 0;
2370 uint32 r = Random();
2373 if (
Chance16(1, 7)) construction_stage =
GB(r, 0, 2);
2378 construction_counter =
GB(r, 2, 2);
2382 MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits);
2383 UpdateTownRadius(t);
2402 DoClearSquare(tile);
2418 if (HouseSpec::Get(house - 1)->building_flags & TILE_SIZE_2x1) {
2421 }
else if (HouseSpec::Get(house - 1)->building_flags & BUILDING_2_TILES_Y) {
2424 }
else if (HouseSpec::Get(house - 2)->building_flags & BUILDING_HAS_4_TILES) {
2427 }
else if (HouseSpec::Get(house - 3)->building_flags & BUILDING_HAS_4_TILES) {
2444 const HouseSpec *hs = HouseSpec::Get(house);
2467 UpdateTownRadius(t);
2513 FOR_ALL_CARGOSPECS(cs) {
2603 uint old_rate = t->
growth_rate & ~TOWN_GROW_RATE_CUSTOM;
2640 UpdateTownRadius(t);
2642 uint n = amount * 10;
2647 for (; p2 > 0; p2--) {
2649 for (uint i = 0; i < 25; i++)
if (
GrowTown(t))
break;
2652 UpdateTownRadius(t);
2654 UpdateTownMaxPass(t);
2677 FOR_ALL_STATIONS(st) {
2678 if (st->
town == t) {
2683 if (ret.
Failed())
return ret;
2695 bool try_clear =
false;
2736 if (ret.
Failed())
return ret;
2741 if (flags &
DC_EXEC)
delete t;
2751 2, 4, 9, 35, 48, 53, 117, 175
2788 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
2790 char *cn =
stredup(company_name);
2830 static const int STATUE_NUMBER_INNER_TILES = 25;
2849 if (statue_data->
tile_count <= STATUE_NUMBER_INNER_TILES) {
2925 SetDParam(0, STR_NEWS_EXCLUSIVE_RIGHTS_TITLE);
2926 SetDParam(1, STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION);
2931 Game::NewEvent(
new ScriptEventExclusiveTransportRights((ScriptCompany::CompanyID)(
Owner)_current_company, t->
index));
2945 FOR_ALL_STATIONS(st) {
2971 static TownActionProc *
const _town_action_proc[] = {
2972 TownActionAdvertiseSmall,
2973 TownActionAdvertiseMedium,
2974 TownActionAdvertiseLarge,
2975 TownActionRoadRebuild,
2977 TownActionFundBuildings,
2978 TownActionBuyRights,
3027 if (nump != NULL) *nump = num;
3052 if (ret.
Failed())
return ret;
3061 static void UpdateTownRating(
Town *t)
3065 FOR_ALL_COMPANIES(c) {
3072 FOR_ALL_STATIONS(st) {
3074 if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
3105 for (
int i = TE_BEGIN; i <
TE_END; i++) {
3106 switch (t->
goal[i]) {
3130 static const uint16 _grow_count_values[2][6] = {
3131 { 120, 120, 120, 100, 80, 60 },
3132 { 320, 420, 300, 220, 160, 100 }
3138 FOR_ALL_STATIONS(st) {
3140 if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
3149 m = _grow_count_values[0][
min(n, 5)];
3151 m = _grow_count_values[1][
min(n, 5)];
3152 if (n == 0 && !
Chance16(1, 12))
return;
3159 m >>= growth_multiplier;
3169 static void UpdateTownAmounts(
Town *t)
3178 static void UpdateTownUnwanted(
Town *t)
3182 FOR_ALL_COMPANIES(c) {
3217 uint best = threshold;
3218 Town *best_town = NULL;
3248 if (tid == (TownID)INVALID_TOWN) {
3265 return Town::GetByTile(tile);
3282 static int ref_count = 0;
3284 if (ref_count == 0) {
3285 _town_test_ratings.
Clear();
3289 assert(ref_count > 0);
3304 if (it != _town_test_ratings.
End()) {
3331 if (rating < max) rating =
max;
3336 if (rating > max) rating =
max;
3340 _town_test_ratings[t] = rating;
3385 void TownsMonthlyLoop()
3396 UpdateTownAmounts(t);
3397 UpdateTownRating(t);
3399 UpdateTownUnwanted(t);
3406 void TownsYearlyLoop()
3420 const HouseSpec *hs = HouseSpec::Get(house);
3425 bool allow_terraform =
true;
3429 hs = HouseSpec::Get(house);
3446 GetSlopePixelZ_Town,
3448 AddAcceptedCargo_Town,
3450 GetTileTrackStatus_Town,
3454 ChangeTileOwner_Town,
3455 AddProducedCargo_Town,
3466 memset(&_house_specs, 0,
sizeof(_house_specs));
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Functions related to OTTD's strings.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
don't allow building on structures
Functions/types related to NewGRF debugging.
AcceptanceMatrix cargo_accepted
Bitmap of cargoes accepted by houses for each 4*4 map square of the town.
byte type
Type of this airport,.
the north corner of the tile is raised
do not change town rating
uint16 custom_town_number
manually entered number of towns
#define RandomTile()
Get a valid random tile.
static bool IsLocalCompany()
Is the current company the local company?
static const int TOWN_GROWTH_TICKS
cycle duration for towns trying to grow. (this originates from the size of the town array in TTD ...
TownRatingCheckType
Action types that a company must ask permission for to a town authority.
There can be only one stadium by town.
Source/destination is a town.
static Year GetHouseAge(TileIndex t)
Get the age of the house.
byte probability
Relative probability of appearing (16 is the standard value)
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.
static void UpdateTownCargoes(Town *t, TileIndex start, bool update_total=true)
Update accepted town cargoes around a specific tile.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static void ChangePopulation(Town *t, int mod)
Change the towns population.
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
Grows the town with an extra house.
static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1)
Grows the given town.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
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 RoadBits GetTownRoadBits(TileIndex tile)
Return the RoadBits of a tile.
TransportedCargoStat< uint16 > received[NUM_TE]
Cargo statistics about received cargotypes.
static TileArea GetAreaForTile(TileIndex tile, uint extend=0)
Get the area of the matrix square that contains a specific tile.
Tile information, used while rendering the tile.
bool bribe
enable bribing the local authority
static const byte TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
CompanyMask statues
which companies have a statue?
south and east corner are raised
static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDirection bridge_dir)
Grows the town with a bridge.
bool VerifyTownName(uint32 r, const TownNameParams *par, TownNames *town_names)
Verifies the town name is valid and unique.
void InitializeLayout(TownLayout layout)
Assigns town layout.
bool GenerateTowns(TownLayout layout)
This function will generate a certain amount of towns, with a certain layout It can be called from th...
the west corner of the tile is raised
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
byte landscape
the landscape we're currently in
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet)...
Geometric 3x3 grid algorithm.
Sprites to use and how to display them for town tiles.
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.
TownLayout layout
tells us what kind of town we're building
TownFoundingByte found_town
town founding,
const Pair * Find(const T &key) const
Finds given key in this map.
EconomySettings economy
settings to change the economy
uint32 squared_town_zone_radius[HZB_END]
UpdateTownRadius updates this given the house count.
int32 TileIndexDiff
An offset value between to tiles.
static bool IsRoadOwner(TileIndex t, RoadType rt, Owner o)
Check if a specific road type is owned by an owner.
static Titem * Get(size_t index)
Returns Titem with given index.
Money GetAvailableMoneyForCommand()
static bool TownLayoutAllows2x2HouseHere(Town *t, TileIndex tile)
Checks if current town layout allows 2x2 building here.
Functions related to dates.
const char * grf
newGRF used for the tile contents
Town * town
Town the object is built in.
byte fund_buildings_months
fund buildings program in action?
CompanyByte exclusivity
which company has exclusivity
Called to determine if one can alter the ground below a house tile.
static bool TownLayoutAllowsHouseHere(Town *t, TileIndex tile)
Checks if current town layout allows building here.
TileIndex best_position
Best position found so far.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
void UpdateAllTownVirtCoords()
Update the virtual coords needed to draw the town sign for all towns.
uint8 unwanted[MAX_COMPANIES]
how many months companies aren't wanted by towns (bribe)
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
static bool _town_rating_test
If true, town rating is in test-mode.
A tile with road (or tram tracks)
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Slope tileh
Slope of the tile.
static const ObjectType OBJECT_STATUE
Statue in towns.
static uint ScaleByMapSize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map...
Full road along the x-axis (south-west + north-east)
Functions used internally by the roads.
Specification of a cargo type.
static bool IsCloseToTown(TileIndex tile, uint dist)
Determines if a town is close to a tile.
bool population_in_label
show the population of a town in his label?
Implementation of simple mapping class.
bool GenerateTownName(uint32 *townnameparts, TownNames *town_names)
Generates valid town name.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
static void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
Make the tile a house.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Town(TileIndex tile=INVALID_TILE)
Creates a new town.
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
byte cargo_acceptance[3]
acceptance level for the cargo slots
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height) ...
Base for all depots (except hangars)
void Clear()
Remove all items from the list.
TownLayoutByte town_layout
select town layout,
static bool HasTileRoadType(TileIndex t, RoadType rt)
Check if a tile has a specific road type.
static const DrawBuildingsTileStruct _town_draw_tile_data[]
structure of houses graphics
Defines the internal data of a functional industry.
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.
Tindex index
Index of this pool item.
static bool CheckFree2x2Area(TileIndex tile, int z, bool noslope)
Checks if a house of size 2x2 can be built at this tile.
the east corner of the tile is raised
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
uint16 time_until_rebuild
time until we rebuild a house
CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Do a town action.
Helper functions to extract data from command parameters.
Cargo behaves water-like.
Used as the user_data for FindFurthestFromWater.
void NewMonth()
Update stats for a new month.
#define lastof(x)
Get the last element of an fixed size array.
The client is spectating.
void UpdateVirtCoord()
Resize the sign(label) of the town after changes in population (creation or growth or else) ...
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
uint32 cargo_produced
Bitmap of all cargoes produced by houses in this town.
Called to determine which cargoes a town building should accept.
byte dist_local_authority
distance for town local authority, default 20
Functions related to world/map generation.
Money GetCost() const
The costs as made up to this moment.
Contains objects such as transmitters and owned land.
uint32 cargo_accepted_total
NOSAVE: Bitmap of all cargoes accepted by houses in this town.
static bool BuildTownHouse(Town *t, TileIndex tile)
Tries to build a house at this tile.
south and west corner are raised
Common return value for all commands.
static bool LiftHasDestination(TileIndex t)
Check if the lift of this animated house has a destination.
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
uint16 callback_mask
Bitmask of house callbacks that have to be called.
CommandFlags GetCommandFlags(uint32 cmd)
static T max(const T a, const T b)
Returns the maximum of two values.
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
bool allow_town_roads
towns are allowed to build roads (always allowed when generating world / in SE)
Town directory; Window numbers:
Town * town
The town this station is associated with.
uint16 HouseID
OpenTTD ID of house types.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
uint32 population
Current population of people.
Year _cur_year
Current year, starting at 0.
void MultiplyCost(int factor)
Multiplies the cost of the command by the given factor.
static RoadBits GenRandomRoadBits()
Generate a random road block.
Tstorage new_act
Actually transported this month.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
decides amount of cargo acceptance
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...
const SmallPair< T, U > * End() const
Get the pointer behind the last valid item (const)
void DeleteSubsidyWith(SourceType type, SourceID index)
Delete the subsidies associated with a given cargo source type and id.
static SmallMap< const Town *, int, 4 > _town_test_ratings
Map of towns to modified ratings, while in town rating test-mode.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
static const uint TILE_SIZE
Tile size in world coordinates.
static byte GetLiftDestination(TileIndex t)
Get the current destination for this lift.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
static const HouseID NUM_HOUSES
Total number of houses.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Owner owner[4]
Name of the owner(s)
static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi)
Check for parallel road inside a given distance.
this house will only appear during town generation in random games, thus the historical ...
north and east corner are raised
static void DoClearTownHouseHelper(TileIndex tile, Town *t, HouseID house)
Update data structures when a house is removed.
HouseZones building_availability
where can it be built (climates, zones)
Class to backup a specific variable and restore it later.
Called to determine the type (if any) of foundation to draw for house tile.
Functions related to (drawing on) viewports.
Pseudo random number generator.
byte population
population (Zero on other tiles in multi tile house.)
The object is owned by a superuser / goal script.
static byte GetHouseBuildingStage(TileIndex t)
House Construction Scheme.
uint32 goal[NUM_TE]
Amount of cargo required for the town to grow.
CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile.
static bool IsHouseCompleted(TileIndex t)
Get the completion of this house.
int16 y
The y value of the coordinate.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Expand a town (scenario editor only).
static void AnimateTile_Town(TileIndex tile)
Animate a tile for a town Only certain houses can be animated The newhouses animation supersedes regu...
static const size_t MAX_SIZE
Make template parameter accessible from outside.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
bool exclusive_rights
allow buying exclusive rights
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
TownActions
Town actions of a company.
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
Critical errors, the MessageBox is shown in all cases.
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.
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
static void DrawTile_Town(TileInfo *ti)
House Tile drawing handler.
static uint TileHash2Bit(uint x, uint y)
Get the last two bits of the TileHash from a tile position.
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
uint max_dist
holds the distance that tile is from the water
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
Grows the town with a road piece.
Header of Action 04 "universal holder" structure and functions.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
static byte GetHouseConstructionTick(TileIndex t)
Gets the construction stage of a house.
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
TownEffect
Town growth effect when delivering cargo.
Functions related to low-level strings.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
uint x
X position of the tile in unit coordinates.
byte rating
Station rating for this cargo.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Called on the Get Tile Description for an house tile.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Foundation
Enumeration for Foundations.
Types related to cheating.
TileIndex xy
town center tile
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
Does the actual town creation.
byte mail_generation
mail generation multiplier (tile based, as the acceptances below)
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
ViewportSign sign
Location of name sign, UpdateVirtCoord updates this.
static CommandCost TownCanBePlacedHere(TileIndex tile)
Checks if it's possible to place a town at given tile.
TileIndex tile
Tile index.
Functions related to errors.
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...
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
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.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
The tile is leveled up to a flat slope.
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...
static DiagDirection RandomDiagDir()
Return a random direction.
TownSize
Supported initial town sizes.
static size_t GetPoolSize()
Returns first unused index.
HouseClassID class_id
defines the class this house has (not grf file based)
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
Information about GRF, used in the game and (part of it) in savegames.
Geometric 2x2 grid algorithm.
static bool IsUniqueTownName(const char *name)
Verifies this custom name is unique.
static void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
Set the owner of a specific road type.
int16 ratings[MAX_COMPANIES]
ratings of each company for this town
static bool HasTownOwnedRoad(TileIndex t)
Checks if given tile has town owned road.
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
Functions related to NewGRF houses.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DoCommandFlag
List of flags for a command.
static const uint16 TOWN_GROW_RATE_CUSTOM
If this mask is applied to Town::growth_rate, the grow_counter will not be calculated by the system (...
ClientSettings _settings_client
The current settings for this game.
bool Succeeded() const
Did this command succeed?
rating needed, "Permissive" difficulty settings
General news (from towns)
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.
when a town grows, all companies have rating increased a bit ...
static void PostDestructor(size_t index)
Invalidating of the "nearest town cache" has to be done after removing item from the pool...
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
Map accessors for object tiles.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a 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.
Number of available town sizes.
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.
static Town * GetRandom()
Return a random valid town.
uint y
Y position of the tile in unit coordinates.
static byte GetLiftPosition(TileIndex t)
Get the position of the lift on this animated house.
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
RoadBits
Enumeration for the road parts on a tile.
BuildingCounts< uint16 > building_counts
The number of each type of building in the town.
An object, such as transmitter, on the map.
CargoID accepts_cargo[3]
3 input cargo slots
rating needed, "Permissive" difficulty settings
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
void UpdateTownCargoBitmap()
Updates the bitmap of all cargoes accepted by houses.
bool fund_roads
allow funding local road reconstruction
Represents the covered area of e.g.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Number of available town actions.
CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the growth rate of the town.
Normal news item. (Newspaper with text only)
decides allowance of autosloping
static DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
don't allow building on water
... up to RATING_MEDIOCRE
static bool FindFurthestFromWater(TileIndex tile, void *user_data)
CircularTileSearch callback; finds the tile furthest from any water.
static void IncHouseConstructionTick(TileIndex t)
Sets the increment stage of a house It is working with the whole counter + stage 5 bits...
uint32 GetWorldPopulation()
Determines the world population Basically, count population of all towns, one by one.
Tstorage new_max
Maximum amount this month.
This structure is the same for both Industries and Houses.
Money GetRemovalCost() const
Get the cost for removing this house.
The tile has no ownership.
static bool GrowTown(Town *t)
Grow the town.
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
Structure for storing data while searching the best place to build a statue.
Station view; Window numbers:
StringID building_name
building name
const TileArea & GetArea() const
Get the total covered area.
StationFacilityByte facilities
The facilities that this station has.
CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Delete a town (scenario editor or worldgen only).
DiagDirection
Enumeration for diagonal directions.
#define lengthof(x)
Return the length of an fixed size array.
bit mask containing all 'simple' slopes
static uint TileHash(uint x, uint y)
Calculate a hash value from a tile position.
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?
RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
static void SetLiftDestination(TileIndex t, byte dest)
Set the new destination of the lift for this animated house, and activate the LiftHasDestination bit...
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
Clean up unnecessary RoadBits of a planed tile.
Functions related to autoslope.
Year max_year
last year it can be built
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
byte number_towns
the amount of towns
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
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.
static bool GrowTownAtRoad(Town *t, TileIndex tile)
Returns "growth" if a house was built, or no if the build failed.
bool build_on_slopes
allow building on slopes
bool Failed() const
Did this command fail?
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Maximum number of companies.
a steep slope falling to east (from west)
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
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.
uint8 town_growth_rate
town growth rate
bool has_newhouses
Set if there are any newhouses loaded.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest to the given tile within threshold.
Number of town checking action types.
Base class for all pools.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static bool IsSea(TileIndex t)
Is it a sea water tile?
Company news item. (Newspaper with face)
static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
Check if a Road is allowed on a given tile.
Determine whether the house can be built on the specified tile.
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
int tile_count
Number of tiles tried.
uint16 override
id of the entity been replaced by
Maximal number of cargo types in a game.
TileIndex tile
The base tile of the area.
OwnerByte owner
The owner of this station.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
uint64 dparam[2]
Parameters of the str string.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
A pair-construct of a TileIndexDiff.
void UpdateAllStationVirtCoords()
Update the virtual coords needed to draw the station sign for all stations.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, HouseID type, byte random_bits)
Write house information into the map.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static void MakeTownHouseBigger(TileIndex tile)
Make the house advance in its construction stages until completion.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
char * text
General text with additional information.
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY
value for custom town number in difficulty settings
execute the given command
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, the function returns the same as GetTileSlope.
static void MakeSingleHouseBigger(TileIndex tile)
Helper function for house completion stages progression.
CommandCost CmdTownCargoGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the cargo goal of a town.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
static Slope InclinedSlope(DiagDirection dir)
Returns the slope that is inclined in a specific direction.
uint16 growth_rate
town growth rate
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...
static void HaltLift(TileIndex t)
Stop the lift of this animated house from moving.
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...
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
Tstorage old_max
Maximum amount last month.
static uint MapSize()
Get the size of the map.
TownEffect town_effect
The effect that delivering this cargo type has on towns. Also affects destination of subsidies...
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.
static void TileLoop_Town(TileIndex tile)
Tile callback function.
void DecreaseBuildingCount(Town *t, HouseID house_id)
DecreaseBuildingCount() Decrease the number of a building when it is deleted.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
There can be only one church by town.
Town authority; Window numbers:
GUISettings gui
settings related to the GUI
Tunnel entry/exit and bridge heads.
HouseExtraFlags extra_flags
some more flags
Invisible tiles at the SW and SE border.
Reference town. Scroll to town when clicking on the news.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
static void SetLiftPosition(TileIndex t, byte pos)
Set 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 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.
Functions related to objects.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Cargo support for NewGRFs.
static int GetRating(const Town *t)
Get the rating of a town for the _current_company.
static size_t GetNumItems()
Returns number of valid items in the pool.
A town owns the tile, or a town is expanding.
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=NULL)
Add a new newsitem to be shown.
static bool FindNearestEmptyLand(TileIndex tile, void *user_data)
CircularTileSearch callback; finds the nearest land tile.
byte minimum_life
The minimum number of years this house will survive before the town rebuilds it.
Buy exclusive transport rights.
uint16 remove_rating_decrease
rating decrease if removed
static HouseID GetHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array.
north and west corner are raised
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Random size, bigger than small, smaller than large.
static const uint16 TOWN_GROW_RATE_CUSTOM_NONE
Special value for Town::growth_rate to disable town growth.
Cheat magic_bulldozer
dynamite industries, objects
byte town_council_tolerance
minimum required town ratings to be allowed to demolish stuff
The tile has no foundation, the slope remains unchanged.
CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type)
Does the town authority allow the (destructive) action of the current company?
TileIndex xy
Base tile of the station.
TileArea location
Location of the object.
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
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.
uint8 initial_city_size
multiplier for the initial size of the cities compared to towns
ObjectType type
Type of the object.
Slope
Enumeration for the slope-type.
static bool CanBuildHouseHere(TileIndex tile, bool noslope)
Checks if a house can be built here.
Town view; Window numbers:
const byte _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
TownCache cache
Container for all cacheable data.
uint8 larger_towns
the number of cities to build. These start off larger and grow twice as fast
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
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 RoadBits GetTownRoadGridElement(Town *t, TileIndex tile, DiagDirection dir)
Generate the RoadBits of a grid tile.
uint8 exclusive_counter
months till the exclusivity expires
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Transport by road vehicle.
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner=OWNER_NONE, struct Town *town=NULL, uint8 view=0)
Actually build the object.
Functions related to OTTD's landscape.
static void ResetHouseAge(TileIndex t)
Sets the age of the house to zero.
byte town_name
the town name generator used for town names
Extended original algorithm (min. 2 distance between roads)
Base functions for all Games.
Allowed, with custom town layout.
Functions related to commands.
bool larger_town
if this is a larger town and should grow more quickly
char * name
Custom town name. If NULL, the town was not renamed and uses the generated name.
Coordinates of a point in 2D.
a steep slope falling to south (from north)
Struct holding a parameters used to generate 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.
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 uint TileHeight(TileIndex tile)
Returns the height of a tile.
decides if default foundations need to be drawn
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Original algorithm (min. 1 distance between roads)
Cargo behaves food/fizzy-drinks-like.
static const uint MAX_LENGTH_TOWN_NAME_CHARS
The maximum length of a town name in characters including '\0'.
TownLayoutByte layout
town specific road layout
static bool TryClearTile(TileIndex tile)
Check whether the land can be cleared.
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)
Functions that have tunnels and bridges in common.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static const HouseSpec _original_house_specs[]
House specifications from original data.
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 void free(const void *ptr)
Version of the standard free that accepts const pointers.
GRFFileProps grf_prop
Properties related the the grf file.
Airport airport
Tile area the airport covers.
when a town grows, company gains reputation for all well serviced stations ...
void ResetOverride()
Resets the override, which is used while initializing game.
const struct GRFFile * grffile
grf file that introduced this entity
StringID str
Description of the tile.
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
uint32 _town_cargoes_accepted
Bitmap of all cargoes accepted by houses.
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
Get a list of available actions to do at a town.
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh)
Tile callback routine.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Town name generator stuff.
void Restore()
Restore the variable.
Base functions for all AIs.
Try to bribe the council.
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 const TileIndex INVALID_TILE
The very nice invalid tile marker.
TileIndex tile
holds the tile that was found
TransportedCargoStat< uint32 > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
GameCreationSettings game_creation
settings used during the creation of a game (map)
A tile without any structures, i.e. grass, rocks, farm fields etc.
int _nb_orig_names
Number of original town names.
Full road along the y-axis (north-west + south-east)
byte CargoID
Cargo slots to indicate a cargo type within a game.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
bool fund_buildings
allow funding new buildings
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
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.
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town...
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
Called to determine how much cargo a town building produces.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
uint32 num_houses
Amount of houses.
a steep slope falling to west (from east)
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
void UpdateTownCargoTotal(Town *t)
Update the total cargo acceptance of the whole town.
Conditions for town growth are met. Grow according to Town::growth_rate.
town rating does not disallow you from building
decide whether the house can be built on a given tile
#define TILE_ADD(x, y)
Adds to tiles together.
SpriteID sprite
The 'real' sprite.
Called to decide how much cargo a town building can accept.
static bool SearchTileForStatue(TileIndex tile, void *user_data)
Search callback function for TownActionBuildStatue.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
static void SetDParamX(uint64 *s, uint n, uint64 v)
Set a string parameter v at index n in a given array s.
static const uint CALLBACK_HOUSEPRODCARGO_END
Sentinel indicating that the loop for CBID_HOUSE_PRODUCE_CARGO has ended.
Functions related to news.
Structure contains cached list of stations nearby.
CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set a custom text in the Town window.
byte road_build_months
fund road reconstruction in action?
CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a town (server-only).
Base classes/functions for stations.
static void SetTownIndex(TileIndex t, TownID index)
Set the town index for a road or house tile.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
static Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap...
bool allow_town_level_crossings
towns are allowed to build level crossings
the south corner of the tile is raised
uint16 grow_counter
counter to count when to grow, value is smaller than or equal to growth_rate
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
... but loses for bad serviced stations
Class for backupping variables and making sure they are restored later.
static uint16 ClampToU16(const uint64 a)
Reduce an unsigned 64-bit int to an unsigned 16-bit one.
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...
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
Functions related to subsidies.
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Create a new town.
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 TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static TileIndexDiffC TileIndexToTileIndexDiffC(TileIndex tile_a, TileIndex tile_b)
Returns the diff between two tiles.
static void IncrementHouseAge(TileIndex t)
Increments the age of the house.
const CargoSpec * FindFirstCargoWithTownEffect(TownEffect effect)
Determines the first cargo with a certain town effect.
a steep slope falling to north (from south)
const TileTypeProcs _tile_type_town_procs
Tile callback functions for a town.
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-...
Tstorage old_act
Actually transported last month.
CompanyMask have_ratings
which companies have a rating
byte HighestSnowLine()
Get the highest possible snow line height, either variable or static.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Cheats _cheats
All the cheats.
static void UpdateTownGrowRate(Town *t)
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
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)
void SetTownRatingTestMode(bool mode)
Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings...