summaryrefslogtreecommitdiff
path: root/src/terraform_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-01-04 22:50:09 +0000
committerrubidium <rubidium@openttd.org>2011-01-04 22:50:09 +0000
commiteab47d2227bad950dd04ab8498588d40f1f4f725 (patch)
tree190356576f6e488e9be4f5810654c8c8ed329a12 /src/terraform_cmd.cpp
parent7dafd04f4b867243e2b0a67f8e41d2c9c7047a5b (diff)
downloadopenttd-eab47d2227bad950dd04ab8498588d40f1f4f725.tar.xz
(svn r21728) -Fix/Feature [FS#4331]: (configurably) limit amount of tiles that can be cleared/terraformed by a company
Diffstat (limited to 'src/terraform_cmd.cpp')
-rw-r--r--src/terraform_cmd.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp
index 5cb7e6b66..a34471a5d 100644
--- a/src/terraform_cmd.cpp
+++ b/src/terraform_cmd.cpp
@@ -18,6 +18,8 @@
#include "economy_func.h"
#include "genworld.h"
#include "object_base.h"
+#include "company_base.h"
+#include "company_func.h"
#include "table/strings.h"
@@ -346,6 +348,11 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
}
}
+ Company *c = Company::GetIfValid(_current_company);
+ if (c != NULL && (int)GB(c->terraform_limit, 16, 16) < ts.modheight_count) {
+ return_cmd_error(STR_ERROR_TERRAFORM_LIMIT_REACHED);
+ }
+
if (flags & DC_EXEC) {
/* change the height */
{
@@ -368,6 +375,8 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
MarkTileDirtyByTile(*ti);
}
}
+
+ if (c != NULL) c->terraform_limit -= ts.modheight_count << 16;
}
return total_cost;
}
@@ -411,6 +420,9 @@ CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
CommandCost last_error(lm == LM_LEVEL ? STR_ERROR_ALREADY_LEVELLED : INVALID_STRING_ID);
bool had_success = false;
+ const Company *c = Company::GetIfValid(_current_company);
+ int limit = (c == NULL ? INT32_MAX : GB(c->terraform_limit, 16, 16));
+
TileArea ta(tile, p1);
TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(ta);
for (; *iter != INVALID_TILE; ++(*iter)) {
@@ -420,6 +432,9 @@ CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
CommandCost ret = DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
if (ret.Failed()) {
last_error = ret;
+
+ /* Did we reach the limit? */
+ if (ret.GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
break;
}
@@ -431,12 +446,21 @@ CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
return cost;
}
DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
+ } else {
+ /* When we're at the terraform limit we better bail (unneeded) testing as well.
+ * This will probably cause the terraforming cost to be underestimated, but only
+ * when it's near the terraforming limit. Even then, the estimation is
+ * completely off due to it basically counting terraforming double, so it being
+ * cut off earlier might even give a better estimate in some cases. */
+ if (--limit <= 0) break;
}
cost.AddCost(ret);
curh += (curh > h) ? -1 : 1;
had_success = true;
}
+
+ if (limit <= 0) break;
}
delete iter;