(engine, "x");
SQAIStation.DefSQConst(engine, AIStation::ERR_STATION_BASE, "ERR_STATION_BASE");
@@ -36,9 +34,6 @@ void SQAIStation_Register(Squirrel *engine) {
SQAIStation.DefSQConst(engine, AIStation::STATION_AIRPORT, "STATION_AIRPORT");
SQAIStation.DefSQConst(engine, AIStation::STATION_DOCK, "STATION_DOCK");
SQAIStation.DefSQConst(engine, AIStation::STATION_ANY, "STATION_ANY");
- SQAIStation.DefSQConst(engine, AIStation::STATION_NEW, "STATION_NEW");
- SQAIStation.DefSQConst(engine, AIStation::STATION_JOIN_ADJACENT, "STATION_JOIN_ADJACENT");
- SQAIStation.DefSQConst(engine, AIStation::STATION_INVALID, "STATION_INVALID");
AIError::RegisterErrorMap(STR_ERROR_STATION_TOO_SPREAD_OUT, AIStation::ERR_STATION_TOO_LARGE);
AIError::RegisterErrorMap(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT, AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION);
@@ -55,9 +50,6 @@ void SQAIStation_Register(Squirrel *engine) {
SQAIStation.DefSQStaticMethod(engine, &AIStation::IsValidStation, "IsValidStation", 2, ".i");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetStationID, "GetStationID", 2, ".i");
- SQAIStation.DefSQStaticMethod(engine, &AIStation::GetName, "GetName", 2, ".i");
- SQAIStation.DefSQStaticMethod(engine, &AIStation::SetName, "SetName", 3, ".is");
- SQAIStation.DefSQStaticMethod(engine, &AIStation::GetLocation, "GetLocation", 2, ".i");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCargoRating, "GetCargoRating", 3, ".ii");
SQAIStation.DefSQStaticMethod(engine, &AIStation::GetCoverageRadius, "GetCoverageRadius", 2, ".i");
diff --git a/src/ai/api/ai_types.hpp b/src/ai/api/ai_types.hpp
index c476c12d21..a27ff6a1c1 100644
--- a/src/ai/api/ai_types.hpp
+++ b/src/ai/api/ai_types.hpp
@@ -60,10 +60,6 @@
* construction, autorenew, autoreplace |
* destruction, autorenew, autoreplace |
* yes |
- * #WaypointID | waypoint |
- * construction |
- * destruction |
- * yes |
*
*
* @remarks
@@ -94,7 +90,6 @@ typedef uint16 SubsidyID; //!< The ID of a subsidy.
typedef uint32 TileIndex; //!< The ID of a tile (just named differently).
typedef uint16 TownID; //!< The ID of a town.
typedef uint16 VehicleID; //!< The ID of a vehicle.
-typedef uint16 WaypointID; //!< The ID of a waypoint.
/* Types we defined ourself, as the OpenTTD core doesn't have them (yet) */
typedef uint AIErrorType; //!< The types of errors inside the NoAI framework.
diff --git a/src/ai/api/ai_waypoint.cpp b/src/ai/api/ai_waypoint.cpp
index d0286c429e..c32df4ee80 100644
--- a/src/ai/api/ai_waypoint.cpp
+++ b/src/ai/api/ai_waypoint.cpp
@@ -12,43 +12,15 @@
#include "../../core/alloc_func.hpp"
#include "table/strings.h"
-/* static */ bool AIWaypoint::IsValidWaypoint(WaypointID waypoint_id)
+/* static */ bool AIWaypoint::IsValidWaypoint(StationID waypoint_id)
{
const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id);
return wp != NULL && wp->owner == _current_company;
}
-/* static */ WaypointID AIWaypoint::GetWaypointID(TileIndex tile)
+/* static */ StationID AIWaypoint::GetWaypointID(TileIndex tile)
{
- if (!AIRail::IsRailWaypointTile(tile)) return WAYPOINT_INVALID;
+ if (!AIRail::IsRailWaypointTile(tile)) return STATION_INVALID;
return ::GetStationIndex(tile);
}
-
-/* static */ char *AIWaypoint::GetName(WaypointID waypoint_id)
-{
- if (!IsValidWaypoint(waypoint_id)) return NULL;
-
- static const int len = 64;
- char *waypoint_name = MallocT(len);
-
- ::SetDParam(0, waypoint_id);
- ::GetString(waypoint_name, STR_WAYPOINT_NAME, &waypoint_name[len - 1]);
- return waypoint_name;
-}
-
-/* static */ bool AIWaypoint::SetName(WaypointID waypoint_id, const char *name)
-{
- EnforcePrecondition(false, IsValidWaypoint(waypoint_id));
- EnforcePrecondition(false, !::StrEmpty(name));
- EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_STATION_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
-
- return AIObject::DoCommand(0, waypoint_id, 0, CMD_RENAME_WAYPOINT, name);
-}
-
-/* static */ TileIndex AIWaypoint::GetLocation(WaypointID waypoint_id)
-{
- if (!IsValidWaypoint(waypoint_id)) return INVALID_TILE;
-
- return ::Waypoint::Get(waypoint_id)->xy;
-}
diff --git a/src/ai/api/ai_waypoint.hpp b/src/ai/api/ai_waypoint.hpp
index 6762eb8f6b..6bc8fd2120 100644
--- a/src/ai/api/ai_waypoint.hpp
+++ b/src/ai/api/ai_waypoint.hpp
@@ -7,63 +7,29 @@
#include "ai_object.hpp"
#include "ai_error.hpp"
+#include "ai_basestation.hpp"
/**
* Class that handles all waypoint related functions.
*/
-class AIWaypoint : public AIObject {
+class AIWaypoint : public AIBaseStation {
public:
static const char *GetClassName() { return "AIWaypoint"; }
- /**
- * Special waypoint IDs signalling different kinds of waypoints.
- */
- enum SpecialWaypointIDs {
- WAYPOINT_INVALID = 0xFFFF, //!< An invalid WaypointID.
- };
-
/**
* Checks whether the given waypoint is valid and owned by you.
* @param waypoint_id The waypoint to check.
* @return True if and only if the waypoint is valid.
*/
- static bool IsValidWaypoint(WaypointID waypoint_id);
+ static bool IsValidWaypoint(StationID waypoint_id);
/**
- * Get the WaypointID of a tile.
- * @param tile The tile to find the WaypointID of.
+ * Get the StationID of a tile.
+ * @param tile The tile to find the StationID of.
* @pre AIRail::IsRailWaypointTile(tile).
- * @return WaypointID of the waypoint.
+ * @return StationID of the waypoint.
*/
- static WaypointID GetWaypointID(TileIndex tile);
-
- /**
- * Get the name of a waypoint.
- * @param waypoint_id The waypoint to get the name of.
- * @pre IsValidWaypoint(waypoint_id).
- * @return The name of the waypoint.
- */
- static char *GetName(WaypointID waypoint_id);
-
- /**
- * Set the name this waypoint.
- * @param waypoint_id The waypoint to set the name of.
- * @param name The new name of the waypoint.
- * @pre IsValidWaypointwaypoint_id).
- * @pre 'name' must have at least one character.
- * @pre 'name' must have at most 30 characters.
- * @exception AIError::ERR_NAME_IS_NOT_UNIQUE
- * @return True if the name was changed.
- */
- static bool SetName(WaypointID waypoint_id, const char *name);
-
- /**
- * Get the current location of a waypoint.
- * @param waypoint_id The waypoint to get the location of.
- * @pre IsValidWaypoint(waypoint_id).
- * @return The tile the waypoint is currently on.
- */
- static TileIndex GetLocation(WaypointID waypoint_id);
+ static StationID GetWaypointID(TileIndex tile);
};
#endif /* AI_WAYPOINT_HPP */
diff --git a/src/ai/api/ai_waypoint.hpp.sq b/src/ai/api/ai_waypoint.hpp.sq
index ef17875ac9..fc6e0aa3a6 100644
--- a/src/ai/api/ai_waypoint.hpp.sq
+++ b/src/ai/api/ai_waypoint.hpp.sq
@@ -4,10 +4,6 @@
#include "ai_waypoint.hpp"
namespace SQConvert {
- /* Allow enums to be used as Squirrel parameters */
- template <> AIWaypoint::SpecialWaypointIDs GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIWaypoint::SpecialWaypointIDs)tmp; }
- template <> int Return(HSQUIRRELVM vm, AIWaypoint::SpecialWaypointIDs res) { sq_pushinteger(vm, (int32)res); return 1; }
-
/* Allow AIWaypoint to be used as Squirrel parameter */
template <> AIWaypoint *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIWaypoint *)instance; }
template <> AIWaypoint &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIWaypoint *)instance; }
@@ -18,16 +14,11 @@ namespace SQConvert {
void SQAIWaypoint_Register(Squirrel *engine) {
DefSQClass SQAIWaypoint("AIWaypoint");
- SQAIWaypoint.PreRegister(engine);
+ SQAIWaypoint.PreRegister(engine, "AIBaseStation");
SQAIWaypoint.AddConstructor(engine, "x");
- SQAIWaypoint.DefSQConst(engine, AIWaypoint::WAYPOINT_INVALID, "WAYPOINT_INVALID");
-
SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::IsValidWaypoint, "IsValidWaypoint", 2, ".i");
SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::GetWaypointID, "GetWaypointID", 2, ".i");
- SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::GetName, "GetName", 2, ".i");
- SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::SetName, "SetName", 3, ".is");
- SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::GetLocation, "GetLocation", 2, ".i");
SQAIWaypoint.PostRegister(engine);
}