(svn r11274) [NoAI] -Add: added LowerTile and RaiseTile to 'terraform' the map a bit (dynaxo)
--- a/src/ai/api/ai_tile.cpp Tue Oct 16 16:07:01 2007 +0000
+++ b/src/ai/api/ai_tile.cpp Tue Oct 16 16:11:33 2007 +0000
@@ -6,6 +6,7 @@
#include "../../tile.h"
#include "../../variables.h"
#include "../../station.h"
+#include "../../command.h"
bool AITile::IsBuildable(TileIndex tile)
{
@@ -56,3 +57,19 @@
GetAcceptanceAroundTiles(accepts, tile, width, height, _patches.modified_catchment ? rad : 4);
return accepts[cargo_type];
}
+
+bool AITile::RaiseTile(TileIndex tile, int32 slope)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return 0;
+
+ return this->DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND);
+}
+
+bool AITile::LowerTile(TileIndex tile, int32 slope)
+{
+ /* Outside of the map */
+ if (tile >= ::MapSize()) return 0;
+
+ return this->DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND);
+}
--- a/src/ai/api/ai_tile.hpp Tue Oct 16 16:07:01 2007 +0000
+++ b/src/ai/api/ai_tile.hpp Tue Oct 16 16:11:33 2007 +0000
@@ -13,6 +13,38 @@
class AITile : public AIObject {
public:
/**
+ * Enumeration for the slope-type (from slopes.h).
+ *
+ * This enumeration use the chars N,E,S,W corresponding the
+ * direction north, east, south and west. The top corner of a tile
+ * is the north-part of the tile. The whole slope is encoded with
+ * 5 bits, 4 bits for each corner and 1 bit for a steep-flag.
+ */
+ enum Slope {
+ SLOPE_FLAT = 0x00, ///< a flat tile
+ SLOPE_W = 0x01, ///< the west corner of the tile is raised
+ SLOPE_S = 0x02, ///< the south corner of the tile is raised
+ SLOPE_E = 0x04, ///< the east corner of the tile is raised
+ SLOPE_N = 0x08, ///< the north corner of the tile is raised
+ SLOPE_STEEP = 0x10, ///< indicates the slope is steep
+ SLOPE_NW = SLOPE_N | SLOPE_W, ///< north and west corner are raised
+ SLOPE_SW = SLOPE_S | SLOPE_W, ///< south and west corner are raised
+ SLOPE_SE = SLOPE_S | SLOPE_E, ///< south and east corner are raised
+ SLOPE_NE = SLOPE_N | SLOPE_E, ///< north and east corner are raised
+ SLOPE_EW = SLOPE_E | SLOPE_W, ///< east and west corner are raised
+ SLOPE_NS = SLOPE_N | SLOPE_S, ///< north and south corner are raised
+ SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W, ///< all corner are raised, similar to SLOPE_FLAT
+ SLOPE_NWS = SLOPE_N | SLOPE_W | SLOPE_S, ///< north, west and south corner are raised
+ SLOPE_WSE = SLOPE_W | SLOPE_S | SLOPE_E, ///< west, south and east corner are raised
+ SLOPE_SEN = SLOPE_S | SLOPE_E | SLOPE_N, ///< south, east and north corner are raised
+ SLOPE_ENW = SLOPE_E | SLOPE_N | SLOPE_W, ///< east, north and west corner are raised
+ SLOPE_STEEP_W = SLOPE_STEEP | SLOPE_NWS, ///< a steep slope falling to east (from west)
+ SLOPE_STEEP_S = SLOPE_STEEP | SLOPE_WSE, ///< a steep slope falling to north (from south)
+ SLOPE_STEEP_E = SLOPE_STEEP | SLOPE_SEN, ///< a steep slope falling to west (from east)
+ SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW ///< a steep slope falling to south (from north)
+ };
+
+ /**
* The name of the class, needed by several sub-processes.
*/
static const char *GetClassName() { return "AITile"; }
@@ -63,6 +95,27 @@
* @return value below 8 means no acceptance; the more the better.
*/
static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius);
+
+ /**
+ * Raise the given corners of the tile. The corners can be combined,
+ * for example: SLOPE_N | SLOPE_W (= SLOPE_NW)
+ * @pre tile is always positive and smaller than AIMap::GetMapSize().
+ * @param tile the tile to raise.
+ * @param slope corners to raise (SLOPE_xxx).
+ * @return 0 means failed, 1 means success.
+ */
+ bool RaiseTile(TileIndex tile, int32 slope);
+
+ /**
+ * Lower the given corners of the tile. The corners can be combined,
+ * for example: SLOPE_N | SLOPE_W (= SLOPE_NW)
+ * @pre tile is always positive and smaller than AIMap::GetMapSize().
+ * @param tile the tile to lower.
+ * @param slope corners to lower (SLOPE_xxx).
+ * @return 0 means failed, 1 means success.
+ */
+ bool LowerTile(TileIndex tile, int32 slope);
+
};
#endif /* AI_TILE_HPP */
--- a/src/ai/api/ai_tile.hpp.sq Tue Oct 16 16:07:01 2007 +0000
+++ b/src/ai/api/ai_tile.hpp.sq Tue Oct 16 16:11:33 2007 +0000
@@ -1,6 +1,10 @@
#include "ai_tile.hpp"
namespace SQConvert {
+ /* Allow enums to be used as Squirrel parameters */
+ template <> AITile::Slope GetParam(ForceType<AITile::Slope>, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AITile::Slope)tmp; }
+ template <> int Return<AITile::Slope>(HSQUIRRELVM vm, AITile::Slope res) { sq_pushinteger(vm, (int32)res); return 1; }
+
/* Allow AITile to be used as Squirrel parameter */
template <> AITile *GetParam(ForceType<AITile *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITile *)instance; }
template <> AITile &GetParam(ForceType<AITile &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AITile *)instance; }
@@ -14,6 +18,28 @@
SQAITile.PreRegister(engine);
SQAITile.AddConstructor<void (AITile::*)(), 1>(engine, "x");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_FLAT, "SLOPE_FLAT");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_W, "SLOPE_W");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_S, "SLOPE_S");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_E, "SLOPE_E");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_N, "SLOPE_N");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP, "SLOPE_STEEP");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_NW, "SLOPE_NW");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_SW, "SLOPE_SW");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_SE, "SLOPE_SE");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_NE, "SLOPE_NE");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_EW, "SLOPE_EW");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_NS, "SLOPE_NS");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_ELEVATED, "SLOPE_ELEVATED");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_NWS, "SLOPE_NWS");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_WSE, "SLOPE_WSE");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_SEN, "SLOPE_SEN");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_ENW, "SLOPE_ENW");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP_W, "SLOPE_STEEP_W");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP_S, "SLOPE_STEEP_S");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP_E, "SLOPE_STEEP_E");
+ SQAITile.DefSQConst(engine, AITile::SLOPE_STEEP_N, "SLOPE_STEEP_N");
+
SQAITile.DefSQStaticMethod(engine, &AITile::GetClassName, "GetClassName", 1, "x");
SQAITile.DefSQStaticMethod(engine, &AITile::IsBuildable, "IsBuildable", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::IsWater, "IsWater", 2, "xi");
@@ -21,5 +47,8 @@
SQAITile.DefSQStaticMethod(engine, &AITile::GetHeight, "GetHeight", 2, "xi");
SQAITile.DefSQStaticMethod(engine, &AITile::GetCargoAcceptance, "GetCargoAcceptance", 6, "xiiiii");
+ SQAITile.DefSQMethod(engine, &AITile::RaiseTile, "RaiseTile", 3, "xii");
+ SQAITile.DefSQMethod(engine, &AITile::LowerTile, "LowerTile", 3, "xii");
+
SQAITile.PostRegister(engine);
}