src/ai/api/ai_road.hpp
branchnoai
changeset 9453 727ff178a582
child 9462 a4f49aab1367
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_road.hpp	Sun Mar 18 18:06:45 2007 +0000
@@ -0,0 +1,121 @@
+/* $Id$ */
+
+/** @file ai_map.hpp Everything to query and build roads */
+
+#ifndef AI_ROAD_HPP
+#define AI_ROAD_HPP
+
+#include "ai_object.hpp"
+
+/**
+ * Class that handles all road related functions.
+ *
+ * Roads are always build from tile center to tile center.
+ * Furthermore stations and depots need to be build on tiles
+ * that already have road on them. For depots and non-drive
+ * through stations that means that only one roadbit may be
+ * built at the location. The advantage of this method is
+ * that the AI does not need to think about pointing the
+ * exit of the depots and roadstations towards the correct
+ * direction. For drive-through roadstops this works about
+ * the same, though they have to be built on straight roads.
+ */
+class AIRoad : public AIObject {
+public:
+	/**
+	 * Checks whether the given tile is actually a tile with road.
+	 * @param tile the tile to check.
+	 * @pre tile is always positive and smaller than AIMap::GetMapSize().
+	 * @return true if and only if the tile has road.
+	 */
+	bool IsRoadTile(TileIndex tile);
+
+	/**
+	 * Builds a road from the center of tile start to the
+	 * center of tile end.
+	 * @param start the start tile of the road.
+	 * @param end   the end tile of the road.
+	 * @pre start is not equal to end
+	 * @pre start is always positive and smaller than AIMap::GetMapSize().
+	 * @pre end is always positive and smaller than AIMap::GetMapSize().
+	 * @pre start and end are in a straight line, i.e.
+	 *  AIMap::GetTileX(start) == AIMap::GetTileX(end) or
+	 *  AIMap::GetTileY(start) == AIMap::GetTileY(end).
+	 * @return whether the road has been/can be build or not.
+	 */
+	bool BuildRoad(TileIndex start, TileIndex end);
+
+	/**
+	 * Builds a road depot.
+	 * @param tile  place to build the depot.
+	 * @param front the tile exactly in front of the depot
+	 * @pre tile is always positive and smaller than AIMap::GetMapSize().
+	 * @pre front is always positive and smaller than AIMap::GetMapSize().
+	 * @pre tile is not equal to front
+	 * @return whether the road depot has been/can be build or not.
+	 */
+	bool BuildRoadDepot(TileIndex tile, TileIndex front);
+
+	/**
+	 * Builds a road bus or truck station.
+	 * @param tile  place to build the depot.
+	 * @param front the tile exactly in front of the station.
+	 *   For drive-through stations either entrance side can be used.
+	 * @param bus   whether to build a bus or truck station.
+	 * @param drive_through whether to make the station drive through or not.
+	 * @pre tile is always positive and smaller than AIMap::GetMapSize().
+	 * @pre front is always positive and smaller than AIMap::GetMapSize().
+	 * @pre tile is not equal to front
+	 * @return whether the station has been/can be build or not.
+	 */
+	bool BuildRoadStation(TileIndex tile, TileIndex front, bool bus, bool drive_through);
+
+	/**
+	 * Removes a road from the center of tile start to the
+	 * center of tile end.
+	 * @param start the start tile of the road.
+	 * @param end   the end tile of the road.
+	 * @pre start is always positive and smaller than AIMap::GetMapSize().
+	 * @pre end is always positive and smaller than AIMap::GetMapSize().
+	 * @pre start and end are in a straight line, i.e.
+	 *  AIMap::GetTileX(start) == AIMap::GetTileX(end) or
+	 *  AIMap::GetTileY(start) == AIMap::GetTileY(end).
+	 * @return whether the road has been/can be removed or not.
+	 */
+	bool RemoveRoad(TileIndex start, TileIndex end);
+
+	/**
+	 * Removes a road depot.
+	 * @param tile place to remove the depot from.
+	 * @pre tile is always positive and smaller than AIMap::GetMapSize().
+	 * @pre tile is a road depot.
+	 * @return whether the road depot has been/can be removed or not.
+	 */
+	bool RemoveRoadDepot(TileIndex tile);
+
+	/**
+	 * Removes a road bus or truck station.
+	 * @param tile place to remove the station from.
+	 * @pre tile is always positive and smaller than AIMap::GetMapSize().
+	 * @pre tile is a road station.
+	 * @return whether the station has been/can be removed or not.
+	 */
+	bool RemoveRoadStation(TileIndex tile);
+};
+
+#ifdef DEFINE_SQUIRREL_CLASS
+void SQAIRoadRegister(Squirrel *engine) {
+	DefSQClass <AIRoad> SQAIRoad("AIRoad");
+	SQAIRoad.PreRegister(engine);
+	SQAIRoad.AddConstructor(engine);
+	SQAIRoad.DefSQFunction(engine, &AIRoad::BuildRoad,         "BuildRoad");
+	SQAIRoad.DefSQFunction(engine, &AIRoad::BuildRoadDepot,    "BuildRoadDepot");
+	SQAIRoad.DefSQFunction(engine, &AIRoad::BuildRoadStation,  "BuildRoadStation");
+	SQAIRoad.DefSQFunction(engine, &AIRoad::RemoveRoad,        "RemoveRoad");
+	SQAIRoad.DefSQFunction(engine, &AIRoad::RemoveRoadDepot,   "RemoveRoadDepot");
+	SQAIRoad.DefSQFunction(engine, &AIRoad::RemoveRoadStation, "RemoveRoadStation");
+	SQAIRoad.PostRegister(engine);
+}
+#endif /* SQUIRREL_CLASS */
+
+#endif /* AI_ROAD_HPP */