Merge branch 'master' into enhanced_viewport_overlay

Notes on conflict resolution:
* MarkTileDirtyByTile gained an extra param on both sides of the merge
  Move bridge level offset to be after zoom level param, as it's used less.
* Add zoom level params to MarkBridgeDirty functions
* Fix undefined behaviour in colour_index cycling in ViewportMapDraw

Conflicts:
	src/clear_cmd.cpp
	src/pbs.cpp
	src/rail_cmd.cpp
	src/toolbar_gui.cpp
	src/train_cmd.cpp
	src/vehicle.cpp
	src/viewport.cpp
	src/viewport_func.h
This commit is contained in:
Jonathan G Rennison
2015-08-05 21:25:13 +01:00
220 changed files with 5428 additions and 4324 deletions

View File

@@ -377,7 +377,8 @@ void Town::UpdateVirtCoord()
SetDParam(0, this->index);
SetDParam(1, this->cache.population);
this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE,
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN);
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN,
STR_VIEWPORT_TOWN);
SetWindowDirty(WC_TOWN_VIEW, this->index);
}
@@ -1296,13 +1297,56 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
GrowTownWithRoad(t1, tile, rcmd);
}
/**
* Checks whether a road can be followed or is a dead end, that can not be extended to the next tile.
* This only checks trivial but often cases.
* @param tile Start tile for road.
* @param dir Direction for road to follow or build.
* @return true If road is or can be connected in the specified direction.
*/
static bool CanFollowRoad(TileIndex tile, DiagDirection dir)
{
TileIndex target_tile = tile + TileOffsByDiagDir(dir);
if (!IsValidTile(target_tile)) return false;
if (HasTileWaterGround(target_tile)) return false;
RoadBits target_rb = GetTownRoadBits(target_tile);
if (_settings_game.economy.allow_town_roads || _generating_world) {
/* Check whether a road connection exists or can be build. */
switch (GetTileType(target_tile)) {
case MP_ROAD:
return target_rb != ROAD_NONE;
case MP_STATION:
return IsDriveThroughStopTile(target_tile);
case MP_TUNNELBRIDGE:
return GetTunnelBridgeTransportType(target_tile) == TRANSPORT_ROAD;
case MP_HOUSE:
case MP_INDUSTRY:
case MP_OBJECT:
return false;
default:
/* Checked for void and water earlier */
return true;
}
} else {
/* Check whether a road connection already exists,
* and it leads somewhere else. */
RoadBits back_rb = DiagDirToRoadBits(ReverseDiagDir(dir));
return (target_rb & back_rb) != 0 && (target_rb & ~back_rb) != 0;
}
}
/**
* Returns "growth" if a house was built, or no if the build failed.
* @param t town to inquiry
* @param tile to inquiry
* @return something other than zero(0)if town expansion was possible
* @return true if town expansion was possible
*/
static int GrowTownAtRoad(Town *t, TileIndex tile)
static bool GrowTownAtRoad(Town *t, TileIndex tile)
{
/* Special case.
* @see GrowTownInTile Check the else if
@@ -1339,7 +1383,7 @@ static int GrowTownAtRoad(Town *t, TileIndex tile)
* and return if no more road blocks available */
if (IsValidDiagDirection(target_dir)) cur_rb &= ~DiagDirToRoadBits(ReverseDiagDir(target_dir));
if (cur_rb == ROAD_NONE) {
return _grow_town_result;
return _grow_town_result == GROWTH_SUCCEED;
}
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
@@ -1348,14 +1392,22 @@ static int GrowTownAtRoad(Town *t, TileIndex tile)
} else {
/* Select a random bit from the blockmask, walk a step
* and continue the search from there. */
do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir)));
do {
if (cur_rb == ROAD_NONE) return false;
RoadBits target_bits;
do {
target_dir = RandomDiagDir();
target_bits = DiagDirToRoadBits(target_dir);
} while (!(cur_rb & target_bits));
cur_rb &= ~target_bits;
} while (!CanFollowRoad(tile, target_dir));
}
tile = TileAddByDiagDir(tile, target_dir);
if (IsTileType(tile, MP_ROAD) && !IsRoadDepot(tile) && HasTileRoadType(tile, ROADTYPE_ROAD)) {
/* Don't allow building over roads of other cities */
if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN) && Town::GetByTile(tile) != t) {
_grow_town_result = GROWTH_SUCCEED;
return false;
} else if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_NONE) && _game_mode == GM_EDITOR) {
/* If we are in the SE, and this road-piece has no town owner yet, it just found an
* owner :) (happy happy happy road now) */
@@ -1367,7 +1419,7 @@ static int GrowTownAtRoad(Town *t, TileIndex tile)
/* Max number of times is checked. */
} while (--_grow_town_result >= 0);
return (_grow_town_result == -2);
return _grow_town_result == GROWTH_SUCCEED - 1;
}
/**
@@ -1389,7 +1441,7 @@ static RoadBits GenRandomRoadBits()
/**
* Grow the town
* @param t town to grow
* @return true iff a house was built
* @return true iff something (house, road, bridge, ...) was built
*/
static bool GrowTown(Town *t)
{
@@ -1418,9 +1470,9 @@ static bool GrowTown(Town *t)
const TileIndexDiffC *ptr;
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
if (GetTownRoadBits(tile) != ROAD_NONE) {
int r = GrowTownAtRoad(t, tile);
bool success = GrowTownAtRoad(t, tile);
cur_company.Restore();
return r != 0;
return success;
}
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
}