summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-09-05 13:31:39 +0000
committerfrosch <frosch@openttd.org>2010-09-05 13:31:39 +0000
commit42a996ec23f15e74c0fe5ba0fdd5ac992456e7ac (patch)
tree201bd6edb559d4b61be8eeba31cf147a7660c189 /src
parentce1cae81ea55ff6bc45d4e2ed11d5c487ac6ba07 (diff)
downloadopenttd-42a996ec23f15e74c0fe5ba0fdd5ac992456e7ac.tar.xz
(svn r20743) -Fix: Make testruns of clearing an object tile not influence repeated testruns resp. the exec run.
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp4
-rw-r--r--src/landscape.cpp19
-rw-r--r--src/object_base.h10
-rw-r--r--src/object_cmd.cpp6
4 files changed, 31 insertions, 8 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 29cf766fe..fcd6fafca 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1695,7 +1695,7 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do
*ip = NULL;
- SmallVector<TileArea, 1> object_areas(_cleared_object_areas);
+ SmallVector<ClearedObjectArea, 1> object_areas(_cleared_object_areas);
CommandCost ret = CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, random_initial_bits, founder, &custom_shape_check);
_cleared_object_areas = object_areas;
if (ret.Failed()) return ret;
@@ -1797,7 +1797,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (num >= count) return CMD_ERROR;
CommandCost ret = CommandCost(STR_ERROR_SITE_UNSUITABLE);
- SmallVector<TileArea, 1> object_areas(_cleared_object_areas);
+ SmallVector<ClearedObjectArea, 1> object_areas(_cleared_object_areas);
do {
if (--count < 0) return ret;
if (--num < 0) num = indspec->num_table - 1;
diff --git a/src/landscape.cpp b/src/landscape.cpp
index e6c5bd5df..e69dcab82 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -30,7 +30,9 @@
#include "animated_tile_func.h"
#include "core/random_func.hpp"
#include "object_base.h"
+#include "water_map.h"
+#include "table/strings.h"
#include "table/sprites.h"
extern const TileTypeProcs
@@ -605,7 +607,20 @@ void ClearSnowLine()
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
for (uint i = 0; i < _cleared_object_areas.Length(); i++) {
- if (_cleared_object_areas[i].Intersects(TileArea(tile, 1, 1))) return CommandCost();
+ /* If this tile was the first tile which caused object destruction, always
+ * pass it on to the tile_type_proc. That way multiple test runs and the exec run stay consistent. */
+ if (_cleared_object_areas[i].first_tile == tile) break;
+
+ /* If this tile belongs to an object which was already cleared via another tile, pretend it has been
+ * already removed.
+ * However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
+ if (_cleared_object_areas[i].area.Intersects(TileArea(tile, 1, 1))) {
+ /* If a object is removed, it leaves either bare land or water. */
+ if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
+ return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
+ }
+ return CommandCost();
+ }
}
return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
}
@@ -638,9 +653,7 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
for (int x = sx; x <= ex; ++x) {
for (int y = sy; y <= ey; ++y) {
- SmallVector<TileArea, 1> object_areas(_cleared_object_areas);
CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
- _cleared_object_areas = object_areas;
if (ret.Failed()) {
last_error = ret;
continue;
diff --git a/src/object_base.h b/src/object_base.h
index fe889073b..3ca3da111 100644
--- a/src/object_base.h
+++ b/src/object_base.h
@@ -87,6 +87,14 @@ protected:
#define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start)
#define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
-extern SmallVector<TileArea, 4> _cleared_object_areas;
+/**
+ * Keeps track of removed objects during execution/testruns of commands.
+ */
+struct ClearedObjectArea {
+ TileIndex first_tile; ///< The first tile being cleared, which then causes the whole object to be cleared.
+ TileArea area; ///< The area of the object.
+};
+
+extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
#endif /* OBJECT_BASE_H */
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index f945a970f..291eaae9f 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -347,7 +347,7 @@ static void ReallyClearObjectTile(Object *o)
delete o;
}
-SmallVector<TileArea, 4> _cleared_object_areas;
+SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
{
@@ -358,7 +358,9 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
Object *o = Object::GetByTile(tile);
TileArea ta = o->location;
- *_cleared_object_areas.Append() = ta;
+ ClearedObjectArea *cleared_area = _cleared_object_areas.Append();
+ cleared_area->first_tile = tile;
+ cleared_area->area = ta;
CommandCost cost(EXPENSES_CONSTRUCTION, spec->GetClearCost() * ta.w * ta.h / 5);
if (spec->flags & OBJECT_FLAG_CLEAR_INCOME) cost.MultiplyCost(-1); // They get an income!