summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorplanetmaker <planetmaker@openttd.org>2013-10-17 21:41:17 +0000
committerplanetmaker <planetmaker@openttd.org>2013-10-17 21:41:17 +0000
commit8033162bb8f175037ccd0cc6a2219605b6f68f26 (patch)
treeec83d2497f5c91f48f94f440fd63a93a744b27ea /src
parent2ee9a2b5e70bb52ae08d8d18d94b7e082a12a63f (diff)
downloadopenttd-8033162bb8f175037ccd0cc6a2219605b6f68f26.tar.xz
(svn r25876) -Codechange: Unify object placement during map creation
Diffstat (limited to 'src')
-rw-r--r--src/object_cmd.cpp62
-rw-r--r--src/table/object_land.h4
2 files changed, 43 insertions, 23 deletions
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index 7c42dce78..3976a6f6a 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -706,15 +706,12 @@ static bool TryBuildTransmitter()
void GenerateObjects()
{
- if (_settings_game.game_creation.landscape == LT_TOYLAND) return;
+ /* Set a guestimate on how much we progress */
+ SetGeneratingWorldProgress(GWP_OBJECT, NUM_OBJECTS);
- /* add radio tower */
- int radiotower_to_build = ScaleByMapSize(15); // maximum number of radio towers on the map
- int lighthouses_to_build = _settings_game.game_creation.landscape == LT_TROPIC ? 0 : ScaleByMapSize1D((Random() & 3) + 7);
-
- /* Scale the amount of lighthouses with the amount of land at the borders. */
- if (_settings_game.construction.freeform_edges && lighthouses_to_build != 0) {
- uint num_water_tiles = 0;
+ /* Determine number of water tiles at map border needed for freeform_edges */
+ uint num_water_tiles = 0;
+ if (_settings_game.construction.freeform_edges) {
for (uint x = 0; x < MapMaxX(); x++) {
if (IsTileType(TileXY(x, 1), MP_WATER)) num_water_tiles++;
if (IsTileType(TileXY(x, MapMaxY() - 1), MP_WATER)) num_water_tiles++;
@@ -723,24 +720,47 @@ void GenerateObjects()
if (IsTileType(TileXY(1, y), MP_WATER)) num_water_tiles++;
if (IsTileType(TileXY(MapMaxX() - 1, y), MP_WATER)) num_water_tiles++;
}
- /* The -6 is because the top borders are MP_VOID (-2) and all corners
- * are counted twice (-4). */
- lighthouses_to_build = lighthouses_to_build * num_water_tiles / (2 * MapMaxY() + 2 * MapMaxX() - 6);
}
- SetGeneratingWorldProgress(GWP_OBJECT, radiotower_to_build + lighthouses_to_build);
+ /* Iterate over all possible object types */
+ for (uint i = 0; i < NUM_OBJECTS; i++) {
+ const ObjectSpec *spec = ObjectSpec::Get(i);
- for (uint i = ScaleByMapSize(1000); i != 0 && Object::CanAllocateItem(); i--) {
- if (!TryBuildTransmitter()) continue;
- IncreaseGeneratingWorldProgress(GWP_OBJECT);
- if (--radiotower_to_build == 0) break;
- }
+ /* Continue, if the object was never available till now or shall not be placed */
+ if (!spec->WasEverAvailable() || spec->generate_amount == 0) continue;
- /* add lighthouses */
- for (int loop_count = 0; loop_count < 1000 && lighthouses_to_build != 0 && Object::CanAllocateItem(); loop_count++) {
- if (!TryBuildLightHouse()) continue;
+ uint16 amount = spec->generate_amount;
+
+ /* Scale by map size */
+ if ((spec->flags & OBJECT_FLAG_SCALE_BY_WATER) && _settings_game.construction.freeform_edges) {
+ /* Scale the amount of lighthouses with the amount of land at the borders.
+ * The -6 is because the top borders are MP_VOID (-2) and all corners
+ * are counted twice (-4). */
+ amount = ScaleByMapSize1D(amount * num_water_tiles) / (2 * MapMaxY() + 2 * MapMaxX() - 6);
+ } else if (spec->flags & OBJECT_FLAG_SCALE_BY_WATER) {
+ amount = ScaleByMapSize1D(amount);
+ } else {
+ amount = ScaleByMapSize(amount);
+ }
+
+ /* Now try to place the requested amount of this object */
+ for (uint j = ScaleByMapSize(1000); j != 0 && amount != 0 && Object::CanAllocateItem(); j--) {
+ switch (i) {
+ case OBJECT_LIGHTHOUSE:
+ if (TryBuildTransmitter()) amount--;
+ break;
+
+ case OBJECT_TRANSMITTER:
+ if (TryBuildLightHouse()) amount--;
+ break;
+
+ default:
+ uint8 view = RandomRange(spec->views);
+ if (CmdBuildObject(RandomTile(), DC_EXEC | DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, i, view, NULL).Succeeded()) amount--;
+ break;
+ }
+ }
IncreaseGeneratingWorldProgress(GWP_OBJECT);
- lighthouses_to_build--;
}
}
diff --git a/src/table/object_land.h b/src/table/object_land.h
index 16f9ee649..035b1ee8e 100644
--- a/src/table/object_land.h
+++ b/src/table/object_land.h
@@ -123,7 +123,7 @@ static const DrawTileSprites _object_hq[] = {
#undef TILE_SPRITE_LINE
-#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) { GRFFilePropsBase<2>(), INVALID_OBJECT_CLASS, name, climate, size, build_cost_multiplier, clear_cost_multiplier, 0, 0, flags, {0, 0, 0, 0}, 0, height, 1, gen_amount, true }
+#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, climate, gen_amount, flags) { GRFFilePropsBase<2>(), INVALID_OBJECT_CLASS, name, climate, size, build_cost_multiplier, clear_cost_multiplier, 0, 0xFFFFFFFF, flags, {0, 0, 0, 0}, 0, height, 1, gen_amount, true }
/* Climates
* T = Temperate
@@ -137,7 +137,7 @@ static const DrawTileSprites _object_hq[] = {
/** Specification of the original object structures. */
extern const ObjectSpec _original_objects[] = {
M(STR_LAI_OBJECT_DESCRIPTION_TRANSMITTER, 0x11, 0, 0, 10, T|A|S , 15, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_ONLY_IN_SCENEDIT),
- M(STR_LAI_OBJECT_DESCRIPTION_LIGHTHOUSE, 0x11, 0, 0, 8, T|A , 7, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_ONLY_IN_SCENEDIT | OBJECT_FLAG_SCALE_BY_WATER),
+ M(STR_LAI_OBJECT_DESCRIPTION_LIGHTHOUSE, 0x11, 0, 0, 8, T|A , 8, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_ONLY_IN_SCENEDIT | OBJECT_FLAG_SCALE_BY_WATER),
M(STR_TOWN_BUILDING_NAME_STATUE_1, 0x11, 0, 0, 5, T|S|A|Y, 0, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_ONLY_IN_GAME | OBJECT_FLAG_ONLY_IN_SCENEDIT), // Yes, we disallow building this everywhere. Happens in "special" case!
M(STR_LAI_OBJECT_DESCRIPTION_COMPANY_OWNED_LAND, 0x11, 10, 10, 0, T|S|A|Y, 0, OBJECT_FLAG_AUTOREMOVE | OBJECT_FLAG_ONLY_IN_GAME | OBJECT_FLAG_CLEAR_INCOME | OBJECT_FLAG_HAS_NO_FOUNDATION ), // Only non-silly use case is to use it when you cannot build a station, so disallow bridges
M(STR_LAI_OBJECT_DESCRIPTION_COMPANY_HEADQUARTERS, 0x22, 0, 0, 7, T|S|A|Y, 0, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_ONLY_IN_GAME),