diff options
author | planetmaker <planetmaker@openttd.org> | 2013-10-17 21:22:39 +0000 |
---|---|---|
committer | planetmaker <planetmaker@openttd.org> | 2013-10-17 21:22:39 +0000 |
commit | 0a481d5ea66ec04c85ec0c6cd9beb098c84d6345 (patch) | |
tree | 0a582eafe8c219c24909824a93201af9584cb0ee /src | |
parent | 8ede002a96c7e41a433e460b885322d0d0d783f0 (diff) | |
download | openttd-0a481d5ea66ec04c85ec0c6cd9beb098c84d6345.tar.xz |
(svn r25870) -Codechange: Move placement rules for transmitter to its own function
Diffstat (limited to 'src')
-rw-r--r-- | src/object_cmd.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 20a392ca6..ae9b2c701 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -643,6 +643,24 @@ static bool HasTransmitter(TileIndex tile, void *user) return IsObjectTypeTile(tile, OBJECT_TRANSMITTER); } +/** + * Try to build a transmitter. + * @return True iff a transmitter was built. + */ +static bool TryBuildTransmitter() +{ + TileIndex tile = RandomTile(); + int h; + if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h >= 4 && !IsBridgeAbove(tile)) { + TileIndex t = tile; + if (CircularTileSearch(&t, 9, HasTransmitter, NULL)) return false; + + BuildObject(OBJECT_TRANSMITTER, tile); + return true; + } + return false; +} + void GenerateObjects() { if (_settings_game.game_creation.landscape == LT_TOYLAND) return; @@ -670,17 +688,9 @@ void GenerateObjects() SetGeneratingWorldProgress(GWP_OBJECT, radiotower_to_build + lighthouses_to_build); for (uint i = ScaleByMapSize(1000); i != 0 && Object::CanAllocateItem(); i--) { - TileIndex tile = RandomTile(); - - int h; - if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h >= 4 && !IsBridgeAbove(tile)) { - TileIndex t = tile; - if (CircularTileSearch(&t, 9, HasTransmitter, NULL)) continue; - - BuildObject(OBJECT_TRANSMITTER, tile); - IncreaseGeneratingWorldProgress(GWP_OBJECT); - if (--radiotower_to_build == 0) break; - } + if (!TryBuildTransmitter()) continue; + IncreaseGeneratingWorldProgress(GWP_OBJECT); + if (--radiotower_to_build == 0) break; } /* add lighthouses */ |