Mercurial > hg > openttd
changeset 18776:3fdd053baa35 draft
(svn r23624) -Add: ScriptVehicle/ScriptStation/ScriptSign::GetOwner, to get the owner of those objects (GameScript only)
author | truebrain <truebrain@openttd.org> |
---|---|
date | Mon, 19 Dec 2011 21:00:40 +0000 |
parents | 26ffd3067724 |
children | 693e2f94cbd1 |
files | src/script/api/game/game_sign.hpp.sq src/script/api/game/game_station.hpp.sq src/script/api/game/game_vehicle.hpp.sq src/script/api/script_sign.cpp src/script/api/script_sign.hpp src/script/api/script_station.cpp src/script/api/script_station.hpp src/script/api/script_vehicle.cpp src/script/api/script_vehicle.hpp |
diffstat | 9 files changed, 52 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/script/api/game/game_sign.hpp.sq +++ b/src/script/api/game/game_sign.hpp.sq @@ -31,6 +31,7 @@ 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");
--- a/src/script/api/game/game_station.hpp.sq +++ b/src/script/api/game/game_station.hpp.sq @@ -45,6 +45,7 @@ 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");
--- a/src/script/api/game/game_vehicle.hpp.sq +++ b/src/script/api/game/game_vehicle.hpp.sq @@ -102,6 +102,7 @@ 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");
--- 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));
--- 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 @@ 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).
--- 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;
--- a/src/script/api/script_station.hpp +++ b/src/script/api/script_station.hpp @@ -60,6 +60,15 @@ 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.
--- 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;
--- a/src/script/api/script_vehicle.hpp +++ b/src/script/api/script_vehicle.hpp @@ -132,6 +132,15 @@ 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).