summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-11-29 23:21:33 +0000
committertruebrain <truebrain@openttd.org>2011-11-29 23:21:33 +0000
commit3da8b5097a4643d531182173df36ca4d3b45a4e2 (patch)
treef310e6fd8a61909b60111f6b2e906e0ab6ff8231 /src/script/api
parent75c4bd280a720592ec4df26efbedd9df5baa2d8f (diff)
downloadopenttd-3da8b5097a4643d531182173df36ca4d3b45a4e2.tar.xz
(svn r23360) -Codechange: move AIInstance to ScriptInstance, making it reusable by other script API instances
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_bridge.cpp8
-rw-r--r--src/script/api/script_controller.hpp2
-rw-r--r--src/script/api/script_group.cpp2
-rw-r--r--src/script/api/script_object.cpp12
-rw-r--r--src/script/api/script_object.hpp20
-rw-r--r--src/script/api/script_order.cpp4
-rw-r--r--src/script/api/script_sign.cpp2
-rw-r--r--src/script/api/script_tunnel.cpp8
-rw-r--r--src/script/api/script_vehicle.cpp4
9 files changed, 29 insertions, 33 deletions
diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp
index 27da5be95..7f6c2ad63 100644
--- a/src/script/api/script_bridge.cpp
+++ b/src/script/api/script_bridge.cpp
@@ -39,10 +39,10 @@
* Helper function to connect a just built bridge to nearby roads.
* @param instance The AI we have to built the road for.
*/
-static void _DoCommandReturnBuildBridge2(class AIInstance *instance)
+static void _DoCommandReturnBuildBridge2(class ScriptInstance *instance)
{
if (!ScriptBridge::_BuildBridgeRoad2()) {
- AIInstance::DoCommandReturn(instance);
+ ScriptInstance::DoCommandReturn(instance);
return;
}
@@ -55,10 +55,10 @@ static void _DoCommandReturnBuildBridge2(class AIInstance *instance)
* Helper function to connect a just built bridge to nearby roads.
* @param instance The AI we have to built the road for.
*/
-static void _DoCommandReturnBuildBridge1(class AIInstance *instance)
+static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
{
if (!ScriptBridge::_BuildBridgeRoad1()) {
- AIInstance::DoCommandReturn(instance);
+ ScriptInstance::DoCommandReturn(instance);
return;
}
diff --git a/src/script/api/script_controller.hpp b/src/script/api/script_controller.hpp
index 00993a6ff..a027c903f 100644
--- a/src/script/api/script_controller.hpp
+++ b/src/script/api/script_controller.hpp
@@ -22,7 +22,7 @@
*/
class ScriptController {
friend class AIScanner;
- friend class AIInstance;
+ friend class ScriptInstance;
public:
/**
diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp
index 14da9e164..026e101d9 100644
--- a/src/script/api/script_group.cpp
+++ b/src/script/api/script_group.cpp
@@ -29,7 +29,7 @@
/* static */ ScriptGroup::GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type)
{
- if (!ScriptObject::DoCommand(0, (::VehicleType)vehicle_type, 0, CMD_CREATE_GROUP, NULL, &AIInstance::DoCommandReturnGroupID)) return GROUP_INVALID;
+ if (!ScriptObject::DoCommand(0, (::VehicleType)vehicle_type, 0, CMD_CREATE_GROUP, NULL, &ScriptInstance::DoCommandReturnGroupID)) return GROUP_INVALID;
/* In case of test-mode, we return GroupID 0 */
return (ScriptGroup::GroupID)0;
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index 8cc9263c5..5afe76beb 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -22,7 +22,7 @@
#include "script_error.hpp"
/**
- * Get the storage associated with the current AIInstance.
+ * Get the storage associated with the current ScriptInstance.
* @return The storage.
*/
static ScriptStorage *GetStorage()
@@ -31,9 +31,9 @@ static ScriptStorage *GetStorage()
}
-/* static */ AIInstance *ScriptObject::ActiveInstance::active = NULL;
+/* static */ ScriptInstance *ScriptObject::ActiveInstance::active = NULL;
-ScriptObject::ActiveInstance::ActiveInstance(AIInstance *instance)
+ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance *instance)
{
this->last_active = ScriptObject::ActiveInstance::active;
ScriptObject::ActiveInstance::active = instance;
@@ -44,7 +44,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
ScriptObject::ActiveInstance::active = this->last_active;
}
-/* static */ AIInstance *ScriptObject::GetActiveInstance()
+/* static */ ScriptInstance *ScriptObject::GetActiveInstance()
{
assert(ScriptObject::ActiveInstance::active != NULL);
return ScriptObject::ActiveInstance::active;
@@ -225,14 +225,14 @@ ScriptObject::ActiveInstance::~ActiveInstance()
return GetStorage()->callback_value[index];
}
-/* static */ bool ScriptObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text, AISuspendCallbackProc *callback)
+/* static */ bool ScriptObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text, Script_SuspendCallbackProc *callback)
{
if (!ScriptObject::CanSuspend()) {
throw Script_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator.");
}
/* Set the default callback to return a true/false result of the DoCommand */
- if (callback == NULL) callback = &AIInstance::DoCommandReturn;
+ if (callback == NULL) callback = &ScriptInstance::DoCommandReturn;
/* Are we only interested in the estimate costs? */
bool estimate_only = GetDoCommandMode() != NULL && !GetDoCommandMode()();
diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp
index b38757cc9..6e6e96d8b 100644
--- a/src/script/api/script_object.hpp
+++ b/src/script/api/script_object.hpp
@@ -17,11 +17,7 @@
#include "../../rail_type.h"
#include "script_types.hpp"
-
-/**
- * The callback function when an AI suspends.
- */
-typedef void (AISuspendCallbackProc)(class AIInstance *instance);
+#include "../script_suspend.hpp"
/**
* The callback function for Mode-classes.
@@ -30,12 +26,12 @@ typedef bool (ScriptModeProc)();
/**
* Uper-parent object of all API classes. You should never use this class in
- * your AI, as it doesn't publish any public functions. It is used
+ * your script, as it doesn't publish any public functions. It is used
* internally to have a common place to handle general things, like internal
* command processing, and command-validation checks.
*/
class ScriptObject : public SimpleCountedObject {
-friend class AIInstance;
+friend class ScriptInstance;
#ifndef DOXYGEN_AI_DOCS
protected:
/**
@@ -47,12 +43,12 @@ protected:
class ActiveInstance {
friend class ScriptObject;
public:
- ActiveInstance(AIInstance *instance);
+ ActiveInstance(ScriptInstance *instance);
~ActiveInstance();
private:
- AIInstance *last_active; ///< The active instance before we go instantiated.
+ ScriptInstance *last_active; ///< The active instance before we go instantiated.
- static AIInstance *active; ///< The global current active instance.
+ static ScriptInstance *active; ///< The global current active instance.
};
public:
@@ -66,13 +62,13 @@ public:
* Get the currently active instance.
* @return The instance.
*/
- static class AIInstance *GetActiveInstance();
+ static class ScriptInstance *GetActiveInstance();
protected:
/**
* Executes a raw DoCommand for the AI.
*/
- static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = NULL, AISuspendCallbackProc *callback = NULL);
+ static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = NULL, Script_SuspendCallbackProc *callback = NULL);
/**
* Sets the DoCommand costs counter to a value.
diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp
index 7a06f68e3..2e72dd350 100644
--- a/src/script/api/script_order.cpp
+++ b/src/script/api/script_order.cpp
@@ -546,10 +546,10 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
* between the wanted and the current order.
* @param instance The AI we are doing the callback for.
*/
-static void _DoCommandReturnSetOrderFlags(class AIInstance *instance)
+static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
{
ScriptObject::SetLastCommandRes(ScriptOrder::_SetOrderFlags());
- AIInstance::DoCommandReturn(instance);
+ ScriptInstance::DoCommandReturn(instance);
}
/* static */ bool ScriptOrder::_SetOrderFlags()
diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp
index 9af5a2fa7..85303b034 100644
--- a/src/script/api/script_sign.cpp
+++ b/src/script/api/script_sign.cpp
@@ -69,7 +69,7 @@
EnforcePrecondition(INVALID_SIGN, !::StrEmpty(text));
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- if (!ScriptObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &AIInstance::DoCommandReturnSignID)) return INVALID_SIGN;
+ if (!ScriptObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &ScriptInstance::DoCommandReturnSignID)) return INVALID_SIGN;
/* In case of test-mode, we return SignID 0 */
return 0;
diff --git a/src/script/api/script_tunnel.cpp b/src/script/api/script_tunnel.cpp
index 98407bf59..e6b7b45cf 100644
--- a/src/script/api/script_tunnel.cpp
+++ b/src/script/api/script_tunnel.cpp
@@ -50,10 +50,10 @@
* Helper function to connect a just built tunnel to nearby roads.
* @param instance The AI we have to built the road for.
*/
-static void _DoCommandReturnBuildTunnel2(class AIInstance *instance)
+static void _DoCommandReturnBuildTunnel2(class ScriptInstance *instance)
{
if (!ScriptTunnel::_BuildTunnelRoad2()) {
- AIInstance::DoCommandReturn(instance);
+ ScriptInstance::DoCommandReturn(instance);
return;
}
@@ -66,10 +66,10 @@ static void _DoCommandReturnBuildTunnel2(class AIInstance *instance)
* Helper function to connect a just built tunnel to nearby roads.
* @param instance The AI we have to built the road for.
*/
-static void _DoCommandReturnBuildTunnel1(class AIInstance *instance)
+static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
{
if (!ScriptTunnel::_BuildTunnelRoad1()) {
- AIInstance::DoCommandReturn(instance);
+ ScriptInstance::DoCommandReturn(instance);
return;
}
diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp
index 216d4cf60..ff240200b 100644
--- a/src/script/api/script_vehicle.cpp
+++ b/src/script/api/script_vehicle.cpp
@@ -60,7 +60,7 @@
EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED);
- if (!ScriptObject::DoCommand(depot, engine_id, 0, ::GetCmdBuildVeh(type), NULL, &AIInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
+ if (!ScriptObject::DoCommand(depot, engine_id, 0, ::GetCmdBuildVeh(type), NULL, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
/* In case of test-mode, we return VehicleID 0 */
return 0;
@@ -70,7 +70,7 @@
{
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
- if (!ScriptObject::DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE, NULL, &AIInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
+ if (!ScriptObject::DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE, NULL, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
/* In case of test-mode, we return VehicleID 0 */
return 0;