Changeset - r14167:e663f87c45ea
[Not reviewed]
master
3 14 0
frosch - 15 years ago 2010-01-04 19:42:29
frosch@openttd.org
(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.
17 files changed with 68 insertions and 110 deletions:
0 comments (0 inline, 0 general)
bin/ai/compat_0.7.nut
Show inline comments
 
@@ -250,3 +250,11 @@ AIEngine.GetPlaneType <- function(engine
 
	if (!AIEngine.IsBuildable(engine_id)) return -1;
 
	return AIEngine._GetPlaneType(engine_id);
 
}
 

	
 
_AIWaypointList <- AIWaypointList;
 
class AIWaypointList extends _AIWaypointList {
 
	constructor()
 
	{
 
		::_AIWaypointList.constructor(AIWaypoint.WAYPOINT_RAIL);
 
	}
 
}
bin/ai/regression/regression.nut
Show inline comments
 
@@ -805,13 +805,17 @@ function Regression::Marine()
 
	print("  IsCanalTile():        " + AIMarine.IsCanalTile(32127));
 
	print("  GetBankBalance():     " + AICompany.GetBankBalance(AICompany.COMPANY_SELF));
 

	
 
	local list = AIBuoyList();
 
	local list = AIWaypointList(AIWaypoint.WAYPOINT_BUOY);
 
	print("");
 
	print("--AIBuoyList--");
 
	print("--AIWaypointList(BUOY)--");
 
	print("  Count():             " + list.Count());
 
	print("  Location ListDump:");
 
	for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
 
		print("    " + i);
 
		print("    " + AIWaypoint.GetLocation(i));
 
	}
 
	print("  HasWaypointType:");
 
	for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
 
		print("    " + AIWaypoint.HasWaypointType(i, AIWaypoint.WAYPOINT_RAIL) + "  " + AIWaypoint.HasWaypointType(i, AIWaypoint.WAYPOINT_BUOY) + "  " + AIWaypoint.HasWaypointType(i, AIWaypoint.WAYPOINT_ANY));
 
	}
 
	print("");
 

	
bin/ai/regression/regression.txt
Show inline comments
 
@@ -7100,10 +7100,12 @@
 
  IsCanalTile():        true
 
  GetBankBalance():     1999951154
 

	
 
--AIBuoyList--
 
--AIWaypointList(BUOY)--
 
  Count():             1
 
  Location ListDump:
 
    28481
 
  HasWaypointType:
 
    false  true  false
 

	
 
  RemoveWaterDepot():   true
 
  RemoveDock():         true
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -2640,10 +2640,6 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_buoylist.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_cargo.hpp"
 
				>
 
			</File>
 
@@ -2864,10 +2860,6 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_buoylist.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_cargo.cpp"
 
				>
 
			</File>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -2637,10 +2637,6 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_buoylist.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_cargo.hpp"
 
				>
 
			</File>
 
@@ -2861,10 +2857,6 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_buoylist.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\ai\api\ai_cargo.cpp"
 
				>
 
			</File>
source.list
Show inline comments
 
@@ -597,7 +597,6 @@ 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
 
ai/api/ai_cargo.hpp
 
ai/api/ai_cargolist.hpp
 
ai/api/ai_changelog.hpp
 
@@ -654,7 +653,6 @@ 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
 
ai/api/ai_cargo.cpp
 
ai/api/ai_cargolist.cpp
 
ai/api/ai_company.cpp
src/ai/ai_instance.cpp
Show inline comments
 
@@ -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);
src/ai/api/ai_buoylist.cpp
Show inline comments
 
deleted file
src/ai/api/ai_buoylist.hpp
Show inline comments
 
deleted file
src/ai/api/ai_buoylist.hpp.sq
Show inline comments
 
deleted file
src/ai/api/ai_changelog.hpp
Show inline comments
 
@@ -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
src/ai/api/ai_waypoint.cpp
Show inline comments
 
@@ -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;
 
}
src/ai/api/ai_waypoint.hpp
Show inline comments
 
@@ -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 */
src/ai/api/ai_waypoint.hpp.sq
Show inline comments
 
@@ -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 *eng
 
	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 *eng
 

	
 
	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);
 
}
src/ai/api/ai_waypointlist.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
 

	
src/ai/api/ai_waypointlist.hpp
Show inline comments
 
@@ -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 AIAbstract
 
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);
 
};
 

	
 
/**
src/ai/api/ai_waypointlist.hpp.sq
Show inline comments
 
@@ -24,7 +24,7 @@ void SQAIWaypointList_Register(Squirrel 
 
{
 
	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);
 
}
0 comments (0 inline, 0 general)