mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-13 02:52:37 +00:00
(svn r21288) -Codechange: Add helper function to find entries in _cleared_object_areas.
This commit is contained in:
parent
0580f3be0b
commit
d5360390d0
@ -614,22 +614,22 @@ CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
|||||||
do_clear = true;
|
do_clear = true;
|
||||||
cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
|
cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
|
||||||
}
|
}
|
||||||
for (uint i = 0; i < _cleared_object_areas.Length(); i++) {
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
|
const ClearedObjectArea *coa = FindClearedObject(tile);
|
||||||
|
|
||||||
|
/* 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 (coa != NULL && coa->first_tile != tile) {
|
||||||
/* If this tile belongs to an object which was already cleared via another tile, pretend it has been
|
/* If this tile belongs to an object which was already cleared via another tile, pretend it has been
|
||||||
* already removed.
|
* already removed.
|
||||||
* However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
|
* 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 a object is removed, it leaves either bare land or water. */
|
||||||
if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
|
if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
|
||||||
return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||||
}
|
|
||||||
if (do_clear && (flags & DC_EXEC)) DoClearSquare(tile);
|
|
||||||
return cost;
|
|
||||||
}
|
}
|
||||||
|
if (do_clear && (flags & DC_EXEC)) DoClearSquare(tile);
|
||||||
|
return cost;
|
||||||
}
|
}
|
||||||
cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
|
cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
|
||||||
if (do_clear && (flags & DC_EXEC)) DoClearSquare(tile);
|
if (do_clear && (flags & DC_EXEC)) DoClearSquare(tile);
|
||||||
|
@ -95,6 +95,7 @@ struct ClearedObjectArea {
|
|||||||
TileArea area; ///< The area of the object.
|
TileArea area; ///< The area of the object.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ClearedObjectArea *FindClearedObject(TileIndex tile);
|
||||||
extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
|
extern SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
|
||||||
|
|
||||||
#endif /* OBJECT_BASE_H */
|
#endif /* OBJECT_BASE_H */
|
||||||
|
@ -371,6 +371,23 @@ static void ReallyClearObjectTile(Object *o)
|
|||||||
|
|
||||||
SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
|
SmallVector<ClearedObjectArea, 4> _cleared_object_areas;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the entry in _cleared_object_areas which occupies a certain tile.
|
||||||
|
* @param tile Tile of interest
|
||||||
|
* @return Occupying entry, or NULL if none
|
||||||
|
*/
|
||||||
|
ClearedObjectArea *FindClearedObject(TileIndex tile)
|
||||||
|
{
|
||||||
|
TileArea ta = TileArea(tile, 1, 1);
|
||||||
|
|
||||||
|
const ClearedObjectArea *end = _cleared_object_areas.End();
|
||||||
|
for (ClearedObjectArea *coa = _cleared_object_areas.Begin(); coa != end; coa++) {
|
||||||
|
if (coa->area.Intersects(ta)) return coa;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
|
||||||
{
|
{
|
||||||
ObjectType type = GetObjectType(tile);
|
ObjectType type = GetObjectType(tile);
|
||||||
|
Loading…
Reference in New Issue
Block a user