summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-12-19 21:00:40 +0000
committertruebrain <truebrain@openttd.org>2011-12-19 21:00:40 +0000
commitd85a628dde5eed0a0a2deb0b6bc199ba939e307f (patch)
tree50edb777ea125e3d0bb8f271fa05a7a1c405f45c
parent3a535690d4e9aaa896a062e7b5b5454b1b07ac47 (diff)
downloadopenttd-d85a628dde5eed0a0a2deb0b6bc199ba939e307f.tar.xz
(svn r23624) -Add: ScriptVehicle/ScriptStation/ScriptSign::GetOwner, to get the owner of those objects (GameScript only)
-rw-r--r--src/script/api/game/game_sign.hpp.sq1
-rw-r--r--src/script/api/game/game_station.hpp.sq1
-rw-r--r--src/script/api/game/game_vehicle.hpp.sq1
-rw-r--r--src/script/api/script_sign.cpp7
-rw-r--r--src/script/api/script_sign.hpp10
-rw-r--r--src/script/api/script_station.cpp7
-rw-r--r--src/script/api/script_station.hpp9
-rw-r--r--src/script/api/script_vehicle.cpp7
-rw-r--r--src/script/api/script_vehicle.hpp9
9 files changed, 52 insertions, 0 deletions
diff --git a/src/script/api/game/game_sign.hpp.sq b/src/script/api/game/game_sign.hpp.sq
index 20eb52ec2..0fba369cf 100644
--- a/src/script/api/game/game_sign.hpp.sq
+++ b/src/script/api/game/game_sign.hpp.sq
@@ -31,6 +31,7 @@ void SQGSSign_Register(Squirrel *engine)
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::IsValidSign, "IsValidSign", 2, ".i");
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::SetName, "SetName", 3, ".i.");
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::GetName, "GetName", 2, ".i");
+ SQGSSign.DefSQStaticMethod(engine, &ScriptSign::GetOwner, "GetOwner", 2, ".i");
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::GetLocation, "GetLocation", 2, ".i");
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::BuildSign, "BuildSign", 3, ".i.");
SQGSSign.DefSQStaticMethod(engine, &ScriptSign::RemoveSign, "RemoveSign", 2, ".i");
diff --git a/src/script/api/game/game_station.hpp.sq b/src/script/api/game/game_station.hpp.sq
index 5aa696794..cf5b59ebe 100644
--- a/src/script/api/game/game_station.hpp.sq
+++ b/src/script/api/game/game_station.hpp.sq
@@ -45,6 +45,7 @@ void SQGSStation_Register(Squirrel *engine)
ScriptError::RegisterErrorMapString(ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN, "ERR_STATION_TOO_MANY_STATIONS_IN_TOWN");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::IsValidStation, "IsValidStation", 2, ".i");
+ SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetOwner, "GetOwner", 2, ".i");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetStationID, "GetStationID", 2, ".i");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoRating, "GetCargoRating", 3, ".ii");
diff --git a/src/script/api/game/game_vehicle.hpp.sq b/src/script/api/game/game_vehicle.hpp.sq
index 9652335e3..9fc5599cd 100644
--- a/src/script/api/game/game_vehicle.hpp.sq
+++ b/src/script/api/game/game_vehicle.hpp.sq
@@ -102,6 +102,7 @@ void SQGSVehicle_Register(Squirrel *engine)
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::IsValidVehicle, "IsValidVehicle", 2, ".i");
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetNumWagons, "GetNumWagons", 2, ".i");
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetName, "GetName", 2, ".i");
+ SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetOwner, "GetOwner", 2, ".i");
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetLocation, "GetLocation", 2, ".i");
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetEngineType, "GetEngineType", 2, ".i");
SQGSVehicle.DefSQStaticMethod(engine, &ScriptVehicle::GetWagonEngineType, "GetWagonEngineType", 3, ".ii");
diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp
index ab7988cc1..fcb9e4370 100644
--- a/src/script/api/script_sign.cpp
+++ b/src/script/api/script_sign.cpp
@@ -27,6 +27,13 @@
return si != NULL && (si->owner == _current_company || si->owner == OWNER_DEITY);
}
+/* static */ ScriptCompany::CompanyID ScriptSign::GetOwner(SignID sign_id)
+{
+ if (!IsValidSign(sign_id)) return ScriptCompany::COMPANY_INVALID;
+
+ return static_cast<ScriptCompany::CompanyID>((int)::Sign::Get(sign_id)->owner);
+}
+
/* static */ bool ScriptSign::SetName(SignID sign_id, const char *name)
{
EnforcePrecondition(false, IsValidSign(sign_id));
diff --git a/src/script/api/script_sign.hpp b/src/script/api/script_sign.hpp
index ee235615d..9aacc409c 100644
--- a/src/script/api/script_sign.hpp
+++ b/src/script/api/script_sign.hpp
@@ -12,6 +12,7 @@
#ifndef SCRIPT_SIGN_HPP
#define SCRIPT_SIGN_HPP
+#include "script_company.hpp"
#include "script_error.hpp"
/**
@@ -60,6 +61,15 @@ public:
static char *GetName(SignID sign_id);
/**
+ * Get the owner of a sign.
+ * @param sign_id The sign to get the owner of.
+ * @pre IsValidSign(sign_id).
+ * @return The owner the sign has.
+ * @api -ai
+ */
+ static ScriptCompany::CompanyID GetOwner(SignID sign_id);
+
+ /**
* Gets the location of the sign.
* @param sign_id The sign to get the location of.
* @pre IsValidSign(sign_id).
diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp
index 61964c47b..4ac930c65 100644
--- a/src/script/api/script_station.cpp
+++ b/src/script/api/script_station.cpp
@@ -26,6 +26,13 @@
return st != NULL && (st->owner == _current_company || _current_company == OWNER_DEITY || st->owner == OWNER_NONE);
}
+/* static */ ScriptCompany::CompanyID ScriptStation::GetOwner(StationID station_id)
+{
+ if (!IsValidStation(station_id)) return ScriptCompany::COMPANY_INVALID;
+
+ return static_cast<ScriptCompany::CompanyID>((int)::Station::Get(station_id)->owner);
+}
+
/* static */ StationID ScriptStation::GetStationID(TileIndex tile)
{
if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION)) return INVALID_STATION;
diff --git a/src/script/api/script_station.hpp b/src/script/api/script_station.hpp
index becff2156..b6da4a913 100644
--- a/src/script/api/script_station.hpp
+++ b/src/script/api/script_station.hpp
@@ -60,6 +60,15 @@ public:
static bool IsValidStation(StationID station_id);
/**
+ * Get the owner of a station.
+ * @param station_id The station to get the owner of.
+ * @pre IsValidStation(station_id).
+ * @return The owner the station has.
+ * @api -ai
+ */
+ static ScriptCompany::CompanyID GetOwner(StationID station_id);
+
+ /**
* Get the StationID of a tile, if there is a station.
* @param tile The tile to find the stationID of
* @return StationID of the station.
diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp
index 2913d7612..17fc8679f 100644
--- a/src/script/api/script_vehicle.cpp
+++ b/src/script/api/script_vehicle.cpp
@@ -31,6 +31,13 @@
return v != NULL && (v->owner == _current_company || _current_company == OWNER_DEITY) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
}
+/* static */ ScriptCompany::CompanyID ScriptVehicle::GetOwner(VehicleID vehicle_id)
+{
+ if (!IsValidVehicle(vehicle_id)) return ScriptCompany::COMPANY_INVALID;
+
+ return static_cast<ScriptCompany::CompanyID>((int)::Vehicle::Get(vehicle_id)->owner);
+}
+
/* static */ int32 ScriptVehicle::GetNumWagons(VehicleID vehicle_id)
{
if (!IsValidVehicle(vehicle_id)) return -1;
diff --git a/src/script/api/script_vehicle.hpp b/src/script/api/script_vehicle.hpp
index 4d0debb4a..f9cf71876 100644
--- a/src/script/api/script_vehicle.hpp
+++ b/src/script/api/script_vehicle.hpp
@@ -132,6 +132,15 @@ public:
static char *GetName(VehicleID vehicle_id);
/**
+ * Get the owner of a vehicle.
+ * @param vehicle_id The vehicle to get the owner of.
+ * @pre IsValidVehicle(vehicle_id).
+ * @return The owner the vehicle has.
+ * @api -ai
+ */
+ static ScriptCompany::CompanyID GetOwner(VehicleID vehicle_id);
+
+ /**
* Get the current location of a vehicle.
* @param vehicle_id The vehicle to get the location of.
* @pre IsValidVehicle(vehicle_id).