Mercurial > hg > openttd
changeset 19245:018c0334584f draft
(svn r24134) -Add: Configurable limits for tree planting.
author | michi_cc <michi_cc@openttd.org> |
---|---|
date | Tue, 17 Apr 2012 19:43:52 +0000 |
parents | a5850617d857 |
children | 4863c11de674 |
files | src/company_base.h src/company_cmd.cpp src/lang/english.txt src/saveload/afterload.cpp src/saveload/company_sl.cpp src/settings_type.h src/table/settings.ini src/tree_cmd.cpp |
diffstat | 8 files changed, 53 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/company_base.h +++ b/src/company_base.h @@ -85,6 +85,7 @@ uint32 terraform_limit; ///< Amount of tileheights we can (still) terraform (times 65536). uint32 clear_limit; ///< Amount of tiles we can (still) clear (times 65536). + uint32 tree_limit; ///< Amount of trees we can (still) plant (times 65536). /** * If \c true, the company is (also) controlled by the computer (a NoAI program).
--- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -59,6 +59,7 @@ this->is_ai = is_ai; this->terraform_limit = _settings_game.construction.terraform_frame_burst << 16; this->clear_limit = _settings_game.construction.clear_frame_burst << 16; + this->tree_limit = _settings_game.construction.tree_frame_burst << 16; for (uint j = 0; j < 4; j++) this->share_owners[j] = COMPANY_SPECTATOR; InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY); @@ -260,6 +261,7 @@ FOR_ALL_COMPANIES(c) { c->terraform_limit = min(c->terraform_limit + _settings_game.construction.terraform_per_64k_frames, (uint32)_settings_game.construction.terraform_frame_burst << 16); c->clear_limit = min(c->clear_limit + _settings_game.construction.clear_per_64k_frames, (uint32)_settings_game.construction.clear_frame_burst << 16); + c->tree_limit = min(c->tree_limit + _settings_game.construction.tree_per_64k_frames, (uint32)_settings_game.construction.tree_frame_burst << 16); } }
--- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3663,6 +3663,7 @@ STR_ERROR_AREA_IS_OWNED_BY_ANOTHER :{WHITE}... area is owned by another company STR_ERROR_TERRAFORM_LIMIT_REACHED :{WHITE}... landscaping limit reached STR_ERROR_CLEARING_LIMIT_REACHED :{WHITE}... tile clearing limit reached +STR_ERROR_TREE_PLANT_LIMIT_REACHED :{WHITE}... tree planting limit reached STR_ERROR_NAME_MUST_BE_UNIQUE :{WHITE}Name must be unique STR_ERROR_GENERIC_OBJECT_IN_THE_WAY :{WHITE}{1:STRING} in the way STR_ERROR_NOT_ALLOWED_WHILE_PAUSED :{WHITE}Not allowed while paused
--- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2736,6 +2736,12 @@ } } + if (IsSavegameVersionBefore(175)) { + /* Introduced tree planting limit. */ + Company *c; + FOR_ALL_COMPANIES(c) c->tree_limit = _settings_game.construction.tree_frame_burst << 16; + } + /* Road stops is 'only' updating some caches */ AfterLoadRoadStops(); AfterLoadLabelMaps();
--- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -289,6 +289,7 @@ SLE_CONDVAR(CompanyProperties, terraform_limit, SLE_UINT32, 156, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, clear_limit, SLE_UINT32, 156, SL_MAX_VERSION), + SLE_CONDVAR(CompanyProperties, tree_limit, SLE_UINT32, 175, SL_MAX_VERSION), SLE_END() };
--- a/src/settings_type.h +++ b/src/settings_type.h @@ -254,6 +254,8 @@ uint16 terraform_frame_burst; ///< how many tile heights may, over a short period, be terraformed? uint32 clear_per_64k_frames; ///< how many tiles may, over a long period, be cleared per 65536 frames? uint16 clear_frame_burst; ///< how many tiles may, over a short period, be cleared? + uint32 tree_per_64k_frames; ///< how many trees may, over a long period, be planted per 65536 frames? + uint16 tree_frame_burst; ///< how many trees may, over a short period, be planted? }; /** Settings related to the AI. */
--- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -411,6 +411,26 @@ max = 1 << 30 interval = 1 +[SDT_VAR] +base = GameSettings +var = construction.tree_per_64k_frames +type = SLE_UINT32 +from = 175 +def = 64 << 16 +min = 0 +max = 1 << 30 +interval = 1 + +[SDT_VAR] +base = GameSettings +var = construction.tree_frame_burst +type = SLE_UINT16 +from = 175 +def = 4096 +min = 0 +max = 1 << 30 +interval = 1 + [SDT_BOOL] base = GameSettings var = construction.autoslope
--- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -340,6 +340,9 @@ /* Check the tree type within the current climate */ if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR; + Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : NULL; + int limit = (c == NULL ? INT32_MAX : GB(c->tree_limit, 16, 16)); + TileArea ta(tile, p2); TILE_AREA_LOOP(tile, ta) { switch (GetTileType(tile)) { @@ -350,9 +353,16 @@ continue; } + /* Test tree limit. */ + if (--limit < 1) { + msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED; + break; + } + if (flags & DC_EXEC) { AddTreeCount(tile, 1); MarkTileDirtyByTile(tile); + if (c != NULL) c->tree_limit -= 1 << 16; } /* 2x as expensive to add more trees to an existing tile */ cost.AddCost(_price[PR_BUILD_TREES] * 2); @@ -383,6 +393,12 @@ continue; } + /* Test tree limit. */ + if (--limit < 1) { + msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED; + break; + } + if (IsTileType(tile, MP_CLEAR)) { /* Remove fields or rocks. Note that the ground will get barrened */ switch (GetRawClearGround(tile)) { @@ -412,6 +428,7 @@ /* Plant full grown trees in scenario editor */ PlantTreesOnTile(tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0); MarkTileDirtyByTile(tile); + if (c != NULL) c->tree_limit -= 1 << 16; /* When planting rainforest-trees, set tropiczone to rainforest in editor. */ if (_game_mode == GM_EDITOR && IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS)) { @@ -426,6 +443,9 @@ msg = STR_ERROR_SITE_UNSUITABLE; break; } + + /* Tree limit used up? No need to check more. */ + if (limit < 0) break; } if (cost.GetCost() == 0) {