Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/release-linux.yml # src/base_consist.h # src/blitter/32bpp_optimized.cpp # src/blitter/32bpp_optimized.hpp # src/blitter/32bpp_sse2.hpp # src/blitter/8bpp_optimized.hpp # src/gfx_func.h # src/industry_cmd.cpp # src/industrytype.h # src/linkgraph/linkgraphjob.cpp # src/mixer.cpp # src/newgrf_callbacks.h # src/openttd.cpp # src/os/macosx/macos.mm # src/os/windows/win32.cpp # src/pathfinder/npf/npf.cpp # src/road_cmd.cpp # src/saveload/afterload.cpp # src/saveload/saveload.h # src/saveload/vehicle_sl.cpp # src/sound.cpp # src/spritecache.cpp # src/spriteloader/spriteloader.hpp # src/station_map.h # src/timetable_cmd.cpp # src/timetable_cmd.h # src/timetable_gui.cpp # src/town_cmd.cpp # src/vehicle_cmd.cpp # src/vehicle_gui_base.h # src/video/opengl.cpp # src/video/opengl.h # src/viewport.cpp
This commit is contained in:
401
src/town_cmd.cpp
401
src/town_cmd.cpp
@@ -85,12 +85,12 @@ void RebuildTownKdtree()
|
||||
|
||||
/**
|
||||
* Check if a town 'owns' a bridge.
|
||||
* Bridges to not directly have an owner, so we check the tiles adjacent to the bridge ends.
|
||||
* Bridges do not directly have an owner, so we check the tiles adjacent to the bridge ends.
|
||||
* If either adjacent tile belongs to the town then it will be assumed that the town built
|
||||
* the bridge.
|
||||
* @param tile Bridge tile to test
|
||||
* @param t Town we are interested in
|
||||
* @return true if town 'owns' a bridge.
|
||||
* @param tile The bridge tile to test
|
||||
* @param t The town we are interested in
|
||||
* @return true If town 'owns' a bridge.
|
||||
*/
|
||||
static bool TestTownOwnsBridge(TileIndex tile, const Town *t)
|
||||
{
|
||||
@@ -174,7 +174,8 @@ void Town::PostDestructor(size_t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns town layout. If Random, generates one based on TileHash.
|
||||
* Assign the town layout.
|
||||
* @param layout The desired layout. If TL_RANDOM, we pick one based on TileHash.
|
||||
*/
|
||||
void Town::InitializeLayout(TownLayout layout)
|
||||
{
|
||||
@@ -188,7 +189,7 @@ void Town::InitializeLayout(TownLayout layout)
|
||||
|
||||
/**
|
||||
* Return a random valid town.
|
||||
* @return random town, nullptr if there are no towns
|
||||
* @return A random town, or nullptr if there are no towns.
|
||||
*/
|
||||
/* static */ Town *Town::GetRandom()
|
||||
{
|
||||
@@ -257,8 +258,8 @@ void Town::FillCachedName() const
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cost for removing this house
|
||||
* @return the cost (inflation corrected etc)
|
||||
* Get the cost for removing this house.
|
||||
* @return The cost adjusted for inflation, etc.
|
||||
*/
|
||||
Money HouseSpec::GetRemovalCost() const
|
||||
{
|
||||
@@ -268,7 +269,7 @@ Money HouseSpec::GetRemovalCost() const
|
||||
/* Local */
|
||||
static int _grow_town_result;
|
||||
|
||||
/* Describe the possible states */
|
||||
/* The possible states of town growth. */
|
||||
enum TownGrowthResult {
|
||||
GROWTH_SUCCEED = -1,
|
||||
GROWTH_SEARCH_STOPPED = 0
|
||||
@@ -300,12 +301,11 @@ static TownDrawTileProc * const _town_draw_tile_procs[1] = {
|
||||
*/
|
||||
static inline DiagDirection RandomDiagDir()
|
||||
{
|
||||
return (DiagDirection)(3 & Random());
|
||||
return (DiagDirection)(RandomRange(DIAGDIR_END));
|
||||
}
|
||||
|
||||
/**
|
||||
* House Tile drawing handler.
|
||||
* Part of the tile loop process
|
||||
* Draw a house and its tile. This is a tile callback routine.
|
||||
* @param ti TileInfo of the tile to draw
|
||||
*/
|
||||
static void DrawTile_Town(TileInfo *ti, DrawTileProcParams params)
|
||||
@@ -437,7 +437,11 @@ static int GetSlopePixelZ_Town(TileIndex tile, uint x, uint y, bool ground_vehic
|
||||
return GetTileMaxPixelZ(tile);
|
||||
}
|
||||
|
||||
/** Tile callback routine */
|
||||
/**
|
||||
* Get the foundation for a house. This is a tile callback routine.
|
||||
* @param tile The tile to find a foundation for.
|
||||
* @param tileh The slope of the tile.
|
||||
*/
|
||||
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh)
|
||||
{
|
||||
HouseID hid = GetHouseType(tile);
|
||||
@@ -465,10 +469,10 @@ uint8 GetAnimatedTileSpeed_Town(TileIndex tile)
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate a tile for a town
|
||||
* Only certain houses can be animated
|
||||
* The newhouses animation supersedes regular ones
|
||||
* @param tile TileIndex of the house to animate
|
||||
* Animate a tile for a town.
|
||||
* Only certain houses can be animated.
|
||||
* The newhouses animation supersedes regular ones.
|
||||
* @param tile TileIndex of the house to animate.
|
||||
*/
|
||||
void AnimateTile_Town(TileIndex tile)
|
||||
{
|
||||
@@ -516,10 +520,10 @@ void AnimateTile_Town(TileIndex tile)
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a town is close to a tile
|
||||
* @param tile TileIndex of the tile to query
|
||||
* @param dist maximum distance to be accepted
|
||||
* @returns true if the tile correspond to the distance criteria
|
||||
* Determines if a town is close to a tile.
|
||||
* @param tile TileIndex of the tile to query.
|
||||
* @param dist The maximum distance to be accepted.
|
||||
* @returns true if the tile is within the specified distance.
|
||||
*/
|
||||
static bool IsCloseToTown(TileIndex tile, uint dist)
|
||||
{
|
||||
@@ -528,10 +532,7 @@ static bool IsCloseToTown(TileIndex tile, uint dist)
|
||||
return DistanceManhattan(tile, t->xy) < dist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the sign(label) of the town after changes in
|
||||
* population (creation or growth or else)
|
||||
*/
|
||||
/** Resize the sign (label) of the town after it changes population. */
|
||||
void Town::UpdateVirtCoord()
|
||||
{
|
||||
this->UpdateLabel();
|
||||
@@ -556,6 +557,7 @@ void UpdateAllTownVirtCoords()
|
||||
}
|
||||
}
|
||||
|
||||
/** Clear the cached_name of all towns. */
|
||||
void ClearAllTownCachedNames()
|
||||
{
|
||||
for (Town *t : Town::Iterate()) {
|
||||
@@ -564,9 +566,9 @@ void ClearAllTownCachedNames()
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the towns population
|
||||
* @param t Town which population has changed
|
||||
* @param mod population change (can be positive or negative)
|
||||
* Change the town's population as recorded in the town cache, town label, and town directory.
|
||||
* @param t The town which has changed.
|
||||
* @param mod The population change (can be positive or negative).
|
||||
*/
|
||||
static void ChangePopulation(Town *t, int mod)
|
||||
{
|
||||
@@ -592,9 +594,9 @@ uint32 GetWorldPopulation()
|
||||
/**
|
||||
* Remove stations from nearby station list if a town is no longer in the catchment area of each.
|
||||
* To improve performance only checks stations that cover the provided house area (doesn't need to contain an actual house).
|
||||
* @param t Town to work on
|
||||
* @param tile Location of house area (north part)
|
||||
* @param flags BuildingFlags containing the size of house area
|
||||
* @param t Town to work on.
|
||||
* @param tile Location of house area (north tile).
|
||||
* @param flags BuildingFlags containing the size of house area.
|
||||
*/
|
||||
static void RemoveNearbyStations(Town *t, TileIndex tile, BuildingFlags flags)
|
||||
{
|
||||
@@ -615,14 +617,14 @@ static void RemoveNearbyStations(Town *t, TileIndex tile, BuildingFlags flags)
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for house completion stages progression
|
||||
* @param tile TileIndex of the house (or parts of it) to "grow"
|
||||
* Helper function for house construction stage progression.
|
||||
* @param tile TileIndex of the house (or parts of it) to construct.
|
||||
*/
|
||||
static void MakeSingleHouseBigger(TileIndex tile)
|
||||
static void AdvanceSingleHouseConstruction(TileIndex tile)
|
||||
{
|
||||
assert_tile(IsTileType(tile, MP_HOUSE), tile);
|
||||
|
||||
/* progress in construction stages */
|
||||
/* Progress in construction stages */
|
||||
IncHouseConstructionTick(tile);
|
||||
if (GetHouseConstructionTick(tile) != 0) return;
|
||||
|
||||
@@ -638,16 +640,16 @@ static void MakeSingleHouseBigger(TileIndex tile)
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the house advance in its construction stages until completion
|
||||
* @param tile TileIndex of house
|
||||
* Increase the construction stage of a house.
|
||||
* @param tile The tile of the house under construction.
|
||||
*/
|
||||
static void MakeTownHouseBigger(TileIndex tile)
|
||||
static void AdvanceHouseConstruction(TileIndex tile)
|
||||
{
|
||||
uint flags = HouseSpec::Get(GetHouseType(tile))->building_flags;
|
||||
if (flags & BUILDING_HAS_1_TILE) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0));
|
||||
if (flags & BUILDING_2_TILES_Y) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1));
|
||||
if (flags & BUILDING_2_TILES_X) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0));
|
||||
if (flags & BUILDING_HAS_4_TILES) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1));
|
||||
if (flags & BUILDING_HAS_1_TILE) AdvanceSingleHouseConstruction(TILE_ADDXY(tile, 0, 0));
|
||||
if (flags & BUILDING_2_TILES_Y) AdvanceSingleHouseConstruction(TILE_ADDXY(tile, 0, 1));
|
||||
if (flags & BUILDING_2_TILES_X) AdvanceSingleHouseConstruction(TILE_ADDXY(tile, 1, 0));
|
||||
if (flags & BUILDING_HAS_4_TILES) AdvanceSingleHouseConstruction(TILE_ADDXY(tile, 1, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -691,8 +693,8 @@ static void TileLoop_Town(TileIndex tile)
|
||||
if (house_id >= NEW_HOUSE_OFFSET && !NewHouseTileLoop(tile)) return;
|
||||
|
||||
if (!IsHouseCompleted(tile)) {
|
||||
/* Construction is not completed. See if we can go further in construction*/
|
||||
MakeTownHouseBigger(tile);
|
||||
/* Construction is not completed, so we advance a construction stage. */
|
||||
AdvanceHouseConstruction(tile);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -807,6 +809,12 @@ static void TileLoop_Town(TileIndex tile)
|
||||
cur_company.Restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function to clear a house tile.
|
||||
* @param tile The tile to clear.
|
||||
* @param flags Type of operation.
|
||||
* @return The cost of this operation or an error.
|
||||
*/
|
||||
static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags)
|
||||
{
|
||||
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
|
||||
@@ -959,6 +967,10 @@ static void ChangeTileOwner_Town(TileIndex, Owner, Owner)
|
||||
|
||||
static bool GrowTown(Town *t);
|
||||
|
||||
/**
|
||||
* Handle the town tick for a single town, by growing the town if desired.
|
||||
* @param t The town to try growing.
|
||||
*/
|
||||
static void TownTickHandler(Town *t)
|
||||
{
|
||||
if (HasBit(t->flags, TOWN_IS_GROWING)) {
|
||||
@@ -975,6 +987,7 @@ static void TownTickHandler(Town *t)
|
||||
}
|
||||
}
|
||||
|
||||
/** Iterate through all towns and call their tick handler. */
|
||||
void OnTick_Town()
|
||||
{
|
||||
if (_game_mode == GM_EDITOR) return;
|
||||
@@ -985,21 +998,22 @@ void OnTick_Town()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the RoadBits of a tile
|
||||
*
|
||||
* @note There are many other functions doing things like that.
|
||||
* @note Needs to be checked for needlessness.
|
||||
* @param tile The tile we want to analyse
|
||||
* @return The roadbits of the given tile
|
||||
* Return the RoadBits of a tile, ignoring depot and bay road stops.
|
||||
* @param tile The tile to check.
|
||||
* @return The roadbits of the given tile.
|
||||
*/
|
||||
static RoadBits GetTownRoadBits(TileIndex tile)
|
||||
{
|
||||
if (IsRoadDepotTile(tile) || IsStandardRoadStopTile(tile)) return ROAD_NONE;
|
||||
if (IsRoadDepotTile(tile) || IsBayRoadStopTile(tile)) return ROAD_NONE;
|
||||
if (!MayTownModifyRoad(tile)) return ROAD_NONE;
|
||||
|
||||
return GetAnyRoadBits(tile, RTT_ROAD, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the road type that towns should build at this current moment.
|
||||
* They may have built a different type in the past.
|
||||
*/
|
||||
RoadType GetTownRoadType()
|
||||
{
|
||||
RoadType best_rt = ROADTYPE_ROAD;
|
||||
@@ -1048,10 +1062,10 @@ bool MayTownModifyRoad(TileIndex tile)
|
||||
* Assuming a road from (tile - TileOffsByDiagDir(dir)) to tile,
|
||||
* is there a parallel road left or right of it within distance dist_multi?
|
||||
*
|
||||
* @param tile current tile
|
||||
* @param dir target direction
|
||||
* @param dist_multi distance multiplayer
|
||||
* @return true if there is a parallel road
|
||||
* @param tile The current tile.
|
||||
* @param dir The target direction.
|
||||
* @param dist_multi The distance multiplier.
|
||||
* @return true if there is a parallel road.
|
||||
*/
|
||||
static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi)
|
||||
{
|
||||
@@ -1080,12 +1094,12 @@ static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dis
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Road is allowed on a given tile
|
||||
* Check if a Road is allowed on a given tile.
|
||||
*
|
||||
* @param t The current town
|
||||
* @param tile The target tile
|
||||
* @param dir The direction in which we want to extend the town
|
||||
* @return true if it is allowed else false
|
||||
* @param t The current town.
|
||||
* @param tile The target tile.
|
||||
* @param dir The direction in which we want to extend the town.
|
||||
* @return true if it is allowed.
|
||||
*/
|
||||
static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
|
||||
{
|
||||
@@ -1157,13 +1171,12 @@ static void LevelTownLand(TileIndex tile)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the RoadBits of a grid tile
|
||||
* Generate the RoadBits of a grid tile.
|
||||
*
|
||||
* @param t current town
|
||||
* @param tile tile in reference to the town
|
||||
* @param dir The direction to which we are growing ATM
|
||||
* @return the RoadBit of the current tile regarding
|
||||
* the selected town layout
|
||||
* @param t The current town.
|
||||
* @param tile The tile in reference to the town.
|
||||
* @param dir The direction to which we are growing.
|
||||
* @return The RoadBit of the current tile regarding the selected town layout.
|
||||
*/
|
||||
static RoadBits GetTownRoadGridElement(Town *t, TileIndex tile, DiagDirection dir)
|
||||
{
|
||||
@@ -1220,9 +1233,9 @@ static RoadBits GetTownRoadGridElement(Town *t, TileIndex tile, DiagDirection di
|
||||
* next to the current tile. If there are enough
|
||||
* add another house.
|
||||
*
|
||||
* @param t The current town
|
||||
* @param tile The target tile for the extra house
|
||||
* @return true if an extra house has been added
|
||||
* @param t The current town.
|
||||
* @param tile The target tile for the extra house.
|
||||
* @return true if an extra house has been added.
|
||||
*/
|
||||
static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
|
||||
{
|
||||
@@ -1261,10 +1274,10 @@ static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
|
||||
/**
|
||||
* Grows the town with a road piece.
|
||||
*
|
||||
* @param t The current town
|
||||
* @param tile The current tile
|
||||
* @param rcmd The RoadBits we want to build on the tile
|
||||
* @return true if the RoadBits have been added else false
|
||||
* @param t The current town.
|
||||
* @param tile The current tile.
|
||||
* @param rcmd The RoadBits we want to build on the tile.
|
||||
* @return true if the RoadBits have been added.
|
||||
*/
|
||||
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
|
||||
{
|
||||
@@ -1519,10 +1532,10 @@ static bool GrowTownWithTunnel(const Town *t, const TileIndex tile, const DiagDi
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether at least one surrounding roads allows to build a house here
|
||||
* Checks whether at least one surrounding road allows to build a house here.
|
||||
*
|
||||
* @param t the tile where the house will be built
|
||||
* @return true if at least one surrounding roadtype allows building houses here
|
||||
* @param t The tile where the house will be built.
|
||||
* @return true if at least one surrounding roadtype allows building houses here.
|
||||
*/
|
||||
static inline bool RoadTypesAllowHouseHere(TileIndex t)
|
||||
{
|
||||
@@ -1886,10 +1899,10 @@ static bool CanFollowRoad(const Town *t, TileIndex tile, DiagDirection dir)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns "growth" if a house was built, or no if the build failed.
|
||||
* @param t town to inquiry
|
||||
* @param tile to inquiry
|
||||
* @return true if town expansion was possible
|
||||
* Try to grow a town at a given road tile.
|
||||
* @param t The town to grow.
|
||||
* @param tile The road tile to try growing from.
|
||||
* @return true if we successfully expanded the town.
|
||||
*/
|
||||
static bool GrowTownAtRoad(Town *t, TileIndex tile)
|
||||
{
|
||||
@@ -1995,9 +2008,9 @@ static RoadBits GenRandomRoadBits()
|
||||
}
|
||||
|
||||
/**
|
||||
* Grow the town
|
||||
* @param t town to grow
|
||||
* @return true iff something (house, road, bridge, ...) was built
|
||||
* Grow the town.
|
||||
* @param t The town to grow
|
||||
* @return true if we successfully grew the town with a road or house.
|
||||
*/
|
||||
static bool GrowTown(Town *t)
|
||||
{
|
||||
@@ -2055,6 +2068,10 @@ static bool GrowTown(Town *t)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the cached town zone radii of a town, based on the number of houses.
|
||||
* @param t The town to update.
|
||||
*/
|
||||
void UpdateTownRadius(Town *t)
|
||||
{
|
||||
static const uint32 _town_squared_town_zone_radius_data[23][5] = {
|
||||
@@ -2145,15 +2162,15 @@ static void UpdateTownGrowthRate(Town *t);
|
||||
static void UpdateTownGrowth(Town *t);
|
||||
|
||||
/**
|
||||
* Does the actual town creation.
|
||||
* Actually create a town.
|
||||
*
|
||||
* @param t The town
|
||||
* @param tile Where to put it
|
||||
* @param townnameparts The town name
|
||||
* @param size Parameter for size determination
|
||||
* @param city whether to build a city or town
|
||||
* @param layout the (road) layout of the town
|
||||
* @param manual was the town placed manually?
|
||||
* @param t The town.
|
||||
* @param tile Where to put it.
|
||||
* @param townnameparts The town name.
|
||||
* @param size The preset size of the town.
|
||||
* @param city Should we create a city?
|
||||
* @param layout The road layout of the town.
|
||||
* @param manual Was the town placed manually?
|
||||
*/
|
||||
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
|
||||
{
|
||||
@@ -2227,9 +2244,9 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if it's possible to place a town at given tile
|
||||
* @param tile tile to check
|
||||
* @return error value or zero cost
|
||||
* Check if it's possible to place a town on a given tile.
|
||||
* @param tile The tile to check.
|
||||
* @return A zero cost if allowed, otherwise an error.
|
||||
*/
|
||||
static CommandCost TownCanBePlacedHere(TileIndex tile, bool city)
|
||||
{
|
||||
@@ -2269,8 +2286,8 @@ static CommandCost TownCanBePlacedHere(TileIndex tile, bool city)
|
||||
|
||||
/**
|
||||
* Verifies this custom name is unique. Only custom names are checked.
|
||||
* @param name name to check
|
||||
* @return is this name unique?
|
||||
* @param name The name to check.
|
||||
* @return true if the name is unique
|
||||
*/
|
||||
static bool IsUniqueTownName(const char *name)
|
||||
{
|
||||
@@ -2291,7 +2308,7 @@ static bool IsUniqueTownName(const char *name)
|
||||
* 6 use random location (randomize \c tile )
|
||||
* @param p2 town name parts
|
||||
* @param text Custom name for the town. If empty, the town name parts will be used.
|
||||
* @return the cost of this operation or an error
|
||||
* @return The cost of this operation or an error.
|
||||
*/
|
||||
CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
@@ -2413,9 +2430,9 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
* interpenetrate their road networks will not mesh nicely; this
|
||||
* function adjusts a tile so that it aligns properly.
|
||||
*
|
||||
* @param tile the tile to start at
|
||||
* @param layout which town layout algo is in effect
|
||||
* @return the adjusted tile
|
||||
* @param tile The tile to start at.
|
||||
* @param layout The town layout in effect.
|
||||
* @return The adjusted tile.
|
||||
*/
|
||||
static TileIndex AlignTileToGrid(TileIndex tile, TownLayout layout)
|
||||
{
|
||||
@@ -2431,9 +2448,9 @@ static TileIndex AlignTileToGrid(TileIndex tile, TownLayout layout)
|
||||
* interpenetrate their road networks will not mesh nicely; this
|
||||
* function tells you if a tile is properly aligned.
|
||||
*
|
||||
* @param tile the tile to start at
|
||||
* @param layout which town layout algo is in effect
|
||||
* @return true if the tile is in the correct location
|
||||
* @param tile The tile to start at.
|
||||
* @param layout The town layout in effect.
|
||||
* @return true if the tile is in the correct location.
|
||||
*/
|
||||
static bool IsTileAlignedToGrid(TileIndex tile, TownLayout layout)
|
||||
{
|
||||
@@ -2486,8 +2503,7 @@ static bool FindFurthestFromWater(TileIndex tile, void *user_data)
|
||||
}
|
||||
|
||||
/**
|
||||
* CircularTileSearch callback; finds the nearest land tile
|
||||
*
|
||||
* CircularTileSearch callback to find the nearest land tile.
|
||||
* @param tile Start looking from this tile
|
||||
*/
|
||||
static bool FindNearestEmptyLand(TileIndex tile, void *)
|
||||
@@ -2498,7 +2514,7 @@ static bool FindNearestEmptyLand(TileIndex tile, void *)
|
||||
/**
|
||||
* Given a spot on the map (presumed to be a water tile), find a good
|
||||
* coastal spot to build a city. We don't want to build too close to
|
||||
* the edge if we can help it (since that retards city growth) hence
|
||||
* the edge if we can help it (since that inhibits city growth) hence
|
||||
* the search within a search within a search. O(n*m^2), where n is
|
||||
* how far to search for land, and m is how far inland to look for a
|
||||
* flat spot.
|
||||
@@ -2568,11 +2584,10 @@ static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size
|
||||
static const byte _num_initial_towns[4] = {5, 11, 23, 46}; // very low, low, normal, high
|
||||
|
||||
/**
|
||||
* This function will generate a certain amount of towns, with a certain layout
|
||||
* It can be called from the scenario editor (i.e.: generate Random Towns)
|
||||
* as well as from world creation.
|
||||
* @param layout which towns will be set to, when created
|
||||
* @return true if towns have been successfully created
|
||||
* Generate a number of towns with a given layout.
|
||||
* This function is used by the Random Towns button in Scenario Editor as well as in world generation.
|
||||
* @param layout The road layout to build.
|
||||
* @return true if towns have been successfully created.
|
||||
*/
|
||||
bool GenerateTowns(TownLayout layout)
|
||||
{
|
||||
@@ -2667,13 +2682,13 @@ HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
|
||||
|
||||
/**
|
||||
* Clears tile and builds a house or house part.
|
||||
* @param tile tile index
|
||||
* @param t The town to clear the house for
|
||||
* @param counter of construction step
|
||||
* @param stage of construction (used for drawing)
|
||||
* @param type of house. Index into house specs array
|
||||
* @param random_bits required for newgrf houses
|
||||
* @pre house can be built here
|
||||
* @param tile The tile to build upon.
|
||||
* @param t The town which will own the house.
|
||||
* @param counter The construction stage counter for the house.
|
||||
* @param stage The current construction stage of the house.
|
||||
* @param type The type of house.
|
||||
* @param random_bits Random bits for newgrf houses to use.
|
||||
* @pre The house can be built here.
|
||||
*/
|
||||
static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
|
||||
{
|
||||
@@ -2689,35 +2704,35 @@ static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byt
|
||||
|
||||
|
||||
/**
|
||||
* Write house information into the map. For houses > 1 tile, all tiles are marked.
|
||||
* @param t tile index
|
||||
* Write house information into the map. For multi-tile houses, all tiles are marked.
|
||||
* @param town The town related to this house
|
||||
* @param counter of construction step
|
||||
* @param stage of construction (used for drawing)
|
||||
* @param type of house. Index into house specs array
|
||||
* @param random_bits required for newgrf houses
|
||||
* @pre house can be built here
|
||||
* @param t The tile to build on. If a multi-tile house, this is the northern-most tile.
|
||||
* @param counter The counter of the construction stage.
|
||||
* @param stage The current construction stage.
|
||||
* @param The type of house.
|
||||
* @param random_bits Random bits for newgrf houses to use.
|
||||
* @pre The house can be built here.
|
||||
*/
|
||||
static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, HouseID type, byte random_bits)
|
||||
static void MakeTownHouse(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
|
||||
{
|
||||
BuildingFlags size = HouseSpec::Get(type)->building_flags;
|
||||
|
||||
ClearMakeHouseTile(t, town, counter, stage, type, random_bits);
|
||||
if (size & BUILDING_2_TILES_Y) ClearMakeHouseTile(t + TileDiffXY(0, 1), town, counter, stage, ++type, random_bits);
|
||||
if (size & BUILDING_2_TILES_X) ClearMakeHouseTile(t + TileDiffXY(1, 0), town, counter, stage, ++type, random_bits);
|
||||
if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), town, counter, stage, ++type, random_bits);
|
||||
ClearMakeHouseTile(tile, t, counter, stage, type, random_bits);
|
||||
if (size & BUILDING_2_TILES_Y) ClearMakeHouseTile(tile + TileDiffXY(0, 1), t, counter, stage, ++type, random_bits);
|
||||
if (size & BUILDING_2_TILES_X) ClearMakeHouseTile(tile + TileDiffXY(1, 0), t, counter, stage, ++type, random_bits);
|
||||
if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(tile + TileDiffXY(1, 1), t, counter, stage, ++type, random_bits);
|
||||
|
||||
if (!_generating_world) {
|
||||
ForAllStationsAroundTiles(TileArea(t, (size & BUILDING_2_TILES_X) ? 2 : 1, (size & BUILDING_2_TILES_Y) ? 2 : 1), [town](Station *st, TileIndex tile) {
|
||||
town->stations_near.insert(st);
|
||||
ForAllStationsAroundTiles(TileArea(tile, (size & BUILDING_2_TILES_X) ? 2 : 1, (size & BUILDING_2_TILES_Y) ? 2 : 1), [t](Station *st, TileIndex tile) {
|
||||
t->stations_near.insert(st);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (_record_house_coords) {
|
||||
_record_house_rect.left = std::min(_record_house_rect.left, (int)TileX(t));
|
||||
_record_house_rect.top = std::min(_record_house_rect.top, (int)TileY(t));
|
||||
_record_house_rect.right = std::max(_record_house_rect.right, (int)TileX(t) + ((size & BUILDING_2_TILES_X) ? 2 : 1));
|
||||
_record_house_rect.bottom = std::max(_record_house_rect.bottom, (int)TileY(t) + ((size & BUILDING_2_TILES_Y) ? 2 : 1));
|
||||
_record_house_rect.left = std::min(_record_house_rect.left, (int)TileX(tile));
|
||||
_record_house_rect.top = std::min(_record_house_rect.top, (int)TileY(tile));
|
||||
_record_house_rect.right = std::max(_record_house_rect.right, (int)TileX(tile) + ((size & BUILDING_2_TILES_X) ? 2 : 1));
|
||||
_record_house_rect.bottom = std::max(_record_house_rect.bottom, (int)TileY(tile) + ((size & BUILDING_2_TILES_Y) ? 2 : 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3042,10 +3057,10 @@ CommandCost CmdBuildHouse(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to build a house at this tile
|
||||
* @param t town the house will belong to
|
||||
* @param tile where the house will be built
|
||||
* @return false iff no house can be built at this tile
|
||||
* Tries to build a house at this tile.
|
||||
* @param t The town the house will belong to.
|
||||
* @param tile The tile to try building on.
|
||||
* @return false iff no house can be built on this tile.
|
||||
*/
|
||||
static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
{
|
||||
@@ -3163,14 +3178,19 @@ TileIndexDiff GetHouseNorthPart(HouseID &house)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a town house.
|
||||
* @param t The town which owns the house.
|
||||
* @param tile The tile to clear.
|
||||
*/
|
||||
void ClearTownHouse(Town *t, TileIndex tile)
|
||||
{
|
||||
assert_tile(IsTileType(tile, MP_HOUSE), tile);
|
||||
|
||||
HouseID house = GetHouseType(tile);
|
||||
|
||||
/* need to align the tile to point to the upper left corner of the house */
|
||||
tile += GetHouseNorthPart(house); // modifies house to the ID of the north tile
|
||||
/* The northernmost tile of the house is the main house. */
|
||||
tile += GetHouseNorthPart(house);
|
||||
|
||||
const HouseSpec *hs = HouseSpec::Get(house);
|
||||
|
||||
@@ -3546,6 +3566,12 @@ const byte _town_action_costs[TACT_COUNT] = {
|
||||
2, 4, 9, 35, 48, 53, 117, 175
|
||||
};
|
||||
|
||||
/**
|
||||
* Perform the "small advertising campaign" town action.
|
||||
* @param t The town to advertise in.
|
||||
* @param flags Type of operation.
|
||||
* @return An empty cost.
|
||||
*/
|
||||
static CommandCost TownActionAdvertiseSmall(Town *t, DoCommandFlag flags)
|
||||
{
|
||||
if (flags & DC_EXEC) {
|
||||
@@ -3554,6 +3580,12 @@ static CommandCost TownActionAdvertiseSmall(Town *t, DoCommandFlag flags)
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the "medium advertising campaign" town action.
|
||||
* @param t The town to advertise in.
|
||||
* @param flags Type of operation.
|
||||
* @return An empty cost.
|
||||
*/
|
||||
static CommandCost TownActionAdvertiseMedium(Town *t, DoCommandFlag flags)
|
||||
{
|
||||
if (flags & DC_EXEC) {
|
||||
@@ -3562,6 +3594,12 @@ static CommandCost TownActionAdvertiseMedium(Town *t, DoCommandFlag flags)
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the "large advertising campaign" town action.
|
||||
* @param t The town to advertise in.
|
||||
* @param flags Type of operation.
|
||||
* @return An empty cost.
|
||||
*/
|
||||
static CommandCost TownActionAdvertiseLarge(Town *t, DoCommandFlag flags)
|
||||
{
|
||||
if (flags & DC_EXEC) {
|
||||
@@ -3570,6 +3608,12 @@ static CommandCost TownActionAdvertiseLarge(Town *t, DoCommandFlag flags)
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the "local road reconstruction" town action.
|
||||
* @param t The town to grief in.
|
||||
* @param flags Type of operation.
|
||||
* @return An empty cost.
|
||||
*/
|
||||
static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
|
||||
{
|
||||
/* Check if the company is allowed to fund new roads. */
|
||||
@@ -3594,9 +3638,9 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
|
||||
/**
|
||||
* Check whether the land can be cleared.
|
||||
* @param tile Tile to check.
|
||||
* @return The tile can be cleared.
|
||||
* @return true if the tile can be cleared.
|
||||
*/
|
||||
static bool TryClearTile(TileIndex tile)
|
||||
static bool CheckClearTile(TileIndex tile)
|
||||
{
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
|
||||
CommandCost r = DoCommand(tile, 0, 0, DC_TOWN, CMD_LANDSCAPE_CLEAR);
|
||||
@@ -3631,7 +3675,7 @@ static bool SearchTileForStatue(TileIndex tile, void *user_data)
|
||||
if (IsBridgeAbove(tile)) return false;
|
||||
|
||||
/* A clear-able open space is always preferred. */
|
||||
if ((IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) && TryClearTile(tile)) {
|
||||
if ((IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) && CheckClearTile(tile)) {
|
||||
statue_data->best_position = tile;
|
||||
return true;
|
||||
}
|
||||
@@ -3641,7 +3685,7 @@ static bool SearchTileForStatue(TileIndex tile, void *user_data)
|
||||
/* Searching inside the inner circle. */
|
||||
if (statue_data->tile_count <= STATUE_NUMBER_INNER_TILES) {
|
||||
/* Save first house in inner circle. */
|
||||
if (house && statue_data->best_position == INVALID_TILE && TryClearTile(tile)) {
|
||||
if (house && statue_data->best_position == INVALID_TILE && CheckClearTile(tile)) {
|
||||
statue_data->best_position = tile;
|
||||
}
|
||||
|
||||
@@ -3651,7 +3695,7 @@ static bool SearchTileForStatue(TileIndex tile, void *user_data)
|
||||
|
||||
/* Searching outside the circle, just pick the first possible spot. */
|
||||
statue_data->best_position = tile; // Is optimistic, the condition below must also hold.
|
||||
return house && TryClearTile(tile);
|
||||
return house && CheckClearTile(tile);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3680,6 +3724,12 @@ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags)
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the "fund new buildings" town action.
|
||||
* @param t The town to fund buildings in.
|
||||
* @param flags Type of operation.
|
||||
* @return An empty cost.
|
||||
*/
|
||||
static CommandCost TownActionFundBuildings(Town *t, DoCommandFlag flags)
|
||||
{
|
||||
/* Check if it's allowed to buy the rights */
|
||||
@@ -3707,6 +3757,12 @@ static CommandCost TownActionFundBuildings(Town *t, DoCommandFlag flags)
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the "buy exclusive transport rights" town action.
|
||||
* @param t The town to buy exclusivity in.
|
||||
* @param flags Type of operation.
|
||||
* @return An empty cost.
|
||||
*/
|
||||
static CommandCost TownActionBuyRights(Town *t, DoCommandFlag flags)
|
||||
{
|
||||
/* Check if it's allowed to buy the rights */
|
||||
@@ -3734,6 +3790,12 @@ static CommandCost TownActionBuyRights(Town *t, DoCommandFlag flags)
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the "bribe" town action.
|
||||
* @param t The town to bribe.
|
||||
* @param flags Type of operation.
|
||||
* @return An empty cost.
|
||||
*/
|
||||
static CommandCost TownActionBribe(Town *t, DoCommandFlag flags)
|
||||
{
|
||||
if (flags & DC_EXEC) {
|
||||
@@ -3785,11 +3847,11 @@ static TownActionProc * const _town_action_proc[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a list of available actions to do at a town.
|
||||
* @param nump if not nullptr add put the number of available actions in it
|
||||
* @param cid the company that is querying the town
|
||||
* @param t the town that is queried
|
||||
* @return bitmasked value of enabled actions
|
||||
* Get a list of available town authority actions.
|
||||
* @param nump if not nullptr, store the number of available actions
|
||||
* @param cid The company that is querying the town.
|
||||
* @param t The town that is queried.
|
||||
* @return The bitmasked value of enabled actions.
|
||||
*/
|
||||
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
|
||||
{
|
||||
@@ -3964,6 +4026,10 @@ static void ForAllStationsNearTown(Town *t, Func func)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Monthly callback to update town and station ratings.
|
||||
* @param t The town to update.
|
||||
*/
|
||||
static void UpdateTownRating(Town *t)
|
||||
{
|
||||
if (_cheats.town_rating.value) return;
|
||||
@@ -4152,22 +4218,6 @@ static void UpdateTownGrowth(Town *t)
|
||||
SetBit(t->flags, TOWN_IS_GROWING);
|
||||
}
|
||||
|
||||
static void UpdateTownAmounts(Town *t)
|
||||
{
|
||||
for (auto &supplied : t->supplied) supplied.NewMonth();
|
||||
for (auto &received : t->received) received.NewMonth();
|
||||
if (t->fund_buildings_months != 0) t->fund_buildings_months--;
|
||||
|
||||
SetWindowDirty(WC_TOWN_VIEW, t->index);
|
||||
}
|
||||
|
||||
static void UpdateTownUnwanted(Town *t)
|
||||
{
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (t->unwanted[c->index] > 0) t->unwanted[c->index]--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile
|
||||
* @param tile The tile where the station shall be constructed.
|
||||
@@ -4395,16 +4445,27 @@ CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType
|
||||
void TownsMonthlyLoop()
|
||||
{
|
||||
for (Town *t : Town::Iterate()) {
|
||||
/* Check for active town actions and decrement their counters. */
|
||||
if (t->road_build_months != 0) t->road_build_months--;
|
||||
if (t->fund_buildings_months != 0) t->fund_buildings_months--;
|
||||
|
||||
if (t->exclusive_counter != 0) {
|
||||
if (--t->exclusive_counter == 0) t->exclusivity = INVALID_COMPANY;
|
||||
}
|
||||
|
||||
UpdateTownAmounts(t);
|
||||
/* Check for active failed bribe cooloff periods and decrement them. */
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (t->unwanted[c->index] > 0) t->unwanted[c->index]--;
|
||||
}
|
||||
|
||||
/* Update cargo statistics. */
|
||||
for (auto &supplied : t->supplied) supplied.NewMonth();
|
||||
for (auto &received : t->received) received.NewMonth();
|
||||
|
||||
UpdateTownGrowth(t);
|
||||
UpdateTownRating(t);
|
||||
UpdateTownUnwanted(t);
|
||||
|
||||
SetWindowDirty(WC_TOWN_VIEW, t->index);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user