diff options
author | frosch <frosch@openttd.org> | 2010-01-04 19:42:29 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-01-04 19:42:29 +0000 |
commit | 1ed599f5cf6a0dec14d91d5442a08560e254d35c (patch) | |
tree | 969762c9812a05d4cc85ffc522779bbc7667496a /src | |
parent | 27fc22a76bf470c2088a38d57d9cd2a8e481cafb (diff) | |
download | openttd-1ed599f5cf6a0dec14d91d5442a08560e254d35c.tar.xz |
(svn r18725) -Add: [NoAI] AIWaypoint::WaypointType and AIWaypoint::HasWaypointType().
-Change: [NoAI] Constructor of AIWaypoint now takes a WaypointType to also handle buoys.
-Remove: [NoAI] AIBuoyList.
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/ai_instance.cpp | 2 | ||||
-rw-r--r-- | src/ai/api/ai_buoylist.cpp | 21 | ||||
-rw-r--r-- | src/ai/api/ai_buoylist.hpp | 28 | ||||
-rw-r--r-- | src/ai/api/ai_buoylist.hpp.sq | 30 | ||||
-rw-r--r-- | src/ai/api/ai_changelog.hpp | 5 | ||||
-rw-r--r-- | src/ai/api/ai_waypoint.cpp | 13 | ||||
-rw-r--r-- | src/ai/api/ai_waypoint.hpp | 20 | ||||
-rw-r--r-- | src/ai/api/ai_waypoint.hpp.sq | 6 | ||||
-rw-r--r-- | src/ai/api/ai_waypointlist.cpp | 5 | ||||
-rw-r--r-- | src/ai/api/ai_waypointlist.hpp | 6 | ||||
-rw-r--r-- | src/ai/api/ai_waypointlist.hpp.sq | 2 |
11 files changed, 50 insertions, 88 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index 41b4c42c0..7adb797f8 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -35,7 +35,6 @@ #include "api/ai_basestation.hpp.sq" #include "api/ai_bridge.hpp.sq" #include "api/ai_bridgelist.hpp.sq" -#include "api/ai_buoylist.hpp.sq" #include "api/ai_cargo.hpp.sq" #include "api/ai_cargolist.hpp.sq" #include "api/ai_company.hpp.sq" @@ -177,7 +176,6 @@ void AIInstance::RegisterAPI() SQAIBridge_Register(this->engine); SQAIBridgeList_Register(this->engine); SQAIBridgeList_Length_Register(this->engine); - SQAIBuoyList_Register(this->engine); SQAICargo_Register(this->engine); SQAICargoList_Register(this->engine); SQAICargoList_IndustryAccepting_Register(this->engine); diff --git a/src/ai/api/ai_buoylist.cpp b/src/ai/api/ai_buoylist.cpp deleted file mode 100644 index 426296b08..000000000 --- a/src/ai/api/ai_buoylist.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* $Id$ */ - -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. - */ - -/** @file ai_buoylist.cpp Implementation of AIBuoyList and friends. */ - -#include "ai_buoylist.hpp" -#include "../../waypoint_base.h" - -AIBuoyList::AIBuoyList() -{ - Waypoint *wp; - FOR_ALL_WAYPOINTS(wp) { - if (wp->facilities & FACIL_DOCK) this->AddItem(wp->xy); - } -} diff --git a/src/ai/api/ai_buoylist.hpp b/src/ai/api/ai_buoylist.hpp deleted file mode 100644 index e46f999ed..000000000 --- a/src/ai/api/ai_buoylist.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* $Id$ */ - -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. - */ - -/** @file ai_buoylist.hpp List all the buoys. */ - -#ifndef AI_BUOYLIST_HPP -#define AI_BUOYLIST_HPP - -#include "ai_abstractlist.hpp" - -/** - * Creates a list of buoys. - * @ingroup AIList - */ -class AIBuoyList : public AIAbstractList { -public: - static const char *GetClassName() { return "AIBuoyList"; } - AIBuoyList(); -}; - - -#endif /* AI_BUOYLIST_HPP */ diff --git a/src/ai/api/ai_buoylist.hpp.sq b/src/ai/api/ai_buoylist.hpp.sq deleted file mode 100644 index 99b3a45ce..000000000 --- a/src/ai/api/ai_buoylist.hpp.sq +++ /dev/null @@ -1,30 +0,0 @@ -/* $Id$ */ - -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. - */ - -/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ - -#include "ai_buoylist.hpp" - -namespace SQConvert { - /* Allow AIBuoyList to be used as Squirrel parameter */ - template <> AIBuoyList *GetParam(ForceType<AIBuoyList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIBuoyList *)instance; } - template <> AIBuoyList &GetParam(ForceType<AIBuoyList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIBuoyList *)instance; } - template <> const AIBuoyList *GetParam(ForceType<const AIBuoyList *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIBuoyList *)instance; } - template <> const AIBuoyList &GetParam(ForceType<const AIBuoyList &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIBuoyList *)instance; } - template <> int Return<AIBuoyList *>(HSQUIRRELVM vm, AIBuoyList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIBuoyList", res, NULL, DefSQDestructorCallback<AIBuoyList>); return 1; } -}; // namespace SQConvert - -void SQAIBuoyList_Register(Squirrel *engine) -{ - DefSQClass <AIBuoyList> SQAIBuoyList("AIBuoyList"); - SQAIBuoyList.PreRegister(engine, "AIAbstractList"); - SQAIBuoyList.AddConstructor<void (AIBuoyList::*)(), 1>(engine, "x"); - - SQAIBuoyList.PostRegister(engine); -} diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp index fa35e559e..23b9d1573 100644 --- a/src/ai/api/ai_changelog.hpp +++ b/src/ai/api/ai_changelog.hpp @@ -20,7 +20,6 @@ * * API additions: * \li AIBaseStation - * \li AIBuoyList * \li AIEngine::IsBuildable * \li AIEventCompanyAskMerger * \li AIIndustry::GetLastMonthTransportedPercentage @@ -34,6 +33,8 @@ * \li AISubsidy::GetDestinationIndex * \li AITown::GetLastMonthTransportedPercentage * \li AIVehicleList_Depot + * \li AIWaypoint::WaypointType + * \li AIWaypoint::HasWaypointType * \li Some error messages to AIWaypoint * * API removals: @@ -59,6 +60,8 @@ * AIBaseStation, but can still be used as AIStation.GetConstructionDate * \li WaypointID was replaced by StationID. All WaypointIDs from previous * savegames are invalid. Use STATION_INVALID instead of WAYPOINT_INVALID + * \li AIWaypointList constructor now needs a WaypointType similiar to AIStationList, + * it can also handle buoys. * \li AIVehicleList_Station now also works for waypoints * \li Stations can be build over rail without signals that is in the right * direction for the to-be built station. It will also convert the rail if diff --git a/src/ai/api/ai_waypoint.cpp b/src/ai/api/ai_waypoint.cpp index 8f7eadf50..f5badfbbb 100644 --- a/src/ai/api/ai_waypoint.cpp +++ b/src/ai/api/ai_waypoint.cpp @@ -11,18 +11,27 @@ #include "ai_waypoint.hpp" #include "ai_rail.hpp" +#include "ai_marine.hpp" #include "../../company_func.h" #include "../../waypoint_base.h" /* static */ bool AIWaypoint::IsValidWaypoint(StationID waypoint_id) { const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id); - return wp != NULL && wp->owner == _current_company; + return wp != NULL && (wp->owner == _current_company || wp->owner == OWNER_NONE); } /* static */ StationID AIWaypoint::GetWaypointID(TileIndex tile) { - if (!AIRail::IsRailWaypointTile(tile)) return STATION_INVALID; + if (!AIRail::IsRailWaypointTile(tile) && !AIMarine::IsBuoyTile(tile)) return STATION_INVALID; return ::GetStationIndex(tile); } + +/* static */ bool AIWaypoint::HasWaypointType(StationID waypoint_id, WaypointType waypoint_type) +{ + if (!IsValidWaypoint(waypoint_id)) return false; + if (CountBits(waypoint_type) != 1) return false; + + return (::Waypoint::Get(waypoint_id)->facilities & waypoint_type) != 0; +} diff --git a/src/ai/api/ai_waypoint.hpp b/src/ai/api/ai_waypoint.hpp index a781a0ba9..ddd6168d5 100644 --- a/src/ai/api/ai_waypoint.hpp +++ b/src/ai/api/ai_waypoint.hpp @@ -24,6 +24,16 @@ public: static const char *GetClassName() { return "AIWaypoint"; } /** + * Type of waypoints known in the game. + */ + enum WaypointType { + /* Values are important, as they represent the internal state of the game. */ + WAYPOINT_RAIL = 0x01, //!< Rail waypoint + WAYPOINT_BUOY = 0x10, //!< Buoy + WAYPOINT_ANY = 0x11, //!< All waypoint types + }; + + /** * All waypoint related error messages. */ enum ErrorMessages { @@ -51,6 +61,16 @@ public: * @return StationID of the waypoint. */ static StationID GetWaypointID(TileIndex tile); + + /** + * Check if any part of the waypoint contains a waypoint of the type waypoint_type + * @param waypoint_id The waypoint to look at. + * @param waypoint_type The WaypointType to look for. + * @return True if the waypoint has a waypoint part of the type waypoint_type. + */ + static bool HasWaypointType(StationID waypoint_id, WaypointType waypoint_type); }; +DECLARE_ENUM_AS_BIT_SET(AIWaypoint::WaypointType); + #endif /* AI_WAYPOINT_HPP */ diff --git a/src/ai/api/ai_waypoint.hpp.sq b/src/ai/api/ai_waypoint.hpp.sq index bdecda56b..704f39701 100644 --- a/src/ai/api/ai_waypoint.hpp.sq +++ b/src/ai/api/ai_waypoint.hpp.sq @@ -13,6 +13,8 @@ namespace SQConvert { /* Allow enums to be used as Squirrel parameters */ + template <> AIWaypoint::WaypointType GetParam(ForceType<AIWaypoint::WaypointType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIWaypoint::WaypointType)tmp; } + template <> int Return<AIWaypoint::WaypointType>(HSQUIRRELVM vm, AIWaypoint::WaypointType res) { sq_pushinteger(vm, (int32)res); return 1; } template <> AIWaypoint::ErrorMessages GetParam(ForceType<AIWaypoint::ErrorMessages>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIWaypoint::ErrorMessages)tmp; } template <> int Return<AIWaypoint::ErrorMessages>(HSQUIRRELVM vm, AIWaypoint::ErrorMessages res) { sq_pushinteger(vm, (int32)res); return 1; } @@ -30,6 +32,9 @@ void SQAIWaypoint_Register(Squirrel *engine) SQAIWaypoint.PreRegister(engine, "AIBaseStation"); SQAIWaypoint.AddConstructor<void (AIWaypoint::*)(), 1>(engine, "x"); + SQAIWaypoint.DefSQConst(engine, AIWaypoint::WAYPOINT_RAIL, "WAYPOINT_RAIL"); + SQAIWaypoint.DefSQConst(engine, AIWaypoint::WAYPOINT_BUOY, "WAYPOINT_BUOY"); + SQAIWaypoint.DefSQConst(engine, AIWaypoint::WAYPOINT_ANY, "WAYPOINT_ANY"); SQAIWaypoint.DefSQConst(engine, AIWaypoint::ERR_WAYPOINT_BASE, "ERR_WAYPOINT_BASE"); SQAIWaypoint.DefSQConst(engine, AIWaypoint::ERR_WAYPOINT_TOO_CLOSE_TO_ANOTHER_WAYPOINT, "ERR_WAYPOINT_TOO_CLOSE_TO_ANOTHER_WAYPOINT"); SQAIWaypoint.DefSQConst(engine, AIWaypoint::ERR_WAYPOINT_ADJOINS_MULTIPLE_WAYPOINTS, "ERR_WAYPOINT_ADJOINS_MULTIPLE_WAYPOINTS"); @@ -42,6 +47,7 @@ void SQAIWaypoint_Register(Squirrel *engine) SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::IsValidWaypoint, "IsValidWaypoint", 2, ".i"); SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::GetWaypointID, "GetWaypointID", 2, ".i"); + SQAIWaypoint.DefSQStaticMethod(engine, &AIWaypoint::HasWaypointType, "HasWaypointType", 3, ".ii"); SQAIWaypoint.PostRegister(engine); } diff --git a/src/ai/api/ai_waypointlist.cpp b/src/ai/api/ai_waypointlist.cpp index 13087df81..79cc62fdf 100644 --- a/src/ai/api/ai_waypointlist.cpp +++ b/src/ai/api/ai_waypointlist.cpp @@ -15,11 +15,12 @@ #include "../../vehicle_base.h" #include "../../waypoint_base.h" -AIWaypointList::AIWaypointList() +AIWaypointList::AIWaypointList(AIWaypoint::WaypointType waypoint_type) { const Waypoint *wp; FOR_ALL_WAYPOINTS(wp) { - if (wp->facilities & FACIL_TRAIN && wp->owner == _current_company) this->AddItem(wp->index); + if ((wp->facilities & waypoint_type) && + (wp->owner == _current_company || wp->owner == OWNER_NONE)) this->AddItem(wp->index); } } diff --git a/src/ai/api/ai_waypointlist.hpp b/src/ai/api/ai_waypointlist.hpp index 4bc11f8d7..e7c322ece 100644 --- a/src/ai/api/ai_waypointlist.hpp +++ b/src/ai/api/ai_waypointlist.hpp @@ -13,6 +13,7 @@ #define AI_WAYPOINTLIST_HPP #include "ai_abstractlist.hpp" +#include "ai_waypoint.hpp" /** * Creates a list of waypoints of which you are the owner. @@ -22,7 +23,10 @@ class AIWaypointList : public AIAbstractList { public: static const char *GetClassName() { return "AIWaypointList"; } - AIWaypointList(); + /** + * @param waypoint_type The type of waypoint to make a list of waypoints for. + */ + AIWaypointList(AIWaypoint::WaypointType waypoint_type); }; /** diff --git a/src/ai/api/ai_waypointlist.hpp.sq b/src/ai/api/ai_waypointlist.hpp.sq index c2f70c3ef..831f56041 100644 --- a/src/ai/api/ai_waypointlist.hpp.sq +++ b/src/ai/api/ai_waypointlist.hpp.sq @@ -24,7 +24,7 @@ void SQAIWaypointList_Register(Squirrel *engine) { DefSQClass <AIWaypointList> SQAIWaypointList("AIWaypointList"); SQAIWaypointList.PreRegister(engine, "AIAbstractList"); - SQAIWaypointList.AddConstructor<void (AIWaypointList::*)(), 1>(engine, "x"); + SQAIWaypointList.AddConstructor<void (AIWaypointList::*)(AIWaypoint::WaypointType waypoint_type), 2>(engine, "xi"); SQAIWaypointList.PostRegister(engine); } |