diff options
author | yexo <yexo@openttd.org> | 2009-07-31 22:30:54 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2009-07-31 22:30:54 +0000 |
commit | 8c05194c0241d88226ba6c727a0c45b00d8495ed (patch) | |
tree | be76ebd36a14a7828a9ed5400f42045b375b7c50 | |
parent | b129184d57cac186c53bda3e8165efd63806c2aa (diff) | |
download | openttd-8c05194c0241d88226ba6c727a0c45b00d8495ed.tar.xz |
(svn r17011) -Change [NoAI]: Add AIBaseStation as a parentclass for AIStation and AIWaypoint, and move GetName, SetName and GetLocation to AIBaseStation
Remove (nearly) all references to WaypointID and replace them with StationID
-rw-r--r-- | projects/openttd_vs80.vcproj | 8 | ||||
-rw-r--r-- | projects/openttd_vs90.vcproj | 8 | ||||
-rw-r--r-- | source.list | 2 | ||||
-rw-r--r-- | src/ai/ai_instance.cpp | 2 | ||||
-rw-r--r-- | src/ai/api/ai_basestation.cpp | 47 | ||||
-rw-r--r-- | src/ai/api/ai_basestation.hpp | 66 | ||||
-rw-r--r-- | src/ai/api/ai_basestation.hpp.sq | 35 | ||||
-rw-r--r-- | src/ai/api/ai_station.cpp | 28 | ||||
-rw-r--r-- | src/ai/api/ai_station.hpp | 41 | ||||
-rw-r--r-- | src/ai/api/ai_station.hpp.sq | 10 | ||||
-rw-r--r-- | src/ai/api/ai_types.hpp | 5 | ||||
-rw-r--r-- | src/ai/api/ai_waypoint.cpp | 34 | ||||
-rw-r--r-- | src/ai/api/ai_waypoint.hpp | 48 | ||||
-rw-r--r-- | src/ai/api/ai_waypoint.hpp.sq | 11 |
14 files changed, 182 insertions, 163 deletions
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index a33c4a3cd..e80cf14ab 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -2620,6 +2620,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_basestation.hpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_bridge.hpp" > </File> @@ -2832,6 +2836,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_basestation.cpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_bridge.cpp" > </File> diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 357e30b3a..68abddf3d 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -2617,6 +2617,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_basestation.hpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_bridge.hpp" > </File> @@ -2829,6 +2833,10 @@ > </File> <File + RelativePath=".\..\src\ai\api\ai_basestation.cpp" + > + </File> + <File RelativePath=".\..\src\ai\api\ai_bridge.cpp" > </File> diff --git a/source.list b/source.list index fc38ccb06..948ff3f95 100644 --- a/source.list +++ b/source.list @@ -608,6 +608,7 @@ ai/api/ai_abstractlist.hpp ai/api/ai_accounting.hpp ai/api/ai_airport.hpp ai/api/ai_base.hpp +ai/api/ai_basestation.hpp ai/api/ai_bridge.hpp ai/api/ai_bridgelist.hpp ai/api/ai_buoylist.hpp @@ -662,6 +663,7 @@ ai/api/ai_abstractlist.cpp ai/api/ai_accounting.cpp ai/api/ai_airport.cpp ai/api/ai_base.cpp +ai/api/ai_basestation.cpp ai/api/ai_bridge.cpp ai/api/ai_bridgelist.cpp ai/api/ai_buoylist.cpp diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index 4566e925d..45e336d5c 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -30,6 +30,7 @@ #include "api/ai_accounting.hpp.sq" #include "api/ai_airport.hpp.sq" #include "api/ai_base.hpp.sq" +#include "api/ai_basestation.hpp.sq" #include "api/ai_bridge.hpp.sq" #include "api/ai_bridgelist.hpp.sq" #include "api/ai_buoylist.hpp.sq" @@ -158,6 +159,7 @@ void AIInstance::RegisterAPI() SQAIAccounting_Register(this->engine); SQAIAirport_Register(this->engine); SQAIBase_Register(this->engine); + SQAIBaseStation_Register(this->engine); SQAIBridge_Register(this->engine); SQAIBridgeList_Register(this->engine); SQAIBridgeList_Length_Register(this->engine); diff --git a/src/ai/api/ai_basestation.cpp b/src/ai/api/ai_basestation.cpp new file mode 100644 index 000000000..c9f68b3f3 --- /dev/null +++ b/src/ai/api/ai_basestation.cpp @@ -0,0 +1,47 @@ +/* $Id$ */ + +/** @file ai_basestation.cpp Implementation of AIBaseStation. */ + +#include "ai_basestation.hpp" +#include "../../base_station_base.h" +#include "../../station_base.h" +#include "../../command_func.h" +#include "../../string_func.h" +#include "../../strings_func.h" +#include "../../company_func.h" +#include "../../core/alloc_func.hpp" +#include "table/strings.h" + +/* static */ bool AIBaseStation::IsValidBaseStation(StationID station_id) +{ + const BaseStation *st = ::BaseStation::GetIfValid(station_id); + return st != NULL && st->owner == _current_company; +} + +/* static */ char *AIBaseStation::GetName(StationID station_id) +{ + if (!IsValidBaseStation(station_id)) return NULL; + + static const int len = 64; + char *name = MallocT<char>(len); + + ::SetDParam(0, station_id); + ::GetString(name, ::Station::IsValidID(station_id) ? STR_STATION_NAME : STR_WAYPOINT_NAME, &name[len - 1]); + return name; +} + +/* static */ bool AIBaseStation::SetName(StationID station_id, const char *name) +{ + EnforcePrecondition(false, IsValidBaseStation(station_id)); + EnforcePrecondition(false, !::StrEmpty(name)); + EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_STATION_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + + return AIObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, name); +} + +/* static */ TileIndex AIBaseStation::GetLocation(StationID station_id) +{ + if (!IsValidBaseStation(station_id)) return INVALID_TILE; + + return ::BaseStation::Get(station_id)->xy; +} diff --git a/src/ai/api/ai_basestation.hpp b/src/ai/api/ai_basestation.hpp new file mode 100644 index 000000000..fa103b59e --- /dev/null +++ b/src/ai/api/ai_basestation.hpp @@ -0,0 +1,66 @@ +/* $Id$ */ + +/** @file ai_waypoint.hpp Everything to query and build waypoints. */ + +#ifndef AI_BASESTATION_HPP +#define AI_BASESTATION_HPP + +#include "ai_object.hpp" +#include "ai_error.hpp" + +/** + * Base class for stations and waypoints. + */ +class AIBaseStation : public AIObject { +public: + static const char *GetClassName() { return "AIBaseStation"; } + + /** + * Special station IDs for building adjacent/new stations when + * the adjacent/distant join features are enabled. + */ + enum SpecialStationIDs { + STATION_NEW = 0xFFFD, //!< Build a new station + STATION_JOIN_ADJACENT = 0xFFFE, //!< Join an neighbouring station if one exists + STATION_INVALID = 0xFFFF, //!< Invalid station id. + WAYPOINT_INVALID = 0xFFFF, //!< @deprecated Use STATION_INVALID instead. + }; + + /** + * Checks whether the given basestation is valid and owned by you. + * @param station_id The station to check. + * @return True if and only if the basestation is valid. + * @note IsValidBaseStation == (IsValidStation || IsValidWaypoint). + */ + static bool IsValidBaseStation(StationID station_id); + + /** + * Get the name of a basestation. + * @param station_id The basestation to get the name of. + * @pre IsValidBaseStation(station_id). + * @return The name of the station. + */ + static char *GetName(StationID station_id); + + /** + * Set the name this basestation. + * @param station_id The basestation to set the name of. + * @param name The new name of the station. + * @pre IsValidBaseStation(station_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(StationID station_id, const char *name); + + /** + * Get the current location of a basestation. + * @param station_id The basestation to get the location of. + * @pre IsValidBaseStation(station_id). + * @return The tile the basestation is currently on. + */ + static TileIndex GetLocation(StationID station_id); +}; + +#endif /* AI_BASESTATION_HPP */ diff --git a/src/ai/api/ai_basestation.hpp.sq b/src/ai/api/ai_basestation.hpp.sq new file mode 100644 index 000000000..f18e6f621 --- /dev/null +++ b/src/ai/api/ai_basestation.hpp.sq @@ -0,0 +1,35 @@ +/* $Id$ */ +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "ai_waypoint.hpp" + +namespace SQConvert { + /* Allow enums to be used as Squirrel parameters */ + template <> AIBaseStation::SpecialStationIDs GetParam(ForceType<AIBaseStation::SpecialStationIDs>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIBaseStation::SpecialStationIDs)tmp; } + template <> int Return<AIBaseStation::SpecialStationIDs>(HSQUIRRELVM vm, AIBaseStation::SpecialStationIDs res) { sq_pushinteger(vm, (int32)res); return 1; } + + /* Allow AIBaseStation to be used as Squirrel parameter */ + template <> AIBaseStation *GetParam(ForceType<AIBaseStation *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIBaseStation *)instance; } + template <> AIBaseStation &GetParam(ForceType<AIBaseStation &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIBaseStation *)instance; } + template <> const AIBaseStation *GetParam(ForceType<const AIBaseStation *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIBaseStation *)instance; } + template <> const AIBaseStation &GetParam(ForceType<const AIBaseStation &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIBaseStation *)instance; } + template <> int Return<AIBaseStation *>(HSQUIRRELVM vm, AIBaseStation *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIBaseStation", res, NULL, DefSQDestructorCallback<AIBaseStation>); return 1; } +}; // namespace SQConvert + +void SQAIBaseStation_Register(Squirrel *engine) { + DefSQClass <AIBaseStation> SQAIBaseStation("AIBaseStation"); + SQAIBaseStation.PreRegister(engine); + SQAIBaseStation.AddConstructor<void (AIBaseStation::*)(), 1>(engine, "x"); + + SQAIBaseStation.DefSQConst(engine, AIBaseStation::STATION_NEW, "STATION_NEW"); + SQAIBaseStation.DefSQConst(engine, AIBaseStation::STATION_JOIN_ADJACENT, "STATION_JOIN_ADJACENT"); + SQAIBaseStation.DefSQConst(engine, AIBaseStation::STATION_INVALID, "STATION_INVALID"); + SQAIBaseStation.DefSQConst(engine, AIBaseStation::WAYPOINT_INVALID, "WAYPOINT_INVALID"); + + SQAIBaseStation.DefSQStaticMethod(engine, &AIBaseStation::IsValidBaseStation, "IsValidBaseStation", 2, ".i"); + SQAIBaseStation.DefSQStaticMethod(engine, &AIBaseStation::GetName, "GetName", 2, ".i"); + SQAIBaseStation.DefSQStaticMethod(engine, &AIBaseStation::SetName, "SetName", 3, ".is"); + SQAIBaseStation.DefSQStaticMethod(engine, &AIBaseStation::GetLocation, "GetLocation", 2, ".i"); + + SQAIBaseStation.PostRegister(engine); +} diff --git a/src/ai/api/ai_station.cpp b/src/ai/api/ai_station.cpp index 244033f58..e2f33400a 100644 --- a/src/ai/api/ai_station.cpp +++ b/src/ai/api/ai_station.cpp @@ -28,34 +28,6 @@ return ::GetStationIndex(tile); } -/* static */ char *AIStation::GetName(StationID station_id) -{ - if (!IsValidStation(station_id)) return NULL; - - static const int len = 64; - char *station_name = MallocT<char>(len); - - ::SetDParam(0, Station::Get(station_id)->index); - ::GetString(station_name, STR_STATION_NAME, &station_name[len - 1]); - return station_name; -} - -/* static */ bool AIStation::SetName(StationID station_id, const char *name) -{ - EnforcePrecondition(false, IsValidStation(station_id)); - EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_STATION_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG); - - return AIObject::DoCommand(0, station_id, 0, CMD_RENAME_STATION, name); -} - -/* static */ TileIndex AIStation::GetLocation(StationID station_id) -{ - if (!IsValidStation(station_id)) return INVALID_TILE; - - return ::Station::Get(station_id)->xy; -} - /* static */ int32 AIStation::GetCargoWaiting(StationID station_id, CargoID cargo_id) { if (!IsValidStation(station_id)) return -1; diff --git a/src/ai/api/ai_station.hpp b/src/ai/api/ai_station.hpp index 783013968..0203b456c 100644 --- a/src/ai/api/ai_station.hpp +++ b/src/ai/api/ai_station.hpp @@ -8,11 +8,12 @@ #include "ai_object.hpp" #include "ai_error.hpp" #include "ai_road.hpp" +#include "ai_basestation.hpp" /** * Class that handles all station related functions. */ -class AIStation : public AIObject { +class AIStation : public AIBaseStation { public: static const char *GetClassName() { return "AIStation"; } @@ -50,16 +51,6 @@ public: }; /** - * Special station IDs for building adjacent/new stations when - * the adjacent/distant join features are enabled. - */ - enum SpecialStationIDs { - STATION_NEW = 0xFFFD, //!< Build a new station - STATION_JOIN_ADJACENT = 0xFFFE, //!< Join an neighbouring station if one exists - STATION_INVALID = 0xFFFF, //!< Invalid station id. - }; - - /** * Checks whether the given station is valid and owned by you. * @param station_id The station to check. * @return True if and only if the station is valid. @@ -75,34 +66,6 @@ public: static StationID GetStationID(TileIndex tile); /** - * Get the name of a station. - * @param station_id The station to get the name of. - * @pre IsValidStation(station_id). - * @return The name of the station. - */ - static char *GetName(StationID station_id); - - /** - * Set the name this station. - * @param station_id The station to set the name of. - * @param name The new name of the station. - * @pre IsValidStation(station_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(StationID station_id, const char *name); - - /** - * Get the current location of a station. - * @param station_id The station to get the location of. - * @pre IsValidStation(station_id). - * @return The tile the station is currently on. - */ - static TileIndex GetLocation(StationID station_id); - - /** * See how much cargo there is waiting on a station. * @param station_id The station to get the cargo-waiting of. * @param cargo_id The cargo to get the cargo-waiting of. diff --git a/src/ai/api/ai_station.hpp.sq b/src/ai/api/ai_station.hpp.sq index 4873fba2a..e2296eecc 100644 --- a/src/ai/api/ai_station.hpp.sq +++ b/src/ai/api/ai_station.hpp.sq @@ -9,8 +9,6 @@ namespace SQConvert { template <> int Return<AIStation::ErrorMessages>(HSQUIRRELVM vm, AIStation::ErrorMessages res) { sq_pushinteger(vm, (int32)res); return 1; } template <> AIStation::StationType GetParam(ForceType<AIStation::StationType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIStation::StationType)tmp; } template <> int Return<AIStation::StationType>(HSQUIRRELVM vm, AIStation::StationType res) { sq_pushinteger(vm, (int32)res); return 1; } - template <> AIStation::SpecialStationIDs GetParam(ForceType<AIStation::SpecialStationIDs>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIStation::SpecialStationIDs)tmp; } - template <> int Return<AIStation::SpecialStationIDs>(HSQUIRRELVM vm, AIStation::SpecialStationIDs res) { sq_pushinteger(vm, (int32)res); return 1; } /* Allow AIStation to be used as Squirrel parameter */ template <> AIStation *GetParam(ForceType<AIStation *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIStation *)instance; } @@ -22,7 +20,7 @@ namespace SQConvert { void SQAIStation_Register(Squirrel *engine) { DefSQClass <AIStation> SQAIStation("AIStation"); - SQAIStation.PreRegister(engine); + SQAIStation.PreRegister(engine, "AIBaseStation"); SQAIStation.AddConstructor<void (AIStation::*)(), 1>(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 c476c12d2..a27ff6a1c 100644 --- a/src/ai/api/ai_types.hpp +++ b/src/ai/api/ai_types.hpp @@ -60,10 +60,6 @@ * <td> construction, autorenew, autoreplace </td> * <td> destruction, autorenew, autoreplace </td> * <td> yes </td></tr> - * <tr><td>#WaypointID </td><td> waypoint </td> - * <td> construction </td> - * <td> destruction </td> - * <td> yes </td></tr> * </table> * * @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 d0286c429..c32df4ee8 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<char>(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 6762eb8f6..6bc8fd212 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. - */ - 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. + * @return StationID of the waypoint. */ - 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 ef17875ac..fc6e0aa3a 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<AIWaypoint::SpecialWaypointIDs>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIWaypoint::SpecialWaypointIDs)tmp; } - template <> int Return<AIWaypoint::SpecialWaypointIDs>(HSQUIRRELVM vm, AIWaypoint::SpecialWaypointIDs res) { sq_pushinteger(vm, (int32)res); return 1; } - /* Allow AIWaypoint to be used as Squirrel parameter */ template <> AIWaypoint *GetParam(ForceType<AIWaypoint *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIWaypoint *)instance; } template <> AIWaypoint &GetParam(ForceType<AIWaypoint &>, 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 <AIWaypoint> SQAIWaypoint("AIWaypoint"); - SQAIWaypoint.PreRegister(engine); + SQAIWaypoint.PreRegister(engine, "AIBaseStation"); SQAIWaypoint.AddConstructor<void (AIWaypoint::*)(), 1>(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); } |