(svn r20729) -Fix [FS#4107]: assert when overbuilding object

This commit is contained in:
yexo 2010-09-03 21:50:51 +00:00
parent bd379e283f
commit a45b598bfc
5 changed files with 25 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "company_base.h" #include "company_base.h"
#include "signal_func.h" #include "signal_func.h"
#include "core/backup_type.hpp" #include "core/backup_type.hpp"
#include "object_base.h"
#include "table/strings.h" #include "table/strings.h"
@ -402,6 +403,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
/* only execute the test call if it's toplevel, or we're not execing. */ /* only execute the test call if it's toplevel, or we're not execing. */
if (_docommand_recursive == 1 || !(flags & DC_EXEC) ) { if (_docommand_recursive == 1 || !(flags & DC_EXEC) ) {
if (_docommand_recursive == 1) _cleared_object_areas.Clear();
SetTownRatingTestMode(true); SetTownRatingTestMode(true);
res = proc(tile, flags & ~DC_EXEC, p1, p2, text); res = proc(tile, flags & ~DC_EXEC, p1, p2, text);
SetTownRatingTestMode(false); SetTownRatingTestMode(false);
@ -424,6 +426,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
/* Execute the command here. All cost-relevant functions set the expenses type /* Execute the command here. All cost-relevant functions set the expenses type
* themselves to the cost object at some point */ * themselves to the cost object at some point */
if (_docommand_recursive == 1) _cleared_object_areas.Clear();
res = proc(tile, flags, p1, p2, text); res = proc(tile, flags, p1, p2, text);
if (res.Failed()) { if (res.Failed()) {
error: error:
@ -610,6 +613,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
CommandCost res; CommandCost res;
if (estimate_only || !skip_test) { if (estimate_only || !skip_test) {
/* Test the command. */ /* Test the command. */
_cleared_object_areas.Clear();
SetTownRatingTestMode(true); SetTownRatingTestMode(true);
res = proc(tile, flags, p1, p2, text); res = proc(tile, flags, p1, p2, text);
SetTownRatingTestMode(false); SetTownRatingTestMode(false);
@ -649,6 +653,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
/* Actually try and execute the command. If no cost-type is given /* Actually try and execute the command. If no cost-type is given
* use the construction one */ * use the construction one */
_cleared_object_areas.Clear();
CommandCost res2 = proc(tile, flags | DC_EXEC, p1, p2, text); CommandCost res2 = proc(tile, flags | DC_EXEC, p1, p2, text);
if (cmd_id == CMD_COMPANY_CTRL) { if (cmd_id == CMD_COMPANY_CTRL) {

View File

@ -13,6 +13,7 @@
#define SMALLVEC_TYPE_HPP #define SMALLVEC_TYPE_HPP
#include "alloc_func.hpp" #include "alloc_func.hpp"
#include "mem_func.hpp"
#include "math_func.hpp" #include "math_func.hpp"
/** /**
@ -35,6 +36,12 @@ protected:
public: public:
SmallVector() : data(NULL), items(0), capacity(0) { } SmallVector() : data(NULL), items(0), capacity(0) { }
template<uint X>
SmallVector(const SmallVector<T, X> &other) : data(NULL), items(0), capacity(0)
{
MemCpyT<T>(this->Append(other.Length()), other.Begin(), other.Length());
}
~SmallVector() ~SmallVector()
{ {
free(this->data); free(this->data);

View File

@ -29,6 +29,7 @@
#include "landscape_type.h" #include "landscape_type.h"
#include "animated_tile_func.h" #include "animated_tile_func.h"
#include "core/random_func.hpp" #include "core/random_func.hpp"
#include "object_base.h"
#include "table/sprites.h" #include "table/sprites.h"
@ -603,6 +604,9 @@ void ClearSnowLine()
*/ */
CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) 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();
}
return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags); return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
} }
@ -634,7 +638,9 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
for (int x = sx; x <= ex; ++x) { for (int x = sx; x <= ex; ++x) {
for (int y = sy; y <= ey; ++y) { 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); CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
_cleared_object_areas = object_areas;
if (ret.Failed()) { if (ret.Failed()) {
last_error = ret; last_error = ret;
continue; continue;

View File

@ -17,6 +17,7 @@
#include "tilearea_type.h" #include "tilearea_type.h"
#include "town_type.h" #include "town_type.h"
#include "date_type.h" #include "date_type.h"
#include "core/smallvec_type.hpp"
typedef Pool<Object, ObjectID, 64, 64000> ObjectPool; typedef Pool<Object, ObjectID, 64, 64000> ObjectPool;
extern ObjectPool _object_pool; extern ObjectPool _object_pool;
@ -86,4 +87,6 @@ protected:
#define FOR_ALL_OBJECTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Object, object_index, var, start) #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) #define FOR_ALL_OBJECTS(var) FOR_ALL_OBJECTS_FROM(var, 0)
extern SmallVector<TileArea, 4> _cleared_object_areas;
#endif /* OBJECT_BASE_H */ #endif /* OBJECT_BASE_H */

View File

@ -342,6 +342,8 @@ static void ReallyClearObjectTile(Object *o)
delete o; delete o;
} }
SmallVector<TileArea, 4> _cleared_object_areas;
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags) static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
{ {
ObjectType type = GetObjectType(tile); ObjectType type = GetObjectType(tile);
@ -351,6 +353,8 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
Object *o = Object::GetByTile(tile); Object *o = Object::GetByTile(tile);
TileArea ta = o->location; TileArea ta = o->location;
*_cleared_object_areas.Append() = ta;
CommandCost cost(EXPENSES_CONSTRUCTION, spec->GetClearCost() * ta.w * ta.h / 5); 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! if (spec->flags & OBJECT_FLAG_CLEAR_INCOME) cost.MultiplyCost(-1); // They get an income!