From 05578c759eae30f627eb72906bfdce597342f642 Mon Sep 17 00:00:00 2001 From: Pavel Stupnikov Date: Sun, 1 Mar 2015 04:19:50 +0300 Subject: [PATCH 1/3] hs fixed --HG-- branch : openttd --- src/town_cmd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 18ca24ce5b..82ee5fe14e 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1300,7 +1300,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t * 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 something other than zero(0) if town expansion was possible */ static int GrowTownAtRoad(Town *t, TileIndex tile) { @@ -1339,7 +1339,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)) { @@ -1355,7 +1355,7 @@ static int GrowTownAtRoad(Town *t, TileIndex tile) 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; + _grow_town_result = GROWTH_SEARCH_STOPPED; } 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) */ @@ -1389,7 +1389,7 @@ static RoadBits GenRandomRoadBits() /** * Grow the town * @param t town to grow - * @return true iff a house was built + * @return true iff something was built (house, road or bridge) */ static bool GrowTown(Town *t) { From 9287d9d0ed4970f49866c525a2568a1840fa0aeb Mon Sep 17 00:00:00 2001 From: Pavel Stupnikov Date: Thu, 5 Mar 2015 03:54:24 +0300 Subject: [PATCH 2/3] less cycle skips patch --HG-- branch : openttd --- src/rev.cpp | 12 ++++++---- src/town_cmd.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/rev.cpp b/src/rev.cpp index afd8bb8f12..880fbf4842 100644 --- a/src/rev.cpp +++ b/src/rev.cpp @@ -1,4 +1,4 @@ -/* $Id: rev.cpp.in 26440 2014-04-01 18:33:16Z frosch $ */ +/* $Id: rev.cpp.in 26482 2014-04-23 20:13:33Z rubidium $ */ /* * This file is part of OpenTTD. @@ -13,6 +13,8 @@ #include "core/bitmath_func.hpp" #include "rev.h" +#include "safeguards.h" + /** * Is this version of OpenTTD a release version? * @return True if it is a release version. @@ -37,7 +39,7 @@ bool IsReleasedVersion() * norev000 is for non-releases that are made on systems without * subversion or sources that are not a checkout of subversion. */ -const char _openttd_revision[] = "1.4.0"; +const char _openttd_revision[] = "h318731efM-openttd"; /** * The text version of OpenTTD's build date. @@ -55,7 +57,7 @@ const char _openttd_build_date[] = __DATE__ " " __TIME__; * (compiling from sources without any version control software) * and 2 is for modified revision. */ -const byte _openttd_revision_modified = 0; +const byte _openttd_revision_modified = 2; /** * The NewGRF revision of OTTD: @@ -70,11 +72,11 @@ const byte _openttd_revision_modified = 0; * final release will always have a lower version number than the released * version, thus making comparisons on specific revisions easy. */ -const uint32 _openttd_newgrf_version = 1 << 28 | 4 << 24 | 0 << 20 | 1 << 19 | (26440 & ((1 << 19) - 1)); +const uint32 _openttd_newgrf_version = 1 << 28 | 5 << 24 | 0 << 20 | 0 << 19 | (0 & ((1 << 19) - 1)); #ifdef __MORPHOS__ /** * Variable used by MorphOS to show the version. */ -extern const char morphos_versions_tag[] = "$VER: OpenTTD 1.4.0 (02.04.14) OpenTTD Team [MorphOS, PowerPC]"; +extern const char morphos_versions_tag[] = "$VER: OpenTTD h318731efM-openttd (05.03.15) OpenTTD Team [MorphOS, PowerPC]"; #endif diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 82ee5fe14e..d4bc09e657 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1296,6 +1296,47 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t GrowTownWithRoad(t1, tile, rcmd); } +/** + * Checks whether it makes sense to go in particular direction for town expansion. + * Does a simple test for most obvious and common things only. + * @param tile search is currently at + * @param dir direction in which it indends to go + * @return true if is worth going in that direction + */ +static bool CanGrowTownInDirection(TileIndex tile, DiagDirection dir) { + TileIndex target_tile = tile + TileOffsByDiagDir(dir); + if (HasTileWaterGround(target_tile)) return false; + if (!IsValidTile(target_tile)) return false; + RoadBits target_rb = GetTownRoadBits(target_tile); + + if (_settings_game.economy.allow_town_roads) { + switch (GetTileType(target_tile)) { + case MP_ROAD: { + if (target_rb == ROAD_NONE) { + /* can't build extra roads here (depot, standard station, etc) */ + return false; + } + break; + } + case MP_HOUSE: + case MP_STATION: + case MP_INDUSTRY: + case MP_OBJECT: + /* checked for void and water earlier */ + return false; + + default:; + } + } else { + /* we can't build roads so bailing out if there is no way + * back or it ends with half-road (i.e. back is the only way) */ + RoadBits back_rb = DiagDirToRoadBits(ReverseDiagDir(dir)); + if (!(target_rb & back_rb) || !(target_rb & ~back_rb)) + return false; + } + return true; +} + /** * Returns "growth" if a house was built, or no if the build failed. * @param t town to inquiry @@ -1346,9 +1387,21 @@ static int GrowTownAtRoad(Town *t, TileIndex tile) /* Only build in the direction away from the tunnel or bridge. */ target_dir = ReverseDiagDir(GetTunnelBridgeDirection(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))); + /* Select a random bit from the blockmask, and check whether + * we can grow in that direction. */ + RoadBits dir_rb = ROAD_NONE; + do { + // excluding direction that failed check + cur_rb &= ~dir_rb; + if (cur_rb == ROAD_NONE) { + return GROWTH_SEARCH_STOPPED; + } + // selecting random direction + do { + target_dir = RandomDiagDir(); + dir_rb = DiagDirToRoadBits(target_dir); + } while (!(cur_rb & dir_rb)); + } while (!CanGrowTownInDirection(tile, target_dir)); } tile = TileAddByDiagDir(tile, target_dir); From 6e6f033afce8f85c1971aedf804598112c6b7920 Mon Sep 17 00:00:00 2001 From: Pavel Stupnikov Date: Thu, 5 Mar 2015 03:56:32 +0300 Subject: [PATCH 3/3] undo no-hs patch to get clear diff --HG-- branch : openttd --- src/town_cmd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d4bc09e657..38145d6e68 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1341,7 +1341,7 @@ static bool CanGrowTownInDirection(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 something other than zero(0) if town expansion was possible + * @return something other than zero(0)if town expansion was possible */ static int GrowTownAtRoad(Town *t, TileIndex tile) { @@ -1380,7 +1380,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 == GROWTH_SUCCEED); + return _grow_town_result; } if (IsTileType(tile, MP_TUNNELBRIDGE)) { @@ -1408,7 +1408,7 @@ static int GrowTownAtRoad(Town *t, TileIndex tile) 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_SEARCH_STOPPED; + _grow_town_result = GROWTH_SUCCEED; } 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) */ @@ -1442,7 +1442,7 @@ static RoadBits GenRandomRoadBits() /** * Grow the town * @param t town to grow - * @return true iff something was built (house, road or bridge) + * @return true iff a house was built */ static bool GrowTown(Town *t) {