diff options
author | truebrain <truebrain@openttd.org> | 2011-11-29 23:15:35 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2011-11-29 23:15:35 +0000 |
commit | 98103121d4f2ed1f1581919b7b1f343ccd410c12 (patch) | |
tree | 1e760dd6517a6b0f9fb669ec277139a8e3f9a4a3 /src/script/api | |
parent | afdb67a3534f85b4efbd3327ece8137211042d7b (diff) | |
download | openttd-98103121d4f2ed1f1581919b7b1f343ccd410c12.tar.xz |
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
Diffstat (limited to 'src/script/api')
101 files changed, 1943 insertions, 1942 deletions
diff --git a/src/script/api/script_accounting.cpp b/src/script/api/script_accounting.cpp index 3255f8613..dfe05df3b 100644 --- a/src/script/api/script_accounting.cpp +++ b/src/script/api/script_accounting.cpp @@ -7,28 +7,28 @@ * 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 script_accounting.cpp Implementation of AIAccounting. */ +/** @file script_accounting.cpp Implementation of ScriptAccounting. */ #include "../../stdafx.h" #include "script_accounting.hpp" -Money AIAccounting::GetCosts() +Money ScriptAccounting::GetCosts() { return this->GetDoCommandCosts(); } -void AIAccounting::ResetCosts() +void ScriptAccounting::ResetCosts() { this->SetDoCommandCosts(0); } -AIAccounting::AIAccounting() +ScriptAccounting::ScriptAccounting() { this->last_costs = this->GetDoCommandCosts(); this->SetDoCommandCosts(0); } -AIAccounting::~AIAccounting() +ScriptAccounting::~ScriptAccounting() { this->SetDoCommandCosts(this->last_costs); } diff --git a/src/script/api/script_accounting.hpp b/src/script/api/script_accounting.hpp index e01a7684a..dd4702052 100644 --- a/src/script/api/script_accounting.hpp +++ b/src/script/api/script_accounting.hpp @@ -20,40 +20,40 @@ * Example: * <pre> * { - * local costs = AIAccounting(); + * local costs = ScriptAccounting(); * BuildRoad(from_here, to_here); * BuildRoad(from_there, to_there); * print("Costs for route is: " + costs.GetCosts()); * } * </pre> */ -class AIAccounting : public AIObject { +class ScriptAccounting : public ScriptObject { public: /** * Creating instance of this class starts counting the costs of commands * from zero. Saves the current value of GetCosts so we can return to * the old value when the instance gets deleted. */ - AIAccounting(); + ScriptAccounting(); /** - * Restore the AIAccounting that was on top when we created this instance. + * Restore the ScriptAccounting that was on top when we created this instance. * So basically restore the value of GetCosts to what it was before we * created this instance. */ - ~AIAccounting(); + ~ScriptAccounting(); /** * Get the current value of the costs. * @return The current costs. - * @note when nesting AIAccounting instances all instances' GetCosts + * @note when nesting ScriptAccounting instances all instances' GetCosts * will always return the value of the 'top' instance. */ Money GetCosts(); /** * Reset the costs to zero. - * @note when nesting AIAccounting instances all instances' ResetCosts + * @note when nesting ScriptAccounting instances all instances' ResetCosts * will always effect on the 'top' instance. */ void ResetCosts(); diff --git a/src/script/api/script_airport.cpp b/src/script/api/script_airport.cpp index 97d6e6bb7..fbc763cb1 100644 --- a/src/script/api/script_airport.cpp +++ b/src/script/api/script_airport.cpp @@ -7,7 +7,7 @@ * 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 script_airport.cpp Implementation of AIAirport. */ +/** @file script_airport.cpp Implementation of ScriptAirport. */ #include "../../stdafx.h" #include "script_airport.hpp" @@ -16,17 +16,17 @@ #include "../../company_func.h" #include "../../town.h" -/* static */ bool AIAirport::IsValidAirportType(AirportType type) +/* static */ bool ScriptAirport::IsValidAirportType(AirportType type) { return IsAirportInformationAvailable(type) && ::AirportSpec::Get(type)->IsAvailable(); } -/* static */ bool AIAirport::IsAirportInformationAvailable(AirportType type) +/* static */ bool ScriptAirport::IsAirportInformationAvailable(AirportType type) { return type >= 0 && type < (AirportType)NUM_AIRPORTS && AirportSpec::Get(type)->enabled; } -/* static */ Money AIAirport::GetPrice(AirportType type) +/* static */ Money ScriptAirport::GetPrice(AirportType type) { if (!IsValidAirportType(type)) return -1; @@ -34,61 +34,61 @@ return _price[PR_BUILD_STATION_AIRPORT] * as->size_x * as->size_y; } -/* static */ bool AIAirport::IsHangarTile(TileIndex tile) +/* static */ bool ScriptAirport::IsHangarTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_STATION) && ::IsHangar(tile); } -/* static */ bool AIAirport::IsAirportTile(TileIndex tile) +/* static */ bool ScriptAirport::IsAirportTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_STATION) && ::IsAirport(tile); } -/* static */ int32 AIAirport::GetAirportWidth(AirportType type) +/* static */ int32 ScriptAirport::GetAirportWidth(AirportType type) { if (!IsAirportInformationAvailable(type)) return -1; return ::AirportSpec::Get(type)->size_x; } -/* static */ int32 AIAirport::GetAirportHeight(AirportType type) +/* static */ int32 ScriptAirport::GetAirportHeight(AirportType type) { if (!IsAirportInformationAvailable(type)) return -1; return ::AirportSpec::Get(type)->size_y; } -/* static */ int32 AIAirport::GetAirportCoverageRadius(AirportType type) +/* static */ int32 ScriptAirport::GetAirportCoverageRadius(AirportType type) { if (!IsAirportInformationAvailable(type)) return -1; return _settings_game.station.modified_catchment ? ::AirportSpec::Get(type)->catchment : (uint)CA_UNMODIFIED; } -/* static */ bool AIAirport::BuildAirport(TileIndex tile, AirportType type, StationID station_id) +/* static */ bool ScriptAirport::BuildAirport(TileIndex tile, AirportType type, StationID station_id) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsValidAirportType(type)); - EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); + EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); - uint p2 = station_id == AIStation::STATION_JOIN_ADJACENT ? 0 : 1; - p2 |= (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; - return AIObject::DoCommand(tile, type, p2, CMD_BUILD_AIRPORT); + uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1; + p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; + return ScriptObject::DoCommand(tile, type, p2, CMD_BUILD_AIRPORT); } -/* static */ bool AIAirport::RemoveAirport(TileIndex tile) +/* static */ bool ScriptAirport::RemoveAirport(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)) EnforcePrecondition(false, IsAirportTile(tile) || IsHangarTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ int32 AIAirport::GetNumHangars(TileIndex tile) +/* static */ int32 ScriptAirport::GetNumHangars(TileIndex tile) { if (!::IsValidTile(tile)) return -1; if (!::IsTileType(tile, MP_STATION)) return -1; @@ -100,7 +100,7 @@ return st->airport.GetNumHangars(); } -/* static */ TileIndex AIAirport::GetHangarOfAirport(TileIndex tile) +/* static */ TileIndex ScriptAirport::GetHangarOfAirport(TileIndex tile) { if (!::IsValidTile(tile)) return INVALID_TILE; if (!::IsTileType(tile, MP_STATION)) return INVALID_TILE; @@ -113,19 +113,19 @@ return st->airport.GetHangarTile(0); } -/* static */ AIAirport::AirportType AIAirport::GetAirportType(TileIndex tile) +/* static */ ScriptAirport::AirportType ScriptAirport::GetAirportType(TileIndex tile) { - if (!AITile::IsStationTile(tile)) return AT_INVALID; + if (!ScriptTile::IsStationTile(tile)) return AT_INVALID; StationID station_id = ::GetStationIndex(tile); - if (!AIStation::HasStationType(station_id, AIStation::STATION_AIRPORT)) return AT_INVALID; + if (!ScriptStation::HasStationType(station_id, ScriptStation::STATION_AIRPORT)) return AT_INVALID; return (AirportType)::Station::Get(station_id)->airport.type; } -/* static */ int AIAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type) +/* static */ int ScriptAirport::GetNoiseLevelIncrease(TileIndex tile, AirportType type) { extern Town *AirportGetNearestTown(const AirportSpec *as, TileIndex airport_tile); extern uint8 GetAirportNoiseLevelForTown(const AirportSpec *as, TileIndex town_tile, TileIndex tile); @@ -142,7 +142,7 @@ return 1; } -/* static */ TownID AIAirport::GetNearestTown(TileIndex tile, AirportType type) +/* static */ TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type) { extern Town *AirportGetNearestTown(const AirportSpec *as, TileIndex airport_tile); diff --git a/src/script/api/script_airport.hpp b/src/script/api/script_airport.hpp index c60564526..9121c33b2 100644 --- a/src/script/api/script_airport.hpp +++ b/src/script/api/script_airport.hpp @@ -17,7 +17,7 @@ /** * Class that handles all airport related functions. */ -class AIAirport : public AIObject { +class ScriptAirport : public ScriptObject { public: /** * The types of airports available in the game. @@ -80,7 +80,7 @@ public: /** * Checks whether the given tile is actually a tile with a hangar. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a hangar. */ static bool IsHangarTile(TileIndex tile); @@ -88,7 +88,7 @@ public: /** * Checks whether the given tile is actually a tile with an airport. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has an airport. */ static bool IsAirportTile(TileIndex tile); @@ -120,7 +120,7 @@ public: /** * Get the number of hangars of the airport. * @param tile Any tile of the airport. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The number of hangars of the airport. */ static int32 GetNumHangars(TileIndex tile); @@ -128,7 +128,7 @@ public: /** * Get the first hanger tile of the airport. * @param tile Any tile of the airport. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre GetNumHangars(tile) > 0. * @return The first hanger tile of the airport. * @note Possible there are more hangars, but you won't be able to find them @@ -141,15 +141,15 @@ public: * Builds a airport with tile at the topleft corner. * @param tile The topleft corner of the airport. * @param type The type of airport to build. - * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. - * @pre AIMap::IsValidTile(tile). + * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. + * @pre ScriptMap::IsValidTile(tile). * @pre AirportAvailable(type). - * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_FLAT_LAND_REQUIRED - * @exception AIError::ERR_LOCAL_AUTHORITY_REFUSES - * @exception AIStation::ERR_STATION_TOO_LARGE - * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION + * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptError::ERR_LOCAL_AUTHORITY_REFUSES + * @exception ScriptStation::ERR_STATION_TOO_LARGE + * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION * @return Whether the airport has been/can be build or not. */ static bool BuildAirport(TileIndex tile, AirportType type, StationID station_id); @@ -157,8 +157,8 @@ public: /** * Removes an airport. * @param tile Any tile of the airport. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the airport has been/can be removed or not. */ static bool RemoveAirport(TileIndex tile); @@ -166,8 +166,8 @@ public: /** * Get the AirportType of an existing airport. * @param tile Any tile of the airport. - * @pre AITile::IsStationTile(tile). - * @pre AIStation::HasStationType(AIStation.GetStationID(tile), AIStation::STATION_AIRPORT). + * @pre ScriptTile::IsStationTile(tile). + * @pre ScriptStation::HasStationType(ScriptStation.GetStationID(tile), ScriptStation::STATION_AIRPORT). * @return The AirportType of the airport. */ static AirportType GetAirportType(TileIndex tile); diff --git a/src/script/api/script_base.cpp b/src/script/api/script_base.cpp index 72e0ad721..5be6dd9a5 100644 --- a/src/script/api/script_base.cpp +++ b/src/script/api/script_base.cpp @@ -7,14 +7,14 @@ * 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 script_base.cpp Implementation of AIBase. */ +/** @file script_base.cpp Implementation of ScriptBase. */ #include "../../stdafx.h" #include "script_base.hpp" #include "../../network/network.h" #include "../../core/random_func.hpp" -/* static */ uint32 AIBase::Rand() +/* static */ uint32 ScriptBase::Rand() { /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) * but we pick InteractiveRandomRange if we are a network_server or network-client. */ @@ -22,12 +22,12 @@ return ::Random(); } -/* static */ uint32 AIBase::RandItem(int unused_param) +/* static */ uint32 ScriptBase::RandItem(int unused_param) { - return AIBase::Rand(); + return ScriptBase::Rand(); } -/* static */ uint AIBase::RandRange(uint max) +/* static */ uint ScriptBase::RandRange(uint max) { /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) * but we pick InteractiveRandomRange if we are a network_server or network-client. */ @@ -35,17 +35,17 @@ return ::RandomRange(max); } -/* static */ uint32 AIBase::RandRangeItem(int unused_param, uint max) +/* static */ uint32 ScriptBase::RandRangeItem(int unused_param, uint max) { - return AIBase::RandRange(max); + return ScriptBase::RandRange(max); } -/* static */ bool AIBase::Chance(uint out, uint max) +/* static */ bool ScriptBase::Chance(uint out, uint max) { return (uint16)Rand() <= (uint16)((65536 * out) / max); } -/* static */ bool AIBase::ChanceItem(int unused_param, uint out, uint max) +/* static */ bool ScriptBase::ChanceItem(int unused_param, uint out, uint max) { - return AIBase::Chance(out, max); + return ScriptBase::Chance(out, max); } diff --git a/src/script/api/script_base.hpp b/src/script/api/script_base.hpp index 13daa3643..9cffe74a7 100644 --- a/src/script/api/script_base.hpp +++ b/src/script/api/script_base.hpp @@ -23,7 +23,7 @@ * ran on the server only, not on all clients). This means that * we use InteractiveRandom in MP. Rand() takes care of this for you. */ -class AIBase : public AIObject { +class ScriptBase : public ScriptObject { public: /** * Get a random value. diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index 2ff811346..9fcb4b593 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -7,7 +7,7 @@ * 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 script_basestation.cpp Implementation of AIBaseStation. */ +/** @file script_basestation.cpp Implementation of ScriptBaseStation. */ #include "../../stdafx.h" #include "script_basestation.hpp" @@ -17,13 +17,13 @@ #include "../../company_func.h" #include "table/strings.h" -/* static */ bool AIBaseStation::IsValidBaseStation(StationID station_id) +/* static */ bool ScriptBaseStation::IsValidBaseStation(StationID station_id) { const BaseStation *st = ::BaseStation::GetIfValid(station_id); return st != NULL && (st->owner == _current_company || st->owner == OWNER_NONE); } -/* static */ char *AIBaseStation::GetName(StationID station_id) +/* static */ char *ScriptBaseStation::GetName(StationID station_id) { if (!IsValidBaseStation(station_id)) return NULL; @@ -35,23 +35,23 @@ return name; } -/* static */ bool AIBaseStation::SetName(StationID station_id, const char *name) +/* static */ bool ScriptBaseStation::SetName(StationID station_id, const char *name) { EnforcePrecondition(false, IsValidBaseStation(station_id)); EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_STATION_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return AIObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, name); + return ScriptObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, name); } -/* static */ TileIndex AIBaseStation::GetLocation(StationID station_id) +/* static */ TileIndex ScriptBaseStation::GetLocation(StationID station_id) { if (!IsValidBaseStation(station_id)) return INVALID_TILE; return ::BaseStation::Get(station_id)->xy; } -/* static */ int32 AIBaseStation::GetConstructionDate(StationID station_id) +/* static */ int32 ScriptBaseStation::GetConstructionDate(StationID station_id) { if (!IsValidBaseStation(station_id)) return -1; diff --git a/src/script/api/script_basestation.hpp b/src/script/api/script_basestation.hpp index b26dbaecc..8399067e3 100644 --- a/src/script/api/script_basestation.hpp +++ b/src/script/api/script_basestation.hpp @@ -17,7 +17,7 @@ /** * Base class for stations and waypoints. */ -class AIBaseStation : public AIObject { +class ScriptBaseStation : public ScriptObject { public: /** * Special station IDs for building adjacent/new stations when @@ -52,7 +52,7 @@ public: * @pre IsValidBaseStation(station_id). * @pre 'name' must have at least one character. * @pre 'name' must have at most 30 characters. - * @exception AIError::ERR_NAME_IS_NOT_UNIQUE + * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. */ static bool SetName(StationID station_id, const char *name); @@ -63,7 +63,7 @@ public: * @pre IsValidBaseStation(station_id). * @return The tile the basestation sign above it. * @note The tile is not necessarily a station tile (and if it is, it could also belong to another station). - * @see AITileList_StationType. + * @see ScriptTileList_StationType. */ static TileIndex GetLocation(StationID station_id); diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp index a1757f315..27da5be95 100644 --- a/src/script/api/script_bridge.cpp +++ b/src/script/api/script_bridge.cpp @@ -7,7 +7,7 @@ * 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 script_bridge.cpp Implementation of AIBridge. */ +/** @file script_bridge.cpp Implementation of ScriptBridge. */ #include "../../stdafx.h" #include "script_bridge.hpp" @@ -18,18 +18,18 @@ #include "../../economy_func.h" #include "../../date_func.h" -/* static */ bool AIBridge::IsValidBridge(BridgeID bridge_id) +/* static */ bool ScriptBridge::IsValidBridge(BridgeID bridge_id) { return bridge_id < MAX_BRIDGES && ::GetBridgeSpec(bridge_id)->avail_year <= _cur_year; } -/* static */ bool AIBridge::IsBridgeTile(TileIndex tile) +/* static */ bool ScriptBridge::IsBridgeTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsBridgeTile(tile); } -/* static */ BridgeID AIBridge::GetBridgeID(TileIndex tile) +/* static */ BridgeID ScriptBridge::GetBridgeID(TileIndex tile) { if (!IsBridgeTile(tile)) return (BridgeID)-1; return (BridgeID)::GetBridgeType(tile); @@ -41,7 +41,7 @@ */ static void _DoCommandReturnBuildBridge2(class AIInstance *instance) { - if (!AIBridge::_BuildBridgeRoad2()) { + if (!ScriptBridge::_BuildBridgeRoad2()) { AIInstance::DoCommandReturn(instance); return; } @@ -57,7 +57,7 @@ static void _DoCommandReturnBuildBridge2(class AIInstance *instance) */ static void _DoCommandReturnBuildBridge1(class AIInstance *instance) { - if (!AIBridge::_BuildBridgeRoad1()) { + if (!ScriptBridge::_BuildBridgeRoad1()) { AIInstance::DoCommandReturn(instance); return; } @@ -67,71 +67,71 @@ static void _DoCommandReturnBuildBridge1(class AIInstance *instance) NOT_REACHED(); } -/* static */ bool AIBridge::BuildBridge(AIVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end) +/* static */ bool ScriptBridge::BuildBridge(ScriptVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end) { EnforcePrecondition(false, start != end); EnforcePrecondition(false, ::IsValidTile(start) && ::IsValidTile(end)); EnforcePrecondition(false, TileX(start) == TileX(end) || TileY(start) == TileY(end)); - EnforcePrecondition(false, vehicle_type == AIVehicle::VT_ROAD || vehicle_type == AIVehicle::VT_RAIL || vehicle_type == AIVehicle::VT_WATER); - EnforcePrecondition(false, vehicle_type != AIVehicle::VT_RAIL || AIRail::IsRailTypeAvailable(AIRail::GetCurrentRailType())); + EnforcePrecondition(false, vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_WATER); + EnforcePrecondition(false, vehicle_type != ScriptVehicle::VT_RAIL || ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())); uint type = 0; switch (vehicle_type) { - case AIVehicle::VT_ROAD: + case ScriptVehicle::VT_ROAD: type |= (TRANSPORT_ROAD << 15); - type |= (::RoadTypeToRoadTypes((::RoadType)AIObject::GetRoadType()) << 8); + type |= (::RoadTypeToRoadTypes((::RoadType)ScriptObject::GetRoadType()) << 8); break; - case AIVehicle::VT_RAIL: + case ScriptVehicle::VT_RAIL: type |= (TRANSPORT_RAIL << 15); - type |= (AIRail::GetCurrentRailType() << 8); + type |= (ScriptRail::GetCurrentRailType() << 8); break; - case AIVehicle::VT_WATER: + case ScriptVehicle::VT_WATER: type |= (TRANSPORT_WATER << 15); break; default: NOT_REACHED(); } /* For rail and water we do nothing special */ - if (vehicle_type == AIVehicle::VT_RAIL || vehicle_type == AIVehicle::VT_WATER) { - return AIObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE); + if (vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_WATER) { + return ScriptObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE); } - AIObject::SetCallbackVariable(0, start); - AIObject::SetCallbackVariable(1, end); - return AIObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE, NULL, &::_DoCommandReturnBuildBridge1); + ScriptObject::SetCallbackVariable(0, start); + ScriptObject::SetCallbackVariable(1, end); + return ScriptObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE, NULL, &::_DoCommandReturnBuildBridge1); } -/* static */ bool AIBridge::_BuildBridgeRoad1() +/* static */ bool ScriptBridge::_BuildBridgeRoad1() { /* Build the piece of road on the 'start' side of the bridge */ - TileIndex end = AIObject::GetCallbackVariable(0); - TileIndex start = AIObject::GetCallbackVariable(1); + TileIndex end = ScriptObject::GetCallbackVariable(0); + TileIndex start = ScriptObject::GetCallbackVariable(1); DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return AIObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildBridge2); + return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildBridge2); } -/* static */ bool AIBridge::_BuildBridgeRoad2() +/* static */ bool ScriptBridge::_BuildBridgeRoad2() { /* Build the piece of road on the 'end' side of the bridge */ - TileIndex end = AIObject::GetCallbackVariable(0); - TileIndex start = AIObject::GetCallbackVariable(1); + TileIndex end = ScriptObject::GetCallbackVariable(0); + TileIndex start = ScriptObject::GetCallbackVariable(1); DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return AIObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD); + return ScriptObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD); } -/* static */ bool AIBridge::RemoveBridge(TileIndex tile) +/* static */ bool ScriptBridge::RemoveBridge(TileIndex tile) { EnforcePrecondition(false, IsBridgeTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ char *AIBridge::GetName(BridgeID bridge_id) +/* static */ char *ScriptBridge::GetName(BridgeID bridge_id) { if (!IsValidBridge(bridge_id)) return NULL; @@ -142,35 +142,35 @@ static void _DoCommandReturnBuildBridge1(class AIInstance *instance) return bridge_name; } -/* static */ int32 AIBridge::GetMaxSpeed(BridgeID bridge_id) +/* static */ int32 ScriptBridge::GetMaxSpeed(BridgeID bridge_id) { if (!IsValidBridge(bridge_id)) return -1; return ::GetBridgeSpec(bridge_id)->speed; // km-ish/h } -/* static */ Money AIBridge::GetPrice(BridgeID bridge_id, uint length) +/* static */ Money ScriptBridge::GetPrice(BridgeID bridge_id, uint length) { if (!IsValidBridge(bridge_id)) return -1; return ::CalcBridgeLenCostFactor(length) * _price[PR_BUILD_BRIDGE] * ::GetBridgeSpec(bridge_id)->price >> 8; } -/* static */ int32 AIBridge::GetMaxLength(BridgeID bridge_id) +/* static */ int32 ScriptBridge::GetMaxLength(BridgeID bridge_id) { if (!IsValidBridge(bridge_id)) return -1; return min(::GetBridgeSpec(bridge_id)->max_length, _settings_game.construction.max_bridge_length) + 2; } -/* static */ int32 AIBridge::GetMinLength(BridgeID bridge_id) +/* static */ int32 ScriptBridge::GetMinLength(BridgeID bridge_id) { if (!IsValidBridge(bridge_id)) return -1; return ::GetBridgeSpec(bridge_id)->min_length + 2; } -/* static */ TileIndex AIBridge::GetOtherBridgeEnd(TileIndex tile) +/* static */ TileIndex ScriptBridge::GetOtherBridgeEnd(TileIndex tile) { if (!::IsValidTile(tile)) return INVALID_TILE; if (!IsBridgeTile(tile)) return INVALID_TILE; diff --git a/src/script/api/script_bridge.hpp b/src/script/api/script_bridge.hpp index bb6f6a9c8..b6d48f0e2 100644 --- a/src/script/api/script_bridge.hpp +++ b/src/script/api/script_bridge.hpp @@ -17,14 +17,14 @@ /** * Class that handles all bridge related functions. */ -class AIBridge : public AIObject { +class ScriptBridge : public ScriptObject { public: /** * All bridge related error messages. */ enum ErrorMessages { /** Base for bridge related errors */ - ERR_BRIDGE_BASE = AIError::ERR_CAT_BRIDGE << AIError::ERR_CAT_BIT_SIZE, + ERR_BRIDGE_BASE = ScriptError::ERR_CAT_BRIDGE << ScriptError::ERR_CAT_BIT_SIZE, /** * The bridge you want to build is not available yet, @@ -49,7 +49,7 @@ public: /** * Checks whether the given tile is actually a bridge start or end tile. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is the beginning or end of a bridge. */ static bool IsBridgeTile(TileIndex tile); @@ -127,31 +127,31 @@ public: * @param bridge_id The bridge-type to build. * @param start Where to start the bridge. * @param end Where to end the bridge. - * @pre AIMap::IsValidTile(start). - * @pre AIMap::IsValidTile(end). + * @pre ScriptMap::IsValidTile(start). + * @pre ScriptMap::IsValidTile(end). * @pre 'start' and 'end' are in a straight line, i.e. - * AIMap::GetTileX(start) == AIMap::GetTileX(end) or - * AIMap::GetTileY(start) == AIMap::GetTileY(end). - * @pre vehicle_type == AIVehicle::VT_ROAD || vehicle_type == AIVehicle::VT_WATER || - * (vehicle_type == AIVehicle::VT_RAIL && AIRail::IsRailTypeAvailable(AIRail::GetCurrentRailType())). - * @exception AIError::ERR_ALREADY_BUILT - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIError::ERR_VEHICLE_IN_THE_WAY - * @exception AIBridge::ERR_BRIDGE_TYPE_UNAVAILABLE - * @exception AIBridge::ERR_BRIDGE_CANNOT_END_IN_WATER - * @exception AIBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT + * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or + * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end). + * @pre vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_WATER || + * (vehicle_type == ScriptVehicle::VT_RAIL && ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())). + * @exception ScriptError::ERR_ALREADY_BUILT + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptBridge::ERR_BRIDGE_TYPE_UNAVAILABLE + * @exception ScriptBridge::ERR_BRIDGE_CANNOT_END_IN_WATER + * @exception ScriptBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT * @return Whether the bridge has been/can be build or not. * @note No matter if the road pieces were build or not, if building the * bridge succeeded, this function returns true. */ - static bool BuildBridge(AIVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end); + static bool BuildBridge(ScriptVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end); /** * Removes a bridge, by executing it on either the start or end tile. * @param tile An end or start tile of the bridge. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the bridge has been/can be removed or not. */ static bool RemoveBridge(TileIndex tile); @@ -159,7 +159,7 @@ public: /** * Get the tile that is on the other end of a bridge starting at tile. * @param tile The tile that is an end of a bridge. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre IsBridgeTile(tile). * @return The TileIndex that is the other end of the bridge. */ diff --git a/src/script/api/script_bridgelist.cpp b/src/script/api/script_bridgelist.cpp index 95ae96cc8..9687663e9 100644 --- a/src/script/api/script_bridgelist.cpp +++ b/src/script/api/script_bridgelist.cpp @@ -7,25 +7,25 @@ * 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 script_bridgelist.cpp Implementation of AIBridgeList and friends. */ +/** @file script_bridgelist.cpp Implementation of ScriptBridgeList and friends. */ #include "../../stdafx.h" #include "script_bridgelist.hpp" #include "script_bridge.hpp" #include "../../bridge.h" -AIBridgeList::AIBridgeList() +ScriptBridgeList::ScriptBridgeList() { for (byte j = 0; j < MAX_BRIDGES; j++) { - if (AIBridge::IsValidBridge(j)) this->AddItem(j); + if (ScriptBridge::IsValidBridge(j)) this->AddItem(j); } } -AIBridgeList_Length::AIBridgeList_Length(uint length) +ScriptBridgeList_Length::ScriptBridgeList_Length(uint length) { for (byte j = 0; j < MAX_BRIDGES; j++) { - if (AIBridge::IsValidBridge(j)) { - if (length >= (uint)AIBridge::GetMinLength(j) && length <= (uint)AIBridge::GetMaxLength(j)) this->AddItem(j); + if (ScriptBridge::IsValidBridge(j)) { + if (length >= (uint)ScriptBridge::GetMinLength(j) && length <= (uint)ScriptBridge::GetMaxLength(j)) this->AddItem(j); } } } diff --git a/src/script/api/script_bridgelist.hpp b/src/script/api/script_bridgelist.hpp index 8d089d4a5..6bcdf8393 100644 --- a/src/script/api/script_bridgelist.hpp +++ b/src/script/api/script_bridgelist.hpp @@ -16,23 +16,23 @@ /** * Create a list of bridges. - * @ingroup AIList + * @ingroup ScriptList */ -class AIBridgeList : public AIList { +class ScriptBridgeList : public ScriptList { public: - AIBridgeList(); + ScriptBridgeList(); }; /** * Create a list of bridges that can be built on a specific length. - * @ingroup AIList + * @ingroup ScriptList */ -class AIBridgeList_Length : public AIList { +class ScriptBridgeList_Length : public ScriptList { public: /** * @param length The length of the bridge you want to build. */ - AIBridgeList_Length(uint length); + ScriptBridgeList_Length(uint length); }; #endif /* SCRIPT_BRIDGELIST_HPP */ diff --git a/src/script/api/script_cargo.cpp b/src/script/api/script_cargo.cpp index a4b9fbd1a..6a0a2b944 100644 --- a/src/script/api/script_cargo.cpp +++ b/src/script/api/script_cargo.cpp @@ -7,7 +7,7 @@ * 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 script_cargo.cpp Implementation of AICargo. */ +/** @file script_cargo.cpp Implementation of ScriptCargo. */ #include "../../stdafx.h" #include "script_cargo.hpp" @@ -15,17 +15,17 @@ #include "../../economy_func.h" #include "../../core/bitmath_func.hpp" -/* static */ bool AICargo::IsValidCargo(CargoID cargo_type) +/* static */ bool ScriptCargo::IsValidCargo(CargoID cargo_type) { return (cargo_type < NUM_CARGO && ::CargoSpec::Get(cargo_type)->IsValid()); } -/* static */ bool AICargo::IsValidTownEffect(TownEffect towneffect_type) +/* static */ bool ScriptCargo::IsValidTownEffect(TownEffect towneffect_type) { return (towneffect_type >= (TownEffect)TE_BEGIN && towneffect_type < (TownEffect)TE_END); } -/* static */ char *AICargo::GetCargoLabel(CargoID cargo_type) +/* static */ char *ScriptCargo::GetCargoLabel(CargoID cargo_type) { if (!IsValidCargo(cargo_type)) return NULL; const CargoSpec *cargo = ::CargoSpec::Get(cargo_type); @@ -40,27 +40,27 @@ return cargo_label; } -/* static */ bool AICargo::IsFreight(CargoID cargo_type) +/* static */ bool ScriptCargo::IsFreight(CargoID cargo_type) { if (!IsValidCargo(cargo_type)) return false; const CargoSpec *cargo = ::CargoSpec::Get(cargo_type); return cargo->is_freight; } -/* static */ bool AICargo::HasCargoClass(CargoID cargo_type, CargoClass cargo_class) +/* static */ bool ScriptCargo::HasCargoClass(CargoID cargo_type, CargoClass cargo_class) { if (!IsValidCargo(cargo_type)) return false; return ::IsCargoInClass(cargo_type, (::CargoClass)cargo_class); } -/* static */ AICargo::TownEffect AICargo::GetTownEffect(CargoID cargo_type) +/* static */ ScriptCargo::TownEffect ScriptCargo::GetTownEffect(CargoID cargo_type) { if (!IsValidCargo(cargo_type)) return TE_NONE; - return (AICargo::TownEffect)::CargoSpec::Get(cargo_type)->town_effect; + return (ScriptCargo::TownEffect)::CargoSpec::Get(cargo_type)->town_effect; } -/* static */ Money AICargo::GetCargoIncome(CargoID cargo_type, uint32 distance, uint32 days_in_transit) +/* static */ Money ScriptCargo::GetCargoIncome(CargoID cargo_type, uint32 distance, uint32 days_in_transit) { if (!IsValidCargo(cargo_type)) return -1; return ::GetTransportedGoodsIncome(1, distance, Clamp(days_in_transit * 2 / 5, 0, 255), cargo_type); diff --git a/src/script/api/script_cargo.hpp b/src/script/api/script_cargo.hpp index ab1e1ea74..9379392b4 100644 --- a/src/script/api/script_cargo.hpp +++ b/src/script/api/script_cargo.hpp @@ -17,7 +17,7 @@ /** * Class that handles all cargo related functions. */ -class AICargo : public AIObject { +class ScriptCargo : public ScriptObject { public: /** * The classes of cargo (from newgrf_cargo.h). @@ -72,7 +72,7 @@ public: /** * Gets the string representation of the cargo label. * @param cargo_type The cargo to get the string representation of. - * @pre AICargo::IsValidCargo(cargo_type). + * @pre ScriptCargo::IsValidCargo(cargo_type). * @return The cargo label. * @note Never use this to check if it is a certain cargo. NewGRF can * redefine all of the names. @@ -84,7 +84,7 @@ public: * This defines whether the "freight train weight multiplier" will apply to * trains transporting this cargo. * @param cargo_type The cargo to check on. - * @pre AICargo::IsValidCargo(cargo_type). + * @pre ScriptCargo::IsValidCargo(cargo_type). * @return True if and only if the cargo is freight. */ static bool IsFreight(CargoID cargo_type); @@ -92,7 +92,7 @@ public: /** * Check if this cargo is in the requested cargo class. * @param cargo_type The cargo to check on. - * @pre AICargo::IsValidCargo(cargo_type). + * @pre ScriptCargo::IsValidCargo(cargo_type). * @param cargo_class The class to check for. * @return True if and only if the cargo is in the cargo class. */ @@ -101,7 +101,7 @@ public: /** * Get the effect this cargo has on a town. * @param cargo_type The cargo to check on. - * @pre AICargo::IsValidCargo(cargo_type). + * @pre ScriptCargo::IsValidCargo(cargo_type). * @return The effect this cargo has on a town, or TE_NONE if it has no effect. */ static TownEffect GetTownEffect(CargoID cargo_type); @@ -110,7 +110,7 @@ public: * Get the income for transporting a piece of cargo over the * given distance within the specified time. * @param cargo_type The cargo to transport. - * @pre AICargo::IsValidCargo(cargo_type). + * @pre ScriptCargo::IsValidCargo(cargo_type). * @param distance The distance the cargo travels from begin to end. * @param days_in_transit Amount of (game) days the cargo is in transit. The max value of this variable is 637. Any value higher returns the same as 637 would. * @return The amount of money that would be earned by this trip. diff --git a/src/script/api/script_cargolist.cpp b/src/script/api/script_cargolist.cpp index 12964a72d..08f705d60 100644 --- a/src/script/api/script_cargolist.cpp +++ b/src/script/api/script_cargolist.cpp @@ -7,7 +7,7 @@ * 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 script_cargolist.cpp Implementation of AICargoList and friends. */ +/** @file script_cargolist.cpp Implementation of ScriptCargoList and friends. */ #include "../../stdafx.h" #include "script_cargolist.hpp" @@ -17,7 +17,7 @@ #include "../../industry.h" #include "../../station_base.h" -AICargoList::AICargoList() +ScriptCargoList::ScriptCargoList() { const CargoSpec *cs; FOR_ALL_CARGOSPECS(cs) { @@ -25,9 +25,9 @@ AICargoList::AICargoList() } } -AICargoList_IndustryAccepting::AICargoList_IndustryAccepting(IndustryID industry_id) +ScriptCargoList_IndustryAccepting::ScriptCargoList_IndustryAccepting(IndustryID industry_id) { - if (!AIIndustry::IsValidIndustry(industry_id)) return; + if (!ScriptIndustry::IsValidIndustry(industry_id)) return; Industry *ind = ::Industry::Get(industry_id); for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) { @@ -38,9 +38,9 @@ AICargoList_IndustryAccepting::AICargoList_IndustryAccepting(IndustryID industry } } -AICargoList_IndustryProducing::AICargoList_IndustryProducing(IndustryID industry_id) +ScriptCargoList_IndustryProducing::ScriptCargoList_IndustryProducing(IndustryID industry_id) { - if (!AIIndustry::IsValidIndustry(industry_id)) return; + if (!ScriptIndustry::IsValidIndustry(industry_id)) return; Industry *ind = ::Industry::Get(industry_id); for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { @@ -51,9 +51,9 @@ AICargoList_IndustryProducing::AICargoList_IndustryProducing(IndustryID industry } } -AICargoList_StationAccepting::AICargoList_StationAccepting(StationID station_id) +ScriptCargoList_StationAccepting::ScriptCargoList_StationAccepting(StationID station_id) { - if (!AIStation::IsValidStation(station_id)) return; + if (!ScriptStation::IsValidStation(station_id)) return; Station *st = ::Station::Get(station_id); for (CargoID i = 0; i < NUM_CARGO; i++) { diff --git a/src/script/api/script_cargolist.hpp b/src/script/api/script_cargolist.hpp index 334792358..964d46fca 100644 --- a/src/script/api/script_cargolist.hpp +++ b/src/script/api/script_cargolist.hpp @@ -16,49 +16,49 @@ /** * Creates a list of cargos that can be produced in the current game. - * @ingroup AIList + * @ingroup ScriptList */ -class AICargoList : public AIList { +class ScriptCargoList : public ScriptList { public: - AICargoList(); + ScriptCargoList(); }; /** * Creates a list of cargos that the given industry accepts. * @note This list also includes cargos that are temporarily not accepted - * by this industry, @see AIIndustry::IsCargoAccepted. - * @ingroup AIList + * by this industry, @see ScriptIndustry::IsCargoAccepted. + * @ingroup ScriptList */ -class AICargoList_IndustryAccepting : public AIList { +class ScriptCargoList_IndustryAccepting : public ScriptList { public: /** * @param industry_id The industry to get the list of cargos it accepts from. */ - AICargoList_IndustryAccepting(IndustryID industry_id); + ScriptCargoList_IndustryAccepting(IndustryID industry_id); }; /** * Creates a list of cargos that the given industry can produce. - * @ingroup AIList + * @ingroup ScriptList */ -class AICargoList_IndustryProducing : public AIList { +class ScriptCargoList_IndustryProducing : public ScriptList { public: /** * @param industry_id The industry to get the list of cargos it produces from. */ - AICargoList_IndustryProducing(IndustryID industry_id); + ScriptCargoList_IndustryProducing(IndustryID industry_id); }; /** * Creates a list of cargos that the given station accepts. - * @ingroup AIList + * @ingroup ScriptList */ -class AICargoList_StationAccepting : public AIList { +class ScriptCargoList_StationAccepting : public ScriptList { public: /** * @param station_id The station to get the list of cargos it accepts from. */ - AICargoList_StationAccepting(StationID station_id); + ScriptCargoList_StationAccepting(StationID station_id); }; #endif /* SCRIPT_CARGOLIST_HPP */ diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index d2b897f94..d241d7d30 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -7,7 +7,7 @@ * 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 script_company.cpp Implementation of AICompany. */ +/** @file script_company.cpp Implementation of ScriptCompany. */ #include "../../stdafx.h" #include "script_company.hpp" @@ -24,27 +24,27 @@ #include "../../settings_func.h" #include "table/strings.h" -/* static */ AICompany::CompanyID AICompany::ResolveCompanyID(AICompany::CompanyID company) +/* static */ ScriptCompany::CompanyID ScriptCompany::ResolveCompanyID(ScriptCompany::CompanyID company) { if (company == COMPANY_SELF) return (CompanyID)((byte)_current_company); return ::Company::IsValidID((::CompanyID)company) ? company : COMPANY_INVALID; } -/* static */ bool AICompany::IsMine(AICompany::CompanyID company) +/* static */ bool ScriptCompany::IsMine(ScriptCompany::CompanyID company) { return ResolveCompanyID(company) == ResolveCompanyID(COMPANY_SELF); } -/* static */ bool AICompany::SetName(const char *name) +/* static */ bool ScriptCompany::SetName(const char *name) { EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_COMPANY_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return AIObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, name); + return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, name); } -/* static */ char *AICompany::GetName(AICompany::CompanyID company) +/* static */ char *ScriptCompany::GetName(ScriptCompany::CompanyID company) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return NULL; @@ -57,14 +57,14 @@ return company_name; } -/* static */ bool AICompany::SetPresidentName(const char *name) +/* static */ bool ScriptCompany::SetPresidentName(const char *name) { EnforcePrecondition(false, !::StrEmpty(name)); - return AIObject::DoCommand(0, 0, 0, CMD_RENAME_PRESIDENT, name); + return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_PRESIDENT, name); } -/* static */ char *AICompany::GetPresidentName(AICompany::CompanyID company) +/* static */ char *ScriptCompany::GetPresidentName(ScriptCompany::CompanyID company) { company = ResolveCompanyID(company); @@ -80,19 +80,19 @@ return president_name; } -/* static */ bool AICompany::SetPresidentGender(Gender gender) +/* static */ bool ScriptCompany::SetPresidentGender(Gender gender) { EnforcePrecondition(false, gender == GENDER_MALE || gender == GENDER_FEMALE); - EnforcePrecondition(false, GetPresidentGender(AICompany::COMPANY_SELF) != gender); + EnforcePrecondition(false, GetPresidentGender(ScriptCompany::COMPANY_SELF) != gender); CompanyManagerFace cmf; GenderEthnicity ge = (GenderEthnicity)((gender == GENDER_FEMALE ? (1 << ::GENDER_FEMALE) : 0) | (::InteractiveRandom() & (1 << ETHNICITY_BLACK))); RandomCompanyManagerFaceBits(cmf, ge, false); - return AIObject::DoCommand(0, 0, cmf, CMD_SET_COMPANY_MANAGER_FACE); + return ScriptObject::DoCommand(0, 0, cmf, CMD_SET_COMPANY_MANAGER_FACE); } -/* static */ AICompany::Gender AICompany::GetPresidentGender(CompanyID company) +/* static */ ScriptCompany::Gender ScriptCompany::GetPresidentGender(CompanyID company) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return GENDER_INVALID; @@ -101,7 +101,7 @@ return HasBit(ge, ::GENDER_FEMALE) ? GENDER_FEMALE : GENDER_MALE; } -/* static */ Money AICompany::GetQuarterlyIncome(AICompany::CompanyID company, uint32 quarter) +/* static */ Money ScriptCompany::GetQuarterlyIncome(ScriptCompany::CompanyID company, uint32 quarter) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return -1; @@ -113,7 +113,7 @@ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].income; } -/* static */ Money AICompany::GetQuarterlyExpenses(AICompany::CompanyID company, uint32 quarter) +/* static */ Money ScriptCompany::GetQuarterlyExpenses(ScriptCompany::CompanyID company, uint32 quarter) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return -1; @@ -125,7 +125,7 @@ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].expenses; } -/* static */ int32 AICompany::GetQuarterlyCargoDelivered(AICompany::CompanyID company, uint32 quarter) +/* static */ int32 ScriptCompany::GetQuarterlyCargoDelivered(ScriptCompany::CompanyID company, uint32 quarter) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return -1; @@ -137,7 +137,7 @@ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].delivered_cargo; } -/* static */ int32 AICompany::GetQuarterlyPerformanceRating(AICompany::CompanyID company, uint32 quarter) +/* static */ int32 ScriptCompany::GetQuarterlyPerformanceRating(ScriptCompany::CompanyID company, uint32 quarter) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return -1; @@ -147,7 +147,7 @@ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].performance_history; } -/* static */ Money AICompany::GetQuarterlyCompanyValue(AICompany::CompanyID company, uint32 quarter) +/* static */ Money ScriptCompany::GetQuarterlyCompanyValue(ScriptCompany::CompanyID company, uint32 quarter) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return -1; @@ -160,7 +160,7 @@ } -/* static */ Money AICompany::GetBankBalance(AICompany::CompanyID company) +/* static */ Money ScriptCompany::GetBankBalance(ScriptCompany::CompanyID company) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return -1; @@ -168,22 +168,22 @@ return ::Company::Get((CompanyID)company)->money; } -/* static */ Money AICompany::GetLoanAmount() +/* static */ Money ScriptCompany::GetLoanAmount() { return ::Company::Get(_current_company)->current_loan; } -/* static */ Money AICompany::GetMaxLoanAmount() +/* static */ Money ScriptCompany::GetMaxLoanAmount() { return _economy.max_loan; } -/* static */ Money AICompany::GetLoanInterval() +/* static */ Money ScriptCompany::GetLoanInterval() { return LOAN_INTERVAL; } -/* static */ bool AICompany::SetLoanAmount(int32 loan) +/* static */ bool ScriptCompany::SetLoanAmount(int32 loan) { EnforcePrecondition(false, loan >= 0); EnforcePrecondition(false, (loan % GetLoanInterval()) == 0); @@ -192,12 +192,12 @@ if (loan == GetLoanAmount()) return true; - return AIObject::DoCommand(0, + return ScriptObject::DoCommand(0, abs(loan - GetLoanAmount()), 2, (loan > GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN); } -/* static */ bool AICompany::SetMinimumLoanAmount(int32 loan) +/* static */ bool ScriptCompany::SetMinimumLoanAmount(int32 loan) { EnforcePrecondition(false, loan >= 0); @@ -211,14 +211,14 @@ return GetLoanAmount() == loan; } -/* static */ bool AICompany::BuildCompanyHQ(TileIndex tile) +/* static */ bool ScriptCompany::BuildCompanyHQ(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, OBJECT_HQ, 0, CMD_BUILD_OBJECT); + return ScriptObject::DoCommand(tile, OBJECT_HQ, 0, CMD_BUILD_OBJECT); } -/* static */ TileIndex AICompany::GetCompanyHQ(CompanyID company) +/* static */ TileIndex ScriptCompany::GetCompanyHQ(CompanyID company) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return INVALID_TILE; @@ -227,12 +227,12 @@ return (loc == 0) ? INVALID_TILE : loc; } -/* static */ bool AICompany::SetAutoRenewStatus(bool autorenew) +/* static */ bool ScriptCompany::SetAutoRenewStatus(bool autorenew) { - return AIObject::DoCommand(0, ::GetCompanySettingIndex("company.engine_renew"), autorenew ? 1 : 0, CMD_CHANGE_COMPANY_SETTING); + return ScriptObject::DoCommand(0, ::GetCompanySettingIndex("company.engine_renew"), autorenew ? 1 : 0, CMD_CHANGE_COMPANY_SETTING); } -/* static */ bool AICompany::GetAutoRenewStatus(CompanyID company) +/* static */ bool ScriptCompany::GetAutoRenewStatus(CompanyID company) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return false; @@ -240,12 +240,12 @@ return ::Company::Get((CompanyID)company)->settings.engine_renew; } -/* static */ bool AICompany::SetAutoRenewMonths(int16 months) +/* static */ bool ScriptCompany::SetAutoRenewMonths(int16 months) { - return AIObject::DoCommand(0, ::GetCompanySettingIndex("company.engine_renew_months"), months, CMD_CHANGE_COMPANY_SETTING); + return ScriptObject::DoCommand(0, ::GetCompanySettingIndex("company.engine_renew_months"), months, CMD_CHANGE_COMPANY_SETTING); } -/* static */ int16 AICompany::GetAutoRenewMonths(CompanyID company) +/* static */ int16 ScriptCompany::GetAutoRenewMonths(CompanyID company) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return 0; @@ -253,12 +253,12 @@ return ::Company::Get((CompanyID)company)->settings.engine_renew_months; } -/* static */ bool AICompany::SetAutoRenewMoney(uint32 money) +/* static */ bool ScriptCompany::SetAutoRenewMoney(uint32 money) { - return AIObject::DoCommand(0, ::GetCompanySettingIndex("company.engine_renew_money"), money, CMD_CHANGE_COMPANY_SETTING); + return ScriptObject::DoCommand(0, ::GetCompanySettingIndex("company.engine_renew_money"), money, CMD_CHANGE_COMPANY_SETTING); } -/* static */ uint32 AICompany::GetAutoRenewMoney(CompanyID company) +/* static */ uint32 ScriptCompany::GetAutoRenewMoney(CompanyID company) { company = ResolveCompanyID(company); if (company == COMPANY_INVALID) return 0; diff --git a/src/script/api/script_company.hpp b/src/script/api/script_company.hpp index c8a7128d7..4c35d7e9b 100644 --- a/src/script/api/script_company.hpp +++ b/src/script/api/script_company.hpp @@ -17,7 +17,7 @@ /** * Class that handles all company related functions. */ -class AICompany : public AIObject { +class ScriptCompany : public ScriptObject { public: /** The range of possible quarters to get company information of. */ enum Quarter { @@ -62,7 +62,7 @@ public: * @param name The new name of the company. * @pre 'name' must have at least one character. * @pre 'name' must have at most 30 characters. - * @exception AIError::ERR_NAME_IS_NOT_UNIQUE + * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. */ static bool SetName(const char *name); @@ -79,7 +79,7 @@ public: * Set the name of your president. * @param name The new name of the president. * @pre 'name' must have at least one character. - * @exception AIError::ERR_NAME_IS_NOT_UNIQUE + * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. */ static bool SetPresidentName(const char *name); @@ -95,7 +95,7 @@ public: /** * Set the gender of the president of your company. * @param gender The new gender for your president. - * @pre GetPresidentGender(AICompany.COMPANY_SELF) != gender. + * @pre GetPresidentGender(ScriptCompany.COMPANY_SELF) != gender. * @return True if the gender was changed. * @note When successful a random face will be created. */ @@ -212,9 +212,9 @@ public: /** * Build your company's HQ on the given tile. * @param tile The tile to build your HQ on, this tile is the most nothern tile of your HQ. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_FLAT_LAND_REQUIRED + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED * @return True if the HQ could be build. * @note An HQ can not be removed, only by water or rebuilding; If an HQ is * build again, the old one is removed. @@ -226,7 +226,7 @@ public: * @param company The company the get the HQ of. * @pre ResolveCompanyID(company) != COMPANY_INVALID. * @return The tile of the company's HQ, this tile is the most nothern tile - * of that HQ, or AIMap::TILE_INVALID if there is no HQ yet. + * of that HQ, or ScriptMap::TILE_INVALID if there is no HQ yet. */ static TileIndex GetCompanyHQ(CompanyID company); @@ -276,6 +276,6 @@ public: static uint32 GetAutoRenewMoney(CompanyID company); }; -DECLARE_POSTFIX_INCREMENT(AICompany::CompanyID) +DECLARE_POSTFIX_INCREMENT(ScriptCompany::CompanyID) #endif /* SCRIPT_COMPANY_HPP */ diff --git a/src/script/api/script_controller.cpp b/src/script/api/script_controller.cpp index bdd9bc1a7..163335f3d 100644 --- a/src/script/api/script_controller.cpp +++ b/src/script/api/script_controller.cpp @@ -22,38 +22,38 @@ #include "../../ai/ai.hpp" #include "script_log.hpp" -/* static */ void AIController::SetCommandDelay(int ticks) +/* static */ void ScriptController::SetCommandDelay(int ticks) { if (ticks <= 0) return; - AIObject::SetDoCommandDelay(ticks); + ScriptObject::SetDoCommandDelay(ticks); } -/* static */ void AIController::Sleep(int ticks) +/* static */ void ScriptController::Sleep(int ticks) { - if (!AIObject::CanSuspend()) { + if (!ScriptObject::CanSuspend()) { throw AI_FatalError("You are not allowed to call Sleep in your constructor, Save(), Load(), and any valuator."); } if (ticks <= 0) { - AILog::Warning("Sleep() value should be > 0. Assuming value 1."); + ScriptLog::Warning("Sleep() value should be > 0. Assuming value 1."); ticks = 1; } throw AI_VMSuspend(ticks, NULL); } -/* static */ void AIController::Print(bool error_msg, const char *message) +/* static */ void ScriptController::Print(bool error_msg, const char *message) { - AILog::Log(error_msg ? AILog::LOG_SQ_ERROR : AILog::LOG_SQ_INFO, message); + ScriptLog::Log(error_msg ? ScriptLog::LOG_SQ_ERROR : ScriptLog::LOG_SQ_INFO, message); } -AIController::AIController() : +ScriptController::ScriptController() : ticks(0), loaded_library_count(0) { } -AIController::~AIController() +ScriptController::~ScriptController() { for (LoadedLibraryList::iterator iter = this->loaded_library.begin(); iter != this->loaded_library.end(); iter++) { free((*iter).second); @@ -63,30 +63,30 @@ AIController::~AIController() this->loaded_library.clear(); } -/* static */ uint AIController::GetTick() +/* static */ uint ScriptController::GetTick() { - return AIObject::GetActiveInstance()->GetController()->ticks; + return ScriptObject::GetActiveInstance()->GetController()->ticks; } -/* static */ int AIController::GetOpsTillSuspend() +/* static */ int ScriptController::GetOpsTillSuspend() { - return AIObject::GetActiveInstance()->GetOpsTillSuspend(); + return ScriptObject::GetActiveInstance()->GetOpsTillSuspend(); } -/* static */ int AIController::GetSetting(const char *name) +/* static */ int ScriptController::GetSetting(const char *name) { return AIConfig::GetConfig(_current_company)->GetSetting(name); } -/* static */ uint AIController::GetVersion() +/* static */ uint ScriptController::GetVersion() { return _openttd_newgrf_version; } -/* static */ HSQOBJECT AIController::Import(const char *library, const char *class_name, int version) +/* static */ HSQOBJECT ScriptController::Import(const char *library, const char *class_name, int version) { - AIController *controller = AIObject::GetActiveInstance()->GetController(); - Squirrel *engine = AIObject::GetActiveInstance()->engine; + ScriptController *controller = ScriptObject::GetActiveInstance()->GetController(); + Squirrel *engine = ScriptObject::GetActiveInstance()->engine; HSQUIRRELVM vm = engine->GetVM(); /* Internally we store libraries as 'library.version' */ diff --git a/src/script/api/script_controller.hpp b/src/script/api/script_controller.hpp index 2e0e64f2e..00993a6ff 100644 --- a/src/script/api/script_controller.hpp +++ b/src/script/api/script_controller.hpp @@ -16,23 +16,24 @@ #include <map> /** - * The Controller, the class each AI should extend. It creates the AI, makes - * sure the logic kicks in correctly, and that GetTick() has a valid value. + * The Controller, the class each Script should extend. It creates the Script, + * makes sure the logic kicks in correctly, and that GetTick() has a valid + * value. */ -class AIController { +class ScriptController { friend class AIScanner; friend class AIInstance; public: /** - * Initializer of the AIController. + * Initializer of the ScriptController. */ - AIController(); + ScriptController(); /** - * Destructor of the AIController. + * Destructor of the ScriptController. */ - ~AIController(); + ~ScriptController(); /** * This function is called to start your AI. Your AI starts here. If you @@ -105,7 +106,7 @@ public: * Squirrel calls this when 'print' is used, or when the script made an error. * @param error_msg If true, it is a Squirrel error message. * @param message The message Squirrel logged. - * @note Use AILog.Info/Warning/Error instead of 'print'. + * @note Use ScriptLog.Info/Warning/Error instead of 'print'. */ static void Print(bool error_msg, const char *message); diff --git a/src/script/api/script_date.cpp b/src/script/api/script_date.cpp index af72a69d1..3f3d16bcc 100644 --- a/src/script/api/script_date.cpp +++ b/src/script/api/script_date.cpp @@ -7,18 +7,18 @@ * 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 script_date.cpp Implementation of AIDate. */ +/** @file script_date.cpp Implementation of ScriptDate. */ #include "../../stdafx.h" #include "script_date.hpp" #include "../../date_func.h" -/* static */ int32 AIDate::GetCurrentDate() +/* static */ int32 ScriptDate::GetCurrentDate() { return ::_date; } -/* static */ int32 AIDate::GetYear(int32 date) +/* static */ int32 ScriptDate::GetYear(int32 date) { if (date < 0) return -1; @@ -27,7 +27,7 @@ return ymd.year; } -/* static */ int32 AIDate::GetMonth(int32 date) +/* static */ int32 ScriptDate::GetMonth(int32 date) { if (date < 0) return -1; @@ -36,7 +36,7 @@ return ymd.month + 1; } -/* static */ int32 AIDate::GetDayOfMonth(int32 date) +/* static */ int32 ScriptDate::GetDayOfMonth(int32 date) { if (date < 0) return -1; @@ -45,7 +45,7 @@ return ymd.day; } -/* static */ int32 AIDate::GetDate(int32 year, int32 month, int32 day_of_month) +/* static */ int32 ScriptDate::GetDate(int32 year, int32 month, int32 day_of_month) { if (month < 1 || month > 12) return -1; if (day_of_month < 1 || day_of_month > 31) return -1; diff --git a/src/script/api/script_date.hpp b/src/script/api/script_date.hpp index d8ed4044f..b2cf326a9 100644 --- a/src/script/api/script_date.hpp +++ b/src/script/api/script_date.hpp @@ -24,7 +24,7 @@ * two different moments in time because they count the number * of days since the year 0. */ -class AIDate : public AIObject { +class ScriptDate : public ScriptObject { public: /** * Get the current date. diff --git a/src/script/api/script_depotlist.cpp b/src/script/api/script_depotlist.cpp index c4b6e2d14..c66850b67 100644 --- a/src/script/api/script_depotlist.cpp +++ b/src/script/api/script_depotlist.cpp @@ -7,7 +7,7 @@ * 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 script_depotlist.cpp Implementation of AIDepotList and friends. */ +/** @file script_depotlist.cpp Implementation of ScriptDepotList and friends. */ #include "../../stdafx.h" #include "script_depotlist.hpp" @@ -15,17 +15,17 @@ #include "../../depot_base.h" #include "../../station_base.h" -AIDepotList::AIDepotList(AITile::TransportType transport_type) +ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type) { ::TileType tile_type; switch (transport_type) { default: return; - case AITile::TRANSPORT_ROAD: tile_type = ::MP_ROAD; break; - case AITile::TRANSPORT_RAIL: tile_type = ::MP_RAILWAY; break; - case AITile::TRANSPORT_WATER: tile_type = ::MP_WATER; break; + case ScriptTile::TRANSPORT_ROAD: tile_type = ::MP_ROAD; break; + case ScriptTile::TRANSPORT_RAIL: tile_type = ::MP_RAILWAY; break; + case ScriptTile::TRANSPORT_WATER: tile_type = ::MP_WATER; break; - case AITile::TRANSPORT_AIR: { + case ScriptTile::TRANSPORT_AIR: { /* Hangars are not seen as real depots by the depot code. */ const Station *st; FOR_ALL_STATIONS(st) { diff --git a/src/script/api/script_depotlist.hpp b/src/script/api/script_depotlist.hpp index 450fea9a8..4067fc7e6 100644 --- a/src/script/api/script_depotlist.hpp +++ b/src/script/api/script_depotlist.hpp @@ -17,14 +17,14 @@ /** * Creates a list of the locations of the depots (and hangars) of which you are the owner. - * @ingroup AIList + * @ingroup ScriptList */ -class AIDepotList : public AIList { +class ScriptDepotList : public ScriptList { public: /** * @param transport_type The type of transport to make a list of depots for. */ - AIDepotList(AITile::TransportType transport_type); + ScriptDepotList(ScriptTile::TransportType transport_type); }; #endif /* SCRIPT_DEPOTLIST_HPP */ diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp index f054bda31..068285dea 100644 --- a/src/script/api/script_engine.cpp +++ b/src/script/api/script_engine.cpp @@ -7,7 +7,7 @@ * 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 script_engine.cpp Implementation of AIEngine. */ +/** @file script_engine.cpp Implementation of ScriptEngine. */ #include "../../stdafx.h" #include "script_engine.hpp" @@ -21,19 +21,19 @@ #include "../../articulated_vehicles.h" #include "table/strings.h" -/* static */ bool AIEngine::IsValidEngine(EngineID engine_id) +/* static */ bool ScriptEngine::IsValidEngine(EngineID engine_id) { const Engine *e = ::Engine::GetIfValid(engine_id); return e != NULL && (::IsEngineBuildable(engine_id, e->type, _current_company) || ::Company::Get(_current_company)->group_all[e->type].num_engines[engine_id] > 0); } -/* static */ bool AIEngine::IsBuildable(EngineID engine_id) +/* static */ bool ScriptEngine::IsBuildable(EngineID engine_id) { const Engine *e = ::Engine::GetIfValid(engine_id); return e != NULL && ::IsEngineBuildable(engine_id, e->type, _current_company); } -/* static */ char *AIEngine::GetName(EngineID engine_id) +/* static */ char *ScriptEngine::GetName(EngineID engine_id) { if (!IsValidEngine(engine_id)) return NULL; @@ -45,7 +45,7 @@ return engine_name; } -/* static */ CargoID AIEngine::GetCargoType(EngineID engine_id) +/* static */ CargoID ScriptEngine::GetCargoType(EngineID engine_id) { if (!IsValidEngine(engine_id)) return CT_INVALID; @@ -63,25 +63,25 @@ return most_cargo; } -/* static */ bool AIEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id) +/* static */ bool ScriptEngine::CanRefitCargo(EngineID engine_id, CargoID cargo_id) { if (!IsValidEngine(engine_id)) return false; - if (!AICargo::IsValidCargo(cargo_id)) return false; + if (!ScriptCargo::IsValidCargo(cargo_id)) return false; return HasBit(::GetUnionOfArticulatedRefitMasks(engine_id, true), cargo_id); } -/* static */ bool AIEngine::CanPullCargo(EngineID engine_id, CargoID cargo_id) +/* static */ bool ScriptEngine::CanPullCargo(EngineID engine_id, CargoID cargo_id) { if (!IsValidEngine(engine_id)) return false; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return false; - if (!AICargo::IsValidCargo(cargo_id)) return false; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return false; + if (!ScriptCargo::IsValidCargo(cargo_id)) return false; - return (::RailVehInfo(engine_id)->ai_passenger_only != 1) || AICargo::HasCargoClass(cargo_id, AICargo::CC_PASSENGERS); + return (::RailVehInfo(engine_id)->ai_passenger_only != 1) || ScriptCargo::HasCargoClass(cargo_id, ScriptCargo::CC_PASSENGERS); } -/* static */ int32 AIEngine::GetCapacity(EngineID engine_id) +/* static */ int32 ScriptEngine::GetCapacity(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; @@ -105,15 +105,15 @@ } } -/* static */ int32 AIEngine::GetReliability(EngineID engine_id) +/* static */ int32 ScriptEngine::GetReliability(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; - if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(engine_id)) return -1; + if (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL && IsWagon(engine_id)) return -1; return ::ToPercent16(::Engine::Get(engine_id)->reliability); } -/* static */ int32 AIEngine::GetMaxSpeed(EngineID engine_id) +/* static */ int32 ScriptEngine::GetMaxSpeed(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; @@ -123,128 +123,128 @@ return max_speed; } -/* static */ Money AIEngine::GetPrice(EngineID engine_id) +/* static */ Money ScriptEngine::GetPrice(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; return ::Engine::Get(engine_id)->GetCost(); } -/* static */ int32 AIEngine::GetMaxAge(EngineID engine_id) +/* static */ int32 ScriptEngine::GetMaxAge(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; - if (GetVehicleType(engine_id) == AIVehicle::VT_RAIL && IsWagon(engine_id)) return -1; + if (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL && IsWagon(engine_id)) return -1; return ::Engine::Get(engine_id)->GetLifeLengthInDays(); } -/* static */ Money AIEngine::GetRunningCost(EngineID engine_id) +/* static */ Money ScriptEngine::GetRunningCost(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; return ::Engine::Get(engine_id)->GetRunningCost(); } -/* static */ int32 AIEngine::GetPower(EngineID engine_id) +/* static */ int32 ScriptEngine::GetPower(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL && GetVehicleType(engine_id) != AIVehicle::VT_ROAD) return -1; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL && GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return -1; if (IsWagon(engine_id)) return -1; return ::Engine::Get(engine_id)->GetPower(); } -/* static */ int32 AIEngine::GetWeight(EngineID engine_id) +/* static */ int32 ScriptEngine::GetWeight(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL && GetVehicleType(engine_id) != AIVehicle::VT_ROAD) return -1; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL && GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return -1; return ::Engine::Get(engine_id)->GetDisplayWeight(); } -/* static */ int32 AIEngine::GetMaxTractiveEffort(EngineID engine_id) +/* static */ int32 ScriptEngine::GetMaxTractiveEffort(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL && GetVehicleType(engine_id) != AIVehicle::VT_ROAD) return -1; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL && GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return -1; if (IsWagon(engine_id)) return -1; return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort(); } -/* static */ int32 AIEngine::GetDesignDate(EngineID engine_id) +/* static */ int32 ScriptEngine::GetDesignDate(EngineID engine_id) { if (!IsValidEngine(engine_id)) return -1; return ::Engine::Get(engine_id)->intro_date; } -/* static */ AIVehicle::VehicleType AIEngine::GetVehicleType(EngineID engine_id) +/* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id) { - if (!IsValidEngine(engine_id)) return AIVehicle::VT_INVALID; + if (!IsValidEngine(engine_id)) return ScriptVehicle::VT_INVALID; switch (::Engine::Get(engine_id)->type) { - case VEH_ROAD: return AIVehicle::VT_ROAD; - case VEH_TRAIN: return AIVehicle::VT_RAIL; - case VEH_SHIP: return AIVehicle::VT_WATER; - case VEH_AIRCRAFT: return AIVehicle::VT_AIR; + case VEH_ROAD: return ScriptVehicle::VT_ROAD; + case VEH_TRAIN: return ScriptVehicle::VT_RAIL; + case VEH_SHIP: return ScriptVehicle::VT_WATER; + case VEH_AIRCRAFT: return ScriptVehicle::VT_AIR; default: NOT_REACHED(); } } -/* static */ bool AIEngine::IsWagon(EngineID engine_id) +/* static */ bool ScriptEngine::IsWagon(EngineID engine_id) { if (!IsValidEngine(engine_id)) return false; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return false; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return false; return ::RailVehInfo(engine_id)->power == 0; } -/* static */ bool AIEngine::CanRunOnRail(EngineID engine_id, AIRail::RailType track_rail_type) +/* static */ bool ScriptEngine::CanRunOnRail(EngineID engine_id, ScriptRail::RailType track_rail_type) { if (!IsValidEngine(engine_id)) return false; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return false; - if (!AIRail::IsRailTypeAvailable(track_rail_type)) return false; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return false; + if (!ScriptRail::IsRailTypeAvailable(track_rail_type)) return false; return ::IsCompatibleRail((::RailType)::RailVehInfo(engine_id)->railtype, (::RailType)track_rail_type); } -/* static */ bool AIEngine::HasPowerOnRail(EngineID engine_id, AIRail::RailType track_rail_type) +/* static */ bool ScriptEngine::HasPowerOnRail(EngineID engine_id, ScriptRail::RailType track_rail_type) { if (!IsValidEngine(engine_id)) return false; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return false; - if (!AIRail::IsRailTypeAvailable(track_rail_type)) return false; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return false; + if (!ScriptRail::IsRailTypeAvailable(track_rail_type)) return false; return ::HasPowerOnRail((::RailType)::RailVehInfo(engine_id)->railtype, (::RailType)track_rail_type); } -/* static */ AIRoad::RoadType AIEngine::GetRoadType(EngineID engine_id) +/* static */ ScriptRoad::RoadType ScriptEngine::GetRoadType(EngineID engine_id) { - if (!IsValidEngine(engine_id)) return AIRoad::ROADTYPE_INVALID; - if (GetVehicleType(engine_id) != AIVehicle::VT_ROAD) return AIRoad::ROADTYPE_INVALID; + if (!IsValidEngine(engine_id)) return ScriptRoad::ROADTYPE_INVALID; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return ScriptRoad::ROADTYPE_INVALID; - return HasBit(::EngInfo(engine_id)->misc_flags, EF_ROAD_TRAM) ? AIRoad::ROADTYPE_TRAM : AIRoad::ROADTYPE_ROAD; + return HasBit(::EngInfo(engine_id)->misc_flags, EF_ROAD_TRAM) ? ScriptRoad::ROADTYPE_TRAM : ScriptRoad::ROADTYPE_ROAD; } -/* static */ AIRail::RailType AIEngine::GetRailType(EngineID engine_id) +/* static */ ScriptRail::RailType ScriptEngine::GetRailType(EngineID engine_id) { - if (!IsValidEngine(engine_id)) return AIRail::RAILTYPE_INVALID; - if (GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return AIRail::RAILTYPE_INVALID; + if (!IsValidEngine(engine_id)) return ScriptRail::RAILTYPE_INVALID; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return ScriptRail::RAILTYPE_INVALID; - return (AIRail::RailType)(uint)::RailVehInfo(engine_id)->railtype; + return (ScriptRail::RailType)(uint)::RailVehInfo(engine_id)->railtype; } -/* static */ bool AIEngine::IsArticulated(EngineID engine_id) +/* static */ bool ScriptEngine::IsArticulated(EngineID engine_id) { if (!IsValidEngine(engine_id)) return false; - if (GetVehicleType(engine_id) != AIVehicle::VT_ROAD && GetVehicleType(engine_id) != AIVehicle::VT_RAIL) return false; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD && GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL) return false; return CountArticulatedParts(engine_id, true) != 0; } -/* static */ AIAirport::PlaneType AIEngine::GetPlaneType(EngineID engine_id) +/* static */ ScriptAirport::PlaneType ScriptEngine::GetPlaneType(EngineID engine_id) { - if (!IsValidEngine(engine_id)) return AIAirport::PT_INVALID; - if (GetVehicleType(engine_id) != AIVehicle::VT_AIR) return AIAirport::PT_INVALID; + if (!IsValidEngine(engine_id)) return ScriptAirport::PT_INVALID; + if (GetVehicleType(engine_id) != ScriptVehicle::VT_AIR) return ScriptAirport::PT_INVALID; - return (AIAirport::PlaneType)::AircraftVehInfo(engine_id)->subtype; + return (ScriptAirport::PlaneType)::AircraftVehInfo(engine_id)->subtype; } diff --git a/src/script/api/script_engine.hpp b/src/script/api/script_engine.hpp index 26788d3d5..b7bd9f700 100644 --- a/src/script/api/script_engine.hpp +++ b/src/script/api/script_engine.hpp @@ -19,7 +19,7 @@ /** * Class that handles all engine related functions. */ -class AIEngine : public AIObject { +class ScriptEngine : public ScriptObject { public: /** * Checks whether the given engine type is valid. An engine is valid if you @@ -61,7 +61,7 @@ public: * @param engine_id The engine to check for refitting. * @param cargo_id The cargo to check for refitting. * @pre IsValidEngine(engine_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return True if the engine can carry this cargo, either via refit, or * by default. */ @@ -72,8 +72,8 @@ public: * @param engine_id The engine to check. * @param cargo_id The cargo to check. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL. - * @pre AICargo::IsValidCargo(cargo_id). + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return True if the engine can pull wagons carrying this cargo. * @note This function is not exhaustive; a true here does not mean * that the vehicle can pull the wagons, a false does mean it can't. @@ -95,7 +95,7 @@ public: * reliability (you most likely don't want to buy it). * @param engine_id The engine to get the reliability of. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) != AIVehicle::VT_TRAIN || !IsWagon(engine_id). + * @pre GetVehicleType(engine_id) != ScriptVehicle::VT_TRAIN || !IsWagon(engine_id). * @return The reliability the engine has. */ static int32 GetReliability(EngineID engine_id); @@ -104,7 +104,7 @@ public: * Get the maximum speed of an engine. * @param engine_id The engine to get the maximum speed of. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) != AIVehicle::VT_TRAIN || !IsWagon(engine_id). + * @pre GetVehicleType(engine_id) != ScriptVehicle::VT_TRAIN || !IsWagon(engine_id). * @return The maximum speed the engine has. * @note The speed is in OpenTTD's internal speed unit. * This is mph / 1.6, which is roughly km/h. @@ -142,7 +142,7 @@ public: * Get the power of an engine. * @param engine_id The engine to get the power of. * @pre IsValidEngine(engine_id). - * @pre (GetVehicleType(engine_id) == AIVehicle::VT_RAIL || GetVehicleType(engine_id) == AIVehicle::VT_ROAD) && !IsWagon(engine_id). + * @pre (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL || GetVehicleType(engine_id) == ScriptVehicle::VT_ROAD) && !IsWagon(engine_id). * @return The power of the engine in hp. */ static int32 GetPower(EngineID engine_id); @@ -151,7 +151,7 @@ public: * Get the weight of an engine. * @param engine_id The engine to get the weight of. * @pre IsValidEngine(engine_id). - * @pre (GetVehicleType(engine_id) == AIVehicle::VT_RAIL || GetVehicleType(engine_id) == AIVehicle::VT_ROAD). + * @pre (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL || GetVehicleType(engine_id) == ScriptVehicle::VT_ROAD). * @return The weight of the engine in metric tons. */ static int32 GetWeight(EngineID engine_id); @@ -160,7 +160,7 @@ public: * Get the maximum tractive effort of an engine. * @param engine_id The engine to get the maximum tractive effort of. * @pre IsValidEngine(engine_id). - * @pre (GetVehicleType(engine_id) == AIVehicle::VT_RAIL || GetVehicleType(engine_id) == AIVehicle::VT_ROAD) && !IsWagon(engine_id). + * @pre (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL || GetVehicleType(engine_id) == ScriptVehicle::VT_ROAD) && !IsWagon(engine_id). * @return The maximum tractive effort of the engine in kN. */ static int32 GetMaxTractiveEffort(EngineID engine_id); @@ -179,13 +179,13 @@ public: * @pre IsValidEngine(engine_id). * @return The type the engine has. */ - static AIVehicle::VehicleType GetVehicleType(EngineID engine_id); + static ScriptVehicle::VehicleType GetVehicleType(EngineID engine_id); /** * Check if an engine is a wagon. * @param engine_id The engine to check. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL. + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. * @return Whether or not the engine is a wagon. */ static bool IsWagon(EngineID engine_id); @@ -195,48 +195,48 @@ public: * @param engine_id The engine to check. * @param track_rail_type The type you want to check. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL. - * @pre AIRail::IsRailTypeAvailable(track_rail_type). + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. + * @pre ScriptRail::IsRailTypeAvailable(track_rail_type). * @return Whether an engine of type 'engine_id' can run on 'track_rail_type'. * @note Even if a train can run on a RailType that doesn't mean that it'll be * able to power the train. Use HasPowerOnRail for that. */ - static bool CanRunOnRail(EngineID engine_id, AIRail::RailType track_rail_type); + static bool CanRunOnRail(EngineID engine_id, ScriptRail::RailType track_rail_type); /** * Check if a train engine has power on a RailType. * @param engine_id The engine to check. * @param track_rail_type Another RailType. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL. - * @pre AIRail::IsRailTypeAvailable(track_rail_type). + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. + * @pre ScriptRail::IsRailTypeAvailable(track_rail_type). * @return Whether an engine of type 'engine_id' has power on 'track_rail_type'. */ - static bool HasPowerOnRail(EngineID engine_id, AIRail::RailType track_rail_type); + static bool HasPowerOnRail(EngineID engine_id, ScriptRail::RailType track_rail_type); /** * Get the RoadType of the engine. * @param engine_id The engine to get the RoadType of. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_ROAD. + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_ROAD. * @return The RoadType the engine has. */ - static AIRoad::RoadType GetRoadType(EngineID engine_id); + static ScriptRoad::RoadType GetRoadType(EngineID engine_id); /** * Get the RailType of the engine. * @param engine_id The engine to get the RailType of. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_RAIL. + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. * @return The RailType the engine has. */ - static AIRail::RailType GetRailType(EngineID engine_id); + static ScriptRail::RailType GetRailType(EngineID engine_id); /** * Check if the engine is articulated. * @param engine_id The engine to check. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_ROAD || GetVehicleType(engine_id) == AIVehicle::VT_RAIL. + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_ROAD || GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL. * @return True if the engine is articulated. */ static bool IsArticulated(EngineID engine_id); @@ -245,10 +245,10 @@ public: * Get the PlaneType of the engine. * @param engine_id The engine to get the PlaneType of. * @pre IsValidEngine(engine_id). - * @pre GetVehicleType(engine_id) == AIVehicle::VT_AIR. + * @pre GetVehicleType(engine_id) == ScriptVehicle::VT_AIR. * @return The PlaneType the engine has. */ - static AIAirport::PlaneType GetPlaneType(EngineID engine_id); + static ScriptAirport::PlaneType GetPlaneType(EngineID engine_id); }; #endif /* SCRIPT_ENGINE_HPP */ diff --git a/src/script/api/script_enginelist.cpp b/src/script/api/script_enginelist.cpp index cbbdb725e..6b0b512ab 100644 --- a/src/script/api/script_enginelist.cpp +++ b/src/script/api/script_enginelist.cpp @@ -7,7 +7,7 @@ * 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 script_enginelist.cpp Implementation of AIEngineList and friends. */ +/** @file script_enginelist.cpp Implementation of ScriptEngineList and friends. */ #include "../../stdafx.h" #include "script_enginelist.hpp" @@ -15,7 +15,7 @@ #include "../../engine_base.h" #include "../../core/bitmath_func.hpp" -AIEngineList::AIEngineList(AIVehicle::VehicleType vehicle_type) +ScriptEngineList::ScriptEngineList(ScriptVehicle::VehicleType vehicle_type) { Engine *e; FOR_ALL_ENGINES_OF_TYPE(e, (::VehicleType)vehicle_type) { diff --git a/src/script/api/script_enginelist.hpp b/src/script/api/script_enginelist.hpp index 763c908fa..5e9bb9941 100644 --- a/src/script/api/script_enginelist.hpp +++ b/src/script/api/script_enginelist.hpp @@ -17,14 +17,14 @@ /** * Create a list of engines based on a vehicle type. - * @ingroup AIList + * @ingroup ScriptList */ -class AIEngineList : public AIList { +class ScriptEngineList : public ScriptList { public: /** * @param vehicle_type The type of vehicle to make a list of engines for. */ - AIEngineList(AIVehicle::VehicleType vehicle_type); + ScriptEngineList(ScriptVehicle::VehicleType vehicle_type); }; #endif /* SCRIPT_ENGINELIST_HPP */ diff --git a/src/script/api/script_error.cpp b/src/script/api/script_error.cpp index 0614c299e..46d287f77 100644 --- a/src/script/api/script_error.cpp +++ b/src/script/api/script_error.cpp @@ -7,26 +7,26 @@ * 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 script_error.cpp Implementation of AIError. */ +/** @file script_error.cpp Implementation of ScriptError. */ #include "../../stdafx.h" #include "script_error.hpp" #include "../../core/bitmath_func.hpp" -AIError::AIErrorMap AIError::error_map = AIError::AIErrorMap(); -AIError::AIErrorMapString AIError::error_map_string = AIError::AIErrorMapString(); +ScriptError::ScriptErrorMap ScriptError::error_map = ScriptError::ScriptErrorMap(); +ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::ScriptErrorMapString(); -/* static */ AIErrorType AIError::GetLastError() +/* static */ ScriptErrorType ScriptError::GetLastError() { - return AIObject::GetLastError(); + return ScriptObject::GetLastError(); } -/* static */ char *AIError::GetLastErrorString() +/* static */ char *ScriptError::GetLastErrorString() { - return strdup((*error_map_string.find(AIError::GetLastError())).second); + return strdup((*error_map_string.find(ScriptError::GetLastError())).second); } -/* static */ AIErrorType AIError::StringToError(StringID internal_string_id) +/* static */ ScriptErrorType ScriptError::StringToError(StringID internal_string_id) { uint index = GB(internal_string_id, 11, 5); switch (GB(internal_string_id, 11, 5)) { @@ -47,22 +47,22 @@ AIError::AIErrorMapString AIError::error_map_string = AIError::AIErrorMapString( break; } - AIErrorMap::iterator it = error_map.find(internal_string_id); + ScriptErrorMap::iterator it = error_map.find(internal_string_id); if (it == error_map.end()) return ERR_UNKNOWN; return (*it).second; } -/* static */ void AIError::RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg) +/* static */ void ScriptError::RegisterErrorMap(StringID internal_string_id, ScriptErrorType ai_error_msg) { error_map[internal_string_id] = ai_error_msg; } -/* static */ void AIError::RegisterErrorMapString(AIErrorType ai_error_msg, const char *message) +/* static */ void ScriptError::RegisterErrorMapString(ScriptErrorType ai_error_msg, const char *message) { error_map_string[ai_error_msg] = message; } -/* static */ AIError::ErrorCategories AIError::GetErrorCategory() +/* static */ ScriptError::ErrorCategories ScriptError::GetErrorCategory() { - return (AIError::ErrorCategories)(GetLastError() >> (uint)ERR_CAT_BIT_SIZE); + return (ScriptError::ErrorCategories)(GetLastError() >> (uint)ERR_CAT_BIT_SIZE); } diff --git a/src/script/api/script_error.hpp b/src/script/api/script_error.hpp index 12fa83b97..cbc74005a 100644 --- a/src/script/api/script_error.hpp +++ b/src/script/api/script_error.hpp @@ -22,7 +22,7 @@ */ #define EnforcePrecondition(returnval, condition) \ if (!(condition)) { \ - AIObject::SetLastError(AIError::ERR_PRECONDITION_FAILED); \ + ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_FAILED); \ return returnval; \ } @@ -30,18 +30,18 @@ * Helper to write precondition enforcers for the AI API in an abbreviated manner. * @param returnval The value to return on failure. * @param condition The condition that must be obeyed. - * @param error_code The error code passed to AIObject::SetLastError. + * @param error_code The error code passed to ScriptObject::SetLastError. */ #define EnforcePreconditionCustomError(returnval, condition, error_code) \ if (!(condition)) { \ - AIObject::SetLastError(error_code); \ + ScriptObject::SetLastError(error_code); \ return returnval; \ } /** * Class that handles all error related functions. */ -class AIError : public AIObject { +class ScriptError : public ScriptObject { public: /** * All categories errors can be divided in. @@ -134,7 +134,7 @@ public: * Get the last error. * @return An ErrorMessages enum value. */ - static AIErrorType GetLastError(); + static ScriptErrorType GetLastError(); /** * Get the last error in string format (for human readability). @@ -149,7 +149,7 @@ public: * @param internal_string_id The string to convert. * @return The NoAI equivalent error message. */ - static AIErrorType StringToError(StringID internal_string_id); + static ScriptErrorType StringToError(StringID internal_string_id); /** * Map an internal OpenTTD error message to its NoAI equivalent. @@ -157,7 +157,7 @@ public: * @param internal_string_id The OpenTTD StringID used for an error. * @param ai_error_msg The NoAI equivalent error message. */ - static void RegisterErrorMap(StringID internal_string_id, AIErrorType ai_error_msg); + static void RegisterErrorMap(StringID internal_string_id, ScriptErrorType ai_error_msg); /** * Map an internal OpenTTD error message to its NoAI equivalent. @@ -165,15 +165,15 @@ public: * @param ai_error_msg The NoAI error message representation. * @param message The string representation of this error message, used for debug purposes. */ - static void RegisterErrorMapString(AIErrorType ai_error_msg, const char *message); + static void RegisterErrorMapString(ScriptErrorType ai_error_msg, const char *message); #endif /* EXPORT_SKIP */ private: - typedef std::map<StringID, AIErrorType> AIErrorMap; ///< The type for mapping between error (internal OpenTTD) StringID to the AI error type. - typedef std::map<AIErrorType, const char *> AIErrorMapString; ///< The type for mapping between error type and textual representation. + typedef std::map<StringID, ScriptErrorType> ScriptErrorMap; ///< The type for mapping between error (internal OpenTTD) StringID to the AI error type. + typedef std::map<ScriptErrorType, const char *> ScriptErrorMapString; ///< The type for mapping between error type and textual representation. - static AIErrorMap error_map; ///< The mapping between error (internal OpenTTD) StringID to the AI error type. - static AIErrorMapString error_map_string; ///< The mapping between error type and textual representation. + static ScriptErrorMap error_map; ///< The mapping between error (internal OpenTTD) StringID to the AI error type. + static ScriptErrorMapString error_map_string; ///< The mapping between error type and textual representation. }; #endif /* SCRIPT_ERROR_HPP */ diff --git a/src/script/api/script_event.cpp b/src/script/api/script_event.cpp index 6fdbea02a..1237402ac 100644 --- a/src/script/api/script_event.cpp +++ b/src/script/api/script_event.cpp @@ -7,7 +7,7 @@ * 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 script_event.cpp Implementation of AIEvent. */ +/** @file script_event.cpp Implementation of ScriptEvent. */ #include "../../stdafx.h" #include "script_event_types.hpp" @@ -15,24 +15,24 @@ #include <queue> /** The queue of events for an AI. */ -struct AIEventData { - std::queue<AIEvent *> stack; ///< The actual queue. +struct ScriptEventData { + std::queue<ScriptEvent *> stack; ///< The actual queue. }; -/* static */ void AIEventController::CreateEventPointer() +/* static */ void ScriptEventController::CreateEventPointer() { - assert(AIObject::GetEventPointer() == NULL); + assert(ScriptObject::GetEventPointer() == NULL); - AIObject::GetEventPointer() = new AIEventData(); + ScriptObject::GetEventPointer() = new ScriptEventData(); } -/* static */ void AIEventController::FreeEventPointer() +/* static */ void ScriptEventController::FreeEventPointer() { - AIEventData *data = (AIEventData *)AIObject::GetEventPointer(); + ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer(); /* Free all waiting events (if any) */ while (!data->stack.empty()) { - AIEvent *e = data->stack.front(); + ScriptEvent *e = data->stack.front(); data->stack.pop(); e->Release(); } @@ -41,30 +41,30 @@ struct AIEventData { delete data; } -/* static */ bool AIEventController::IsEventWaiting() +/* static */ bool ScriptEventController::IsEventWaiting() { - if (AIObject::GetEventPointer() == NULL) AIEventController::CreateEventPointer(); - AIEventData *data = (AIEventData *)AIObject::GetEventPointer(); + if (ScriptObject::GetEventPointer() == NULL) ScriptEventController::CreateEventPointer(); + ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer(); return !data->stack.empty(); } -/* static */ AIEvent *AIEventController::GetNextEvent() +/* static */ ScriptEvent *ScriptEventController::GetNextEvent() { - if (AIObject::GetEventPointer() == NULL) AIEventController::CreateEventPointer(); - AIEventData *data = (AIEventData *)AIObject::GetEventPointer(); + if (ScriptObject::GetEventPointer() == NULL) ScriptEventController::CreateEventPointer(); + ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer(); if (data->stack.empty()) return NULL; - AIEvent *e = data->stack.front(); + ScriptEvent *e = data->stack.front(); data->stack.pop(); return e; } -/* static */ void AIEventController::InsertEvent(AIEvent *event) +/* static */ void ScriptEventController::InsertEvent(ScriptEvent *event) { - if (AIObject::GetEventPointer() == NULL) AIEventController::CreateEventPointer(); - AIEventData *data = (AIEventData *)AIObject::GetEventPointer(); + if (ScriptObject::GetEventPointer() == NULL) ScriptEventController::CreateEventPointer(); + ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer(); event->AddRef(); data->stack.push(event); diff --git a/src/script/api/script_event.hpp b/src/script/api/script_event.hpp index 449ee0361..eb15ded2e 100644 --- a/src/script/api/script_event.hpp +++ b/src/script/api/script_event.hpp @@ -19,12 +19,12 @@ * You can lookup the type, and than convert it to the real event-class. * That way you can request more detailed information about the event. */ -class AIEvent : public AIObject { +class ScriptEvent : public ScriptObject { public: /** * The type of event. Needed to lookup the detailed class. */ - enum AIEventType { + enum ScriptEventType { AI_ET_INVALID = 0, AI_ET_TEST, AI_ET_SUBSIDY_OFFER, @@ -51,31 +51,31 @@ public: }; /** - * Constructor of AIEvent, to get the type of event. + * Constructor of ScriptEvent, to get the type of event. */ - AIEvent(AIEvent::AIEventType type) : + ScriptEvent(ScriptEvent::ScriptEventType type) : type(type) {} /** * Get the event-type. - * @return The @c AIEventType. + * @return The @c ScriptEventType. */ - AIEventType GetEventType() { return this->type; } + ScriptEventType GetEventType() { return this->type; } protected: /** * The type of this event. */ - AIEventType type; + ScriptEventType type; }; /** * Class that handles all event related functions. - * @note it is not needed to create an instance of AIEvent to access it, as + * @note it is not needed to create an instance of ScriptEvent to access it, as * all members are static, and all data is stored AI-wide. */ -class AIEventController : public AIObject { +class ScriptEventController : public ScriptObject { public: /** * Check if there is an event waiting. @@ -87,7 +87,7 @@ public: * Get the next event. * @return a class of the event-child issues. */ - static AIEvent *GetNextEvent(); + static ScriptEvent *GetNextEvent(); #ifndef EXPORT_SKIP /** @@ -95,7 +95,7 @@ public: * @param event The event to insert. * @note DO NOT CALL YOURSELF; leave it to the internal AI programming. */ - static void InsertEvent(AIEvent *event); + static void InsertEvent(ScriptEvent *event); /** * Free the event pointer. diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp index a74f84969..387e678bd 100644 --- a/src/script/api/script_event_types.cpp +++ b/src/script/api/script_event_types.cpp @@ -19,13 +19,13 @@ #include "../../articulated_vehicles.h" #include "table/strings.h" -bool AIEventEnginePreview::IsEngineValid() const +bool ScriptEventEnginePreview::IsEngineValid() const { const Engine *e = ::Engine::GetIfValid(this->engine); return e != NULL && e->IsEnabled(); } -char *AIEventEnginePreview::GetName() +char *ScriptEventEnginePreview::GetName() { if (!this->IsEngineValid()) return NULL; static const int len = 64; @@ -36,7 +36,7 @@ char *AIEventEnginePreview::GetName() return engine_name; } -CargoID AIEventEnginePreview::GetCargoType() +CargoID ScriptEventEnginePreview::GetCargoType() { if (!this->IsEngineValid()) return CT_INVALID; CargoArray cap = ::GetCapacityOfArticulatedParts(this->engine); @@ -53,7 +53,7 @@ CargoID AIEventEnginePreview::GetCargoType() return most_cargo; } -int32 AIEventEnginePreview::GetCapacity() +int32 ScriptEventEnginePreview::GetCapacity() { if (!this->IsEngineValid()) return -1; const Engine *e = ::Engine::Get(this->engine); @@ -76,7 +76,7 @@ int32 AIEventEnginePreview::GetCapacity() } } -int32 AIEventEnginePreview::GetMaxSpeed() +int32 ScriptEventEnginePreview::GetMaxSpeed() { if (!this->IsEngineValid()) return -1; const Engine *e = ::Engine::Get(this->engine); @@ -85,37 +85,37 @@ int32 AIEventEnginePreview::GetMaxSpeed() return max_speed; } -Money AIEventEnginePreview::GetPrice() +Money ScriptEventEnginePreview::GetPrice() { if (!this->IsEngineValid()) return -1; return ::Engine::Get(this->engine)->GetCost(); } -Money AIEventEnginePreview::GetRunningCost() +Money ScriptEventEnginePreview::GetRunningCost() { if (!this->IsEngineValid()) return -1; return ::Engine::Get(this->engine)->GetRunningCost(); } -int32 AIEventEnginePreview::GetVehicleType() +int32 ScriptEventEnginePreview::GetVehicleType() { - if (!this->IsEngineValid()) return AIVehicle::VT_INVALID; + if (!this->IsEngineValid()) return ScriptVehicle::VT_INVALID; switch (::Engine::Get(this->engine)->type) { - case VEH_ROAD: return AIVehicle::VT_ROAD; - case VEH_TRAIN: return AIVehicle::VT_RAIL; - case VEH_SHIP: return AIVehicle::VT_WATER; - case VEH_AIRCRAFT: return AIVehicle::VT_AIR; + case VEH_ROAD: return ScriptVehicle::VT_ROAD; + case VEH_TRAIN: return ScriptVehicle::VT_RAIL; + case VEH_SHIP: return ScriptVehicle::VT_WATER; + case VEH_AIRCRAFT: return ScriptVehicle::VT_AIR; default: NOT_REACHED(); } } -bool AIEventEnginePreview::AcceptPreview() +bool ScriptEventEnginePreview::AcceptPreview() { if (!this->IsEngineValid()) return false; - return AIObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW); + return ScriptObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW); } -bool AIEventCompanyAskMerger::AcceptMerger() +bool ScriptEventCompanyAskMerger::AcceptMerger() { - return AIObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY); + return ScriptObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY); } diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp index 8c541241b..163c9e54c 100644 --- a/src/script/api/script_event_types.hpp +++ b/src/script/api/script_event_types.hpp @@ -19,7 +19,7 @@ * Event Vehicle Crash, indicating a vehicle of yours is crashed. * It contains the crash site, the crashed vehicle and the reason for the crash. */ -class AIEventVehicleCrashed : public AIEvent { +class ScriptEventVehicleCrashed : public ScriptEvent { public: /** * The reasons for vehicle crashes @@ -38,19 +38,19 @@ public: * @param crash_site Where the vehicle crashed. * @param crash_reason The reason why the vehicle crashed. */ - AIEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason) : - AIEvent(AI_ET_VEHICLE_CRASHED), + ScriptEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason) : + ScriptEvent(AI_ET_VEHICLE_CRASHED), crash_site(crash_site), vehicle(vehicle), crash_reason(crash_reason) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventVehicleCrashed *Convert(AIEvent *instance) { return (AIEventVehicleCrashed *)instance; } + static ScriptEventVehicleCrashed *Convert(ScriptEvent *instance) { return (ScriptEventVehicleCrashed *)instance; } /** * Get the VehicleID of the crashed vehicle. @@ -79,22 +79,22 @@ private: /** * Event Subsidy Offered, indicating someone offered a subsidy. */ -class AIEventSubsidyOffer : public AIEvent { +class ScriptEventSubsidyOffer : public ScriptEvent { public: /** * @param subsidy_id The index of this subsidy in the _subsidies array. */ - AIEventSubsidyOffer(SubsidyID subsidy_id) : - AIEvent(AI_ET_SUBSIDY_OFFER), + ScriptEventSubsidyOffer(SubsidyID subsidy_id) : + ScriptEvent(AI_ET_SUBSIDY_OFFER), subsidy_id(subsidy_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventSubsidyOffer *Convert(AIEvent *instance) { return (AIEventSubsidyOffer *)instance; } + static ScriptEventSubsidyOffer *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyOffer *)instance; } /** * Get the SubsidyID of the subsidy. @@ -109,22 +109,22 @@ private: /** * Event Subsidy Offer Expired, indicating a subsidy will no longer be awarded. */ -class AIEventSubsidyOfferExpired : public AIEvent { +class ScriptEventSubsidyOfferExpired : public ScriptEvent { public: /** * @param subsidy_id The index of this subsidy in the _subsidies array. */ - AIEventSubsidyOfferExpired(SubsidyID subsidy_id) : - AIEvent(AI_ET_SUBSIDY_OFFER_EXPIRED), + ScriptEventSubsidyOfferExpired(SubsidyID subsidy_id) : + ScriptEvent(AI_ET_SUBSIDY_OFFER_EXPIRED), subsidy_id(subsidy_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventSubsidyOfferExpired *Convert(AIEvent *instance) { return (AIEventSubsidyOfferExpired *)instance; } + static ScriptEventSubsidyOfferExpired *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyOfferExpired *)instance; } /** * Get the SubsidyID of the subsidy. @@ -139,22 +139,22 @@ private: /** * Event Subidy Awarded, indicating a subsidy is awarded to some company. */ -class AIEventSubsidyAwarded : public AIEvent { +class ScriptEventSubsidyAwarded : public ScriptEvent { public: /** * @param subsidy_id The index of this subsidy in the _subsidies array. */ - AIEventSubsidyAwarded(SubsidyID subsidy_id) : - AIEvent(AI_ET_SUBSIDY_AWARDED), + ScriptEventSubsidyAwarded(SubsidyID subsidy_id) : + ScriptEvent(AI_ET_SUBSIDY_AWARDED), subsidy_id(subsidy_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventSubsidyAwarded *Convert(AIEvent *instance) { return (AIEventSubsidyAwarded *)instance; } + static ScriptEventSubsidyAwarded *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyAwarded *)instance; } /** * Get the SubsidyID of the subsidy. @@ -169,22 +169,22 @@ private: /** * Event Subsidy Expired, indicating a route that was once subsidized no longer is. */ -class AIEventSubsidyExpired : public AIEvent { +class ScriptEventSubsidyExpired : public ScriptEvent { public: /** * @param subsidy_id The index of this subsidy in the _subsidies array. */ - AIEventSubsidyExpired(SubsidyID subsidy_id) : - AIEvent(AI_ET_SUBSIDY_EXPIRED), + ScriptEventSubsidyExpired(SubsidyID subsidy_id) : + ScriptEvent(AI_ET_SUBSIDY_EXPIRED), subsidy_id(subsidy_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventSubsidyExpired *Convert(AIEvent *instance) { return (AIEventSubsidyExpired *)instance; } + static ScriptEventSubsidyExpired *Convert(ScriptEvent *instance) { return (ScriptEventSubsidyExpired *)instance; } /** * Get the SubsidyID of the subsidy. @@ -201,22 +201,22 @@ private: * You can get the same information about the offered engine as a real user * would see in the offer window. And you can also accept the offer. */ -class AIEventEnginePreview : public AIEvent { +class ScriptEventEnginePreview : public ScriptEvent { public: /** * @param engine The engine offered to test. */ - AIEventEnginePreview(EngineID engine) : - AIEvent(AI_ET_ENGINE_PREVIEW), + ScriptEventEnginePreview(EngineID engine) : + ScriptEvent(AI_ET_ENGINE_PREVIEW), engine(engine) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventEnginePreview *Convert(AIEvent *instance) { return (AIEventEnginePreview *)instance; } + static ScriptEventEnginePreview *Convert(ScriptEvent *instance) { return (ScriptEventEnginePreview *)instance; } /** * Get the name of the offered engine. @@ -265,7 +265,7 @@ public: * @return The type the engine has. */ #ifdef DOXYGEN_AI_DOCS - AIVehicle::VehicleType GetVehicleType(); + ScriptVehicle::VehicleType GetVehicleType(); #else int32 GetVehicleType(); #endif @@ -289,92 +289,92 @@ private: /** * Event Company New, indicating a new company has been created. */ -class AIEventCompanyNew : public AIEvent { +class ScriptEventCompanyNew : public ScriptEvent { public: /** * @param owner The new company. */ - AIEventCompanyNew(Owner owner) : - AIEvent(AI_ET_COMPANY_NEW), - owner((AICompany::CompanyID)owner) + ScriptEventCompanyNew(Owner owner) : + ScriptEvent(AI_ET_COMPANY_NEW), + owner((ScriptCompany::CompanyID)owner) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventCompanyNew *Convert(AIEvent *instance) { return (AIEventCompanyNew *)instance; } + static ScriptEventCompanyNew *Convert(ScriptEvent *instance) { return (ScriptEventCompanyNew *)instance; } /** * Get the CompanyID of the company that has been created. * @return The CompanyID of the company. */ - AICompany::CompanyID GetCompanyID() { return this->owner; } + ScriptCompany::CompanyID GetCompanyID() { return this->owner; } private: - AICompany::CompanyID owner; ///< The new company. + ScriptCompany::CompanyID owner; ///< The new company. }; /** * Event Company In Trouble, indicating a company is in trouble and might go * bankrupt soon. */ -class AIEventCompanyInTrouble : public AIEvent { +class ScriptEventCompanyInTrouble : public ScriptEvent { public: /** * @param owner The company that is in trouble. */ - AIEventCompanyInTrouble(Owner owner) : - AIEvent(AI_ET_COMPANY_IN_TROUBLE), - owner((AICompany::CompanyID)owner) + ScriptEventCompanyInTrouble(Owner owner) : + ScriptEvent(AI_ET_COMPANY_IN_TROUBLE), + owner((ScriptCompany::CompanyID)owner) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventCompanyInTrouble *Convert(AIEvent *instance) { return (AIEventCompanyInTrouble *)instance; } + static ScriptEventCompanyInTrouble *Convert(ScriptEvent *instance) { return (ScriptEventCompanyInTrouble *)instance; } /** * Get the CompanyID of the company that is in trouble. * @return The CompanyID of the company in trouble. */ - AICompany::CompanyID GetCompanyID() { return this->owner; } + ScriptCompany::CompanyID GetCompanyID() { return this->owner; } private: - AICompany::CompanyID owner; ///< The company that is in trouble. + ScriptCompany::CompanyID owner; ///< The company that is in trouble. }; /** * Event Company Ask Merger, indicating a company can be bought (cheaply) by you. */ -class AIEventCompanyAskMerger : public AIEvent { +class ScriptEventCompanyAskMerger : public ScriptEvent { public: /** * @param owner The company that can be bough. * @param value The value/costs of buying the company. */ - AIEventCompanyAskMerger(Owner owner, int32 value) : - AIEvent(AI_ET_COMPANY_ASK_MERGER), - owner((AICompany::CompanyID)owner), + ScriptEventCompanyAskMerger(Owner owner, int32 value) : + ScriptEvent(AI_ET_COMPANY_ASK_MERGER), + owner((ScriptCompany::CompanyID)owner), value(value) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventCompanyAskMerger *Convert(AIEvent *instance) { return (AIEventCompanyAskMerger *)instance; } + static ScriptEventCompanyAskMerger *Convert(ScriptEvent *instance) { return (ScriptEventCompanyAskMerger *)instance; } /** * Get the CompanyID of the company that can be bought. * @return The CompanyID of the company that can be bought. * @note If the company is bought this will become invalid. */ - AICompany::CompanyID GetCompanyID() { return this->owner; } + ScriptCompany::CompanyID GetCompanyID() { return this->owner; } /** * Get the value of the new company. @@ -389,7 +389,7 @@ public: bool AcceptMerger(); private: - AICompany::CompanyID owner; ///< The company that is in trouble. + ScriptCompany::CompanyID owner; ///< The company that is in trouble. int32 value; ///< The value of the company, i.e. the amount you would pay. }; @@ -397,94 +397,94 @@ private: * Event Company Merger, indicating a company has been bought by another * company. */ -class AIEventCompanyMerger : public AIEvent { +class ScriptEventCompanyMerger : public ScriptEvent { public: /** * @param old_owner The company bought off. * @param new_owner The company that bougth owner. */ - AIEventCompanyMerger(Owner old_owner, Owner new_owner) : - AIEvent(AI_ET_COMPANY_MERGER), - old_owner((AICompany::CompanyID)old_owner), - new_owner((AICompany::CompanyID)new_owner) + ScriptEventCompanyMerger(Owner old_owner, Owner new_owner) : + ScriptEvent(AI_ET_COMPANY_MERGER), + old_owner((ScriptCompany::CompanyID)old_owner), + new_owner((ScriptCompany::CompanyID)new_owner) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventCompanyMerger *Convert(AIEvent *instance) { return (AIEventCompanyMerger *)instance; } + static ScriptEventCompanyMerger *Convert(ScriptEvent *instance) { return (ScriptEventCompanyMerger *)instance; } /** * Get the CompanyID of the company that has been bought. * @return The CompanyID of the company that has been bought. * @note: The value below is not valid anymore as CompanyID, and - * AICompany::ResolveCompanyID will return COMPANY_COMPANY. It's + * ScriptCompany::ResolveCompanyID will return COMPANY_COMPANY. It's * only usefull if you're keeping track of company's yourself. */ - AICompany::CompanyID GetOldCompanyID() { return this->old_owner; } + ScriptCompany::CompanyID GetOldCompanyID() { return this->old_owner; } /** * Get the CompanyID of the new owner. * @return The CompanyID of the new owner. */ - AICompany::CompanyID GetNewCompanyID() { return this->new_owner; } + ScriptCompany::CompanyID GetNewCompanyID() { return this->new_owner; } private: - AICompany::CompanyID old_owner; ///< The company that ended to exist. - AICompany::CompanyID new_owner; ///< The company that's the end result of the merger. + ScriptCompany::CompanyID old_owner; ///< The company that ended to exist. + ScriptCompany::CompanyID new_owner; ///< The company that's the end result of the merger. }; /** * Event Company Bankrupt, indicating a company has gone bankrupt. */ -class AIEventCompanyBankrupt : public AIEvent { +class ScriptEventCompanyBankrupt : public ScriptEvent { public: /** * @param owner The company that has gone bankrupt. */ - AIEventCompanyBankrupt(Owner owner) : - AIEvent(AI_ET_COMPANY_BANKRUPT), - owner((AICompany::CompanyID)owner) + ScriptEventCompanyBankrupt(Owner owner) : + ScriptEvent(AI_ET_COMPANY_BANKRUPT), + owner((ScriptCompany::CompanyID)owner) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventCompanyBankrupt *Convert(AIEvent *instance) { return (AIEventCompanyBankrupt *)instance; } + static ScriptEventCompanyBankrupt *Convert(ScriptEvent *instance) { return (ScriptEventCompanyBankrupt *)instance; } /** * Get the CompanyID of the company that has gone bankrupt. * @return The CompanyID of the company that has gone bankrupt. */ - AICompany::CompanyID GetCompanyID() { return this->owner; } + ScriptCompany::CompanyID GetCompanyID() { return this->owner; } private: - AICompany::CompanyID owner; ///< The company that has gone bankrupt. + ScriptCompany::CompanyID owner; ///< The company that has gone bankrupt. }; /** * Event Vehicle Lost, indicating a vehicle can't find its way to its destination. */ -class AIEventVehicleLost : public AIEvent { +class ScriptEventVehicleLost : public ScriptEvent { public: /** * @param vehicle_id The vehicle that is lost. */ - AIEventVehicleLost(VehicleID vehicle_id) : - AIEvent(AI_ET_VEHICLE_LOST), + ScriptEventVehicleLost(VehicleID vehicle_id) : + ScriptEvent(AI_ET_VEHICLE_LOST), vehicle_id(vehicle_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventVehicleLost *Convert(AIEvent *instance) { return (AIEventVehicleLost *)instance; } + static ScriptEventVehicleLost *Convert(ScriptEvent *instance) { return (ScriptEventVehicleLost *)instance; } /** * Get the VehicleID of the vehicle that is lost. @@ -499,22 +499,22 @@ private: /** * Event VehicleWaitingInDepot, indicating a vehicle has arrived a depot and is now waiting there. */ -class AIEventVehicleWaitingInDepot : public AIEvent { +class ScriptEventVehicleWaitingInDepot : public ScriptEvent { public: /** * @param vehicle_id The vehicle that is waiting in a depot. */ - AIEventVehicleWaitingInDepot(VehicleID vehicle_id) : - AIEvent(AI_ET_VEHICLE_WAITING_IN_DEPOT), + ScriptEventVehicleWaitingInDepot(VehicleID vehicle_id) : + ScriptEvent(AI_ET_VEHICLE_WAITING_IN_DEPOT), vehicle_id(vehicle_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventVehicleWaitingInDepot *Convert(AIEvent *instance) { return (AIEventVehicleWaitingInDepot *)instance; } + static ScriptEventVehicleWaitingInDepot *Convert(ScriptEvent *instance) { return (ScriptEventVehicleWaitingInDepot *)instance; } /** * Get the VehicleID of the vehicle that is waiting in a depot. @@ -529,22 +529,22 @@ private: /** * Event Vehicle Unprofitable, indicating a vehicle lost money last year. */ -class AIEventVehicleUnprofitable : public AIEvent { +class ScriptEventVehicleUnprofitable : public ScriptEvent { public: /** * @param vehicle_id The vehicle that was unprofitable. */ - AIEventVehicleUnprofitable(VehicleID vehicle_id) : - AIEvent(AI_ET_VEHICLE_UNPROFITABLE), + ScriptEventVehicleUnprofitable(VehicleID vehicle_id) : + ScriptEvent(AI_ET_VEHICLE_UNPROFITABLE), vehicle_id(vehicle_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventVehicleUnprofitable *Convert(AIEvent *instance) { return (AIEventVehicleUnprofitable *)instance; } + static ScriptEventVehicleUnprofitable *Convert(ScriptEvent *instance) { return (ScriptEventVehicleUnprofitable *)instance; } /** * Get the VehicleID of the vehicle that lost money. @@ -559,22 +559,22 @@ private: /** * Event Industry Open, indicating a new industry has been created. */ -class AIEventIndustryOpen : public AIEvent { +class ScriptEventIndustryOpen : public ScriptEvent { public: /** * @param industry_id The new industry. */ - AIEventIndustryOpen(IndustryID industry_id) : - AIEvent(AI_ET_INDUSTRY_OPEN), + ScriptEventIndustryOpen(IndustryID industry_id) : + ScriptEvent(AI_ET_INDUSTRY_OPEN), industry_id(industry_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventIndustryOpen *Convert(AIEvent *instance) { return (AIEventIndustryOpen *)instance; } + static ScriptEventIndustryOpen *Convert(ScriptEvent *instance) { return (ScriptEventIndustryOpen *)instance; } /** * Get the IndustryID of the new industry. @@ -589,22 +589,22 @@ private: /** * Event Industry Close, indicating an industry is going to be closed. */ -class AIEventIndustryClose : public AIEvent { +class ScriptEventIndustryClose : public ScriptEvent { public: /** * @param industry_id The new industry. */ - AIEventIndustryClose(IndustryID industry_id) : - AIEvent(AI_ET_INDUSTRY_CLOSE), + ScriptEventIndustryClose(IndustryID industry_id) : + ScriptEvent(AI_ET_INDUSTRY_CLOSE), industry_id(industry_id) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventIndustryClose *Convert(AIEvent *instance) { return (AIEventIndustryClose *)instance; } + static ScriptEventIndustryClose *Convert(ScriptEvent *instance) { return (ScriptEventIndustryClose *)instance; } /** * Get the IndustryID of the closing industry. @@ -619,22 +619,22 @@ private: /** * Event Engine Available, indicating a new engine is available. */ -class AIEventEngineAvailable : public AIEvent { +class ScriptEventEngineAvailable : public ScriptEvent { public: /** * @param engine The engine that is available. */ - AIEventEngineAvailable(EngineID engine) : - AIEvent(AI_ET_ENGINE_AVAILABLE), + ScriptEventEngineAvailable(EngineID engine) : + ScriptEvent(AI_ET_ENGINE_AVAILABLE), engine(engine) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventEngineAvailable *Convert(AIEvent *instance) { return (AIEventEngineAvailable *)instance; } + static ScriptEventEngineAvailable *Convert(ScriptEvent *instance) { return (ScriptEventEngineAvailable *)instance; } /** * Get the EngineID of the new engine. @@ -649,24 +649,24 @@ private: /** * Event Station First Vehicle, indicating a station has been visited by a vehicle for the first time. */ -class AIEventStationFirstVehicle : public AIEvent { +class ScriptEventStationFirstVehicle : public ScriptEvent { public: /** * @param station The station visited for the first time. * @param vehicle The vehicle visiting the station. */ - AIEventStationFirstVehicle(StationID station, VehicleID vehicle) : - AIEvent(AI_ET_STATION_FIRST_VEHICLE), + ScriptEventStationFirstVehicle(StationID station, VehicleID vehicle) : + ScriptEvent(AI_ET_STATION_FIRST_VEHICLE), station(station), vehicle(vehicle) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventStationFirstVehicle *Convert(AIEvent *instance) { return (AIEventStationFirstVehicle *)instance; } + static ScriptEventStationFirstVehicle *Convert(ScriptEvent *instance) { return (ScriptEventStationFirstVehicle *)instance; } /** * Get the StationID of the visited station. @@ -688,22 +688,22 @@ private: /** * Event Disaster Zeppeliner Crashed, indicating a zeppeliner has crashed on an airport and is blocking the runway. */ -class AIEventDisasterZeppelinerCrashed : public AIEvent { +class ScriptEventDisasterZeppelinerCrashed : public ScriptEvent { public: /** * @param station The station containing the affected airport */ - AIEventDisasterZeppelinerCrashed(StationID station) : - AIEvent(AI_ET_DISASTER_ZEPPELINER_CRASHED), + ScriptEventDisasterZeppelinerCrashed(StationID station) : + ScriptEvent(AI_ET_DISASTER_ZEPPELINER_CRASHED), station(station) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventDisasterZeppelinerCrashed *Convert(AIEvent *instance) { return (AIEventDisasterZeppelinerCrashed *)instance; } + static ScriptEventDisasterZeppelinerCrashed *Convert(ScriptEvent *instance) { return (ScriptEventDisasterZeppelinerCrashed *)instance; } /** * Get the StationID of the station containing the affected airport. @@ -718,22 +718,22 @@ private: /** * Event Disaster Zeppeliner Cleared, indicating a previously crashed zeppeliner has been removed, and the airport is operating again. */ -class AIEventDisasterZeppelinerCleared : public AIEvent { +class ScriptEventDisasterZeppelinerCleared : public ScriptEvent { public: /** * @param station The station containing the affected airport */ - AIEventDisasterZeppelinerCleared(StationID station) : - AIEvent(AI_ET_DISASTER_ZEPPELINER_CLEARED), + ScriptEventDisasterZeppelinerCleared(StationID station) : + ScriptEvent(AI_ET_DISASTER_ZEPPELINER_CLEARED), station(station) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventDisasterZeppelinerCleared *Convert(AIEvent *instance) { return (AIEventDisasterZeppelinerCleared *)instance; } + static ScriptEventDisasterZeppelinerCleared *Convert(ScriptEvent *instance) { return (ScriptEventDisasterZeppelinerCleared *)instance; } /** * Get the StationID of the station containing the affected airport. @@ -748,22 +748,22 @@ private: /** * Event Town Founded, indicating a new town has been created. */ -class AIEventTownFounded : public AIEvent { +class ScriptEventTownFounded : public ScriptEvent { public: /** * @param town The town that was created. */ - AIEventTownFounded(TownID town) : - AIEvent(AI_ET_TOWN_FOUNDED), + ScriptEventTownFounded(TownID town) : + ScriptEvent(AI_ET_TOWN_FOUNDED), town(town) {} /** - * Convert an AIEvent to the real instance. + * Convert an ScriptEvent to the real instance. * @param instance The instance to convert. * @return The converted instance. */ - static AIEventTownFounded *Convert(AIEvent *instance) { return (AIEventTownFounded *)instance; } + static ScriptEventTownFounded *Convert(ScriptEvent *instance) { return (ScriptEventTownFounded *)instance; } /** * Get the TownID of the town. diff --git a/src/script/api/script_execmode.cpp b/src/script/api/script_execmode.cpp index b4631b0f0..23f4c683d 100644 --- a/src/script/api/script_execmode.cpp +++ b/src/script/api/script_execmode.cpp @@ -7,7 +7,7 @@ * 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 script_execmode.cpp Implementation of AIExecMode. */ +/** @file script_execmode.cpp Implementation of ScriptExecMode. */ #include "../../stdafx.h" #include "script_execmode.hpp" @@ -15,26 +15,26 @@ #include "../../company_func.h" #include "../../ai/ai_instance.hpp" -bool AIExecMode::ModeProc() +bool ScriptExecMode::ModeProc() { /* In execution mode we only return 'true', telling the DoCommand it * should continue with the real execution of the command. */ return true; } -AIExecMode::AIExecMode() +ScriptExecMode::ScriptExecMode() { this->last_mode = this->GetDoCommandMode(); this->last_instance = this->GetDoCommandModeInstance(); - this->SetDoCommandMode(&AIExecMode::ModeProc, this); + this->SetDoCommandMode(&ScriptExecMode::ModeProc, this); } -AIExecMode::~AIExecMode() +ScriptExecMode::~ScriptExecMode() { if (this->GetDoCommandModeInstance() != this) { /* Ignore this error if the AI already died. */ - if (!AIObject::GetActiveInstance()->IsDead()) { - throw AI_FatalError("AIExecMode object was removed while it was not the latest AI*Mode object created."); + if (!ScriptObject::GetActiveInstance()->IsDead()) { + throw AI_FatalError("ScriptExecMode object was removed while it was not the latest AI*Mode object created."); } } this->SetDoCommandMode(this->last_mode, this->last_instance); diff --git a/src/script/api/script_execmode.hpp b/src/script/api/script_execmode.hpp index 4772251d7..8dfa00938 100644 --- a/src/script/api/script_execmode.hpp +++ b/src/script/api/script_execmode.hpp @@ -21,10 +21,10 @@ * instance is destroyed. * In Execute mode all commands you do are executed for real. */ -class AIExecMode : public AIObject { +class ScriptExecMode : public ScriptObject { private: AIModeProc *last_mode; ///< The previous mode we were in. - AIObject *last_instance; ///< The previous instace of the mode. + ScriptObject *last_instance; ///< The previous instace of the mode. protected: /** @@ -38,13 +38,13 @@ public: * @note When the instance is destroyed, he restores the mode that was * current when the instance was created! */ - AIExecMode(); + ScriptExecMode(); /** * Destroying this instance reset the building mode to the mode it was * in when the instance was created. */ - ~AIExecMode(); + ~ScriptExecMode(); }; #endif /* SCRIPT_EXECMODE_HPP */ diff --git a/src/script/api/script_gamesettings.cpp b/src/script/api/script_gamesettings.cpp index 3dba54a00..839486b8b 100644 --- a/src/script/api/script_gamesettings.cpp +++ b/src/script/api/script_gamesettings.cpp @@ -7,20 +7,20 @@ * 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 script_gamesettings.cpp Implementation of AIGameSettings. */ +/** @file script_gamesettings.cpp Implementation of ScriptGameSettings. */ #include "../../stdafx.h" #include "script_gamesettings.hpp" #include "../../settings_internal.h" -/* static */ bool AIGameSettings::IsValid(const char *setting) +/* static */ bool ScriptGameSettings::IsValid(const char *setting) { uint i; const SettingDesc *sd = GetSettingFromName(setting, &i); return sd != NULL && sd->desc.cmd != SDT_STRING; } -/* static */ int32 AIGameSettings::GetValue(const char *setting) +/* static */ int32 ScriptGameSettings::GetValue(const char *setting) { if (!IsValid(setting)) return -1; @@ -33,13 +33,13 @@ return (int32)ReadValue(ptr, sd->save.conv); } -/* static */ bool AIGameSettings::IsDisabledVehicleType(AIVehicle::VehicleType vehicle_type) +/* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type) { switch (vehicle_type) { - case AIVehicle::VT_RAIL: return _settings_game.ai.ai_disable_veh_train; - case AIVehicle::VT_ROAD: return _settings_game.ai.ai_disable_veh_roadveh; - case AIVehicle::VT_WATER: return _settings_game.ai.ai_disable_veh_ship; - case AIVehicle::VT_AIR: return _settings_game.ai.ai_disable_veh_aircraft; + case ScriptVehicle::VT_RAIL: return _settings_game.ai.ai_disable_veh_train; + case ScriptVehicle::VT_ROAD: return _settings_game.ai.ai_disable_veh_roadveh; + case ScriptVehicle::VT_WATER: return _settings_game.ai.ai_disable_veh_ship; + case ScriptVehicle::VT_AIR: return _settings_game.ai.ai_disable_veh_aircraft; default: return true; } } diff --git a/src/script/api/script_gamesettings.hpp b/src/script/api/script_gamesettings.hpp index 07efd630e..8643df5de 100644 --- a/src/script/api/script_gamesettings.hpp +++ b/src/script/api/script_gamesettings.hpp @@ -17,24 +17,24 @@ /** * Class that handles all game settings related functions. * - * @note AIGameSettings::IsValid and AIGameSettings::GetValue are functions + * @note ScriptGameSettings::IsValid and ScriptGameSettings::GetValue are functions * that rely on the settings as OpenTTD stores them in savegame and * openttd.cfg. No guarantees can be given on the long term validity, * consistency and stability of the names, values and value ranges. * Using these settings can be dangerous and could cause issues in * future versions. To make sure that a setting still exists in the - * current version you have to run AIGameSettings::IsValid before + * current version you have to run ScriptGameSettings::IsValid before * accessing it. * - * @note The names of the setting for AIGameSettings::IsValid and - * AIGameSettings::GetValue are the same ones as those that are shown by + * @note The names of the setting for ScriptGameSettings::IsValid and + * ScriptGameSettings::GetValue are the same ones as those that are shown by * the list_settings command in the in-game console. Settings that are * string based are NOT supported and AIGAmeSettings::IsValid will return * false for them. These settings will not be supported either because * they have no relevance for the AI (default client names, server IPs, * etc.). */ -class AIGameSettings : public AIObject { +class ScriptGameSettings : public ScriptObject { public: /** * Is the given game setting a valid setting for this instance of OpenTTD? @@ -65,7 +65,7 @@ public: * @param vehicle_type The vehicle-type to check. * @return True if the vehicle-type is disabled. */ - static bool IsDisabledVehicleType(AIVehicle::VehicleType vehicle_type); + static bool IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type); }; #endif /* SCRIPT_GAMESETTINGS_HPP */ diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index 3c879bf52..14da9e164 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -7,7 +7,7 @@ * 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 script_group.cpp Implementation of AIGroup. */ +/** @file script_group.cpp Implementation of ScriptGroup. */ #include "../../stdafx.h" #include "script_group.hpp" @@ -21,44 +21,44 @@ #include "../../settings_func.h" #include "table/strings.h" -/* static */ bool AIGroup::IsValidGroup(GroupID group_id) +/* static */ bool ScriptGroup::IsValidGroup(GroupID group_id) { const Group *g = ::Group::GetIfValid(group_id); return g != NULL && g->owner == _current_company; } -/* static */ AIGroup::GroupID AIGroup::CreateGroup(AIVehicle::VehicleType vehicle_type) +/* static */ ScriptGroup::GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type) { - if (!AIObject::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, &AIInstance::DoCommandReturnGroupID)) return GROUP_INVALID; /* In case of test-mode, we return GroupID 0 */ - return (AIGroup::GroupID)0; + return (ScriptGroup::GroupID)0; } -/* static */ bool AIGroup::DeleteGroup(GroupID group_id) +/* static */ bool ScriptGroup::DeleteGroup(GroupID group_id) { EnforcePrecondition(false, IsValidGroup(group_id)); - return AIObject::DoCommand(0, group_id, 0, CMD_DELETE_GROUP); + return ScriptObject::DoCommand(0, group_id, 0, CMD_DELETE_GROUP); } -/* static */ AIVehicle::VehicleType AIGroup::GetVehicleType(GroupID group_id) +/* static */ ScriptVehicle::VehicleType ScriptGroup::GetVehicleType(GroupID group_id) { - if (!IsValidGroup(group_id)) return AIVehicle::VT_INVALID; + if (!IsValidGroup(group_id)) return ScriptVehicle::VT_INVALID; - return (AIVehicle::VehicleType)((::VehicleType)::Group::Get(group_id)->vehicle_type); + return (ScriptVehicle::VehicleType)((::VehicleType)::Group::Get(group_id)->vehicle_type); } -/* static */ bool AIGroup::SetName(GroupID group_id, const char *name) +/* static */ bool ScriptGroup::SetName(GroupID group_id, const char *name) { EnforcePrecondition(false, IsValidGroup(group_id)); EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_GROUP_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return AIObject::DoCommand(0, group_id, 0, CMD_RENAME_GROUP, name); + return ScriptObject::DoCommand(0, group_id, 0, CMD_RENAME_GROUP, name); } -/* static */ char *AIGroup::GetName(GroupID group_id) +/* static */ char *ScriptGroup::GetName(GroupID group_id) { if (!IsValidGroup(group_id)) return NULL; @@ -70,65 +70,65 @@ return group_name; } -/* static */ bool AIGroup::EnableAutoReplaceProtection(GroupID group_id, bool enable) +/* static */ bool ScriptGroup::EnableAutoReplaceProtection(GroupID group_id, bool enable) { EnforcePrecondition(false, IsValidGroup(group_id)); - return AIObject::DoCommand(0, group_id, enable ? 1 : 0, CMD_SET_GROUP_REPLACE_PROTECTION); + return ScriptObject::DoCommand(0, group_id, enable ? 1 : 0, CMD_SET_GROUP_REPLACE_PROTECTION); } -/* static */ bool AIGroup::GetAutoReplaceProtection(GroupID group_id) +/* static */ bool ScriptGroup::GetAutoReplaceProtection(GroupID group_id) { if (!IsValidGroup(group_id)) return false; return ::Group::Get(group_id)->replace_protection; } -/* static */ int32 AIGroup::GetNumEngines(GroupID group_id, EngineID engine_id) +/* static */ int32 ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id) { if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return -1; return GetGroupNumEngines(_current_company, group_id, engine_id); } -/* static */ bool AIGroup::MoveVehicle(GroupID group_id, VehicleID vehicle_id) +/* static */ bool ScriptGroup::MoveVehicle(GroupID group_id, VehicleID vehicle_id) { EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT); - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); - return AIObject::DoCommand(0, group_id, vehicle_id, CMD_ADD_VEHICLE_GROUP); + return ScriptObject::DoCommand(0, group_id, vehicle_id, CMD_ADD_VEHICLE_GROUP); } -/* static */ bool AIGroup::EnableWagonRemoval(bool enable_removal) +/* static */ bool ScriptGroup::EnableWagonRemoval(bool enable_removal) { if (HasWagonRemoval() == enable_removal) return true; - return AIObject::DoCommand(0, ::GetCompanySettingIndex("company.renew_keep_length"), enable_removal ? 1 : 0, CMD_CHANGE_COMPANY_SETTING); + return ScriptObject::DoCommand(0, ::GetCompanySettingIndex("company.renew_keep_length"), enable_removal ? 1 : 0, CMD_CHANGE_COMPANY_SETTING); } -/* static */ bool AIGroup::HasWagonRemoval() +/* static */ bool ScriptGroup::HasWagonRemoval() { return ::Company::Get(_current_company)->settings.renew_keep_length; } -/* static */ bool AIGroup::SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new) +/* static */ bool ScriptGroup::SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new) { EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL); - EnforcePrecondition(false, AIEngine::IsBuildable(engine_id_new)); + EnforcePrecondition(false, ScriptEngine::IsBuildable(engine_id_new)); - return AIObject::DoCommand(0, group_id << 16, (engine_id_new << 16) | engine_id_old, CMD_SET_AUTOREPLACE); + return ScriptObject::DoCommand(0, group_id << 16, (engine_id_new << 16) | engine_id_old, CMD_SET_AUTOREPLACE); } -/* static */ EngineID AIGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id) +/* static */ EngineID ScriptGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id) { if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::INVALID_ENGINE; return ::EngineReplacementForCompany(Company::Get(_current_company), engine_id, group_id); } -/* static */ bool AIGroup::StopAutoReplace(GroupID group_id, EngineID engine_id) +/* static */ bool ScriptGroup::StopAutoReplace(GroupID group_id, EngineID engine_id) { EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL); - return AIObject::DoCommand(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, CMD_SET_AUTOREPLACE); + return ScriptObject::DoCommand(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, CMD_SET_AUTOREPLACE); } diff --git a/src/script/api/script_group.hpp b/src/script/api/script_group.hpp index 2c9368188..3eb3e06ca 100644 --- a/src/script/api/script_group.hpp +++ b/src/script/api/script_group.hpp @@ -17,7 +17,7 @@ /** * Class that handles all group related functions. */ -class AIGroup : public AIObject { +class ScriptGroup : public ScriptObject { public: /** * The group IDs of some special groups. @@ -44,7 +44,7 @@ public: * it failed. Check the return value using IsValidGroup(). In test-mode * 0 is returned if it was successful; any other value indicates failure. */ - static GroupID CreateGroup(AIVehicle::VehicleType vehicle_type); + static GroupID CreateGroup(ScriptVehicle::VehicleType vehicle_type); /** * Delete the given group. When the deletion succeeds all vehicles in the @@ -61,7 +61,7 @@ public: * @pre IsValidGroup(group_id). * @return The vehicletype of the given group. */ - static AIVehicle::VehicleType GetVehicleType(GroupID group_id); + static ScriptVehicle::VehicleType GetVehicleType(GroupID group_id); /** * Set the name of a group. @@ -70,7 +70,7 @@ public: * @pre IsValidGroup(group_id). * @pre 'name' must have at least one character. * @pre 'name' must have at most 30 characters. - * @exception AIError::ERR_NAME_IS_NOT_UNIQUE + * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ static bool SetName(GroupID group_id, const char *name); @@ -115,7 +115,7 @@ public: * @param group_id The group to move the vehicel to. * @param vehicle_id The vehicle to move to the group. * @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @return True if and only if the vehicle was successfully moved to the group. * @note A vehicle can be in only one group at the same time. To remove it from * a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the @@ -146,7 +146,7 @@ public: * @param engine_id_old The engine id to start replacing. * @param engine_id_new The engine id to replace with. * @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL. - * @pre AIEngine.IsBuildable(engine_id_new). + * @pre ScriptEngine.IsBuildable(engine_id_new). * @return True if and if the replacing was successfully started. * @note To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old). */ diff --git a/src/script/api/script_grouplist.cpp b/src/script/api/script_grouplist.cpp index 017af8b8a..cbaeea0ac 100644 --- a/src/script/api/script_grouplist.cpp +++ b/src/script/api/script_grouplist.cpp @@ -7,14 +7,14 @@ * 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 script_grouplist.cpp Implementation of AIGroupList and friends. */ +/** @file script_grouplist.cpp Implementation of ScriptGroupList and friends. */ #include "../../stdafx.h" #include "script_grouplist.hpp" #include "../../company_func.h" #include "../../group.h" -AIGroupList::AIGroupList() +ScriptGroupList::ScriptGroupList() { Group *g; FOR_ALL_GROUPS(g) { diff --git a/src/script/api/script_grouplist.hpp b/src/script/api/script_grouplist.hpp index 3e02d1ce3..6ce66c16c 100644 --- a/src/script/api/script_grouplist.hpp +++ b/src/script/api/script_grouplist.hpp @@ -16,12 +16,12 @@ /** * Creates a list of groups of which you are the owner. - * @note Neither AIGroup::GROUP_ALL nor AIGroup::GROUP_DEFAULT is in this list. - * @ingroup AIList + * @note Neither ScriptGroup::GROUP_ALL nor ScriptGroup::GROUP_DEFAULT is in this list. + * @ingroup ScriptList */ -class AIGroupList : public AIList { +class ScriptGroupList : public ScriptList { public: - AIGroupList(); + ScriptGroupList(); }; #endif /* SCRIPT_GROUPLIST_HPP */ diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index a3330fdeb..5d76bb005 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -7,7 +7,7 @@ * 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 script_industry.cpp Implementation of AIIndustry. */ +/** @file script_industry.cpp Implementation of ScriptIndustry. */ #include "../../stdafx.h" #include "script_industry.hpp" @@ -19,23 +19,23 @@ #include "../../newgrf_industries.h" #include "table/strings.h" -/* static */ int32 AIIndustry::GetIndustryCount() +/* static */ int32 ScriptIndustry::GetIndustryCount() { return (int32)::Industry::GetNumItems(); } -/* static */ bool AIIndustry::IsValidIndustry(IndustryID industry_id) +/* static */ bool ScriptIndustry::IsValidIndustry(IndustryID industry_id) { return ::Industry::IsValidID(industry_id); } -/* static */ IndustryID AIIndustry::GetIndustryID(TileIndex tile) +/* static */ IndustryID ScriptIndustry::GetIndustryID(TileIndex tile) { if (!::IsValidTile(tile) || !::IsTileType(tile, MP_INDUSTRY)) return INVALID_INDUSTRY; return ::GetIndustryIndex(tile); } -/* static */ char *AIIndustry::GetName(IndustryID industry_id) +/* static */ char *ScriptIndustry::GetName(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return NULL; static const int len = 64; @@ -47,10 +47,10 @@ return industry_name; } -/* static */ AIIndustry::CargoAcceptState AIIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id) +/* static */ ScriptIndustry::CargoAcceptState ScriptIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id) { if (!IsValidIndustry(industry_id)) return CAS_NOT_ACCEPTED; - if (!AICargo::IsValidCargo(cargo_id)) return CAS_NOT_ACCEPTED; + if (!ScriptCargo::IsValidCargo(cargo_id)) return CAS_NOT_ACCEPTED; Industry *i = ::Industry::Get(industry_id); @@ -64,10 +64,10 @@ return CAS_NOT_ACCEPTED; } -/* static */ int32 AIIndustry::GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id) +/* static */ int32 ScriptIndustry::GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id) { if (!IsValidIndustry(industry_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; Industry *ind = ::Industry::Get(industry_id); for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) { @@ -80,10 +80,10 @@ return -1; } -/* static */ int32 AIIndustry::GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id) +/* static */ int32 ScriptIndustry::GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id) { if (!IsValidIndustry(industry_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; const Industry *i = ::Industry::Get(industry_id); @@ -94,10 +94,10 @@ return -1; } -/* static */ int32 AIIndustry::GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id) +/* static */ int32 ScriptIndustry::GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id) { if (!IsValidIndustry(industry_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; const Industry *i = ::Industry::Get(industry_id); @@ -108,10 +108,10 @@ return -1; } -/* static */ int32 AIIndustry::GetLastMonthTransportedPercentage(IndustryID industry_id, CargoID cargo_id) +/* static */ int32 ScriptIndustry::GetLastMonthTransportedPercentage(IndustryID industry_id, CargoID cargo_id) { if (!IsValidIndustry(industry_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; const Industry *i = ::Industry::Get(industry_id); @@ -122,14 +122,14 @@ return -1; } -/* static */ TileIndex AIIndustry::GetLocation(IndustryID industry_id) +/* static */ TileIndex ScriptIndustry::GetLocation(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return INVALID_TILE; return ::Industry::Get(industry_id)->location.tile; } -/* static */ int32 AIIndustry::GetAmountOfStationsAround(IndustryID industry_id) +/* static */ int32 ScriptIndustry::GetAmountOfStationsAround(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return -1; @@ -139,35 +139,35 @@ return (int32)stations.Length(); } -/* static */ int32 AIIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile) +/* static */ int32 ScriptIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile) { if (!IsValidIndustry(industry_id)) return -1; - return AIMap::DistanceManhattan(tile, GetLocation(industry_id)); + return ScriptMap::DistanceManhattan(tile, GetLocation(industry_id)); } -/* static */ int32 AIIndustry::GetDistanceSquareToTile(IndustryID industry_id, TileIndex tile) +/* static */ int32 ScriptIndustry::GetDistanceSquareToTile(IndustryID industry_id, TileIndex tile) { if (!IsValidIndustry(industry_id)) return -1; - return AIMap::DistanceSquare(tile, GetLocation(industry_id)); + return ScriptMap::DistanceSquare(tile, GetLocation(industry_id)); } -/* static */ bool AIIndustry::IsBuiltOnWater(IndustryID industry_id) +/* static */ bool ScriptIndustry::IsBuiltOnWater(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return false; return (::GetIndustrySpec(::Industry::Get(industry_id)->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0; } -/* static */ bool AIIndustry::HasHeliport(IndustryID industry_id) +/* static */ bool ScriptIndustry::HasHeliport(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return false; return (::GetIndustrySpec(::Industry::Get(industry_id)->type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) != 0; } -/* static */ TileIndex AIIndustry::GetHeliportLocation(IndustryID industry_id) +/* static */ TileIndex ScriptIndustry::GetHeliportLocation(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return INVALID_TILE; if (!HasHeliport(industry_id)) return INVALID_TILE; @@ -182,14 +182,14 @@ return INVALID_TILE; } -/* static */ bool AIIndustry::HasDock(IndustryID industry_id) +/* static */ bool ScriptIndustry::HasDock(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return false; return (::GetIndustrySpec(::Industry::Get(industry_id)->type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) != 0; } -/* static */ TileIndex AIIndustry::GetDockLocation(IndustryID industry_id) +/* static */ TileIndex ScriptIndustry::GetDockLocation(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return INVALID_TILE; if (!HasDock(industry_id)) return INVALID_TILE; @@ -204,7 +204,7 @@ return INVALID_TILE; } -/* static */ IndustryType AIIndustry::GetIndustryType(IndustryID industry_id) +/* static */ IndustryType ScriptIndustry::GetIndustryType(IndustryID industry_id) { if (!IsValidIndustry(industry_id)) return INVALID_INDUSTRYTYPE; diff --git a/src/script/api/script_industry.hpp b/src/script/api/script_industry.hpp index 32c77ee25..747d29061 100644 --- a/src/script/api/script_industry.hpp +++ b/src/script/api/script_industry.hpp @@ -17,7 +17,7 @@ /** * Class that handles all industry related functions. */ -class AIIndustry : public AIObject { +class ScriptIndustry : public ScriptObject { public: /** Ways for an industry to accept a cargo. */ enum CargoAcceptState { @@ -63,7 +63,7 @@ public: * @param industry_id The index of the industry. * @param cargo_id The index of the cargo. * @pre IsValidIndustry(industry_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return Whether the industry accepts, temporarily refuses or never accepts this cargo. */ static CargoAcceptState IsCargoAccepted(IndustryID industry_id, CargoID cargo_id); @@ -73,7 +73,7 @@ public: * @param industry_id The index of the industry. * @param cargo_id The index of the cargo. * @pre IsValidIndustry(industry_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return The amount of cargo that is waiting for processing. */ static int32 GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id); @@ -83,7 +83,7 @@ public: * @param industry_id The index of the industry. * @param cargo_id The index of the cargo. * @pre IsValidIndustry(industry_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return The last month's production of the given cargo for this industry. */ static int32 GetLastMonthProduction(IndustryID industry_id, CargoID cargo_id); @@ -93,7 +93,7 @@ public: * @param industry_id The index of the industry. * @param cargo_id The index of the cargo. * @pre IsValidIndustry(industry_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return The amount of given cargo transported from this industry last month. */ static int32 GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id); @@ -103,7 +103,7 @@ public: * @param industry_id The index of the industry. * @param cargo_id The index of the cargo. * @pre IsValidIndustry(industry_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return The percentage of given cargo transported from this industry last month. */ static int32 GetLastMonthTransportedPercentage(IndustryID industry_id, CargoID cargo_id); @@ -127,23 +127,23 @@ public: static int32 GetAmountOfStationsAround(IndustryID industry_id); /** - * Get the manhattan distance from the tile to the AIIndustry::GetLocation() + * Get the manhattan distance from the tile to the ScriptIndustry::GetLocation() * of the industry. * @param industry_id The industry to get the distance to. * @param tile The tile to get the distance to. * @pre IsValidIndustry(industry_id). - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The distance between industry and tile. */ static int32 GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile); /** - * Get the square distance from the tile to the AIIndustry::GetLocation() + * Get the square distance from the tile to the ScriptIndustry::GetLocation() * of the industry. * @param industry_id The industry to get the distance to. * @param tile The tile to get the distance to. * @pre IsValidIndustry(industry_id). - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The distance between industry and tile. */ static int32 GetDistanceSquareToTile(IndustryID industry_id, TileIndex tile); diff --git a/src/script/api/script_industrylist.cpp b/src/script/api/script_industrylist.cpp index c3ec20fa3..b9824b9ac 100644 --- a/src/script/api/script_industrylist.cpp +++ b/src/script/api/script_industrylist.cpp @@ -7,13 +7,13 @@ * 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 script_industrylist.cpp Implementation of AIIndustryList and friends. */ +/** @file script_industrylist.cpp Implementation of ScriptIndustryList and friends. */ #include "../../stdafx.h" #include "script_industrylist.hpp" #include "../../industry.h" -AIIndustryList::AIIndustryList() +ScriptIndustryList::ScriptIndustryList() { Industry *i; FOR_ALL_INDUSTRIES(i) { @@ -21,7 +21,7 @@ AIIndustryList::AIIndustryList() } } -AIIndustryList_CargoAccepting::AIIndustryList_CargoAccepting(CargoID cargo_id) +ScriptIndustryList_CargoAccepting::ScriptIndustryList_CargoAccepting(CargoID cargo_id) { const Industry *i; @@ -32,7 +32,7 @@ AIIndustryList_CargoAccepting::AIIndustryList_CargoAccepting(CargoID cargo_id) } } -AIIndustryList_CargoProducing::AIIndustryList_CargoProducing(CargoID cargo_id) +ScriptIndustryList_CargoProducing::ScriptIndustryList_CargoProducing(CargoID cargo_id) { const Industry *i; diff --git a/src/script/api/script_industrylist.hpp b/src/script/api/script_industrylist.hpp index 41a2e6586..f36d72d06 100644 --- a/src/script/api/script_industrylist.hpp +++ b/src/script/api/script_industrylist.hpp @@ -16,36 +16,36 @@ /** * Creates a list of industries that are currently on the map. - * @ingroup AIList + * @ingroup ScriptList */ -class AIIndustryList : public AIList { +class ScriptIndustryList : public ScriptList { public: - AIIndustryList(); + ScriptIndustryList(); }; /** * Creates a list of industries that accepts a given cargo. - * @ingroup AIList + * @ingroup ScriptList */ -class AIIndustryList_CargoAccepting : public AIList { +class ScriptIndustryList_CargoAccepting : public ScriptList { public: /** * @param cargo_id The cargo this industry should accept. */ - AIIndustryList_CargoAccepting(CargoID cargo_id); + ScriptIndustryList_CargoAccepting(CargoID cargo_id); }; /** * Creates a list of industries that can produce a given cargo. * @note It also contains industries that currently produces 0 units of the cargo. - * @ingroup AIList + * @ingroup ScriptList */ -class AIIndustryList_CargoProducing : public AIList { +class ScriptIndustryList_CargoProducing : public ScriptList { public: /** * @param cargo_id The cargo this industry should produce. */ - AIIndustryList_CargoProducing(CargoID cargo_id); + ScriptIndustryList_CargoProducing(CargoID cargo_id); }; #endif /* SCRIPT_INDUSTRYLIST_HPP */ diff --git a/src/script/api/script_industrytype.cpp b/src/script/api/script_industrytype.cpp index 0a369b8f1..f61bedd3f 100644 --- a/src/script/api/script_industrytype.cpp +++ b/src/script/api/script_industrytype.cpp @@ -7,7 +7,7 @@ * 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 script_industrytype.cpp Implementation of AIIndustryType. */ +/** @file script_industrytype.cpp Implementation of ScriptIndustryType. */ #include "../../stdafx.h" #include "script_industrytype.hpp" @@ -18,21 +18,21 @@ #include "../../newgrf_industries.h" #include "../../core/random_func.hpp" -/* static */ bool AIIndustryType::IsValidIndustryType(IndustryType industry_type) +/* static */ bool ScriptIndustryType::IsValidIndustryType(IndustryType industry_type) { if (industry_type >= NUM_INDUSTRYTYPES) return false; return ::GetIndustrySpec(industry_type)->enabled; } -/* static */ bool AIIndustryType::IsRawIndustry(IndustryType industry_type) +/* static */ bool ScriptIndustryType::IsRawIndustry(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return false; return ::GetIndustrySpec(industry_type)->IsRawIndustry(); } -/* static */ bool AIIndustryType::ProductionCanIncrease(IndustryType industry_type) +/* static */ bool ScriptIndustryType::ProductionCanIncrease(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return false; @@ -40,7 +40,7 @@ return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_DONT_INCR_PROD) == 0; } -/* static */ Money AIIndustryType::GetConstructionCost(IndustryType industry_type) +/* static */ Money ScriptIndustryType::GetConstructionCost(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return -1; if (::GetIndustrySpec(industry_type)->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) return -1; @@ -48,7 +48,7 @@ return ::GetIndustrySpec(industry_type)->GetConstructionCost(); } -/* static */ char *AIIndustryType::GetName(IndustryType industry_type) +/* static */ char *ScriptIndustryType::GetName(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return NULL; static const int len = 64; @@ -59,13 +59,13 @@ return industrytype_name; } -/* static */ AIList *AIIndustryType::GetProducedCargo(IndustryType industry_type) +/* static */ ScriptList *ScriptIndustryType::GetProducedCargo(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return NULL; const IndustrySpec *ins = ::GetIndustrySpec(industry_type); - AIList *list = new AIList(); + ScriptList *list = new ScriptList(); for (size_t i = 0; i < lengthof(ins->produced_cargo); i++) { if (ins->produced_cargo[i] != CT_INVALID) list->AddItem(ins->produced_cargo[i]); } @@ -73,13 +73,13 @@ return list; } -/* static */ AIList *AIIndustryType::GetAcceptedCargo(IndustryType industry_type) +/* static */ ScriptList *ScriptIndustryType::GetAcceptedCargo(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return NULL; const IndustrySpec *ins = ::GetIndustrySpec(industry_type); - AIList *list = new AIList(); + ScriptList *list = new ScriptList(); for (size_t i = 0; i < lengthof(ins->accepts_cargo); i++) { if (ins->accepts_cargo[i] != CT_INVALID) list->AddItem(ins->accepts_cargo[i]); } @@ -87,7 +87,7 @@ return list; } -/* static */ bool AIIndustryType::CanBuildIndustry(IndustryType industry_type) +/* static */ bool ScriptIndustryType::CanBuildIndustry(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return false; @@ -98,7 +98,7 @@ return _settings_game.construction.raw_industry_construction == 1; } -/* static */ bool AIIndustryType::CanProspectIndustry(IndustryType industry_type) +/* static */ bool ScriptIndustryType::CanProspectIndustry(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return false; @@ -109,38 +109,38 @@ return _settings_game.construction.raw_industry_construction == 2; } -/* static */ bool AIIndustryType::BuildIndustry(IndustryType industry_type, TileIndex tile) +/* static */ bool ScriptIndustryType::BuildIndustry(IndustryType industry_type, TileIndex tile) { EnforcePrecondition(false, CanBuildIndustry(industry_type)); - EnforcePrecondition(false, AIMap::IsValidTile(tile)); + EnforcePrecondition(false, ScriptMap::IsValidTile(tile)); uint32 seed = ::InteractiveRandom(); - return AIObject::DoCommand(tile, (::InteractiveRandomRange(::GetIndustrySpec(industry_type)->num_table) << 8) | industry_type, seed, CMD_BUILD_INDUSTRY); + return ScriptObject::DoCommand(tile, (::InteractiveRandomRange(::GetIndustrySpec(industry_type)->num_table) << 8) | industry_type, seed, CMD_BUILD_INDUSTRY); } -/* static */ bool AIIndustryType::ProspectIndustry(IndustryType industry_type) +/* static */ bool ScriptIndustryType::ProspectIndustry(IndustryType industry_type) { EnforcePrecondition(false, CanProspectIndustry(industry_type)); uint32 seed = ::InteractiveRandom(); - return AIObject::DoCommand(0, industry_type, seed, CMD_BUILD_INDUSTRY); + return ScriptObject::DoCommand(0, industry_type, seed, CMD_BUILD_INDUSTRY); } -/* static */ bool AIIndustryType::IsBuiltOnWater(IndustryType industry_type) +/* static */ bool ScriptIndustryType::IsBuiltOnWater(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return false; return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0; } -/* static */ bool AIIndustryType::HasHeliport(IndustryType industry_type) +/* static */ bool ScriptIndustryType::HasHeliport(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return false; return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) != 0; } -/* static */ bool AIIndustryType::HasDock(IndustryType industry_type) +/* static */ bool ScriptIndustryType::HasDock(IndustryType industry_type) { if (!IsValidIndustryType(industry_type)) return false; diff --git a/src/script/api/script_industrytype.hpp b/src/script/api/script_industrytype.hpp index ad37aceda..a8ee5aef3 100644 --- a/src/script/api/script_industrytype.hpp +++ b/src/script/api/script_industrytype.hpp @@ -17,14 +17,14 @@ /** * Class that handles all industry-type related functions. */ -class AIIndustryType : public AIObject { +class ScriptIndustryType : public ScriptObject { public: /** * Special IndustryTypes. */ enum SpecialIndustryType { - INDUSTRYTYPE_UNKNOWN = 0xFE, ///< Unknown/unspecific industrytype. (Usable for AIRail::BuildNewGRFRailStation()) - INDUSTRYTYPE_TOWN = 0xFF, ///< No industry, but town. (Usable for AIRail::BuildNewGRFRailStation()) + INDUSTRYTYPE_UNKNOWN = 0xFE, ///< Unknown/unspecific industrytype. (Usable for ScriptRail::BuildNewGRFRailStation()) + INDUSTRYTYPE_TOWN = 0xFF, ///< No industry, but town. (Usable for ScriptRail::BuildNewGRFRailStation()) }; /** @@ -50,7 +50,7 @@ public: * @pre IsValidIndustryType(industry_type). * @return The CargoIDs of all cargotypes this industry could produce. */ - static AIList *GetProducedCargo(IndustryType industry_type); + static ScriptList *GetProducedCargo(IndustryType industry_type); /** * Get a list of CargoID accepted by this industry-type. @@ -60,7 +60,7 @@ public: * @pre IsValidIndustryType(industry_type). * @return The CargoIDs of all cargotypes this industry accepts. */ - static AIList *GetAcceptedCargo(IndustryType industry_type); + static ScriptList *GetAcceptedCargo(IndustryType industry_type); /** * Is this industry type a raw industry? diff --git a/src/script/api/script_industrytypelist.cpp b/src/script/api/script_industrytypelist.cpp index fbbe6bcf2..c72fabcaa 100644 --- a/src/script/api/script_industrytypelist.cpp +++ b/src/script/api/script_industrytypelist.cpp @@ -7,15 +7,15 @@ * 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 script_industrytypelist.cpp Implementation of AIIndustryTypeList. */ +/** @file script_industrytypelist.cpp Implementation of ScriptIndustryTypeList. */ #include "../../stdafx.h" #include "script_industrytypelist.hpp" #include "../../industry.h" -AIIndustryTypeList::AIIndustryTypeList() +ScriptIndustryTypeList::ScriptIndustryTypeList() { for (int i = 0; i < NUM_INDUSTRYTYPES; i++) { - if (AIIndustryType::IsValidIndustryType(i)) this->AddItem(i); + if (ScriptIndustryType::IsValidIndustryType(i)) this->AddItem(i); } } diff --git a/src/script/api/script_industrytypelist.hpp b/src/script/api/script_industrytypelist.hpp index b0f25715d..bc3676da1 100644 --- a/src/script/api/script_industrytypelist.hpp +++ b/src/script/api/script_industrytypelist.hpp @@ -16,11 +16,11 @@ /** * Creates a list of valid industry types. - * @ingroup AIList + * @ingroup ScriptList */ -class AIIndustryTypeList : public AIList { +class ScriptIndustryTypeList : public ScriptList { public: - AIIndustryTypeList(); + ScriptIndustryTypeList(); }; diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index 331b852d8..37321fdcf 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -7,7 +7,7 @@ * 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 script_list.cpp Implementation of AIList. */ +/** @file script_list.cpp Implementation of ScriptList. */ #include "../../stdafx.h" #include "script_list.hpp" @@ -15,11 +15,11 @@ #include "../../script/squirrel.hpp" /** - * Base class for any AIList sorter. + * Base class for any ScriptList sorter. */ -class AIListSorter { +class ScriptListSorter { protected: - AIList *list; ///< The list that's being sorted. + ScriptList *list; ///< The list that's being sorted. bool has_no_more_items; ///< Whether we have more items to iterate over. int32 item_next; ///< The next item we will show. @@ -27,7 +27,7 @@ public: /** * Virtual dtor, needed to mute warnings. */ - virtual ~AIListSorter() { } + virtual ~ScriptListSorter() { } /** * Get the first item of the sorter. @@ -61,18 +61,18 @@ public: /** * Sort by value, ascending. */ -class AIListSorterValueAscending : public AIListSorter { +class ScriptListSorterValueAscending : public ScriptListSorter { private: - AIList::AIListBucket::iterator bucket_iter; ///< The iterator over the list to find the buckets. - AIList::AIItemList *bucket_list; ///< The current bucket list we're iterator over. - AIList::AIItemList::iterator bucket_list_iter; ///< The iterator over the bucket list. + ScriptList::ScriptListBucket::iterator bucket_iter; ///< The iterator over the list to find the buckets. + ScriptList::AIItemList *bucket_list; ///< The current bucket list we're iterator over. + ScriptList::AIItemList::iterator bucket_list_iter; ///< The iterator over the bucket list. public: /** * Create a new sorter. * @param list The list to sort. */ - AIListSorterValueAscending(AIList *list) + ScriptListSorterValueAscending(ScriptList *list) { this->list = list; this->End(); @@ -147,18 +147,18 @@ public: /** * Sort by value, descending. */ -class AIListSorterValueDescending : public AIListSorter { +class ScriptListSorterValueDescending : public ScriptListSorter { private: - AIList::AIListBucket::iterator bucket_iter; ///< The iterator over the list to find the buckets. - AIList::AIItemList *bucket_list; ///< The current bucket list we're iterator over. - AIList::AIItemList::iterator bucket_list_iter; ///< The iterator over the bucket list. + ScriptList::ScriptListBucket::iterator bucket_iter; ///< The iterator over the list to find the buckets. + ScriptList::AIItemList *bucket_list; ///< The current bucket list we're iterator over. + ScriptList::AIItemList::iterator bucket_list_iter; ///< The iterator over the bucket list. public: /** * Create a new sorter. * @param list The list to sort. */ - AIListSorterValueDescending(AIList *list) + ScriptListSorterValueDescending(ScriptList *list) { this->list = list; this->End(); @@ -241,16 +241,16 @@ public: /** * Sort by item, ascending. */ -class AIListSorterItemAscending : public AIListSorter { +class ScriptListSorterItemAscending : public ScriptListSorter { private: - AIList::AIListMap::iterator item_iter; ///< The iterator over the items in the map. + ScriptList::ScriptListMap::iterator item_iter; ///< The iterator over the items in the map. public: /** * Create a new sorter. * @param list The list to sort. */ - AIListSorterItemAscending(AIList *list) + ScriptListSorterItemAscending(ScriptList *list) { this->list = list; this->End(); @@ -311,16 +311,16 @@ public: /** * Sort by item, descending. */ -class AIListSorterItemDescending : public AIListSorter { +class ScriptListSorterItemDescending : public ScriptListSorter { private: - AIList::AIListMap::iterator item_iter; ///< The iterator over the items in the map. + ScriptList::ScriptListMap::iterator item_iter; ///< The iterator over the items in the map. public: /** * Create a new sorter. * @param list The list to sort. */ - AIListSorterItemDescending(AIList *list) + ScriptListSorterItemDescending(ScriptList *list) { this->list = list; this->End(); @@ -381,27 +381,27 @@ public: -AIList::AIList() +ScriptList::ScriptList() { /* Default sorter */ - this->sorter = new AIListSorterValueDescending(this); + this->sorter = new ScriptListSorterValueDescending(this); this->sorter_type = SORT_BY_VALUE; this->sort_ascending = false; this->initialized = false; this->modifications = 0; } -AIList::~AIList() +ScriptList::~ScriptList() { delete this->sorter; } -bool AIList::HasItem(int32 item) +bool ScriptList::HasItem(int32 item) { return this->items.count(item) == 1; } -void AIList::Clear() +void ScriptList::Clear() { this->modifications++; @@ -410,7 +410,7 @@ void AIList::Clear() this->sorter->End(); } -void AIList::AddItem(int32 item, int32 value) +void ScriptList::AddItem(int32 item, int32 value) { this->modifications++; @@ -422,7 +422,7 @@ void AIList::AddItem(int32 item, int32 value) this->SetValue(item, value); } -void AIList::RemoveItem(int32 item) +void ScriptList::RemoveItem(int32 item) { this->modifications++; @@ -436,13 +436,13 @@ void AIList::RemoveItem(int32 item) this->items.erase(item); } -int32 AIList::Begin() +int32 ScriptList::Begin() { this->initialized = true; return this->sorter->Begin(); } -int32 AIList::Next() +int32 ScriptList::Next() { if (this->initialized == false) { DEBUG(ai, 0, "Next() is invalid as Begin() is never called"); @@ -451,12 +451,12 @@ int32 AIList::Next() return this->sorter->Next(); } -bool AIList::IsEmpty() +bool ScriptList::IsEmpty() { return this->items.empty(); } -bool AIList::IsEnd() +bool ScriptList::IsEnd() { if (this->initialized == false) { DEBUG(ai, 0, "IsEnd() is invalid as Begin() is never called"); @@ -465,19 +465,19 @@ bool AIList::IsEnd() return this->sorter->IsEnd(); } -int32 AIList::Count() +int32 ScriptList::Count() { return (int32)this->items.size(); } -int32 AIList::GetValue(int32 item) +int32 ScriptList::GetValue(int32 item) { if (!this->HasItem(item)) return 0; return this->items[item]; } -bool AIList::SetValue(int32 item, int32 value) +bool ScriptList::SetValue(int32 item, int32 value) { this->modifications++; @@ -495,7 +495,7 @@ bool AIList::SetValue(int32 item, int32 value) return true; } -void AIList::Sort(SorterType sorter, bool ascending) +void ScriptList::Sort(SorterType sorter, bool ascending) { this->modifications++; @@ -506,17 +506,17 @@ void AIList::Sort(SorterType sorter, bool ascending) switch (sorter) { case SORT_BY_ITEM: if (ascending) { - this->sorter = new AIListSorterItemAscending(this); + this->sorter = new ScriptListSorterItemAscending(this); } else { - this->sorter = new AIListSorterItemDescending(this); + this->sorter = new ScriptListSorterItemDescending(this); } break; case SORT_BY_VALUE: if (ascending) { - this->sorter = new AIListSorterValueAscending(this); + this->sorter = new ScriptListSorterValueAscending(this); } else { - this->sorter = new AIListSorterValueDescending(this); + this->sorter = new ScriptListSorterValueDescending(this); } break; @@ -529,56 +529,56 @@ void AIList::Sort(SorterType sorter, bool ascending) this->initialized = false; } -void AIList::AddList(AIList *list) +void ScriptList::AddList(ScriptList *list) { - AIListMap *list_items = &list->items; - for (AIListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { + ScriptListMap *list_items = &list->items; + for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { this->AddItem((*iter).first); this->SetValue((*iter).first, (*iter).second); } } -void AIList::RemoveAboveValue(int32 value) +void ScriptList::RemoveAboveValue(int32 value) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second > value) this->RemoveItem((*iter).first); } } -void AIList::RemoveBelowValue(int32 value) +void ScriptList::RemoveBelowValue(int32 value) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second < value) this->RemoveItem((*iter).first); } } -void AIList::RemoveBetweenValue(int32 start, int32 end) +void ScriptList::RemoveBetweenValue(int32 start, int32 end) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second > start && (*iter).second < end) this->RemoveItem((*iter).first); } } -void AIList::RemoveValue(int32 value) +void ScriptList::RemoveValue(int32 value) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second == value) this->RemoveItem((*iter).first); } } -void AIList::RemoveTop(int32 count) +void ScriptList::RemoveTop(int32 count) { this->modifications++; @@ -592,7 +592,7 @@ void AIList::RemoveTop(int32 count) switch (this->sorter_type) { default: NOT_REACHED(); case SORT_BY_VALUE: - for (AIListBucket::iterator iter = this->buckets.begin(); iter != this->buckets.end(); iter = this->buckets.begin()) { + for (ScriptListBucket::iterator iter = this->buckets.begin(); iter != this->buckets.end(); iter = this->buckets.begin()) { AIItemList *items = &(*iter).second; size_t size = items->size(); for (AIItemList::iterator iter = items->begin(); iter != items->end(); iter = items->begin()) { @@ -607,7 +607,7 @@ void AIList::RemoveTop(int32 count) break; case SORT_BY_ITEM: - for (AIListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter = this->items.begin()) { + for (ScriptListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter = this->items.begin()) { if (--count < 0) return; this->RemoveItem((*iter).first); } @@ -615,7 +615,7 @@ void AIList::RemoveTop(int32 count) } } -void AIList::RemoveBottom(int32 count) +void ScriptList::RemoveBottom(int32 count) { this->modifications++; @@ -629,7 +629,7 @@ void AIList::RemoveBottom(int32 count) switch (this->sorter_type) { default: NOT_REACHED(); case SORT_BY_VALUE: - for (AIListBucket::reverse_iterator iter = this->buckets.rbegin(); iter != this->buckets.rend(); iter = this->buckets.rbegin()) { + for (ScriptListBucket::reverse_iterator iter = this->buckets.rbegin(); iter != this->buckets.rend(); iter = this->buckets.rbegin()) { AIItemList *items = &(*iter).second; size_t size = items->size(); for (AIItemList::reverse_iterator iter = items->rbegin(); iter != items->rend(); iter = items->rbegin()) { @@ -643,7 +643,7 @@ void AIList::RemoveBottom(int32 count) } case SORT_BY_ITEM: - for (AIListMap::reverse_iterator iter = this->items.rbegin(); iter != this->items.rend(); iter = this->items.rbegin()) { + for (ScriptListMap::reverse_iterator iter = this->items.rbegin(); iter != this->items.rend(); iter = this->items.rbegin()) { if (--count < 0) return; this->RemoveItem((*iter).first); } @@ -651,76 +651,76 @@ void AIList::RemoveBottom(int32 count) } } -void AIList::RemoveList(AIList *list) +void ScriptList::RemoveList(ScriptList *list) { this->modifications++; - AIListMap *list_items = &list->items; - for (AIListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { + ScriptListMap *list_items = &list->items; + for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { this->RemoveItem((*iter).first); } } -void AIList::KeepAboveValue(int32 value) +void ScriptList::KeepAboveValue(int32 value) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second <= value) this->RemoveItem((*iter).first); } } -void AIList::KeepBelowValue(int32 value) +void ScriptList::KeepBelowValue(int32 value) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second >= value) this->RemoveItem((*iter).first); } } -void AIList::KeepBetweenValue(int32 start, int32 end) +void ScriptList::KeepBetweenValue(int32 start, int32 end) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second <= start || (*iter).second >= end) this->RemoveItem((*iter).first); } } -void AIList::KeepValue(int32 value) +void ScriptList::KeepValue(int32 value) { this->modifications++; - for (AIListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { + for (ScriptListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { next_iter = iter; next_iter++; if ((*iter).second != value) this->RemoveItem((*iter).first); } } -void AIList::KeepTop(int32 count) +void ScriptList::KeepTop(int32 count) { this->modifications++; this->RemoveBottom(this->Count() - count); } -void AIList::KeepBottom(int32 count) +void ScriptList::KeepBottom(int32 count) { this->modifications++; this->RemoveTop(this->Count() - count); } -void AIList::KeepList(AIList *list) +void ScriptList::KeepList(ScriptList *list) { this->modifications++; - AIList tmp; - for (AIListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { + ScriptList tmp; + for (ScriptListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { tmp.AddItem((*iter).first); tmp.SetValue((*iter).first, (*iter).second); } @@ -729,7 +729,7 @@ void AIList::KeepList(AIList *list) this->RemoveList(&tmp); } -SQInteger AIList::_get(HSQUIRRELVM vm) +SQInteger ScriptList::_get(HSQUIRRELVM vm) { if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR; @@ -742,7 +742,7 @@ SQInteger AIList::_get(HSQUIRRELVM vm) return 1; } -SQInteger AIList::_set(HSQUIRRELVM vm) +SQInteger ScriptList::_set(HSQUIRRELVM vm) { if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR; if (sq_gettype(vm, 3) != OT_INTEGER || sq_gettype(vm, 3) == OT_NULL) { @@ -766,7 +766,7 @@ SQInteger AIList::_set(HSQUIRRELVM vm) return 0; } -SQInteger AIList::_nexti(HSQUIRRELVM vm) +SQInteger ScriptList::_nexti(HSQUIRRELVM vm) { if (sq_gettype(vm, 2) == OT_NULL) { if (this->IsEmpty()) { @@ -790,15 +790,15 @@ SQInteger AIList::_nexti(HSQUIRRELVM vm) return 1; } -SQInteger AIList::Valuate(HSQUIRRELVM vm) +SQInteger ScriptList::Valuate(HSQUIRRELVM vm) { this->modifications++; - /* The first parameter is the instance of AIList. */ + /* The first parameter is the instance of ScriptList. */ int nparam = sq_gettop(vm) - 1; if (nparam < 1) { - return sq_throwerror(vm, _SC("You need to give a least a Valuator as parameter to AIList::Valuate")); + return sq_throwerror(vm, _SC("You need to give a least a Valuator as parameter to ScriptList::Valuate")); } /* Make sure the valuator function is really a function, and not any @@ -811,13 +811,13 @@ SQInteger AIList::Valuate(HSQUIRRELVM vm) /* Don't allow docommand from a Valuator, as we can't resume in * mid C++-code. */ - bool backup_allow = AIObject::GetAllowDoCommand(); - AIObject::SetAllowDoCommand(false); + bool backup_allow = ScriptObject::GetAllowDoCommand(); + ScriptObject::SetAllowDoCommand(false); /* Push the function to call */ sq_push(vm, 2); - for (AIListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { + for (ScriptListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { /* Check for changing of items. */ int previous_modification_count = this->modifications; @@ -831,7 +831,7 @@ SQInteger AIList::Valuate(HSQUIRRELVM vm) /* Call the function. Squirrel pops all parameters and pushes the return value. */ if (SQ_FAILED(sq_call(vm, nparam + 1, SQTrue, SQTrue))) { - AIObject::SetAllowDoCommand(backup_allow); + ScriptObject::SetAllowDoCommand(backup_allow); return SQ_ERROR; } @@ -854,7 +854,7 @@ SQInteger AIList::Valuate(HSQUIRRELVM vm) /* See below for explanation. The extra pop is the return value. */ sq_pop(vm, nparam + 4); - AIObject::SetAllowDoCommand(backup_allow); + ScriptObject::SetAllowDoCommand(backup_allow); return sq_throwerror(vm, _SC("return value of valuator is not valid (not integer/bool)")); } } @@ -864,7 +864,7 @@ SQInteger AIList::Valuate(HSQUIRRELVM vm) /* See below for explanation. The extra pop is the return value. */ sq_pop(vm, nparam + 4); - AIObject::SetAllowDoCommand(backup_allow); + ScriptObject::SetAllowDoCommand(backup_allow); return sq_throwerror(vm, _SC("modifying valuated list outside of valuator function")); } @@ -879,9 +879,9 @@ SQInteger AIList::Valuate(HSQUIRRELVM vm) * 1. The root stable (as instance object). * 2. The valuator function. * 3. The parameters given to this function. - * 4. The AIList instance object. */ + * 4. The ScriptList instance object. */ sq_pop(vm, nparam + 3); - AIObject::SetAllowDoCommand(backup_allow); + ScriptObject::SetAllowDoCommand(backup_allow); return 0; } diff --git a/src/script/api/script_list.hpp b/src/script/api/script_list.hpp index 9c5765b21..75dc7ac69 100644 --- a/src/script/api/script_list.hpp +++ b/src/script/api/script_list.hpp @@ -8,7 +8,7 @@ */ /** @file script_list.hpp A list which can keep item/value pairs, which you can walk. */ -/** @defgroup AIList Classes that create a list of items. */ +/** @defgroup ScriptList Classes that create a list of items. */ #ifndef SCRIPT_LIST_HPP #define SCRIPT_LIST_HPP @@ -17,12 +17,12 @@ #include <map> #include <set> -class AIListSorter; +class ScriptListSorter; /** * Class that creates a list which can keep item/value pairs, which you can walk. */ -class AIList : public AIObject { +class ScriptList : public ScriptObject { public: /** Type of sorter */ enum SorterType { @@ -36,7 +36,7 @@ public: static const bool SORT_DESCENDING = false; private: - AIListSorter *sorter; ///< Sorting algorithm + ScriptListSorter *sorter; ///< Sorting algorithm SorterType sorter_type; ///< Sorting type bool sort_ascending; ///< Whether to sort ascending or descending bool initialized; ///< Whether an iteration has been started @@ -44,14 +44,14 @@ private: public: typedef std::set<int32> AIItemList; ///< The list of items inside the bucket - typedef std::map<int32, AIItemList> AIListBucket; ///< The bucket list per value - typedef std::map<int32, int32> AIListMap; ///< List per item + typedef std::map<int32, AIItemList> ScriptListBucket; ///< The bucket list per value + typedef std::map<int32, int32> ScriptListMap; ///< List per item - AIListMap items; ///< The items in the list - AIListBucket buckets; ///< The items in the list, sorted by value + ScriptListMap items; ///< The items in the list + ScriptListBucket buckets; ///< The items in the list, sorted by value - AIList(); - ~AIList(); + ScriptList(); + ~ScriptList(); /** * Add a single item to the list. @@ -146,7 +146,7 @@ public: * @note If the item already exists inside the caller, the value of the * list that is added is set on the item. */ - void AddList(AIList *list); + void AddList(ScriptList *list); /** * Removes all items with a higher value than 'value'. @@ -190,7 +190,7 @@ public: * @param list the list of items to remove. * @pre list != NULL */ - void RemoveList(AIList *list); + void RemoveList(ScriptList *list); /** * Keep all items with a higher value than 'value'. @@ -234,7 +234,7 @@ public: * @param list the list of items to keep. * @pre list != NULL */ - void KeepList(AIList *list); + void KeepList(ScriptList *list); #ifndef DOXYGEN_AI_DOCS /** @@ -268,8 +268,8 @@ public: * the first parameter should be the index-value, and it should return * an integer. * @note Example: - * list.Valuate(AIBridge.GetPrice, 5); - * list.Valuate(AIBridge.GetMaxLength); + * list.Valuate(ScriptBridge.GetPrice, 5); + * list.Valuate(ScriptBridge.GetMaxLength); * function MyVal(bridge_id, myparam) * { * return myparam * bridge_id; // This is silly diff --git a/src/script/api/script_log.cpp b/src/script/api/script_log.cpp index 10eff9088..26eca7475 100644 --- a/src/script/api/script_log.cpp +++ b/src/script/api/script_log.cpp @@ -7,7 +7,7 @@ * 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 script_log.cpp Implementation of AILog. */ +/** @file script_log.cpp Implementation of ScriptLog. */ #include "../../stdafx.h" #include "script_log.hpp" @@ -16,34 +16,34 @@ #include "../../debug.h" #include "../../window_func.h" -/* static */ void AILog::Info(const char *message) +/* static */ void ScriptLog::Info(const char *message) { - AILog::Log(LOG_INFO, message); + ScriptLog::Log(LOG_INFO, message); } -/* static */ void AILog::Warning(const char *message) +/* static */ void ScriptLog::Warning(const char *message) { - AILog::Log(LOG_WARNING, message); + ScriptLog::Log(LOG_WARNING, message); } -/* static */ void AILog::Error(const char *message) +/* static */ void ScriptLog::Error(const char *message) { - AILog::Log(LOG_ERROR, message); + ScriptLog::Log(LOG_ERROR, message); } -/* static */ void AILog::Log(AILog::AILogType level, const char *message) +/* static */ void ScriptLog::Log(ScriptLog::ScriptLogType level, const char *message) { - if (AIObject::GetLogPointer() == NULL) { - AIObject::GetLogPointer() = new LogData(); - LogData *log = (LogData *)AIObject::GetLogPointer(); + if (ScriptObject::GetLogPointer() == NULL) { + ScriptObject::GetLogPointer() = new LogData(); + LogData *log = (LogData *)ScriptObject::GetLogPointer(); log->lines = CallocT<char *>(400); - log->type = CallocT<AILog::AILogType>(400); + log->type = CallocT<ScriptLog::ScriptLogType>(400); log->count = 400; log->pos = log->count - 1; log->used = 0; } - LogData *log = (LogData *)AIObject::GetLogPointer(); + LogData *log = (LogData *)ScriptObject::GetLogPointer(); /* Go to the next log-line */ log->pos = (log->pos + 1) % log->count; @@ -78,9 +78,9 @@ InvalidateWindowData(WC_AI_DEBUG, 0, _current_company); } -/* static */ void AILog::FreeLogPointer() +/* static */ void ScriptLog::FreeLogPointer() { - LogData *log = (LogData *)AIObject::GetLogPointer(); + LogData *log = (LogData *)ScriptObject::GetLogPointer(); for (int i = 0; i < log->count; i++) { free(log->lines[i]); diff --git a/src/script/api/script_log.hpp b/src/script/api/script_log.hpp index e352e232c..ba5a5f025 100644 --- a/src/script/api/script_log.hpp +++ b/src/script/api/script_log.hpp @@ -17,10 +17,10 @@ /** * Class that handles all log related functions. */ -class AILog : public AIObject { - /* AIController needs access to Enum and Log, in order to keep the flow from +class ScriptLog : public ScriptObject { + /* ScriptController needs access to Enum and Log, in order to keep the flow from * OpenTTD core to NoAI API clear and simple. */ - friend class AIController; + friend class ScriptController; public: #ifndef EXPORT_SKIP @@ -28,7 +28,7 @@ public: * Log levels; The value is also feed to DEBUG() lvl. * This has no use for you, as AI writer. */ - enum AILogType { + enum ScriptLogType { LOG_SQ_ERROR = 0, ///< Squirrel printed an error. LOG_ERROR = 1, ///< User printed an error. LOG_SQ_INFO = 2, ///< Squirrel printed some info. @@ -42,7 +42,7 @@ public: */ struct LogData { char **lines; ///< The log-lines. - AILog::AILogType *type; ///< Per line, which type of log it was. + ScriptLog::ScriptLogType *type; ///< Per line, which type of log it was. int count; ///< Total amount of log-lines possible. int pos; ///< Current position in lines. int used; ///< Total amount of used log-lines. @@ -79,7 +79,7 @@ private: /** * Internal command to log the message in a common way. */ - static void Log(AILog::AILogType level, const char *message); + static void Log(ScriptLog::ScriptLogType level, const char *message); }; #endif /* SCRIPT_LOG_HPP */ diff --git a/src/script/api/script_map.cpp b/src/script/api/script_map.cpp index b347f4572..3f224b3d1 100644 --- a/src/script/api/script_map.cpp +++ b/src/script/api/script_map.cpp @@ -7,68 +7,68 @@ * 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 script_map.cpp Implementation of AIMap. */ +/** @file script_map.cpp Implementation of ScriptMap. */ #include "../../stdafx.h" #include "script_map.hpp" #include "../../tile_map.h" -/* static */ bool AIMap::IsValidTile(TileIndex t) +/* static */ bool ScriptMap::IsValidTile(TileIndex t) { return ::IsValidTile(t); } -/* static */ TileIndex AIMap::GetMapSize() +/* static */ TileIndex ScriptMap::GetMapSize() { return ::MapSize(); } -/* static */ uint32 AIMap::GetMapSizeX() +/* static */ uint32 ScriptMap::GetMapSizeX() { return ::MapSizeX(); } -/* static */ uint32 AIMap::GetMapSizeY() +/* static */ uint32 ScriptMap::GetMapSizeY() { return ::MapSizeY(); } -/* static */ int32 AIMap::GetTileX(TileIndex t) +/* static */ int32 ScriptMap::GetTileX(TileIndex t) { if (!::IsValidTile(t)) return -1; return ::TileX(t); } -/* static */ int32 AIMap::GetTileY(TileIndex t) +/* static */ int32 ScriptMap::GetTileY(TileIndex t) { if (!::IsValidTile(t)) return -1; return ::TileY(t); } -/* static */ TileIndex AIMap::GetTileIndex(uint32 x, uint32 y) +/* static */ TileIndex ScriptMap::GetTileIndex(uint32 x, uint32 y) { return ::TileXY(x, y); } -/* static */ int32 AIMap::DistanceManhattan(TileIndex t1, TileIndex t2) +/* static */ int32 ScriptMap::DistanceManhattan(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1; return ::DistanceManhattan(t1, t2); } -/* static */ int32 AIMap::DistanceMax(TileIndex t1, TileIndex t2) +/* static */ int32 ScriptMap::DistanceMax(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1; return ::DistanceMax(t1, t2); } -/* static */ int32 AIMap::DistanceSquare(TileIndex t1, TileIndex t2) +/* static */ int32 ScriptMap::DistanceSquare(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1) || !::IsValidTile(t2)) return -1; return ::DistanceSquare(t1, t2); } -/* static */ int32 AIMap::DistanceFromEdge(TileIndex t) +/* static */ int32 ScriptMap::DistanceFromEdge(TileIndex t) { if (!::IsValidTile(t)) return -1; return ::DistanceFromEdge(t); diff --git a/src/script/api/script_map.hpp b/src/script/api/script_map.hpp index 3567a5890..bb944952c 100644 --- a/src/script/api/script_map.hpp +++ b/src/script/api/script_map.hpp @@ -18,7 +18,7 @@ /** * Class that handles all map related functions. */ -class AIMap : public AIObject { +class ScriptMap : public ScriptObject { public: static const int TILE_INVALID = (int)INVALID_TILE; ///< Invalid TileIndex. diff --git a/src/script/api/script_marine.cpp b/src/script/api/script_marine.cpp index 1bfd7ddb3..f67b8d24c 100644 --- a/src/script/api/script_marine.cpp +++ b/src/script/api/script_marine.cpp @@ -7,7 +7,7 @@ * 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 script_marine.cpp Implementation of AIMarine. */ +/** @file script_marine.cpp Implementation of ScriptMarine. */ #include "../../stdafx.h" #include "script_marine.hpp" @@ -16,42 +16,42 @@ #include "../../tile_cmd.h" -/* static */ bool AIMarine::IsWaterDepotTile(TileIndex tile) +/* static */ bool ScriptMarine::IsWaterDepotTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_WATER) && ::GetWaterTileType(tile) == WATER_TILE_DEPOT; } -/* static */ bool AIMarine::IsDockTile(TileIndex tile) +/* static */ bool ScriptMarine::IsDockTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_STATION) && ::IsDock(tile); } -/* static */ bool AIMarine::IsBuoyTile(TileIndex tile) +/* static */ bool ScriptMarine::IsBuoyTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_STATION) && ::IsBuoy(tile); } -/* static */ bool AIMarine::IsLockTile(TileIndex tile) +/* static */ bool ScriptMarine::IsLockTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_WATER) && ::GetWaterTileType(tile) == WATER_TILE_LOCK; } -/* static */ bool AIMarine::IsCanalTile(TileIndex tile) +/* static */ bool ScriptMarine::IsCanalTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_WATER) && ::IsCanal(tile); } -/* static */ bool AIMarine::AreWaterTilesConnected(TileIndex t1, TileIndex t2) +/* static */ bool ScriptMarine::AreWaterTilesConnected(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1)) return false; if (!::IsValidTile(t2)) return false; @@ -71,87 +71,87 @@ return gtts2 != TRACK_BIT_NONE; } -/* static */ bool AIMarine::BuildWaterDepot(TileIndex tile, TileIndex front) +/* static */ bool ScriptMarine::BuildWaterDepot(TileIndex tile, TileIndex front) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsValidTile(front)); EnforcePrecondition(false, (::TileX(front) == ::TileX(tile)) != (::TileY(front) == ::TileY(tile))); - return AIObject::DoCommand(tile, ::TileX(front) == ::TileX(tile), 0, CMD_BUILD_SHIP_DEPOT); + return ScriptObject::DoCommand(tile, ::TileX(front) == ::TileX(tile), 0, CMD_BUILD_SHIP_DEPOT); } -/* static */ bool AIMarine::BuildDock(TileIndex tile, StationID station_id) +/* static */ bool ScriptMarine::BuildDock(TileIndex tile, StationID station_id) { EnforcePrecondition(false, ::IsValidTile(tile)); - EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); + EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); - uint p1 = station_id == AIStation::STATION_JOIN_ADJACENT ? 0 : 1; - uint p2 = (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; - return AIObject::DoCommand(tile, p1, p2, CMD_BUILD_DOCK); + uint p1 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1; + uint p2 = (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; + return ScriptObject::DoCommand(tile, p1, p2, CMD_BUILD_DOCK); } -/* static */ bool AIMarine::BuildBuoy(TileIndex tile) +/* static */ bool ScriptMarine::BuildBuoy(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_BUILD_BUOY); + return ScriptObject::DoCommand(tile, 0, 0, CMD_BUILD_BUOY); } -/* static */ bool AIMarine::BuildLock(TileIndex tile) +/* static */ bool ScriptMarine::BuildLock(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_BUILD_LOCK); + return ScriptObject::DoCommand(tile, 0, 0, CMD_BUILD_LOCK); } -/* static */ bool AIMarine::BuildCanal(TileIndex tile) +/* static */ bool ScriptMarine::BuildCanal(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, tile, WATER_CLASS_CANAL, CMD_BUILD_CANAL); + return ScriptObject::DoCommand(tile, tile, WATER_CLASS_CANAL, CMD_BUILD_CANAL); } -/* static */ bool AIMarine::RemoveWaterDepot(TileIndex tile) +/* static */ bool ScriptMarine::RemoveWaterDepot(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsWaterDepotTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ bool AIMarine::RemoveDock(TileIndex tile) +/* static */ bool ScriptMarine::RemoveDock(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsDockTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ bool AIMarine::RemoveBuoy(TileIndex tile) +/* static */ bool ScriptMarine::RemoveBuoy(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsBuoyTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ bool AIMarine::RemoveLock(TileIndex tile) +/* static */ bool ScriptMarine::RemoveLock(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsLockTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ bool AIMarine::RemoveCanal(TileIndex tile) +/* static */ bool ScriptMarine::RemoveCanal(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsCanalTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ Money AIMarine::GetBuildCost(BuildType build_type) +/* static */ Money ScriptMarine::GetBuildCost(BuildType build_type) { switch (build_type) { case BT_DOCK: return ::GetPrice(PR_BUILD_STATION_DOCK, 1, NULL); diff --git a/src/script/api/script_marine.hpp b/src/script/api/script_marine.hpp index d9d013c9d..93776159b 100644 --- a/src/script/api/script_marine.hpp +++ b/src/script/api/script_marine.hpp @@ -17,14 +17,14 @@ /** * Class that handles all marine related functions. */ -class AIMarine : public AIObject { +class ScriptMarine : public ScriptObject { public: /** * All marine related error messages. */ enum ErrorMessages { /** Base for marine related errors */ - ERR_MARINE_BASE = AIError::ERR_CAT_MARINE << AIError::ERR_CAT_BIT_SIZE, + ERR_MARINE_BASE = ScriptError::ERR_CAT_MARINE << ScriptError::ERR_CAT_BIT_SIZE, /** Infrastructure must be built on water */ ERR_MARINE_MUST_BE_BUILT_ON_WATER, // [STR_ERROR_MUST_BE_BUILT_ON_WATER] @@ -42,7 +42,7 @@ public: /** * Checks whether the given tile is actually a tile with a water depot. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a water depot. */ static bool IsWaterDepotTile(TileIndex tile); @@ -50,7 +50,7 @@ public: /** * Checks whether the given tile is actually a tile with a dock. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a dock. */ static bool IsDockTile(TileIndex tile); @@ -58,7 +58,7 @@ public: /** * Checks whether the given tile is actually a tile with a buoy. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a buoy. */ static bool IsBuoyTile(TileIndex tile); @@ -66,7 +66,7 @@ public: /** * Checks whether the given tile is actually a tile with a lock. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a lock. */ static bool IsLockTile(TileIndex tile); @@ -74,7 +74,7 @@ public: /** * Checks whether the given tile is actually a tile with a canal. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a canal. */ static bool IsCanalTile(TileIndex tile); @@ -85,8 +85,8 @@ public: * center of the second tile. * @param tile_from The source tile. * @param tile_to The destination tile. - * @pre AIMap::IsValidTile(tile_from). - * @pre AIMap::IsValidTile(tile_to). + * @pre ScriptMap::IsValidTile(tile_from). + * @pre ScriptMap::IsValidTile(tile_to). * @pre 'tile_from' and 'tile_to' are directly neighbouring tiles. * @return True if and only if a ship can go from tile_from to tile_to. */ @@ -96,11 +96,11 @@ public: * Builds a water depot on tile. * @param tile The tile where the water depot will be build. * @param front A tile on the same axis with 'tile' as the depot shall be oriented. - * @pre AIMap::IsValidTile(tile). - * @pre AIMap::IsValidTile(front). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_SITE_UNSUITABLE - * @exception AIMarine::ERR_MARINE_MUST_BE_BUILT_ON_WATER + * @pre ScriptMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(front). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_SITE_UNSUITABLE + * @exception ScriptMarine::ERR_MARINE_MUST_BE_BUILT_ON_WATER * @return Whether the water depot has been/can be build or not. * @note A WaterDepot is 1 tile in width, and 2 tiles in length. * @note The depot will be built towards the south from 'tile', not necessarily towards 'front'. @@ -110,13 +110,13 @@ public: /** * Builds a dock where tile is the tile still on land. * @param tile The tile still on land of the dock. - * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. - * @pre AIMap::IsValidTile(tile). - * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_SITE_UNSUITABLE - * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS + * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. + * @pre ScriptMap::IsValidTile(tile). + * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_SITE_UNSUITABLE + * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS * @return Whether the dock has been/can be build or not. */ static bool BuildDock(TileIndex tile, StationID station_id); @@ -124,10 +124,10 @@ public: /** * Builds a buoy on tile. * @param tile The tile where the buoy will be build. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_SITE_UNSUITABLE - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_SITE_UNSUITABLE + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS * @return Whether the buoy has been/can be build or not. */ static bool BuildBuoy(TileIndex tile); @@ -135,9 +135,9 @@ public: /** * Builds a lock on tile. * @param tile The tile where the lock will be build. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIError::ERR_SITE_UNSUITABLE + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptError::ERR_SITE_UNSUITABLE * @return Whether the lock has been/can be build or not. */ static bool BuildLock(TileIndex tile); @@ -145,11 +145,11 @@ public: /** * Builds a canal on tile. * @param tile The tile where the canal will be build. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_ALREADY_BUILT + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_ALREADY_BUILT * @return Whether the canal has been/can be build or not. */ static bool BuildCanal(TileIndex tile); @@ -157,8 +157,8 @@ public: /** * Removes a water depot. * @param tile Any tile of the water depot. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the water depot has been/can be removed or not. */ static bool RemoveWaterDepot(TileIndex tile); @@ -166,8 +166,8 @@ public: /** * Removes a dock. * @param tile Any tile of the dock. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the dock has been/can be removed or not. */ static bool RemoveDock(TileIndex tile); @@ -175,8 +175,8 @@ public: /** * Removes a buoy. * @param tile Any tile of the buoy. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the buoy has been/can be removed or not. */ static bool RemoveBuoy(TileIndex tile); @@ -184,8 +184,8 @@ public: /** * Removes a lock. * @param tile Any tile of the lock. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the lock has been/can be removed or not. */ static bool RemoveLock(TileIndex tile); @@ -193,8 +193,8 @@ public: /** * Removes a canal. * @param tile Any tile of the canal. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the canal has been/can be removed or not. */ static bool RemoveCanal(TileIndex tile); diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index ce734c608..2b6a3039b 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -7,7 +7,7 @@ * 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 script_object.cpp Implementation of AIObject. */ +/** @file script_object.cpp Implementation of ScriptObject. */ #include "../../stdafx.h" #include "../../script/squirrel.hpp" @@ -25,113 +25,113 @@ */ static AIStorage *GetStorage() { - return AIObject::GetActiveInstance()->GetStorage(); + return ScriptObject::GetActiveInstance()->GetStorage(); } -/* static */ AIInstance *AIObject::ActiveInstance::active = NULL; +/* static */ AIInstance *ScriptObject::ActiveInstance::active = NULL; -AIObject::ActiveInstance::ActiveInstance(AIInstance *instance) +ScriptObject::ActiveInstance::ActiveInstance(AIInstance *instance) { - this->last_active = AIObject::ActiveInstance::active; - AIObject::ActiveInstance::active = instance; + this->last_active = ScriptObject::ActiveInstance::active; + ScriptObject::ActiveInstance::active = instance; } -AIObject::ActiveInstance::~ActiveInstance() +ScriptObject::ActiveInstance::~ActiveInstance() { - AIObject::ActiveInstance::active = this->last_active; + ScriptObject::ActiveInstance::active = this->last_active; } -/* static */ AIInstance *AIObject::GetActiveInstance() +/* static */ AIInstance *ScriptObject::GetActiveInstance() { - assert(AIObject::ActiveInstance::active != NULL); - return AIObject::ActiveInstance::active; + assert(ScriptObject::ActiveInstance::active != NULL); + return ScriptObject::ActiveInstance::active; } -/* static */ void AIObject::SetDoCommandDelay(uint ticks) +/* static */ void ScriptObject::SetDoCommandDelay(uint ticks) { assert(ticks > 0); GetStorage()->delay = ticks; } -/* static */ uint AIObject::GetDoCommandDelay() +/* static */ uint ScriptObject::GetDoCommandDelay() { return GetStorage()->delay; } -/* static */ void AIObject::SetDoCommandMode(AIModeProc *proc, AIObject *instance) +/* static */ void ScriptObject::SetDoCommandMode(AIModeProc *proc, ScriptObject *instance) { GetStorage()->mode = proc; GetStorage()->mode_instance = instance; } -/* static */ AIModeProc *AIObject::GetDoCommandMode() +/* static */ AIModeProc *ScriptObject::GetDoCommandMode() { return GetStorage()->mode; } -/* static */ AIObject *AIObject::GetDoCommandModeInstance() +/* static */ ScriptObject *ScriptObject::GetDoCommandModeInstance() { return GetStorage()->mode_instance; } -/* static */ void AIObject::SetDoCommandCosts(Money value) +/* static */ void ScriptObject::SetDoCommandCosts(Money value) { GetStorage()->costs = CommandCost(value); } -/* static */ void AIObject::IncreaseDoCommandCosts(Money value) +/* static */ void ScriptObject::IncreaseDoCommandCosts(Money value) { GetStorage()->costs.AddCost(value); } -/* static */ Money AIObject::GetDoCommandCosts() +/* static */ Money ScriptObject::GetDoCommandCosts() { return GetStorage()->costs.GetCost(); } -/* static */ void AIObject::SetLastError(AIErrorType last_error) +/* static */ void ScriptObject::SetLastError(ScriptErrorType last_error) { GetStorage()->last_error = last_error; } -/* static */ AIErrorType AIObject::GetLastError() +/* static */ ScriptErrorType ScriptObject::GetLastError() { return GetStorage()->last_error; } -/* static */ void AIObject::SetLastCost(Money last_cost) +/* static */ void ScriptObject::SetLastCost(Money last_cost) { GetStorage()->last_cost = last_cost; } -/* static */ Money AIObject::GetLastCost() +/* static */ Money ScriptObject::GetLastCost() { return GetStorage()->last_cost; } -/* static */ void AIObject::SetRoadType(RoadType road_type) +/* static */ void ScriptObject::SetRoadType(RoadType road_type) { GetStorage()->road_type = road_type; } -/* static */ RoadType AIObject::GetRoadType() +/* static */ RoadType ScriptObject::GetRoadType() { return GetStorage()->road_type; } -/* static */ void AIObject::SetRailType(RailType rail_type) +/* static */ void ScriptObject::SetRailType(RailType rail_type) { GetStorage()->rail_type = rail_type; } -/* static */ RailType AIObject::GetRailType() +/* static */ RailType ScriptObject::GetRailType() { return GetStorage()->rail_type; } -/* static */ void AIObject::SetLastCommandRes(bool res) +/* static */ void ScriptObject::SetLastCommandRes(bool res) { GetStorage()->last_command_res = res; /* Also store the results of various global variables */ @@ -141,91 +141,91 @@ AIObject::ActiveInstance::~ActiveInstance() SetNewGroupID(_new_group_id); } -/* static */ bool AIObject::GetLastCommandRes() +/* static */ bool ScriptObject::GetLastCommandRes() { return GetStorage()->last_command_res; } -/* static */ void AIObject::SetNewVehicleID(VehicleID vehicle_id) +/* static */ void ScriptObject::SetNewVehicleID(VehicleID vehicle_id) { GetStorage()->new_vehicle_id = vehicle_id; } -/* static */ VehicleID AIObject::GetNewVehicleID() +/* static */ VehicleID ScriptObject::GetNewVehicleID() { return GetStorage()->new_vehicle_id; } -/* static */ void AIObject::SetNewSignID(SignID sign_id) +/* static */ void ScriptObject::SetNewSignID(SignID sign_id) { GetStorage()->new_sign_id = sign_id; } -/* static */ SignID AIObject::GetNewSignID() +/* static */ SignID ScriptObject::GetNewSignID() { return GetStorage()->new_sign_id; } -/* static */ void AIObject::SetNewTunnelEndtile(TileIndex tile) +/* static */ void ScriptObject::SetNewTunnelEndtile(TileIndex tile) { GetStorage()->new_tunnel_endtile = tile; } -/* static */ TileIndex AIObject::GetNewTunnelEndtile() +/* static */ TileIndex ScriptObject::GetNewTunnelEndtile() { return GetStorage()->new_tunnel_endtile; } -/* static */ void AIObject::SetNewGroupID(GroupID group_id) +/* static */ void ScriptObject::SetNewGroupID(GroupID group_id) { GetStorage()->new_group_id = group_id; } -/* static */ GroupID AIObject::GetNewGroupID() +/* static */ GroupID ScriptObject::GetNewGroupID() { return GetStorage()->new_group_id; } -/* static */ void AIObject::SetAllowDoCommand(bool allow) +/* static */ void ScriptObject::SetAllowDoCommand(bool allow) { GetStorage()->allow_do_command = allow; } -/* static */ bool AIObject::GetAllowDoCommand() +/* static */ bool ScriptObject::GetAllowDoCommand() { return GetStorage()->allow_do_command; } -/* static */ bool AIObject::CanSuspend() +/* static */ bool ScriptObject::CanSuspend() { - Squirrel *squirrel = AIObject::GetActiveInstance()->engine; + Squirrel *squirrel = ScriptObject::GetActiveInstance()->engine; return GetStorage()->allow_do_command && squirrel->CanSuspend(); } -/* static */ void *&AIObject::GetEventPointer() +/* static */ void *&ScriptObject::GetEventPointer() { return GetStorage()->event_data; } -/* static */ void *&AIObject::GetLogPointer() +/* static */ void *&ScriptObject::GetLogPointer() { return GetStorage()->log_data; } -/* static */ void AIObject::SetCallbackVariable(int index, int value) +/* static */ void ScriptObject::SetCallbackVariable(int index, int value) { if ((size_t)index >= GetStorage()->callback_value.size()) GetStorage()->callback_value.resize(index + 1); GetStorage()->callback_value[index] = value; } -/* static */ int AIObject::GetCallbackVariable(int index) +/* static */ int ScriptObject::GetCallbackVariable(int index) { return GetStorage()->callback_value[index]; } -/* static */ bool AIObject::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, AISuspendCallbackProc *callback) { - if (!AIObject::CanSuspend()) { + if (!ScriptObject::CanSuspend()) { throw AI_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator."); } @@ -245,12 +245,12 @@ AIObject::ActiveInstance::~ActiveInstance() /* We failed; set the error and bail out */ if (res.Failed()) { - SetLastError(AIError::StringToError(res.GetErrorMessage())); + SetLastError(ScriptError::StringToError(res.GetErrorMessage())); return false; } /* No error, then clear it. */ - SetLastError(AIError::ERR_NONE); + SetLastError(ScriptError::ERR_NONE); /* Estimates, update the cost for the estimate and be done */ if (estimate_only) { diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index 214d0e7cc..b4b55c740 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -34,7 +34,7 @@ typedef bool (AIModeProc)(); * internally to have a common place to handle general things, like internal * command processing, and command-validation checks. */ -class AIObject : public SimpleCountedObject { +class ScriptObject : public SimpleCountedObject { friend class AIInstance; #ifndef DOXYGEN_AI_DOCS protected: @@ -45,7 +45,7 @@ protected: * reverts to the active instance it was before instantiating. */ class ActiveInstance { - friend class AIObject; + friend class ScriptObject; public: ActiveInstance(AIInstance *instance); ~ActiveInstance(); @@ -92,12 +92,12 @@ protected: /** * Set the DoCommand last error. */ - static void SetLastError(AIErrorType last_error); + static void SetLastError(ScriptErrorType last_error); /** * Get the DoCommand last error. */ - static AIErrorType GetLastError(); + static ScriptErrorType GetLastError(); /** * Set the road type. @@ -122,7 +122,7 @@ protected: /** * Set the current mode of your AI to this proc. */ - static void SetDoCommandMode(AIModeProc *proc, AIObject *instance); + static void SetDoCommandMode(AIModeProc *proc, ScriptObject *instance); /** * Get the current mode your AI is currently under. @@ -132,7 +132,7 @@ protected: /** * Get the instance of the current mode your AI is currently under. */ - static AIObject *GetDoCommandModeInstance(); + static ScriptObject *GetDoCommandModeInstance(); /** * Set the delay of the DoCommand. diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp index 1811207cb..7a06f68e3 100644 --- a/src/script/api/script_order.cpp +++ b/src/script/api/script_order.cpp @@ -7,7 +7,7 @@ * 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 script_order.cpp Implementation of AIOrder. */ +/** @file script_order.cpp Implementation of ScriptOrder. */ #include "../../stdafx.h" #include "script_order.hpp" @@ -47,9 +47,9 @@ static OrderType GetOrderTypeByTile(TileIndex t) return OT_END; } -/* static */ bool AIOrder::IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position) { - return AIVehicle::IsValidVehicle(vehicle_id) && order_position >= 0 && (order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders() || order_position == ORDER_CURRENT); + return ScriptVehicle::IsValidVehicle(vehicle_id) && order_position >= 0 && (order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders() || order_position == ORDER_CURRENT); } /** @@ -57,19 +57,19 @@ static OrderType GetOrderTypeByTile(TileIndex t) * the order list, return the order from the orderlist. If the current order * was a manual order, return the current order. */ -static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition order_position) +static const Order *ResolveOrder(VehicleID vehicle_id, ScriptOrder::OrderPosition order_position) { const Vehicle *v = ::Vehicle::Get(vehicle_id); - if (order_position == AIOrder::ORDER_CURRENT) { + if (order_position == ScriptOrder::ORDER_CURRENT) { const Order *order = &v->current_order; if (order->GetType() == OT_GOTO_DEPOT && !(order->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return order; - order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); - if (order_position == AIOrder::ORDER_INVALID) return NULL; + order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); + if (order_position == ScriptOrder::ORDER_INVALID) return NULL; } const Order *order = v->orders.list->GetFirstOrder(); while (order->GetType() == OT_IMPLICIT) order = order->next; while (order_position > 0) { - order_position = (AIOrder::OrderPosition)(order_position - 1); + order_position = (ScriptOrder::OrderPosition)(order_position - 1); order = order->next; while (order->GetType() == OT_IMPLICIT) order = order->next; } @@ -77,23 +77,23 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or } /** - * Convert an AIOrder::OrderPosition (which is the manual order index) to an order index + * Convert an ScriptOrder::OrderPosition (which is the manual order index) to an order index * as expected by the OpenTTD commands. * @param order_position The OrderPosition to convert. * @return An OpenTTD-internal index for the same order. */ -static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::OrderPosition order_position) +static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOrder::OrderPosition order_position) { const Vehicle *v = ::Vehicle::Get(vehicle_id); if (order_position == v->GetNumManualOrders()) return v->GetNumOrders(); - assert(AIOrder::IsValidVehicleOrder(vehicle_id, order_position)); + assert(ScriptOrder::IsValidVehicleOrder(vehicle_id, order_position)); int res = (int)order_position; const Order *order = v->orders.list->GetFirstOrder(); for (; order->GetType() == OT_IMPLICIT; order = order->next) res++; while (order_position > 0) { - order_position = (AIOrder::OrderPosition)(order_position - 1); + order_position = (ScriptOrder::OrderPosition)(order_position - 1); order = order->next; for (; order->GetType() == OT_IMPLICIT; order = order->next) res++; } @@ -101,7 +101,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return res; } -/* static */ bool AIOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; @@ -109,7 +109,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return order != NULL && order->GetType() == OT_GOTO_STATION; } -/* static */ bool AIOrder::IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; @@ -117,7 +117,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return order != NULL && order->GetType() == OT_GOTO_DEPOT; } -/* static */ bool AIOrder::IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; @@ -125,16 +125,16 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return order != NULL && order->GetType() == OT_GOTO_WAYPOINT; } -/* static */ bool AIOrder::IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position) { if (order_position == ORDER_CURRENT) return false; if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; - const Order *order = ::Vehicle::Get(vehicle_id)->GetOrder(AIOrderPositionToRealOrderPosition(vehicle_id, order_position)); + const Order *order = ::Vehicle::Get(vehicle_id)->GetOrder(ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position)); return order->GetType() == OT_CONDITIONAL; } -/* static */ bool AIOrder::IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position) { if (order_position == ORDER_CURRENT) return false; if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; @@ -143,7 +143,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return order->GetType() == OT_DUMMY; } -/* static */ bool AIOrder::IsRefitOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::IsRefitOrder(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; @@ -151,9 +151,9 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return order != NULL && order->IsRefit(); } -/* static */ bool AIOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id) +/* static */ bool ScriptOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id) { - if (!AIVehicle::IsValidVehicle(vehicle_id)) return false; + if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return false; if (GetOrderCount(vehicle_id) == 0) return false; const Order *order = &::Vehicle::Get(vehicle_id)->current_order; @@ -161,9 +161,9 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return (order->GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0; } -/* static */ AIOrder::OrderPosition AIOrder::ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position) +/* static */ ScriptOrder::OrderPosition ScriptOrder::ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position) { - if (!AIVehicle::IsValidVehicle(vehicle_id)) return ORDER_INVALID; + if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return ORDER_INVALID; if (order_position == ORDER_CURRENT) { int cur_order_pos = ::Vehicle::Get(vehicle_id)->cur_real_order_index; @@ -174,13 +174,13 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord if (order->GetType() == OT_IMPLICIT) num_implicit_orders++; order = order->next; } - return (AIOrder::OrderPosition)(cur_order_pos - num_implicit_orders); + return (ScriptOrder::OrderPosition)(cur_order_pos - num_implicit_orders); } return (order_position >= 0 && order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders()) ? order_position : ORDER_INVALID; } -/* static */ bool AIOrder::AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags) +/* static */ bool ScriptOrder::AreOrderFlagsValid(TileIndex destination, ScriptOrderFlags order_flags) { OrderType ot = (order_flags & AIOF_GOTO_NEAREST_DEPOT) ? OT_GOTO_DEPOT : ::GetOrderTypeByTile(destination); switch (ot) { @@ -203,7 +203,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord } } -/* static */ bool AIOrder::IsValidConditionalOrder(OrderCondition condition, CompareFunction compare) +/* static */ bool ScriptOrder::IsValidConditionalOrder(OrderCondition condition, CompareFunction compare) { switch (condition) { case OC_LOAD_PERCENTAGE: @@ -223,12 +223,12 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord } } -/* static */ int32 AIOrder::GetOrderCount(VehicleID vehicle_id) +/* static */ int32 ScriptOrder::GetOrderCount(VehicleID vehicle_id) { - return AIVehicle::IsValidVehicle(vehicle_id) ? ::Vehicle::Get(vehicle_id)->GetNumManualOrders() : -1; + return ScriptVehicle::IsValidVehicle(vehicle_id) ? ::Vehicle::Get(vehicle_id)->GetNumManualOrders() : -1; } -/* static */ TileIndex AIOrder::GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position) +/* static */ TileIndex ScriptOrder::GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return INVALID_TILE; @@ -282,15 +282,15 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord } } -/* static */ AIOrder::AIOrderFlags AIOrder::GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position) +/* static */ ScriptOrder::ScriptOrderFlags ScriptOrder::GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return AIOF_INVALID; const Order *order = ::ResolveOrder(vehicle_id, order_position); if (order == NULL || order->GetType() == OT_CONDITIONAL || order->GetType() == OT_DUMMY) return AIOF_INVALID; - AIOrderFlags order_flags = AIOF_NONE; - order_flags |= (AIOrderFlags)order->GetNonStopType(); + ScriptOrderFlags order_flags = AIOF_NONE; + order_flags |= (ScriptOrderFlags)order->GetNonStopType(); switch (order->GetType()) { case OT_GOTO_DEPOT: if (order->GetDepotOrderType() & ODTFB_SERVICE) order_flags |= AIOF_SERVICE_IF_NEEDED; @@ -299,8 +299,8 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord break; case OT_GOTO_STATION: - order_flags |= (AIOrderFlags)(order->GetLoadType() << 5); - order_flags |= (AIOrderFlags)(order->GetUnloadType() << 2); + order_flags |= (ScriptOrderFlags)(order->GetLoadType() << 5); + order_flags |= (ScriptOrderFlags)(order->GetUnloadType() << 2); break; default: break; @@ -309,7 +309,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return order_flags; } -/* static */ AIOrder::OrderPosition AIOrder::GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position) +/* static */ ScriptOrder::OrderPosition ScriptOrder::GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return ORDER_INVALID; if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return ORDER_INVALID; @@ -318,7 +318,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return (OrderPosition)order->GetConditionSkipToOrder(); } -/* static */ AIOrder::OrderCondition AIOrder::GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position) +/* static */ ScriptOrder::OrderCondition ScriptOrder::GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return OC_INVALID; if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return OC_INVALID; @@ -327,7 +327,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return (OrderCondition)order->GetConditionVariable(); } -/* static */ AIOrder::CompareFunction AIOrder::GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position) +/* static */ ScriptOrder::CompareFunction ScriptOrder::GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return CF_INVALID; if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return CF_INVALID; @@ -336,7 +336,7 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return (CompareFunction)order->GetConditionComparator(); } -/* static */ int32 AIOrder::GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position) +/* static */ int32 ScriptOrder::GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return -1; if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return -1; @@ -347,17 +347,17 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return value; } -/* static */ AIOrder::StopLocation AIOrder::GetStopLocation(VehicleID vehicle_id, OrderPosition order_position) +/* static */ ScriptOrder::StopLocation ScriptOrder::GetStopLocation(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return STOPLOCATION_INVALID; - if (AIVehicle::GetVehicleType(vehicle_id) != AIVehicle::VT_RAIL) return STOPLOCATION_INVALID; + if (ScriptVehicle::GetVehicleType(vehicle_id) != ScriptVehicle::VT_RAIL) return STOPLOCATION_INVALID; if (!IsGotoStationOrder(vehicle_id, order_position)) return STOPLOCATION_INVALID; const Order *order = ::ResolveOrder(vehicle_id, order_position); - return (AIOrder::StopLocation)order->GetStopLocation(); + return (ScriptOrder::StopLocation)order->GetStopLocation(); } -/* static */ CargoID AIOrder::GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position) +/* static */ CargoID ScriptOrder::GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position) { if (!IsValidVehicleOrder(vehicle_id, order_position)) return CT_NO_REFIT; if (order_position != ORDER_CURRENT && !IsGotoStationOrder(vehicle_id, order_position) && !IsGotoDepotOrder(vehicle_id, order_position)) return CT_NO_REFIT; @@ -366,94 +366,94 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord return order->IsRefit() ? order->GetRefitCargo() : (CargoID)CT_NO_REFIT; } -/* static */ bool AIOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to) +/* static */ bool ScriptOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to) { EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT); - return AIObject::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), CMD_MODIFY_ORDER); + return ScriptObject::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), CMD_MODIFY_ORDER); } -/* static */ bool AIOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition) +/* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition) { EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VARIABLE | (condition << 4), CMD_MODIFY_ORDER); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VARIABLE | (condition << 4), CMD_MODIFY_ORDER); } -/* static */ bool AIOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare) +/* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare) { EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_COMPARATOR | (compare << 4), CMD_MODIFY_ORDER); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_COMPARATOR | (compare << 4), CMD_MODIFY_ORDER); } -/* static */ bool AIOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value) +/* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value) { EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, value >= 0 && value < 2048); if (GetOrderCondition(vehicle_id, order_position) == OC_MAX_SPEED) value = value * 10 / 16; - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VALUE | (value << 4), CMD_MODIFY_ORDER); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VALUE | (value << 4), CMD_MODIFY_ORDER); } -/* static */ bool AIOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location) +/* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location) { EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); - EnforcePrecondition(false, AIVehicle::GetVehicleType(vehicle_id) == AIVehicle::VT_RAIL); + EnforcePrecondition(false, ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL); EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position)); EnforcePrecondition(false, stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR); - order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); + order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); uint32 p1 = vehicle_id | (order_pos << 20); uint32 p2 = MOF_STOP_LOCATION | (stop_location << 4); - return AIObject::DoCommand(0, p1, p2, CMD_MODIFY_ORDER); + return ScriptObject::DoCommand(0, p1, p2, CMD_MODIFY_ORDER); } -/* static */ bool AIOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo) +/* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo) { EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT)); - EnforcePrecondition(false, AICargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT); + EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT); uint32 p1 = vehicle_id; - uint32 p2 = refit_cargo | AIOrderPositionToRealOrderPosition(vehicle_id, AIOrder::ResolveOrderPosition(vehicle_id, order_position)) << 16; - return AIObject::DoCommand(0, p1, p2, CMD_ORDER_REFIT); + uint32 p2 = refit_cargo | ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)) << 16; + return ScriptObject::DoCommand(0, p1, p2, CMD_ORDER_REFIT); } -/* static */ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags) +/* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags) { - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags)); - return InsertOrder(vehicle_id, (AIOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumManualOrders(), destination, order_flags); + return InsertOrder(vehicle_id, (ScriptOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumManualOrders(), destination, order_flags); } -/* static */ bool AIOrder::AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to) +/* static */ bool ScriptOrder::AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to) { - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to)); - return InsertConditionalOrder(vehicle_id, (AIOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumManualOrders(), jump_to); + return InsertConditionalOrder(vehicle_id, (ScriptOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumManualOrders(), jump_to); } -/* static */ bool AIOrder::InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrder::AIOrderFlags order_flags) +/* static */ bool ScriptOrder::InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, ScriptOrder::ScriptOrderFlags order_flags) { /* IsValidVehicleOrder is not good enough because it does not allow appending. */ - if (order_position == ORDER_CURRENT) order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); + if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders()); EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags)); @@ -498,44 +498,44 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord order.SetNonStopType((OrderNonStopFlags)GB(order_flags, 0, 2)); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER); } -/* static */ bool AIOrder::InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to) +/* static */ bool ScriptOrder::InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to) { /* IsValidVehicleOrder is not good enough because it does not allow appending. */ - if (order_position == ORDER_CURRENT) order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); + if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders()); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT); Order order; order.MakeConditional(jump_to); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER); } -/* static */ bool AIOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position) +/* static */ bool ScriptOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position) { - order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); + order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); - return AIObject::DoCommand(0, vehicle_id, order_pos, CMD_DELETE_ORDER); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); + return ScriptObject::DoCommand(0, vehicle_id, order_pos, CMD_DELETE_ORDER); } -/* static */ bool AIOrder::SkipToOrder(VehicleID vehicle_id, OrderPosition next_order) +/* static */ bool ScriptOrder::SkipToOrder(VehicleID vehicle_id, OrderPosition next_order) { - next_order = AIOrder::ResolveOrderPosition(vehicle_id, next_order); + next_order = ScriptOrder::ResolveOrderPosition(vehicle_id, next_order); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order)); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, next_order); - return AIObject::DoCommand(0, vehicle_id, order_pos, CMD_SKIP_TO_ORDER); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, next_order); + return ScriptObject::DoCommand(0, vehicle_id, order_pos, CMD_SKIP_TO_ORDER); } /** @@ -548,38 +548,38 @@ static int AIOrderPositionToRealOrderPosition(VehicleID vehicle_id, AIOrder::Ord */ static void _DoCommandReturnSetOrderFlags(class AIInstance *instance) { - AIObject::SetLastCommandRes(AIOrder::_SetOrderFlags()); + ScriptObject::SetLastCommandRes(ScriptOrder::_SetOrderFlags()); AIInstance::DoCommandReturn(instance); } -/* static */ bool AIOrder::_SetOrderFlags() +/* static */ bool ScriptOrder::_SetOrderFlags() { /* Make sure we don't go into an infinite loop */ - int retry = AIObject::GetCallbackVariable(3) - 1; + int retry = ScriptObject::GetCallbackVariable(3) - 1; if (retry < 0) { DEBUG(ai, 0, "Possible infinite loop in SetOrderFlags() detected"); return false; } - AIObject::SetCallbackVariable(3, retry); + ScriptObject::SetCallbackVariable(3, retry); - VehicleID vehicle_id = (VehicleID)AIObject::GetCallbackVariable(0); - OrderPosition order_position = (OrderPosition)AIObject::GetCallbackVariable(1); - AIOrderFlags order_flags = (AIOrderFlags)AIObject::GetCallbackVariable(2); + VehicleID vehicle_id = (VehicleID)ScriptObject::GetCallbackVariable(0); + OrderPosition order_position = (OrderPosition)ScriptObject::GetCallbackVariable(1); + ScriptOrderFlags order_flags = (ScriptOrderFlags)ScriptObject::GetCallbackVariable(2); - order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); + order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags)); const Order *order = ::ResolveOrder(vehicle_id, order_position); - int order_pos = AIOrderPositionToRealOrderPosition(vehicle_id, order_position); + int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); - AIOrderFlags current = GetOrderFlags(vehicle_id, order_position); + ScriptOrderFlags current = GetOrderFlags(vehicle_id, order_position); EnforcePrecondition(false, (order_flags & AIOF_GOTO_NEAREST_DEPOT) == (current & AIOF_GOTO_NEAREST_DEPOT)); if ((current & AIOF_NON_STOP_FLAGS) != (order_flags & AIOF_NON_STOP_FLAGS)) { - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & AIOF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & AIOF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); } switch (order->GetType()) { @@ -588,16 +588,16 @@ static void _DoCommandReturnSetOrderFlags(class AIInstance *instance) uint data = DA_ALWAYS_GO; if (order_flags & AIOF_SERVICE_IF_NEEDED) data = DA_SERVICE; if (order_flags & AIOF_STOP_IN_DEPOT) data = DA_STOP; - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); } break; case OT_GOTO_STATION: if ((current & AIOF_UNLOAD_FLAGS) != (order_flags & AIOF_UNLOAD_FLAGS)) { - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & AIOF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & AIOF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); } if ((current & AIOF_LOAD_FLAGS) != (order_flags & AIOF_LOAD_FLAGS)) { - return AIObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & AIOF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & AIOF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); } break; @@ -609,49 +609,49 @@ static void _DoCommandReturnSetOrderFlags(class AIInstance *instance) return true; } -/* static */ bool AIOrder::SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrder::AIOrderFlags order_flags) +/* static */ bool ScriptOrder::SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, ScriptOrder::ScriptOrderFlags order_flags) { - AIObject::SetCallbackVariable(0, vehicle_id); - AIObject::SetCallbackVariable(1, order_position); - AIObject::SetCallbackVariable(2, order_flags); + ScriptObject::SetCallbackVariable(0, vehicle_id); + ScriptObject::SetCallbackVariable(1, order_position); + ScriptObject::SetCallbackVariable(2, order_flags); /* In case another client(s) change orders at the same time we could * end in an infinite loop. This stops that from happening ever. */ - AIObject::SetCallbackVariable(3, 8); - return AIOrder::_SetOrderFlags(); + ScriptObject::SetCallbackVariable(3, 8); + return ScriptOrder::_SetOrderFlags(); } -/* static */ bool AIOrder::MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target) +/* static */ bool ScriptOrder::MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target) { - order_position_move = AIOrder::ResolveOrderPosition(vehicle_id, order_position_move); - order_position_target = AIOrder::ResolveOrderPosition(vehicle_id, order_position_target); + order_position_move = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_move); + order_position_target = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position_target); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_move)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_target)); - int order_pos_move = AIOrderPositionToRealOrderPosition(vehicle_id, order_position_move); - int order_pos_target = AIOrderPositionToRealOrderPosition(vehicle_id, order_position_target); - return AIObject::DoCommand(0, vehicle_id, order_pos_move | (order_pos_target << 16), CMD_MOVE_ORDER); + int order_pos_move = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_move); + int order_pos_target = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_target); + return ScriptObject::DoCommand(0, vehicle_id, order_pos_move | (order_pos_target << 16), CMD_MOVE_ORDER); } -/* static */ bool AIOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) +/* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) { - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); - EnforcePrecondition(false, AIVehicle::IsValidVehicle(main_vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id)); - return AIObject::DoCommand(0, vehicle_id | CO_COPY << 30, main_vehicle_id, CMD_CLONE_ORDER); + return ScriptObject::DoCommand(0, vehicle_id | CO_COPY << 30, main_vehicle_id, CMD_CLONE_ORDER); } -/* static */ bool AIOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) +/* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) { - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); - EnforcePrecondition(false, AIVehicle::IsValidVehicle(main_vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id)); - return AIObject::DoCommand(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, CMD_CLONE_ORDER); + return ScriptObject::DoCommand(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, CMD_CLONE_ORDER); } -/* static */ bool AIOrder::UnshareOrders(VehicleID vehicle_id) +/* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id) { - EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); + EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); - return AIObject::DoCommand(0, vehicle_id | CO_UNSHARE << 30, 0, CMD_CLONE_ORDER); + return ScriptObject::DoCommand(0, vehicle_id | CO_UNSHARE << 30, 0, CMD_CLONE_ORDER); } diff --git a/src/script/api/script_order.hpp b/src/script/api/script_order.hpp index 0f2372e77..ca92d41fc 100644 --- a/src/script/api/script_order.hpp +++ b/src/script/api/script_order.hpp @@ -17,14 +17,14 @@ /** * Class that handles all order related functions. */ -class AIOrder : public AIObject { +class ScriptOrder : public ScriptObject { public: /** * All order related error messages. */ enum ErrorMessages { /** Base for all order related errors */ - ERR_ORDER_BASE = AIError::ERR_CAT_ORDER << AIError::ERR_CAT_BIT_SIZE, + ERR_ORDER_BASE = ScriptError::ERR_CAT_ORDER << ScriptError::ERR_CAT_BIT_SIZE, /** No more space for orders */ ERR_ORDER_TOO_MANY, // [STR_ERROR_NO_MORE_SPACE_FOR_ORDERS] @@ -36,7 +36,7 @@ public: /** * Flags that can be used to modify the behaviour of orders. */ - enum AIOrderFlags { + enum ScriptOrderFlags { /** Just go to the station/depot, stop unload if possible and load if needed. */ AIOF_NONE = 0, @@ -86,7 +86,7 @@ public: /* Order _is_ important, as it's based on OrderConditionVariable in order_type.h. */ OC_LOAD_PERCENTAGE, ///< Skip based on the amount of load, value is in tons. OC_RELIABILITY, ///< Skip based on the reliability, value is percent (0..100). - OC_MAX_SPEED, ///< Skip based on the maximum speed, value is in OpenTTD's internal speed unit, see AIEngine::GetMaxSpeed. + OC_MAX_SPEED, ///< Skip based on the maximum speed, value is in OpenTTD's internal speed unit, see ScriptEngine::GetMaxSpeed. OC_AGE, ///< Skip based on the age, value is in years. OC_REQUIRES_SERVICE, ///< Skip when the vehicle requires service, no value. OC_UNCONDITIONALLY, ///< Always skip, no compare function, no value. @@ -134,7 +134,7 @@ public: * Checks whether the given order id is valid for the given vehicle. * @param vehicle_id The vehicle to check the order index for. * @param order_position The order index to check. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @return True if and only if the order_position is valid for the given vehicle. */ static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position); @@ -199,7 +199,7 @@ public: /** * Checks whether the current order is part of the orderlist. * @param vehicle_id The vehicle to check. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @return True if and only if the current order is part of the order list. * @note If the order is a non-'non-stop' order, and the vehicle is currently * (un)loading at a station that is not the final destination, this function @@ -214,7 +214,7 @@ public: * given index does not exist it will return ORDER_INVALID. * @param vehicle_id The vehicle to check the order index for. * @param order_position The order index to resolve. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @return The resolved order index. */ static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position); @@ -225,7 +225,7 @@ public: * @param order_flags The flags given to the order. * @return True if and only if the order_flags are valid for the given location. */ - static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags); + static bool AreOrderFlagsValid(TileIndex destination, ScriptOrderFlags order_flags); /** * Checks whether the given combination of condition and compare function is valid. @@ -238,7 +238,7 @@ public: /** * Returns the number of orders for the given vehicle. * @param vehicle_id The vehicle to get the order count of. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @return The number of orders for the given vehicle or a negative * value when the vehicle does not exist. */ @@ -260,7 +260,7 @@ public: static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position); /** - * Gets the AIOrderFlags of the given order for the given vehicle. + * Gets the ScriptOrderFlags of the given order for the given vehicle. * @param vehicle_id The vehicle to get the destination for. * @param order_position The order to get the destination for. * @pre IsValidVehicleOrder(vehicle_id, order_position). @@ -270,9 +270,9 @@ public: * current order as given by ResolveOrderPosition (the current index in the * order list) as manual or autoservicing depot orders do not show up * in the orderlist, but they can be the current order of a vehicle. - * @return The AIOrderFlags of the order. + * @return The ScriptOrderFlags of the order. */ - static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position); + static ScriptOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position); /** * Gets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle. @@ -319,7 +319,7 @@ public: * @param vehicle_id The vehicle to get the value for. * @param order_position The order to get the value for. * @pre IsValidVehicleOrder(vehicle_id, order_position). - * @pre AIVehicle::GetVehicleType(vehicle_id) == AIVehicle::VT_RAIL. + * @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL. * @pre IsGotoStationOrder(vehicle_id, order_position). * @return The relative position where the train will stop inside a station. */ @@ -394,7 +394,7 @@ public: * @param order_position The order to get the value for. * @param stop_location The relative position where a train will stop inside a station. * @pre IsValidVehicleOrder(vehicle_id, order_position). - * @pre AIVehicle::GetVehicleType(vehicle_id) == AIVehicle::VT_RAIL. + * @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL. * @pre IsGotoStationOrder(vehicle_id, order_position). * @pre stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR * @return Whether the order has been/can be changed. @@ -408,7 +408,7 @@ public: * @param refit_cargo The cargo to refit to. The refit can be cleared by passing CT_NO_REFIT. * @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT). - * @pre AICargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT + * @pre ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT * @return Whether the order has been/can be changed. */ static bool SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo); @@ -418,23 +418,23 @@ public: * @param vehicle_id The vehicle to append the order to. * @param destination The destination of the order. * @param order_flags The flags given to the order. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @pre AreOrderFlagsValid(destination, order_flags). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIOrder::ERR_ORDER_TOO_MANY - * @exception AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptOrder::ERR_ORDER_TOO_MANY + * @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION * @return True if and only if the order was appended. */ - static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags); + static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags); /** * Appends a conditional order to the end of the vehicle's order list. * @param vehicle_id The vehicle to append the order to. * @param jump_to The OrderPosition to jump to if the condition is true. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @pre IsValidVehicleOrder(vehicle_id, jump_to). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIOrder::ERR_ORDER_TOO_MANY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptOrder::ERR_ORDER_TOO_MANY * @return True if and only if the order was appended. */ static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to); @@ -447,12 +447,12 @@ public: * @param order_flags The flags given to the order. * @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre AreOrderFlagsValid(destination, order_flags). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIOrder::ERR_ORDER_TOO_MANY - * @exception AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptOrder::ERR_ORDER_TOO_MANY + * @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION * @return True if and only if the order was inserted. */ - static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags); + static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, ScriptOrderFlags order_flags); /** * Appends a conditional order before the given order_position into the vehicle's order list. @@ -461,8 +461,8 @@ public: * @param jump_to The OrderPosition to jump to if the condition is true. * @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre IsValidVehicleOrder(vehicle_id, jump_to). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIOrder::ERR_ORDER_TOO_MANY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptOrder::ERR_ORDER_TOO_MANY * @return True if and only if the order was inserted. */ static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to); @@ -472,7 +472,7 @@ public: * @param vehicle_id The vehicle to remove the order from. * @param order_position The order to remove from the order list. * @pre IsValidVehicleOrder(vehicle_id, order_position). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return True if and only if the order was removed. */ static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position); @@ -492,10 +492,10 @@ public: * @pre IsValidVehicleOrder(vehicle_id, order_position). * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags). * @pre (order_flags & AIOF_GOTO_NEAREST_DEPOT) == (GetOrderFlags(vehicle_id, order_position) & AIOF_GOTO_NEAREST_DEPOT). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return True if and only if the order was changed. */ - static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags); + static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, ScriptOrderFlags order_flags); /** * Move an order inside the orderlist @@ -504,7 +504,7 @@ public: * @param order_position_target The target order * @pre IsValidVehicleOrder(vehicle_id, order_position_move). * @pre IsValidVehicleOrder(vehicle_id, order_position_target). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return True if and only if the order was moved. * @note If the order is moved to a lower place (e.g. from 7 to 2) * the target order is moved upwards (e.g. 3). If the order is moved @@ -518,7 +518,7 @@ public: * @param vehicle_id The vehicle that should skip some orders. * @param next_order The order the vehicle should skip to. * @pre IsValidVehicleOrder(vehicle_id, next_order). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return True if and only the current order was changed. */ static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order); @@ -528,10 +528,10 @@ public: * are going to be the orders of the changed vehicle. * @param vehicle_id The vehicle to copy the orders to. * @param main_vehicle_id The vehicle to copy the orders from. - * @pre AIVehicle::IsValidVehicle(vehicle_id). - * @pre AIVehicle::IsValidVehicle(main_vehicle_id). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIOrder::ERR_ORDER_TOO_MANY + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(main_vehicle_id). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptOrder::ERR_ORDER_TOO_MANY * @return True if and only if the copying succeeded. */ static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); @@ -541,9 +541,9 @@ public: * vehicle are going to be the orders of the changed vehicle. * @param vehicle_id The vehicle to add to the shared order list. * @param main_vehicle_id The vehicle to share the orders with. - * @pre AIVehicle::IsValidVehicle(vehicle_id). - * @pre AIVehicle::IsValidVehicle(main_vehicle_id). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(main_vehicle_id). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return True if and only if the sharing succeeded. */ static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); @@ -551,11 +551,11 @@ public: /** * Removes the given vehicle from a shared orders list. * @param vehicle_id The vehicle to remove from the shared order list. - * @pre AIVehicle::IsValidVehicle(vehicle_id). + * @pre ScriptVehicle::IsValidVehicle(vehicle_id). * @return True if and only if the unsharing succeeded. */ static bool UnshareOrders(VehicleID vehicle_id); }; -DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags) +DECLARE_ENUM_AS_BIT_SET(ScriptOrder::ScriptOrderFlags) #endif /* SCRIPT_ORDER_HPP */ diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index 236106d15..1ebeb74ec 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -7,7 +7,7 @@ * 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 script_rail.cpp Implementation of AIRail. */ +/** @file script_rail.cpp Implementation of ScriptRail. */ #include "../../stdafx.h" #include "script_rail.hpp" @@ -23,7 +23,7 @@ #include "../../newgrf_station.h" #include "../../strings_func.h" -/* static */ char *AIRail::GetName(RailType rail_type) +/* static */ char *ScriptRail::GetName(RailType rail_type) { if (!IsRailTypeAvailable(rail_type)) return NULL; @@ -34,7 +34,7 @@ return railtype_name; } -/* static */ bool AIRail::IsRailTile(TileIndex tile) +/* static */ bool ScriptRail::IsRailTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; @@ -42,100 +42,100 @@ (::HasStationTileRail(tile) && !::IsStationTileBlocked(tile)) || ::IsLevelCrossingTile(tile); } -/* static */ bool AIRail::IsLevelCrossingTile(TileIndex tile) +/* static */ bool ScriptRail::IsLevelCrossingTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsLevelCrossingTile(tile); } -/* static */ bool AIRail::IsRailDepotTile(TileIndex tile) +/* static */ bool ScriptRail::IsRailDepotTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsRailDepotTile(tile); } -/* static */ bool AIRail::IsRailStationTile(TileIndex tile) +/* static */ bool ScriptRail::IsRailStationTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsRailStationTile(tile); } -/* static */ bool AIRail::IsRailWaypointTile(TileIndex tile) +/* static */ bool ScriptRail::IsRailWaypointTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsRailWaypointTile(tile); } -/* static */ bool AIRail::IsRailTypeAvailable(RailType rail_type) +/* static */ bool ScriptRail::IsRailTypeAvailable(RailType rail_type) { if ((::RailType)rail_type < RAILTYPE_BEGIN || (::RailType)rail_type >= RAILTYPE_END) return false; return ::HasRailtypeAvail(_current_company, (::RailType)rail_type); } -/* static */ AIRail::RailType AIRail::GetCurrentRailType() +/* static */ ScriptRail::RailType ScriptRail::GetCurrentRailType() { - return (RailType)AIObject::GetRailType(); + return (RailType)ScriptObject::GetRailType(); } -/* static */ void AIRail::SetCurrentRailType(RailType rail_type) +/* static */ void ScriptRail::SetCurrentRailType(RailType rail_type) { if (!IsRailTypeAvailable(rail_type)) return; - AIObject::SetRailType((::RailType)rail_type); + ScriptObject::SetRailType((::RailType)rail_type); } -/* static */ bool AIRail::TrainCanRunOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type) +/* static */ bool ScriptRail::TrainCanRunOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type) { - if (!AIRail::IsRailTypeAvailable(engine_rail_type)) return false; - if (!AIRail::IsRailTypeAvailable(track_rail_type)) return false; + if (!ScriptRail::IsRailTypeAvailable(engine_rail_type)) return false; + if (!ScriptRail::IsRailTypeAvailable(track_rail_type)) return false; return ::IsCompatibleRail((::RailType)engine_rail_type, (::RailType)track_rail_type); } -/* static */ bool AIRail::TrainHasPowerOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type) +/* static */ bool ScriptRail::TrainHasPowerOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type) {\ - if (!AIRail::IsRailTypeAvailable(engine_rail_type)) return false; - if (!AIRail::IsRailTypeAvailable(track_rail_type)) return false; + if (!ScriptRail::IsRailTypeAvailable(engine_rail_type)) return false; + if (!ScriptRail::IsRailTypeAvailable(track_rail_type)) return false; return ::HasPowerOnRail((::RailType)engine_rail_type, (::RailType)track_rail_type); } -/* static */ AIRail::RailType AIRail::GetRailType(TileIndex tile) +/* static */ ScriptRail::RailType ScriptRail::GetRailType(TileIndex tile) { - if (!AITile::HasTransportType(tile, AITile::TRANSPORT_RAIL)) return RAILTYPE_INVALID; + if (!ScriptTile::HasTransportType(tile, ScriptTile::TRANSPORT_RAIL)) return RAILTYPE_INVALID; return (RailType)::GetRailType(tile); } -/* static */ bool AIRail::ConvertRailType(TileIndex start_tile, TileIndex end_tile, AIRail::RailType convert_to) +/* static */ bool ScriptRail::ConvertRailType(TileIndex start_tile, TileIndex end_tile, ScriptRail::RailType convert_to) { EnforcePrecondition(false, ::IsValidTile(start_tile)); EnforcePrecondition(false, ::IsValidTile(end_tile)); EnforcePrecondition(false, IsRailTypeAvailable(convert_to)); - return AIObject::DoCommand(start_tile, end_tile, convert_to, CMD_CONVERT_RAIL); + return ScriptObject::DoCommand(start_tile, end_tile, convert_to, CMD_CONVERT_RAIL); } -/* static */ TileIndex AIRail::GetRailDepotFrontTile(TileIndex depot) +/* static */ TileIndex ScriptRail::GetRailDepotFrontTile(TileIndex depot) { if (!IsRailDepotTile(depot)) return INVALID_TILE; return depot + ::TileOffsByDiagDir(::GetRailDepotDirection(depot)); } -/* static */ AIRail::RailTrack AIRail::GetRailStationDirection(TileIndex tile) +/* static */ ScriptRail::RailTrack ScriptRail::GetRailStationDirection(TileIndex tile) { if (!IsRailStationTile(tile)) return RAILTRACK_INVALID; return (RailTrack)::GetRailStationTrackBits(tile); } -/* static */ bool AIRail::BuildRailDepot(TileIndex tile, TileIndex front) +/* static */ bool ScriptRail::BuildRailDepot(TileIndex tile, TileIndex front) { EnforcePrecondition(false, tile != front); EnforcePrecondition(false, ::IsValidTile(tile)); @@ -145,43 +145,43 @@ uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0); - return AIObject::DoCommand(tile, AIObject::GetRailType(), entrance_dir, CMD_BUILD_TRAIN_DEPOT); + return ScriptObject::DoCommand(tile, ScriptObject::GetRailType(), entrance_dir, CMD_BUILD_TRAIN_DEPOT); } -/* static */ bool AIRail::BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id) +/* static */ bool ScriptRail::BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW); EnforcePrecondition(false, num_platforms > 0 && num_platforms <= 0xFF); EnforcePrecondition(false, platform_length > 0 && platform_length <= 0xFF); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); - EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); + EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8); if (direction == RAILTRACK_NW_SE) p1 |= (1 << 4); - if (station_id != AIStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24); - return AIObject::DoCommand(tile, p1, (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, CMD_BUILD_RAIL_STATION); + if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24); + return ScriptObject::DoCommand(tile, p1, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, CMD_BUILD_RAIL_STATION); } -/* static */ bool AIRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station) +/* static */ bool ScriptRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW); EnforcePrecondition(false, num_platforms > 0 && num_platforms <= 0xFF); EnforcePrecondition(false, platform_length > 0 && platform_length <= 0xFF); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); - EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); - EnforcePrecondition(false, AICargo::IsValidCargo(cargo_id)); - EnforcePrecondition(false, source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry)); - EnforcePrecondition(false, goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry)); + EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); + EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_id)); + EnforcePrecondition(false, source_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(source_industry)); + EnforcePrecondition(false, goal_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(goal_industry)); uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8); if (direction == RAILTRACK_NW_SE) p1 |= 1 << 4; - if (station_id != AIStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24); + if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24); const GRFFile *file; uint16 res = GetAiPurchaseCallbackResult(GSF_STATIONS, cargo_id, 0, source_industry, goal_industry, min(255, distance / 2), AICE_STATION_GET_STATION_ID, source_station ? 0 : 1, min(15, num_platforms) << 4 | min(15, platform_length), &file); - uint32 p2 = (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; + uint32 p2 = (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; if (res != CALLBACK_FAILED) { int index = 0; const StationSpec *spec = StationClass::GetByGrf(file->grfid, res, &index); @@ -192,36 +192,36 @@ } } - return AIObject::DoCommand(tile, p1, p2, CMD_BUILD_RAIL_STATION); + return ScriptObject::DoCommand(tile, p1, p2, CMD_BUILD_RAIL_STATION); } -/* static */ bool AIRail::BuildRailWaypoint(TileIndex tile) +/* static */ bool ScriptRail::BuildRailWaypoint(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsRailTile(tile)); EnforcePrecondition(false, GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); - return AIObject::DoCommand(tile, GetCurrentRailType() | (GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y) << 4 | 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, CMD_BUILD_RAIL_WAYPOINT); + return ScriptObject::DoCommand(tile, GetCurrentRailType() | (GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y) << 4 | 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, CMD_BUILD_RAIL_WAYPOINT); } -/* static */ bool AIRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail) +/* static */ bool ScriptRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsValidTile(tile2)); - return AIObject::DoCommand(tile, tile2, keep_rail ? 1 : 0, CMD_REMOVE_FROM_RAIL_WAYPOINT); + return ScriptObject::DoCommand(tile, tile2, keep_rail ? 1 : 0, CMD_REMOVE_FROM_RAIL_WAYPOINT); } -/* static */ bool AIRail::RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail) +/* static */ bool ScriptRail::RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsValidTile(tile2)); - return AIObject::DoCommand(tile, tile2, keep_rail ? 1 : 0, CMD_REMOVE_FROM_RAIL_STATION); + return ScriptObject::DoCommand(tile, tile2, keep_rail ? 1 : 0, CMD_REMOVE_FROM_RAIL_STATION); } -/* static */ uint AIRail::GetRailTracks(TileIndex tile) +/* static */ uint ScriptRail::GetRailTracks(TileIndex tile) { if (!IsRailTile(tile)) return RAILTRACK_INVALID; @@ -231,7 +231,7 @@ return ::GetTrackBits(tile); } -/* static */ bool AIRail::BuildRailTrack(TileIndex tile, RailTrack rail_track) +/* static */ bool ScriptRail::BuildRailTrack(TileIndex tile, RailTrack rail_track) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, rail_track != 0); @@ -239,23 +239,23 @@ EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); - return AIObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_BUILD_RAILROAD_TRACK); + return ScriptObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_BUILD_RAILROAD_TRACK); } -/* static */ bool AIRail::RemoveRailTrack(TileIndex tile, RailTrack rail_track) +/* static */ bool ScriptRail::RemoveRailTrack(TileIndex tile, RailTrack rail_track) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsPlainRailTile(tile) || ::IsLevelCrossingTile(tile)); EnforcePrecondition(false, GetRailTracks(tile) & rail_track); EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0); - return AIObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_REMOVE_RAILROAD_TRACK); + return ScriptObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_REMOVE_RAILROAD_TRACK); } -/* static */ bool AIRail::AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to) +/* static */ bool ScriptRail::AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to) { if (!IsRailTile(tile)) return false; - if (from == to || AIMap::DistanceManhattan(from, tile) != 1 || AIMap::DistanceManhattan(tile, to) != 1) return false; + if (from == to || ScriptMap::DistanceManhattan(from, tile) != 1 || ScriptMap::DistanceManhattan(tile, to) != 1) return false; if (to < from) ::Swap(from, to); @@ -280,7 +280,7 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) { int diag_offset = abs(abs((int)::TileX(*to) - (int)::TileX(tile)) - abs((int)::TileY(*to) - (int)::TileY(tile))); - uint32 p2 = AIRail::GetCurrentRailType(); + uint32 p2 = ScriptRail::GetCurrentRailType(); if (::TileY(from) == ::TileY(*to)) { p2 |= (TRACK_X << 4); *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); @@ -335,7 +335,7 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) return p2; } -/* static */ bool AIRail::BuildRail(TileIndex from, TileIndex tile, TileIndex to) +/* static */ bool ScriptRail::BuildRail(TileIndex from, TileIndex tile, TileIndex to) { EnforcePrecondition(false, ::IsValidTile(from)); EnforcePrecondition(false, ::IsValidTile(tile)); @@ -349,10 +349,10 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) (::TileY(from) == ::TileY(tile) && ::TileY(tile) == ::TileY(to))); uint32 p2 = SimulateDrag(from, tile, &to) | 1 << 8; - return AIObject::DoCommand(tile, to, p2, CMD_BUILD_RAILROAD_TRACK); + return ScriptObject::DoCommand(tile, to, p2, CMD_BUILD_RAILROAD_TRACK); } -/* static */ bool AIRail::RemoveRail(TileIndex from, TileIndex tile, TileIndex to) +/* static */ bool ScriptRail::RemoveRail(TileIndex from, TileIndex tile, TileIndex to) { EnforcePrecondition(false, ::IsValidTile(from)); EnforcePrecondition(false, ::IsValidTile(tile)); @@ -366,14 +366,14 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) if (!IsRailTypeAvailable(GetCurrentRailType())) SetCurrentRailType(GetRailType(tile)); uint32 p2 = SimulateDrag(from, tile, &to); - return AIObject::DoCommand(tile, to, p2, CMD_REMOVE_RAILROAD_TRACK); + return ScriptObject::DoCommand(tile, to, p2, CMD_REMOVE_RAILROAD_TRACK); } /** * Contains information about the trackdir that belongs to a track when entering * from a specific direction. */ -struct AIRailSignalData { +struct ScriptRailSignalData { Track track; ///< The track that will be taken to travel. Trackdir trackdir; ///< The Trackdir belonging to that track. uint signal_cycles; ///< How many times the signal should be cycled in order to build it in the correct direction. @@ -387,7 +387,7 @@ static const int NUM_TRACK_DIRECTIONS = 3; ///< The number of directions you can * TileIndex of the previous and current tile, where (-)MapSizeX is replaced with -2 / 2 and * 2 it added. */ -static const AIRailSignalData _possible_trackdirs[5][NUM_TRACK_DIRECTIONS] = { +static const ScriptRailSignalData _possible_trackdirs[5][NUM_TRACK_DIRECTIONS] = { {{TRACK_UPPER, TRACKDIR_UPPER_E, 0}, {TRACK_Y, TRACKDIR_Y_SE, 0}, {TRACK_LEFT, TRACKDIR_LEFT_S, 1}}, {{TRACK_RIGHT, TRACKDIR_RIGHT_S, 1}, {TRACK_X, TRACKDIR_X_SW, 1}, {TRACK_UPPER, TRACKDIR_UPPER_W, 1}}, {{INVALID_TRACK, INVALID_TRACKDIR, 0}, {INVALID_TRACK, INVALID_TRACKDIR, 0}, {INVALID_TRACK, INVALID_TRACKDIR, 0}}, @@ -395,9 +395,9 @@ static const AIRailSignalData _possible_trackdirs[5][NUM_TRACK_DIRECTIONS] = { {{TRACK_RIGHT, TRACKDIR_RIGHT_N, 0}, {TRACK_Y, TRACKDIR_Y_NW, 1}, {TRACK_LOWER, TRACKDIR_LOWER_W, 1}} }; -/* static */ AIRail::SignalType AIRail::GetSignalType(TileIndex tile, TileIndex front) +/* static */ ScriptRail::SignalType ScriptRail::GetSignalType(TileIndex tile, TileIndex front) { - if (AIMap::DistanceManhattan(tile, front) != 1) return SIGNALTYPE_NONE; + if (ScriptMap::DistanceManhattan(tile, front) != 1) return SIGNALTYPE_NONE; if (!::IsTileType(tile, MP_RAILWAY) || !::HasSignals(tile)) return SIGNALTYPE_NONE; int data_index = 2 + (::TileX(front) - ::TileX(tile)) + 2 * (::TileY(front) - ::TileY(tile)); @@ -420,14 +420,14 @@ static const AIRailSignalData _possible_trackdirs[5][NUM_TRACK_DIRECTIONS] = { */ static bool IsValidSignalType(int signal_type) { - if (signal_type < AIRail::SIGNALTYPE_NORMAL || signal_type > AIRail::SIGNALTYPE_COMBO_TWOWAY) return false; - if (signal_type > AIRail::SIGNALTYPE_PBS_ONEWAY && signal_type < AIRail::SIGNALTYPE_NORMAL_TWOWAY) return false; + if (signal_type < ScriptRail::SIGNALTYPE_NORMAL || signal_type > ScriptRail::SIGNALTYPE_COMBO_TWOWAY) return false; + if (signal_type > ScriptRail::SIGNALTYPE_PBS_ONEWAY && signal_type < ScriptRail::SIGNALTYPE_NORMAL_TWOWAY) return false; return true; } -/* static */ bool AIRail::BuildSignal(TileIndex tile, TileIndex front, SignalType signal) +/* static */ bool ScriptRail::BuildSignal(TileIndex tile, TileIndex front, SignalType signal) { - EnforcePrecondition(false, AIMap::DistanceManhattan(tile, front) == 1) + EnforcePrecondition(false, ScriptMap::DistanceManhattan(tile, front) == 1) EnforcePrecondition(false, ::IsPlainRailTile(tile)); EnforcePrecondition(false, ::IsValidSignalType(signal)); @@ -451,12 +451,12 @@ static bool IsValidSignalType(int signal_type) } p1 |= ((signal >= SIGNALTYPE_TWOWAY ? signal ^ SIGNALTYPE_TWOWAY : signal) << 5); - return AIObject::DoCommand(tile, p1, 0, CMD_BUILD_SIGNALS); + return ScriptObject::DoCommand(tile, p1, 0, CMD_BUILD_SIGNALS); } -/* static */ bool AIRail::RemoveSignal(TileIndex tile, TileIndex front) +/* static */ bool ScriptRail::RemoveSignal(TileIndex tile, TileIndex front) { - EnforcePrecondition(false, AIMap::DistanceManhattan(tile, front) == 1) + EnforcePrecondition(false, ScriptMap::DistanceManhattan(tile, front) == 1) EnforcePrecondition(false, GetSignalType(tile, front) != SIGNALTYPE_NONE); Track track = INVALID_TRACK; @@ -469,12 +469,12 @@ static bool IsValidSignalType(int signal_type) } EnforcePrecondition(false, track != INVALID_TRACK); - return AIObject::DoCommand(tile, track, 0, CMD_REMOVE_SIGNALS); + return ScriptObject::DoCommand(tile, track, 0, CMD_REMOVE_SIGNALS); } -/* static */ Money AIRail::GetBuildCost(RailType railtype, BuildType build_type) +/* static */ Money ScriptRail::GetBuildCost(RailType railtype, BuildType build_type) { - if (!AIRail::IsRailTypeAvailable(railtype)) return -1; + if (!ScriptRail::IsRailTypeAvailable(railtype)) return -1; switch (build_type) { case BT_TRACK: return ::RailBuildCost((::RailType)railtype); @@ -486,9 +486,9 @@ static bool IsValidSignalType(int signal_type) } } -/* static */ int32 AIRail::GetMaxSpeed(RailType railtype) +/* static */ int32 ScriptRail::GetMaxSpeed(RailType railtype) { - if (!AIRail::IsRailTypeAvailable(railtype)) return -1; + if (!ScriptRail::IsRailTypeAvailable(railtype)) return -1; return ::GetRailTypeInfo((::RailType)railtype)->max_speed; } diff --git a/src/script/api/script_rail.hpp b/src/script/api/script_rail.hpp index 57b0fa42b..0fac99a74 100644 --- a/src/script/api/script_rail.hpp +++ b/src/script/api/script_rail.hpp @@ -17,14 +17,14 @@ /** * Class that handles all rail related functions. */ -class AIRail : public AIObject { +class ScriptRail : public ScriptObject { public: /** * All rail related error messages. */ enum ErrorMessages { /** Base for rail building / maintaining errors */ - ERR_RAIL_BASE = AIError::ERR_CAT_RAIL << AIError::ERR_CAT_BIT_SIZE, + ERR_RAIL_BASE = ScriptError::ERR_CAT_RAIL << ScriptError::ERR_CAT_BIT_SIZE, /** One-way roads cannot have crossings */ ERR_CROSSING_ON_ONEWAY_ROAD, // [STR_ERROR_CROSSING_ON_ONEWAY_ROAD] @@ -105,7 +105,7 @@ public: * used to traverse a tile. This excludes rail depots but includes * stations and waypoints. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has rail. */ static bool IsRailTile(TileIndex tile); @@ -120,7 +120,7 @@ public: /** * Checks whether the given tile is actually a tile with a rail depot. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a rail depot. */ static bool IsRailDepotTile(TileIndex tile); @@ -128,7 +128,7 @@ public: /** * Checks whether the given tile is actually a tile with a rail station. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a rail station. */ static bool IsRailStationTile(TileIndex tile); @@ -136,7 +136,7 @@ public: /** * Checks whether the given tile is actually a tile with a rail waypoint. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a rail waypoint. */ static bool IsRailWaypointTile(TileIndex tile); @@ -149,13 +149,13 @@ public: static bool IsRailTypeAvailable(RailType rail_type); /** - * Get the current RailType set for all AIRail functions. + * Get the current RailType set for all ScriptRail functions. * @return The RailType currently set. */ static RailType GetCurrentRailType(); /** - * Set the RailType for all further AIRail functions. + * Set the RailType for all further ScriptRail functions. * @param rail_type The RailType to set. */ static void SetCurrentRailType(RailType rail_type); @@ -164,28 +164,28 @@ public: * Check if a train build for a rail type can run on another rail type. * @param engine_rail_type The rail type the train is build for. * @param track_rail_type The type you want to check. - * @pre AIRail::IsRailTypeAvailable(engine_rail_type). - * @pre AIRail::IsRailTypeAvailable(track_rail_type). + * @pre ScriptRail::IsRailTypeAvailable(engine_rail_type). + * @pre ScriptRail::IsRailTypeAvailable(track_rail_type). * @return Whether a train build for 'engine_rail_type' can run on 'track_rail_type'. * @note Even if a train can run on a RailType that doesn't mean that it'll be * able to power the train. Use TrainHasPowerOnRail for that. */ - static bool TrainCanRunOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type); + static bool TrainCanRunOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type); /** * Check if a train build for a rail type has power on another rail type. * @param engine_rail_type The rail type the train is build for. * @param track_rail_type The type you want to check. - * @pre AIRail::IsRailTypeAvailable(engine_rail_type). - * @pre AIRail::IsRailTypeAvailable(track_rail_type). + * @pre ScriptRail::IsRailTypeAvailable(engine_rail_type). + * @pre ScriptRail::IsRailTypeAvailable(track_rail_type). * @return Whether a train build for 'engine_rail_type' has power on 'track_rail_type'. */ - static bool TrainHasPowerOnRail(AIRail::RailType engine_rail_type, AIRail::RailType track_rail_type); + static bool TrainHasPowerOnRail(ScriptRail::RailType engine_rail_type, ScriptRail::RailType track_rail_type); /** * Get the RailType that is used on a tile. * @param tile The tile to check. - * @pre AITile::HasTransportType(tile, AITile.TRANSPORT_RAIL). + * @pre ScriptTile::HasTransportType(tile, ScriptTile.TRANSPORT_RAIL). * @return The RailType that is used on a tile. */ static RailType GetRailType(TileIndex tile); @@ -195,13 +195,13 @@ public: * @param start_tile One corner of the rectangle. * @param end_tile The opposite corner of the rectangle. * @param convert_to The RailType you want to convert the rails to. - * @pre AIMap::IsValidTile(start_tile). - * @pre AIMap::IsValidTile(end_tile). + * @pre ScriptMap::IsValidTile(start_tile). + * @pre ScriptMap::IsValidTile(end_tile). * @pre IsRailTypeAvailable(convert_to). - * @exception AIRail::ERR_UNSUITABLE_TRACK + * @exception ScriptRail::ERR_UNSUITABLE_TRACK * @return Whether at least some rail has been converted successfully. */ - static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, AIRail::RailType convert_to); + static bool ConvertRailType(TileIndex start_tile, TileIndex end_tile, ScriptRail::RailType convert_to); /** * Gets the tile in front of a rail depot. @@ -223,12 +223,12 @@ public: * Builds a rail depot. * @param tile Place to build the depot. * @param front The tile exactly in front of the depot. - * @pre AIMap::IsValidTile(tile). - * @pre AIMap::IsValidTile(front). + * @pre ScriptMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(front). * @pre 'tile' is not equal to 'front', but in a straight line of it. * @pre IsRailTypeAvailable(GetCurrentRailType()). - * @exception AIError::ERR_FLAT_LAND_REQUIRED - * @exception AIError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptError::ERR_AREA_NOT_CLEAR * @return Whether the rail depot has been/can be build or not. */ static bool BuildRailDepot(TileIndex tile, TileIndex front); @@ -239,19 +239,19 @@ public: * @param direction The direction to build the station. * @param num_platforms The number of platforms to build. * @param platform_length The length of each platform. - * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. + * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. * @pre IsRailTypeAvailable(GetCurrentRailType()). - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW. * @pre num_platforms > 0 && num_platforms <= 255. * @pre platform_length > 0 && platform_length <= 255. - * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_FLAT_LAND_REQUIRED - * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN + * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN * @return Whether the station has been/can be build or not. */ static bool BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id); @@ -264,27 +264,27 @@ public: * @param direction The direction to build the station. * @param num_platforms The number of platforms to build. * @param platform_length The length of each platform. - * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. + * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. * @param cargo_id The CargoID of the cargo that will be transported from / to this station. - * @param source_industry The IndustryType of the industry you'll transport goods from, AIIndustryType::INDUSTRYTYPE_UNKNOWN or AIIndustryType::INDUSTRYTYPE_TOWN. - * @param goal_industry The IndustryType of the industry you'll transport goods to, AIIndustryType::INDUSTRYTYPE_UNKNOWN or AIIndustryType::INDUSTRYTYPE_TOWN. + * @param source_industry The IndustryType of the industry you'll transport goods from, ScriptIndustryType::INDUSTRYTYPE_UNKNOWN or ScriptIndustryType::INDUSTRYTYPE_TOWN. + * @param goal_industry The IndustryType of the industry you'll transport goods to, ScriptIndustryType::INDUSTRYTYPE_UNKNOWN or ScriptIndustryType::INDUSTRYTYPE_TOWN. * @param distance The manhattan distance you'll transport the cargo over. * @param source_station True if this is the source station, false otherwise. * @pre IsRailTypeAvailable(GetCurrentRailType()). - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre direction == RAILTRACK_NW_SE || direction == RAILTRACK_NE_SW. * @pre num_platforms > 0 && num_platforms <= 255. * @pre platform_length > 0 && platform_length <= 255. - * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). - * @pre AICargo::IsValidCargo(cargo_type) - * @pre source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry). - * @pre goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_FLAT_LAND_REQUIRED - * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN + * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). + * @pre ScriptCargo::IsValidCargo(cargo_type) + * @pre source_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(source_industry). + * @pre goal_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(goal_industry). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN * @return Whether the station has been/can be build or not. */ static bool BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station); @@ -292,11 +292,11 @@ public: /** * Build a rail waypoint. * @param tile Place to build the waypoint. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre IsRailTile(tile). * @pre GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE. * @pre IsRailTypeAvailable(GetCurrentRailType()). - * @exception AIError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED * @return Whether the rail waypoint has been/can be build or not. */ static bool BuildRailWaypoint(TileIndex tile); @@ -336,13 +336,13 @@ public: * Build rail on the given tile. * @param tile The tile to build on. * @param rail_track The RailTrack to build. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre IsRailTypeAvailable(GetCurrentRailType()). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS - * @exception AIRail::ERR_CROSSING_ON_ONEWAY_ROAD - * @exception AIError::ERR_ALREADY_BUILT + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptRail::ERR_CROSSING_ON_ONEWAY_ROAD + * @exception ScriptError::ERR_ALREADY_BUILT * @return Whether the rail has been/can be build or not. * @note You can only build a single track with this function so do not * use the values from RailTrack as bitmask. @@ -353,7 +353,7 @@ public: * Remove rail on the given tile. * @param tile The tile to remove rail from. * @param rail_track The RailTrack to remove. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre (GetRailTracks(tile) & rail_track) != 0. * @return Whether the rail has been/can be removed or not. * @note You can only remove a single track with this function so do not @@ -367,8 +367,8 @@ public: * @param tile The tile that is checked. * @param to The second tile to connect. * @pre from != to. - * @pre AIMap::DistanceManhattan(from, tile) == 1. - * @pre AIMap::DistanceManhattan(to, tile) == 1. + * @pre ScriptMap::DistanceManhattan(from, tile) == 1. + * @pre ScriptMap::DistanceManhattan(to, tile) == 1. * @return True if 'tile' connects 'from' and 'to'. */ static bool AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to); @@ -379,18 +379,18 @@ public: * @param tile The first tile to build on. * @param to The tile just after the last tile to build on. * @pre from != to. - * @pre AIMap::DistanceManhattan(from, tile) == 1. - * @pre AIMap::DistanceManhattan(to, tile) >= 1. - * @pre (abs(abs(AIMap::GetTileX(to) - AIMap::GetTileX(tile)) - - * abs(AIMap::GetTileY(to) - AIMap::GetTileY(tile))) <= 1) || - * (AIMap::GetTileX(from) == AIMap::GetTileX(tile) && AIMap::GetTileX(tile) == AIMap::GetTileX(to)) || - * (AIMap::GetTileY(from) == AIMap::GetTileY(tile) && AIMap::GetTileY(tile) == AIMap::GetTileY(to)). + * @pre ScriptMap::DistanceManhattan(from, tile) == 1. + * @pre ScriptMap::DistanceManhattan(to, tile) >= 1. + * @pre (abs(abs(ScriptMap::GetTileX(to) - ScriptMap::GetTileX(tile)) - + * abs(ScriptMap::GetTileY(to) - ScriptMap::GetTileY(tile))) <= 1) || + * (ScriptMap::GetTileX(from) == ScriptMap::GetTileX(tile) && ScriptMap::GetTileX(tile) == ScriptMap::GetTileX(to)) || + * (ScriptMap::GetTileY(from) == ScriptMap::GetTileY(tile) && ScriptMap::GetTileY(tile) == ScriptMap::GetTileY(to)). * @pre IsRailTypeAvailable(GetCurrentRailType()). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIRail::ERR_CROSSING_ON_ONEWAY_ROAD - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS - * @exception AIError::ERR_ALREADY_BUILT + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptRail::ERR_CROSSING_ON_ONEWAY_ROAD + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptError::ERR_ALREADY_BUILT * @note Construction will fail if an obstacle is found between the start and end tiles. * @return Whether the rail has been/can be build or not. */ @@ -402,19 +402,19 @@ public: * @param tile The first tile to remove rail from. * @param to The tile just after the last tile to remove rail from. * @pre from != to. - * @pre AIMap::DistanceManhattan(from, tile) == 1. - * @pre AIMap::DistanceManhattan(to, tile) >= 1. - * @pre (abs(abs(AIMap::GetTileX(to) - AIMap::GetTileX(tile)) - - * abs(AIMap::GetTileY(to) - AIMap::GetTileY(tile))) <= 1) || - * (AIMap::GetTileX(from) == AIMap::GetTileX(tile) && AIMap::GetTileX(tile) == AIMap::GetTileX(to)) || - * (AIMap::GetTileY(from) == AIMap::GetTileY(tile) && AIMap::GetTileY(tile) == AIMap::GetTileY(to)). + * @pre ScriptMap::DistanceManhattan(from, tile) == 1. + * @pre ScriptMap::DistanceManhattan(to, tile) >= 1. + * @pre (abs(abs(ScriptMap::GetTileX(to) - ScriptMap::GetTileX(tile)) - + * abs(ScriptMap::GetTileY(to) - ScriptMap::GetTileY(tile))) <= 1) || + * (ScriptMap::GetTileX(from) == ScriptMap::GetTileX(tile) && ScriptMap::GetTileX(tile) == ScriptMap::GetTileX(to)) || + * (ScriptMap::GetTileY(from) == ScriptMap::GetTileY(tile) && ScriptMap::GetTileY(tile) == ScriptMap::GetTileY(to)). * @return Whether the rail has been/can be removed or not. */ static bool RemoveRail(TileIndex from, TileIndex tile, TileIndex to); /** * Get the SignalType of the signal on a tile or SIGNALTYPE_NONE if there is no signal. - * @pre AIMap::DistanceManhattan(tile, front) == 1. + * @pre ScriptMap::DistanceManhattan(tile, front) == 1. * @param tile The tile that might have a signal. * @param front The tile in front of 'tile'. * @return The SignalType of the signal on 'tile' facing to 'front'. @@ -426,9 +426,9 @@ public: * @param tile The tile to build on. * @param front The tile in front of the signal. * @param signal The SignalType to build. - * @pre AIMap::DistanceManhattan(tile, front) == 1. + * @pre ScriptMap::DistanceManhattan(tile, front) == 1. * @pre IsRailTile(tile) && !IsRailStationTile(tile) && !IsRailWaypointTile(tile). - * @exception AIRail::ERR_UNSUITABLE_TRACK + * @exception ScriptRail::ERR_UNSUITABLE_TRACK * @return Whether the signal has been/can be build or not. */ static bool BuildSignal(TileIndex tile, TileIndex front, SignalType signal); @@ -437,7 +437,7 @@ public: * Remove a signal. * @param tile The tile to remove the signal from. * @param front The tile in front of the signal. - * @pre AIMap::DistanceManhattan(tile, front) == 1. + * @pre ScriptMap::DistanceManhattan(tile, front) == 1. * @pre GetSignalType(tile, front) != SIGNALTYPE_NONE. * @return Whether the signal has been/can be removed or not. */ diff --git a/src/script/api/script_railtypelist.cpp b/src/script/api/script_railtypelist.cpp index 7052f7551..4f0f1d62b 100644 --- a/src/script/api/script_railtypelist.cpp +++ b/src/script/api/script_railtypelist.cpp @@ -7,14 +7,14 @@ * 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 script_railtypelist.cpp Implementation of AIRailTypeList and friends. */ +/** @file script_railtypelist.cpp Implementation of ScriptRailTypeList and friends. */ #include "../../stdafx.h" #include "script_railtypelist.hpp" #include "../../rail.h" #include "../../company_func.h" -AIRailTypeList::AIRailTypeList() +ScriptRailTypeList::ScriptRailTypeList() { for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { if (::HasRailtypeAvail(_current_company, rt)) this->AddItem(rt); diff --git a/src/script/api/script_railtypelist.hpp b/src/script/api/script_railtypelist.hpp index fcc7595cf..7a662e2fd 100644 --- a/src/script/api/script_railtypelist.hpp +++ b/src/script/api/script_railtypelist.hpp @@ -16,11 +16,11 @@ /** * Creates a list of all available railtypes. - * @ingroup AIList + * @ingroup ScriptList */ -class AIRailTypeList : public AIList { +class ScriptRailTypeList : public ScriptList { public: - AIRailTypeList(); + ScriptRailTypeList(); }; #endif /* SCRIPT_RAILTYPELIST_HPP */ diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp index a60f99480..06991e5ac 100644 --- a/src/script/api/script_road.cpp +++ b/src/script/api/script_road.cpp @@ -7,7 +7,7 @@ * 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 script_road.cpp Implementation of AIRoad. */ +/** @file script_road.cpp Implementation of ScriptRoad. */ #include "../../stdafx.h" #include "script_map.hpp" @@ -17,12 +17,12 @@ #include "../../company_func.h" #include "../../script/squirrel_helper_type.hpp" -/* static */ AIRoad::RoadVehicleType AIRoad::GetRoadVehicleTypeForCargo(CargoID cargo_type) +/* static */ ScriptRoad::RoadVehicleType ScriptRoad::GetRoadVehicleTypeForCargo(CargoID cargo_type) { - return AICargo::HasCargoClass(cargo_type, AICargo::CC_PASSENGERS) ? ROADVEHTYPE_BUS : ROADVEHTYPE_TRUCK; + return ScriptCargo::HasCargoClass(cargo_type, ScriptCargo::CC_PASSENGERS) ? ROADVEHTYPE_BUS : ROADVEHTYPE_TRUCK; } -/* static */ bool AIRoad::IsRoadTile(TileIndex tile) +/* static */ bool ScriptRoad::IsRoadTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; @@ -30,7 +30,7 @@ IsDriveThroughRoadStationTile(tile); } -/* static */ bool AIRoad::IsRoadDepotTile(TileIndex tile) +/* static */ bool ScriptRoad::IsRoadDepotTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; @@ -38,45 +38,45 @@ (::RoadTypeToRoadTypes((::RoadType)GetCurrentRoadType()) & ::GetRoadTypes(tile)) != 0; } -/* static */ bool AIRoad::IsRoadStationTile(TileIndex tile) +/* static */ bool ScriptRoad::IsRoadStationTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsRoadStopTile(tile) && (::RoadTypeToRoadTypes((::RoadType)GetCurrentRoadType()) & ::GetRoadTypes(tile)) != 0; } -/* static */ bool AIRoad::IsDriveThroughRoadStationTile(TileIndex tile) +/* static */ bool ScriptRoad::IsDriveThroughRoadStationTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsDriveThroughStopTile(tile) && (::RoadTypeToRoadTypes((::RoadType)GetCurrentRoadType()) & ::GetRoadTypes(tile)) != 0; } -/* static */ bool AIRoad::IsRoadTypeAvailable(RoadType road_type) +/* static */ bool ScriptRoad::IsRoadTypeAvailable(RoadType road_type) { return ::HasRoadTypesAvail(_current_company, ::RoadTypeToRoadTypes((::RoadType)road_type)); } -/* static */ AIRoad::RoadType AIRoad::GetCurrentRoadType() +/* static */ ScriptRoad::RoadType ScriptRoad::GetCurrentRoadType() { - return (RoadType)AIObject::GetRoadType(); + return (RoadType)ScriptObject::GetRoadType(); } -/* static */ void AIRoad::SetCurrentRoadType(RoadType road_type) +/* static */ void ScriptRoad::SetCurrentRoadType(RoadType road_type) { if (!IsRoadTypeAvailable(road_type)) return; - AIObject::SetRoadType((::RoadType)road_type); + ScriptObject::SetRoadType((::RoadType)road_type); } -/* static */ bool AIRoad::HasRoadType(TileIndex tile, RoadType road_type) +/* static */ bool ScriptRoad::HasRoadType(TileIndex tile, RoadType road_type) { - if (!AIMap::IsValidTile(tile)) return false; + if (!ScriptMap::IsValidTile(tile)) return false; if (!IsRoadTypeAvailable(road_type)) return false; return ::GetAnyRoadBits(tile, (::RoadType)road_type, false) != ROAD_NONE; } -/* static */ bool AIRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2) +/* static */ bool ScriptRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1)) return false; if (!::IsValidTile(t2)) return false; @@ -85,8 +85,8 @@ /* Tiles not neighbouring */ if ((abs((int)::TileX(t1) - (int)::TileX(t2)) + abs((int)::TileY(t1) - (int)::TileY(t2))) != 1) return false; - RoadBits r1 = ::GetAnyRoadBits(t1, AIObject::GetRoadType()); - RoadBits r2 = ::GetAnyRoadBits(t2, AIObject::GetRoadType()); + RoadBits r1 = ::GetAnyRoadBits(t1, ScriptObject::GetRoadType()); + RoadBits r2 = ::GetAnyRoadBits(t2, ScriptObject::GetRoadType()); uint dir_1 = (::TileX(t1) == ::TileX(t2)) ? (::TileY(t1) < ::TileY(t2) ? 2 : 0) : (::TileX(t1) < ::TileX(t2) ? 1 : 3); uint dir_2 = 2 ^ dir_1; @@ -96,7 +96,7 @@ return HasBit(r1, dir_1) && HasBit(r2, dir_2) && drd2 != DRD_BOTH && drd2 != (dir_1 > dir_2 ? DRD_SOUTHBOUND : DRD_NORTHBOUND); } -/* Helper functions for AIRoad::CanBuildConnectedRoadParts(). */ +/* Helper functions for ScriptRoad::CanBuildConnectedRoadParts(). */ /** * Check whether the given existing bits the start and end part can be build. @@ -341,7 +341,7 @@ static bool NormaliseTileOffset(int32 *tile) return false; } -/* static */ int32 AIRoad::CanBuildConnectedRoadParts(AITile::Slope slope_, Array *existing, TileIndex start_, TileIndex end_) +/* static */ int32 ScriptRoad::CanBuildConnectedRoadParts(ScriptTile::Slope slope_, Array *existing, TileIndex start_, TileIndex end_) { ::Slope slope = (::Slope)slope_; int32 start = start_; @@ -362,7 +362,7 @@ static bool NormaliseTileOffset(int32 *tile) return _settings_game.construction.build_on_slopes ? LookupWithBuildOnSlopes(slope, existing, start, end) : LookupWithoutBuildOnSlopes(slope, existing, start, end); } -/* static */ int32 AIRoad::CanBuildConnectedRoadPartsHere(TileIndex tile, TileIndex start, TileIndex end) +/* static */ int32 ScriptRoad::CanBuildConnectedRoadPartsHere(TileIndex tile, TileIndex start, TileIndex end) { if (!::IsValidTile(tile) || !::IsValidTile(start) || !::IsValidTile(end)) return -1; if (::DistanceManhattan(tile, start) != 1 || ::DistanceManhattan(tile, end) != 1) return -1; @@ -382,7 +382,7 @@ static bool NormaliseTileOffset(int32 *tile) if (HasBit(rb, i)) existing->array[existing->size++] = neighbours[i]; } - return AIRoad::CanBuildConnectedRoadParts(AITile::GetSlope(tile), existing, start - tile, end - tile); + return ScriptRoad::CanBuildConnectedRoadParts(ScriptTile::GetSlope(tile), existing, start - tile, end - tile); } /** @@ -413,7 +413,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia } } -/* static */ int32 AIRoad::GetNeighbourRoadCount(TileIndex tile) +/* static */ int32 ScriptRoad::GetNeighbourRoadCount(TileIndex tile) { if (!::IsValidTile(tile)) return false; if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false; @@ -429,60 +429,60 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia return neighbour; } -/* static */ TileIndex AIRoad::GetRoadDepotFrontTile(TileIndex depot) +/* static */ TileIndex ScriptRoad::GetRoadDepotFrontTile(TileIndex depot) { if (!IsRoadDepotTile(depot)) return INVALID_TILE; return depot + ::TileOffsByDiagDir(::GetRoadDepotDirection(depot)); } -/* static */ TileIndex AIRoad::GetRoadStationFrontTile(TileIndex station) +/* static */ TileIndex ScriptRoad::GetRoadStationFrontTile(TileIndex station) { if (!IsRoadStationTile(station)) return INVALID_TILE; return station + ::TileOffsByDiagDir(::GetRoadStopDir(station)); } -/* static */ TileIndex AIRoad::GetDriveThroughBackTile(TileIndex station) +/* static */ TileIndex ScriptRoad::GetDriveThroughBackTile(TileIndex station) { if (!IsDriveThroughRoadStationTile(station)) return INVALID_TILE; return station + ::TileOffsByDiagDir(::ReverseDiagDir(::GetRoadStopDir(station))); } -/* static */ bool AIRoad::_BuildRoadInternal(TileIndex start, TileIndex end, bool one_way, bool full) +/* static */ bool ScriptRoad::_BuildRoadInternal(TileIndex start, TileIndex end, bool one_way, bool full) { EnforcePrecondition(false, start != end); EnforcePrecondition(false, ::IsValidTile(start)); EnforcePrecondition(false, ::IsValidTile(end)); EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end)); - EnforcePrecondition(false, !one_way || AIObject::GetRoadType() == ::ROADTYPE_ROAD); + EnforcePrecondition(false, !one_way || ScriptObject::GetRoadType() == ::ROADTYPE_ROAD); EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); - return AIObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (AIObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 5) | 1 << 6, CMD_BUILD_LONG_ROAD); + return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (ScriptObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 5) | 1 << 6, CMD_BUILD_LONG_ROAD); } -/* static */ bool AIRoad::BuildRoad(TileIndex start, TileIndex end) +/* static */ bool ScriptRoad::BuildRoad(TileIndex start, TileIndex end) { return _BuildRoadInternal(start, end, false, false); } -/* static */ bool AIRoad::BuildOneWayRoad(TileIndex start, TileIndex end) +/* static */ bool ScriptRoad::BuildOneWayRoad(TileIndex start, TileIndex end) { return _BuildRoadInternal(start, end, true, false); } -/* static */ bool AIRoad::BuildRoadFull(TileIndex start, TileIndex end) +/* static */ bool ScriptRoad::BuildRoadFull(TileIndex start, TileIndex end) { return _BuildRoadInternal(start, end, false, true); } -/* static */ bool AIRoad::BuildOneWayRoadFull(TileIndex start, TileIndex end) +/* static */ bool ScriptRoad::BuildOneWayRoadFull(TileIndex start, TileIndex end) { return _BuildRoadInternal(start, end, true, true); } -/* static */ bool AIRoad::BuildRoadDepot(TileIndex tile, TileIndex front) +/* static */ bool ScriptRoad::BuildRoadDepot(TileIndex tile, TileIndex front) { EnforcePrecondition(false, tile != front); EnforcePrecondition(false, ::IsValidTile(tile)); @@ -492,16 +492,16 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0); - return AIObject::DoCommand(tile, entrance_dir | (AIObject::GetRoadType() << 2), 0, CMD_BUILD_ROAD_DEPOT); + return ScriptObject::DoCommand(tile, entrance_dir | (ScriptObject::GetRoadType() << 2), 0, CMD_BUILD_ROAD_DEPOT); } -/* static */ bool AIRoad::_BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id) +/* static */ bool ScriptRoad::_BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id) { EnforcePrecondition(false, tile != front); EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsValidTile(front)); EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front)); - EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); + EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); EnforcePrecondition(false, road_veh_type == ROADVEHTYPE_BUS || road_veh_type == ROADVEHTYPE_TRUCK); EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); @@ -512,66 +512,66 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0); } - uint p2 = station_id == AIStation::STATION_JOIN_ADJACENT ? 0 : 32; + uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 32; p2 |= drive_through ? 2 : 0; p2 |= road_veh_type == ROADVEHTYPE_TRUCK ? 1 : 0; - p2 |= ::RoadTypeToRoadTypes(AIObject::GetRoadType()) << 2; + p2 |= ::RoadTypeToRoadTypes(ScriptObject::GetRoadType()) << 2; p2 |= entrance_dir << 6; - p2 |= (AIStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; - return AIObject::DoCommand(tile, 1 | 1 << 8, p2, CMD_BUILD_ROAD_STOP); + p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16; + return ScriptObject::DoCommand(tile, 1 | 1 << 8, p2, CMD_BUILD_ROAD_STOP); } -/* static */ bool AIRoad::BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id) +/* static */ bool ScriptRoad::BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id) { return _BuildRoadStationInternal(tile, front, road_veh_type, false, station_id); } -/* static */ bool AIRoad::BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id) +/* static */ bool ScriptRoad::BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id) { return _BuildRoadStationInternal(tile, front, road_veh_type, true, station_id); } -/* static */ bool AIRoad::RemoveRoad(TileIndex start, TileIndex end) +/* static */ bool ScriptRoad::RemoveRoad(TileIndex start, TileIndex end) { EnforcePrecondition(false, ::IsValidTile(start)); EnforcePrecondition(false, ::IsValidTile(end)); EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end)); EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); - return AIObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD); + return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ScriptObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD); } -/* static */ bool AIRoad::RemoveRoadFull(TileIndex start, TileIndex end) +/* static */ bool ScriptRoad::RemoveRoadFull(TileIndex start, TileIndex end) { EnforcePrecondition(false, ::IsValidTile(start)); EnforcePrecondition(false, ::IsValidTile(end)); EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end)); EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType())); - return AIObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD); + return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (ScriptObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD); } -/* static */ bool AIRoad::RemoveRoadDepot(TileIndex tile) +/* static */ bool ScriptRoad::RemoveRoadDepot(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsTileType(tile, MP_ROAD)) EnforcePrecondition(false, GetRoadTileType(tile) == ROAD_TILE_DEPOT); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ bool AIRoad::RemoveRoadStation(TileIndex tile) +/* static */ bool ScriptRoad::RemoveRoadStation(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, IsTileType(tile, MP_STATION)); EnforcePrecondition(false, IsRoadStop(tile)); - return AIObject::DoCommand(tile, 1 | 1 << 8, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP); + return ScriptObject::DoCommand(tile, 1 | 1 << 8, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP); } -/* static */ Money AIRoad::GetBuildCost(RoadType roadtype, BuildType build_type) +/* static */ Money ScriptRoad::GetBuildCost(RoadType roadtype, BuildType build_type) { - if (!AIRoad::IsRoadTypeAvailable(roadtype)) return -1; + if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return -1; switch (build_type) { case BT_ROAD: return ::GetPrice(PR_BUILD_ROAD, 1, NULL); diff --git a/src/script/api/script_road.hpp b/src/script/api/script_road.hpp index 8e6757499..87a049929 100644 --- a/src/script/api/script_road.hpp +++ b/src/script/api/script_road.hpp @@ -17,14 +17,14 @@ /** * Class that handles all road related functions. */ -class AIRoad : public AIObject { +class ScriptRoad : public ScriptObject { public: /** * All road related error messages. */ enum ErrorMessages { /** Base for road building / maintaining errors */ - ERR_ROAD_BASE = AIError::ERR_CAT_ROAD << AIError::ERR_CAT_BIT_SIZE, + ERR_ROAD_BASE = ScriptError::ERR_CAT_ROAD << ScriptError::ERR_CAT_BIT_SIZE, /** Road works are in progress */ ERR_ROAD_WORKS_IN_PROGRESS, // [STR_ERROR_ROAD_WORKS_IN_PROGRESS] @@ -72,7 +72,7 @@ public: /** * Determines whether a busstop or a truckstop is needed to transport a certain cargo. * @param cargo_type The cargo to test. - * @pre AICargo::IsValidCargo(cargo_type). + * @pre ScriptCargo::IsValidCargo(cargo_type). * @return The road vehicle type needed to transport the cargo. */ static RoadVehicleType GetRoadVehicleTypeForCargo(CargoID cargo_type); @@ -82,7 +82,7 @@ public: * used to traverse a tile. This excludes road depots and 'normal' road * stations, but includes drive through stations. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has road. */ static bool IsRoadTile(TileIndex tile); @@ -90,7 +90,7 @@ public: /** * Checks whether the given tile is actually a tile with a road depot. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a road depot. */ static bool IsRoadDepotTile(TileIndex tile); @@ -98,7 +98,7 @@ public: /** * Checks whether the given tile is actually a tile with a road station. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a road station. */ static bool IsRoadStationTile(TileIndex tile); @@ -107,7 +107,7 @@ public: * Checks whether the given tile is actually a tile with a drive through * road station. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile has a drive through road station. */ static bool IsDriveThroughRoadStationTile(TileIndex tile); @@ -120,13 +120,13 @@ public: static bool IsRoadTypeAvailable(RoadType road_type); /** - * Get the current RoadType set for all AIRoad functions. + * Get the current RoadType set for all ScriptRoad functions. * @return The RoadType currently set. */ static RoadType GetCurrentRoadType(); /** - * Set the RoadType for all further AIRoad functions. + * Set the RoadType for all further ScriptRoad functions. * @param road_type The RoadType to set. */ static void SetCurrentRoadType(RoadType road_type); @@ -135,7 +135,7 @@ public: * Check if a given tile has RoadType. * @param tile The tile to check. * @param road_type The RoadType to check for. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre IsRoadTypeAvailable(road_type). * @return True if the tile contains a RoadType object. */ @@ -148,8 +148,8 @@ public: * @param tile_from The source tile. * @param tile_to The destination tile. * @pre IsRoadTypeAvailable(GetCurrentRoadType()). - * @pre AIMap::IsValidTile(tile_from). - * @pre AIMap::IsValidTile(tile_to). + * @pre ScriptMap::IsValidTile(tile_from). + * @pre ScriptMap::IsValidTile(tile_to). * @pre 'tile_from' and 'tile_to' are directly neighbouring tiles. * @return True if and only if a road vehicle can go from tile_from to tile_to. */ @@ -162,19 +162,19 @@ public: * it needs the slope and existing road parts of the tile as information. * @param slope The slope of the tile to examine. * @param existing An array with the existing neighbours in the same format - * as "start" and "end", e.g. AIMap.GetTileIndex(0, 1). + * as "start" and "end", e.g. ScriptMap.GetTileIndex(0, 1). * As a result of this all values of the existing array * must be of type integer. * @param start The tile from where the 'tile to be considered' will be * entered. This is a relative tile, so valid parameters are: - * AIMap.GetTileIndex(0, 1), AIMap.GetTileIndex(0, -1), - * AIMap.GetTileIndex(1, 0) and AIMap.GetTileIndex(-1, 0). + * ScriptMap.GetTileIndex(0, 1), ScriptMap.GetTileIndex(0, -1), + * ScriptMap.GetTileIndex(1, 0) and ScriptMap.GetTileIndex(-1, 0). * @param end The tile from where the 'tile to be considered' will be * exited. This is a relative tile, sovalid parameters are: - * AIMap.GetTileIndex(0, 1), AIMap.GetTileIndex(0, -1), - * AIMap.GetTileIndex(1, 0) and AIMap.GetTileIndex(-1, 0). + * ScriptMap.GetTileIndex(0, 1), ScriptMap.GetTileIndex(0, -1), + * ScriptMap.GetTileIndex(1, 0) and ScriptMap.GetTileIndex(-1, 0). * @pre start != end. - * @pre slope must be a valid slope, i.e. one specified in AITile::Slope. + * @pre slope must be a valid slope, i.e. one specified in ScriptTile::Slope. * @note Passing data that would be invalid in-game, e.g. existing containing * road parts that can not be build on a tile with the given slope, * does not necessarily means that -1 is returned, i.e. not all @@ -184,7 +184,7 @@ public: * they are build or 2 when building the first part automatically * builds the second part. -1 means the preconditions are not met. */ - static int32 CanBuildConnectedRoadParts(AITile::Slope slope, struct Array *existing, TileIndex start, TileIndex end); + static int32 CanBuildConnectedRoadParts(ScriptTile::Slope slope, struct Array *existing, TileIndex start, TileIndex end); /** * Lookup function for building road parts independend on whether the @@ -196,11 +196,11 @@ public: * @pre start != end. * @pre tile != start. * @pre tile != end. - * @pre AIMap.IsValidTile(tile). - * @pre AIMap.IsValidTile(start). - * @pre AIMap.IsValidTile(end). - * @pre AIMap.GetDistanceManhattanToTile(tile, start) == 1. - * @pre AIMap.GetDistanceManhattanToTile(tile, end) == 1. + * @pre ScriptMap.IsValidTile(tile). + * @pre ScriptMap.IsValidTile(start). + * @pre ScriptMap.IsValidTile(end). + * @pre ScriptMap.GetDistanceManhattanToTile(tile, start) == 1. + * @pre ScriptMap.GetDistanceManhattanToTile(tile, end) == 1. * @return 0 when the build parts do not connect, 1 when they do connect once * they are build or 2 when building the first part automatically * builds the second part. -1 means the preconditions are not met. @@ -210,7 +210,7 @@ public: /** * Count how many neighbours are road. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre IsRoadTypeAvailable(GetCurrentRoadType()). * @return 0 means no neighbour road; max value is 4. */ @@ -247,18 +247,18 @@ public: * @param start The start tile of the road. * @param end The end tile of the road. * @pre 'start' is not equal to 'end'. - * @pre AIMap::IsValidTile(start). - * @pre AIMap::IsValidTile(end). + * @pre ScriptMap::IsValidTile(start). + * @pre ScriptMap::IsValidTile(end). * @pre 'start' and 'end' are in a straight line, i.e. - * AIMap::GetTileX(start) == AIMap::GetTileX(end) or - * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or + * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end). * @pre IsRoadTypeAvailable(GetCurrentRoadType()). - * @exception AIError::ERR_ALREADY_BUILT - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS - * @exception AIError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptError::ERR_ALREADY_BUILT + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY * @note Construction will fail if an obstacle is found between the start and end tiles. * @return Whether the road has been/can be build or not. */ @@ -274,18 +274,18 @@ public: * @param start The start tile of the road. * @param end The end tile of the road. * @pre 'start' is not equal to 'end'. - * @pre AIMap::IsValidTile(start). - * @pre AIMap::IsValidTile(end). + * @pre ScriptMap::IsValidTile(start). + * @pre ScriptMap::IsValidTile(end). * @pre 'start' and 'end' are in a straight line, i.e. - * AIMap::GetTileX(start) == AIMap::GetTileX(end) or - * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or + * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end). * @pre GetCurrentRoadType() == ROADTYPE_ROAD. - * @exception AIError::ERR_ALREADY_BUILT - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS - * @exception AIError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptError::ERR_ALREADY_BUILT + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY * @note Construction will fail if an obstacle is found between the start and end tiles. * @return Whether the road has been/can be build or not. */ @@ -297,18 +297,18 @@ public: * @param start The start tile of the road. * @param end The end tile of the road. * @pre 'start' is not equal to 'end'. - * @pre AIMap::IsValidTile(start). - * @pre AIMap::IsValidTile(end). + * @pre ScriptMap::IsValidTile(start). + * @pre ScriptMap::IsValidTile(end). * @pre 'start' and 'end' are in a straight line, i.e. - * AIMap::GetTileX(start) == AIMap::GetTileX(end) or - * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or + * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end). * @pre IsRoadTypeAvailable(GetCurrentRoadType()). - * @exception AIError::ERR_ALREADY_BUILT - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS - * @exception AIError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptError::ERR_ALREADY_BUILT + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY * @note Construction will fail if an obstacle is found between the start and end tiles. * @return Whether the road has been/can be build or not. */ @@ -325,18 +325,18 @@ public: * @param start The start tile of the road. * @param end The end tile of the road. * @pre 'start' is not equal to 'end'. - * @pre AIMap::IsValidTile(start). - * @pre AIMap::IsValidTile(end). + * @pre ScriptMap::IsValidTile(start). + * @pre ScriptMap::IsValidTile(end). * @pre 'start' and 'end' are in a straight line, i.e. - * AIMap::GetTileX(start) == AIMap::GetTileX(end) or - * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or + * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end). * @pre GetCurrentRoadType() == ROADTYPE_ROAD. - * @exception AIError::ERR_ALREADY_BUILT - * @exception AIError::ERR_LAND_SLOPED_WRONG - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS - * @exception AIError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptError::ERR_ALREADY_BUILT + * @exception ScriptError::ERR_LAND_SLOPED_WRONG + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY * @note Construction will fail if an obstacle is found between the start and end tiles. * @return Whether the road has been/can be build or not. */ @@ -346,12 +346,12 @@ public: * Builds a road depot. * @param tile Place to build the depot. * @param front The tile exactly in front of the depot. - * @pre AIMap::IsValidTile(tile). - * @pre AIMap::IsValidTile(front). + * @pre ScriptMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(front). * @pre 'tile' is not equal to 'front', but in a straight line of it. * @pre IsRoadTypeAvailable(GetCurrentRoadType()). - * @exception AIError::ERR_FLAT_LAND_REQUIRED - * @exception AIError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptError::ERR_AREA_NOT_CLEAR * @return Whether the road depot has been/can be build or not. */ static bool BuildRoadDepot(TileIndex tile, TileIndex front); @@ -361,21 +361,21 @@ public: * @param tile Place to build the station. * @param front The tile exactly in front of the station. * @param road_veh_type Whether to build a truck or bus station. - * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. - * @pre AIMap::IsValidTile(tile). - * @pre AIMap::IsValidTile(front). + * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. + * @pre ScriptMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(front). * @pre 'tile' is not equal to 'front', but in a straight line of it. - * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). + * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). * @pre GetCurrentRoadType() == ROADTYPE_ROAD. - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_FLAT_LAND_REQUIRED - * @exception AIRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION - * @exception AIRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD - * @exception AIError::ERR_VEHICLE_IN_THE_WAY - * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION + * @exception ScriptRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN * @return Whether the station has been/can be build or not. */ static bool BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id); @@ -385,21 +385,21 @@ public: * @param tile Place to build the station. * @param front A tile on the same axis with 'tile' as the station shall be oriented. * @param road_veh_type Whether to build a truck or bus station. - * @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT. - * @pre AIMap::IsValidTile(tile). - * @pre AIMap::IsValidTile(front). + * @param station_id The station to join, ScriptStation::STATION_NEW or ScriptStation::STATION_JOIN_ADJACENT. + * @pre ScriptMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(front). * @pre 'tile' is not equal to 'front', but in a straight line of it. - * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). + * @pre station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id). * @pre IsRoadTypeAvailable(GetCurrentRoadType()). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_FLAT_LAND_REQUIRED - * @exception AIRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION - * @exception AIRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD - * @exception AIError::ERR_VEHICLE_IN_THE_WAY - * @exception AIStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS - * @exception AIStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_FLAT_LAND_REQUIRED + * @exception ScriptRoad::ERR_ROAD_DRIVE_THROUGH_WRONG_DIRECTION + * @exception ScriptRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptStation::ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS + * @exception ScriptStation::ERR_STATION_TOO_MANY_STATIONS_IN_TOWN * @return Whether the station has been/can be build or not. */ static bool BuildDriveThroughRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id); @@ -408,15 +408,15 @@ public: * Removes a road from the center of tile start to the center of tile end. * @param start The start tile of the road. * @param end The end tile of the road. - * @pre AIMap::IsValidTile(start). - * @pre AIMap::IsValidTile(end). + * @pre ScriptMap::IsValidTile(start). + * @pre ScriptMap::IsValidTile(end). * @pre 'start' and 'end' are in a straight line, i.e. - * AIMap::GetTileX(start) == AIMap::GetTileX(end) or - * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or + * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end). * @pre IsRoadTypeAvailable(GetCurrentRoadType()). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_VEHICLE_IN_THE_WAY - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS * @return Whether the road has been/can be removed or not. */ static bool RemoveRoad(TileIndex start, TileIndex end); @@ -426,15 +426,15 @@ public: * included). * @param start The start tile of the road. * @param end The end tile of the road. - * @pre AIMap::IsValidTile(start). - * @pre AIMap::IsValidTile(end). + * @pre ScriptMap::IsValidTile(start). + * @pre ScriptMap::IsValidTile(end). * @pre 'start' and 'end' are in a straight line, i.e. - * AIMap::GetTileX(start) == AIMap::GetTileX(end) or - * AIMap::GetTileY(start) == AIMap::GetTileY(end). + * ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or + * ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end). * @pre IsRoadTypeAvailable(GetCurrentRoadType()). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_VEHICLE_IN_THE_WAY - * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptRoad::ERR_ROAD_WORKS_IN_PROGRESS * @return Whether the road has been/can be removed or not. */ static bool RemoveRoadFull(TileIndex start, TileIndex end); @@ -442,10 +442,10 @@ public: /** * Removes a road depot. * @param tile Place to remove the depot from. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre Tile is a road depot. - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY * @return Whether the road depot has been/can be removed or not. */ static bool RemoveRoadDepot(TileIndex tile); @@ -453,10 +453,10 @@ public: /** * Removes a road bus or truck station. * @param tile Place to remove the station from. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre Tile is a road station. - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY - * @exception AIError::ERR_VEHICLE_IN_THE_WAY + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY + * @exception ScriptError::ERR_VEHICLE_IN_THE_WAY * @return Whether the station has been/can be removed or not. */ static bool RemoveRoadStation(TileIndex tile); diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp index 2178f3846..9af5a2fa7 100644 --- a/src/script/api/script_sign.cpp +++ b/src/script/api/script_sign.cpp @@ -7,7 +7,7 @@ * 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 script_sign.cpp Implementation of AISign. */ +/** @file script_sign.cpp Implementation of ScriptSign. */ #include "../../stdafx.h" #include "script_sign.hpp" @@ -21,22 +21,22 @@ #include "../../tile_map.h" #include "../../company_func.h" -/* static */ bool AISign::IsValidSign(SignID sign_id) +/* static */ bool ScriptSign::IsValidSign(SignID sign_id) { const Sign *si = ::Sign::GetIfValid(sign_id); return si != NULL && si->owner == _current_company; } -/* static */ bool AISign::SetName(SignID sign_id, const char *name) +/* static */ bool ScriptSign::SetName(SignID sign_id, const char *name) { EnforcePrecondition(false, IsValidSign(sign_id)); EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_SIGN_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, name); + return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, name); } -/* static */ char *AISign::GetName(SignID sign_id) +/* static */ char *ScriptSign::GetName(SignID sign_id) { if (!IsValidSign(sign_id)) return NULL; @@ -49,7 +49,7 @@ return sign_name; } -/* static */ TileIndex AISign::GetLocation(SignID sign_id) +/* static */ TileIndex ScriptSign::GetLocation(SignID sign_id) { if (!IsValidSign(sign_id)) return INVALID_TILE; @@ -57,19 +57,19 @@ return ::TileVirtXY(sign->x, sign->y); } -/* static */ bool AISign::RemoveSign(SignID sign_id) +/* static */ bool ScriptSign::RemoveSign(SignID sign_id) { EnforcePrecondition(false, IsValidSign(sign_id)); - return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, ""); + return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, ""); } -/* static */ SignID AISign::BuildSign(TileIndex location, const char *text) +/* static */ SignID ScriptSign::BuildSign(TileIndex location, const char *text) { EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); EnforcePrecondition(INVALID_SIGN, !::StrEmpty(text)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - if (!AIObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &AIInstance::DoCommandReturnSignID)) return INVALID_SIGN; + if (!ScriptObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &AIInstance::DoCommandReturnSignID)) return INVALID_SIGN; /* In case of test-mode, we return SignID 0 */ return 0; diff --git a/src/script/api/script_sign.hpp b/src/script/api/script_sign.hpp index 385e24f68..81ab35360 100644 --- a/src/script/api/script_sign.hpp +++ b/src/script/api/script_sign.hpp @@ -17,7 +17,7 @@ /** * Class that handles all sign related functions. */ -class AISign : public AIObject { +class ScriptSign : public ScriptObject { public: /** * All sign related error messages. @@ -25,7 +25,7 @@ public: enum ErrorMessages { /** Base for sign building related errors */ - ERR_SIGN_BASE = AIError::ERR_CAT_SIGN << AIError::ERR_CAT_BIT_SIZE, + ERR_SIGN_BASE = ScriptError::ERR_CAT_SIGN << ScriptError::ERR_CAT_BIT_SIZE, /** Too many signs have been placed */ ERR_SIGN_TOO_MANY_SIGNS, // [STR_ERROR_TOO_MANY_SIGNS] @@ -45,7 +45,7 @@ public: * @pre IsValidSign(sign_id). * @pre 'name' must have at least one character. * @pre 'name' must have at most 30 characters. - * @exception AIError::ERR_NAME_IS_NOT_UNIQUE + * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ static bool SetName(SignID sign_id, const char *name); @@ -70,10 +70,10 @@ public: * Builds a sign on the map. * @param location The place to build the sign. * @param text The text to place on the sign. - * @pre AIMap::IsValidTile(location). + * @pre ScriptMap::IsValidTile(location). * @pre 'text' must have at least one character. * @pre 'text' must have at most 30 characters. - * @exception AISign::ERR_SIGN_TOO_MANY_SIGNS + * @exception ScriptSign::ERR_SIGN_TOO_MANY_SIGNS * @return The SignID of the build sign (use IsValidSign() to check for validity). * In test-mode it returns 0 if successful, or any other value to indicate * failure. diff --git a/src/script/api/script_signlist.cpp b/src/script/api/script_signlist.cpp index 3d7b228f3..5f6c6075b 100644 --- a/src/script/api/script_signlist.cpp +++ b/src/script/api/script_signlist.cpp @@ -7,17 +7,17 @@ * 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 script_signlist.cpp Implementation of AISignList and friends. */ +/** @file script_signlist.cpp Implementation of ScriptSignList and friends. */ #include "../../stdafx.h" #include "script_signlist.hpp" #include "script_sign.hpp" #include "../../signs_base.h" -AISignList::AISignList() +ScriptSignList::ScriptSignList() { Sign *s; FOR_ALL_SIGNS(s) { - if (AISign::IsValidSign(s->index)) this->AddItem(s->index); + if (ScriptSign::IsValidSign(s->index)) this->AddItem(s->index); } } diff --git a/src/script/api/script_signlist.hpp b/src/script/api/script_signlist.hpp index af6a9614b..5540e269d 100644 --- a/src/script/api/script_signlist.hpp +++ b/src/script/api/script_signlist.hpp @@ -16,11 +16,11 @@ /** * Create a list of signs your company has created. - * @ingroup AIList + * @ingroup ScriptList */ -class AISignList : public AIList { +class ScriptSignList : public ScriptList { public: - AISignList(); + ScriptSignList(); }; #endif /* SCRIPT_SIGNLIST_HPP */ diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp index 6dc0c009d..d848ebe66 100644 --- a/src/script/api/script_station.cpp +++ b/src/script/api/script_station.cpp @@ -7,7 +7,7 @@ * 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 script_station.cpp Implementation of AIStation. */ +/** @file script_station.cpp Implementation of ScriptStation. */ #include "../../stdafx.h" #include "script_station.hpp" @@ -20,38 +20,38 @@ #include "../../company_func.h" #include "../../town.h" -/* static */ bool AIStation::IsValidStation(StationID station_id) +/* static */ bool ScriptStation::IsValidStation(StationID station_id) { const Station *st = ::Station::GetIfValid(station_id); return st != NULL && (st->owner == _current_company || st->owner == OWNER_NONE); } -/* static */ StationID AIStation::GetStationID(TileIndex tile) +/* static */ StationID ScriptStation::GetStationID(TileIndex tile) { if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION)) return INVALID_STATION; return ::GetStationIndex(tile); } -/* static */ int32 AIStation::GetCargoWaiting(StationID station_id, CargoID cargo_id) +/* static */ int32 ScriptStation::GetCargoWaiting(StationID station_id, CargoID cargo_id) { if (!IsValidStation(station_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; return ::Station::Get(station_id)->goods[cargo_id].cargo.Count(); } -/* static */ int32 AIStation::GetCargoRating(StationID station_id, CargoID cargo_id) +/* static */ int32 ScriptStation::GetCargoRating(StationID station_id, CargoID cargo_id) { if (!IsValidStation(station_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; return ::ToPercent8(::Station::Get(station_id)->goods[cargo_id].rating); } -/* static */ int32 AIStation::GetCoverageRadius(AIStation::StationType station_type) +/* static */ int32 ScriptStation::GetCoverageRadius(ScriptStation::StationType station_type) { if (station_type == STATION_AIRPORT) { - DEBUG(ai, 0, "GetCoverageRadius(): coverage radius of airports needs to be requested via AIAirport::GetAirportCoverageRadius(), as it requires AirportType"); + DEBUG(ai, 0, "GetCoverageRadius(): coverage radius of airports needs to be requested via ScriptAirport::GetAirportCoverageRadius(), as it requires AirportType"); return -1; } if (!HasExactlyOneBit(station_type)) return -1; @@ -66,28 +66,28 @@ } } -/* static */ int32 AIStation::GetDistanceManhattanToTile(StationID station_id, TileIndex tile) +/* static */ int32 ScriptStation::GetDistanceManhattanToTile(StationID station_id, TileIndex tile) { if (!IsValidStation(station_id)) return -1; - return AIMap::DistanceManhattan(tile, GetLocation(station_id)); + return ScriptMap::DistanceManhattan(tile, GetLocation(station_id)); } -/* static */ int32 AIStation::GetDistanceSquareToTile(StationID station_id, TileIndex tile) +/* static */ int32 ScriptStation::GetDistanceSquareToTile(StationID station_id, TileIndex tile) { if (!IsValidStation(station_id)) return -1; - return AIMap::DistanceSquare(tile, GetLocation(station_id)); + return ScriptMap::DistanceSquare(tile, GetLocation(station_id)); } -/* static */ bool AIStation::IsWithinTownInfluence(StationID station_id, TownID town_id) +/* static */ bool ScriptStation::IsWithinTownInfluence(StationID station_id, TownID town_id) { if (!IsValidStation(station_id)) return false; - return AITown::IsWithinTownInfluence(town_id, GetLocation(station_id)); + return ScriptTown::IsWithinTownInfluence(town_id, GetLocation(station_id)); } -/* static */ bool AIStation::HasStationType(StationID station_id, StationType station_type) +/* static */ bool ScriptStation::HasStationType(StationID station_id, StationType station_type) { if (!IsValidStation(station_id)) return false; if (!HasExactlyOneBit(station_type)) return false; @@ -95,10 +95,10 @@ return (::Station::Get(station_id)->facilities & station_type) != 0; } -/* static */ bool AIStation::HasRoadType(StationID station_id, AIRoad::RoadType road_type) +/* static */ bool ScriptStation::HasRoadType(StationID station_id, ScriptRoad::RoadType road_type) { if (!IsValidStation(station_id)) return false; - if (!AIRoad::IsRoadTypeAvailable(road_type)) return false; + if (!ScriptRoad::IsRoadTypeAvailable(road_type)) return false; ::RoadTypes r = RoadTypeToRoadTypes((::RoadType)road_type); @@ -112,7 +112,7 @@ return false; } -/* static */ TownID AIStation::GetNearestTown(StationID station_id) +/* static */ TownID ScriptStation::GetNearestTown(StationID station_id) { if (!IsValidStation(station_id)) return INVALID_TOWN; diff --git a/src/script/api/script_station.hpp b/src/script/api/script_station.hpp index b9266c7d3..0d013708a 100644 --- a/src/script/api/script_station.hpp +++ b/src/script/api/script_station.hpp @@ -18,14 +18,14 @@ /** * Class that handles all station related functions. */ -class AIStation : public AIBaseStation { +class ScriptStation : public ScriptBaseStation { public: /** * All station related error messages. */ enum ErrorMessages { /** Base for station related errors */ - ERR_STATION_BASE = AIError::ERR_CAT_STATION << AIError::ERR_CAT_BIT_SIZE, + ERR_STATION_BASE = ScriptError::ERR_CAT_STATION << ScriptError::ERR_CAT_BIT_SIZE, /** The station is build too close to another station, airport or dock */ ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION, // [STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT, STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION, STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK] @@ -90,10 +90,10 @@ public: * @param station_type The type of station. * @return The radius in tiles. */ - static int32 GetCoverageRadius(AIStation::StationType station_type); + static int32 GetCoverageRadius(ScriptStation::StationType station_type); /** - * Get the manhattan distance from the tile to the AIStation::GetLocation() + * Get the manhattan distance from the tile to the ScriptStation::GetLocation() * of the station. * @param station_id The station to get the distance to. * @param tile The tile to get the distance to. @@ -103,7 +103,7 @@ public: static int32 GetDistanceManhattanToTile(StationID station_id, TileIndex tile); /** - * Get the square distance from the tile to the AIStation::GetLocation() + * Get the square distance from the tile to the ScriptStation::GetLocation() * of the station. * @param station_id The station to get the distance to. * @param tile The tile to get the distance to. @@ -138,7 +138,7 @@ public: * @param road_type The RoadType to look for. * @return True if the station has a station part of the type RoadType. */ - static bool HasRoadType(StationID station_id, AIRoad::RoadType road_type); + static bool HasRoadType(StationID station_id, ScriptRoad::RoadType road_type); /** * Get the town that was nearest to the given station when the station was built. @@ -153,6 +153,6 @@ public: static TownID GetNearestTown(StationID station_id); }; -DECLARE_ENUM_AS_BIT_SET(AIStation::StationType) +DECLARE_ENUM_AS_BIT_SET(ScriptStation::StationType) #endif /* SCRIPT_STATION_HPP */ diff --git a/src/script/api/script_stationlist.cpp b/src/script/api/script_stationlist.cpp index 46394851f..bba90cc2b 100644 --- a/src/script/api/script_stationlist.cpp +++ b/src/script/api/script_stationlist.cpp @@ -7,7 +7,7 @@ * 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 script_stationlist.cpp Implementation of AIStationList and friends. */ +/** @file script_stationlist.cpp Implementation of ScriptStationList and friends. */ #include "../../stdafx.h" #include "script_stationlist.hpp" @@ -16,7 +16,7 @@ #include "../../station_base.h" #include "../../vehicle_base.h" -AIStationList::AIStationList(AIStation::StationType station_type) +ScriptStationList::ScriptStationList(ScriptStation::StationType station_type) { Station *st; FOR_ALL_STATIONS(st) { @@ -24,9 +24,9 @@ AIStationList::AIStationList(AIStation::StationType station_type) } } -AIStationList_Vehicle::AIStationList_Vehicle(VehicleID vehicle_id) +ScriptStationList_Vehicle::ScriptStationList_Vehicle(VehicleID vehicle_id) { - if (!AIVehicle::IsValidVehicle(vehicle_id)) return; + if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return; Vehicle *v = ::Vehicle::Get(vehicle_id); diff --git a/src/script/api/script_stationlist.hpp b/src/script/api/script_stationlist.hpp index 6894ecf41..84d509d2e 100644 --- a/src/script/api/script_stationlist.hpp +++ b/src/script/api/script_stationlist.hpp @@ -17,26 +17,26 @@ /** * Creates a list of stations of which you are the owner. - * @ingroup AIList + * @ingroup ScriptList */ -class AIStationList : public AIList { +class ScriptStationList : public ScriptList { public: /** * @param station_type The type of station to make a list of stations for. */ - AIStationList(AIStation::StationType station_type); + ScriptStationList(ScriptStation::StationType station_type); }; /** * Creates a list of stations which the vehicle has in its orders. - * @ingroup AIList + * @ingroup ScriptList */ -class AIStationList_Vehicle : public AIList { +class ScriptStationList_Vehicle : public ScriptList { public: /** * @param vehicle_id The vehicle to get the list of stations he has in its orders from. */ - AIStationList_Vehicle(VehicleID vehicle_id); + ScriptStationList_Vehicle(VehicleID vehicle_id); }; #endif /* SCRIPT_STATIONLIST_HPP */ diff --git a/src/script/api/script_subsidy.cpp b/src/script/api/script_subsidy.cpp index f770d29f7..6bc7ba8b9 100644 --- a/src/script/api/script_subsidy.cpp +++ b/src/script/api/script_subsidy.cpp @@ -7,7 +7,7 @@ * 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 script_subsidy.cpp Implementation of AISubsidy. */ +/** @file script_subsidy.cpp Implementation of ScriptSubsidy. */ #include "../../stdafx.h" #include "script_subsidy.hpp" @@ -15,69 +15,69 @@ #include "../../subsidy_base.h" #include "../../station_base.h" -/* static */ bool AISubsidy::IsValidSubsidy(SubsidyID subsidy_id) +/* static */ bool ScriptSubsidy::IsValidSubsidy(SubsidyID subsidy_id) { return ::Subsidy::IsValidID(subsidy_id); } -/* static */ bool AISubsidy::IsAwarded(SubsidyID subsidy_id) +/* static */ bool ScriptSubsidy::IsAwarded(SubsidyID subsidy_id) { if (!IsValidSubsidy(subsidy_id)) return false; return ::Subsidy::Get(subsidy_id)->IsAwarded(); } -/* static */ AICompany::CompanyID AISubsidy::GetAwardedTo(SubsidyID subsidy_id) +/* static */ ScriptCompany::CompanyID ScriptSubsidy::GetAwardedTo(SubsidyID subsidy_id) { - if (!IsAwarded(subsidy_id)) return AICompany::COMPANY_INVALID; + if (!IsAwarded(subsidy_id)) return ScriptCompany::COMPANY_INVALID; - return (AICompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded); + return (ScriptCompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded); } -/* static */ int32 AISubsidy::GetExpireDate(SubsidyID subsidy_id) +/* static */ int32 ScriptSubsidy::GetExpireDate(SubsidyID subsidy_id) { if (!IsValidSubsidy(subsidy_id)) return -1; - int year = AIDate::GetYear(AIDate::GetCurrentDate()); - int month = AIDate::GetMonth(AIDate::GetCurrentDate()); + int year = ScriptDate::GetYear(ScriptDate::GetCurrentDate()); + int month = ScriptDate::GetMonth(ScriptDate::GetCurrentDate()); month += ::Subsidy::Get(subsidy_id)->remaining; year += (month - 1) / 12; month = ((month - 1) % 12) + 1; - return AIDate::GetDate(year, month, 1); + return ScriptDate::GetDate(year, month, 1); } -/* static */ CargoID AISubsidy::GetCargoType(SubsidyID subsidy_id) +/* static */ CargoID ScriptSubsidy::GetCargoType(SubsidyID subsidy_id) { if (!IsValidSubsidy(subsidy_id)) return CT_INVALID; return ::Subsidy::Get(subsidy_id)->cargo_type; } -/* static */ AISubsidy::SubsidyParticipantType AISubsidy::GetSourceType(SubsidyID subsidy_id) +/* static */ ScriptSubsidy::SubsidyParticipantType ScriptSubsidy::GetSourceType(SubsidyID subsidy_id) { if (!IsValidSubsidy(subsidy_id)) return SPT_INVALID; return (SubsidyParticipantType)(uint)::Subsidy::Get(subsidy_id)->src_type; } -/* static */ int32 AISubsidy::GetSourceIndex(SubsidyID subsidy_id) +/* static */ int32 ScriptSubsidy::GetSourceIndex(SubsidyID subsidy_id) { if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION; return ::Subsidy::Get(subsidy_id)->src; } -/* static */ AISubsidy::SubsidyParticipantType AISubsidy::GetDestinationType(SubsidyID subsidy_id) +/* static */ ScriptSubsidy::SubsidyParticipantType ScriptSubsidy::GetDestinationType(SubsidyID subsidy_id) { if (!IsValidSubsidy(subsidy_id)) return SPT_INVALID; return (SubsidyParticipantType)(uint)::Subsidy::Get(subsidy_id)->dst_type; } -/* static */ int32 AISubsidy::GetDestinationIndex(SubsidyID subsidy_id) +/* static */ int32 ScriptSubsidy::GetDestinationIndex(SubsidyID subsidy_id) { if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION; diff --git a/src/script/api/script_subsidy.hpp b/src/script/api/script_subsidy.hpp index 3e7ac3ee0..f9b397774 100644 --- a/src/script/api/script_subsidy.hpp +++ b/src/script/api/script_subsidy.hpp @@ -17,7 +17,7 @@ /** * Class that handles all subsidy related functions. */ -class AISubsidy : public AIObject { +class ScriptSubsidy : public ScriptObject { public: /** * Enumeration for source and destination of a subsidy. @@ -50,7 +50,7 @@ public: * @pre IsAwarded(subsidy_id). * @return The companyindex of the company this subsidy is awarded to. */ - static AICompany::CompanyID GetAwardedTo(SubsidyID subsidy_id); + static ScriptCompany::CompanyID GetAwardedTo(SubsidyID subsidy_id); /** * Get the date this subsidy expires. In case the subsidy is already diff --git a/src/script/api/script_subsidylist.cpp b/src/script/api/script_subsidylist.cpp index f694b9870..68644846f 100644 --- a/src/script/api/script_subsidylist.cpp +++ b/src/script/api/script_subsidylist.cpp @@ -7,13 +7,13 @@ * 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 script_subsidylist.cpp Implementation of AISubsidyList. */ +/** @file script_subsidylist.cpp Implementation of ScriptSubsidyList. */ #include "../../stdafx.h" #include "script_subsidylist.hpp" #include "../../subsidy_base.h" -AISubsidyList::AISubsidyList() +ScriptSubsidyList::ScriptSubsidyList() { const Subsidy *s; FOR_ALL_SUBSIDIES(s) { diff --git a/src/script/api/script_subsidylist.hpp b/src/script/api/script_subsidylist.hpp index 332412c9d..254446ca7 100644 --- a/src/script/api/script_subsidylist.hpp +++ b/src/script/api/script_subsidylist.hpp @@ -16,11 +16,11 @@ /** * Creates a list of all current subsidies. - * @ingroup AIList + * @ingroup ScriptList */ -class AISubsidyList : public AIList { +class ScriptSubsidyList : public ScriptList { public: - AISubsidyList(); + ScriptSubsidyList(); }; #endif /* SCRIPT_SUBSIDYLIST_HPP */ diff --git a/src/script/api/script_testmode.cpp b/src/script/api/script_testmode.cpp index a2e696f59..87b4aea57 100644 --- a/src/script/api/script_testmode.cpp +++ b/src/script/api/script_testmode.cpp @@ -7,7 +7,7 @@ * 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 script_testmode.cpp Implementation of AITestMode. */ +/** @file script_testmode.cpp Implementation of ScriptTestMode. */ #include "../../stdafx.h" #include "script_testmode.hpp" @@ -15,25 +15,25 @@ #include "../../company_func.h" #include "../../ai/ai_instance.hpp" -bool AITestMode::ModeProc() +bool ScriptTestMode::ModeProc() { /* In test mode we only return 'false', telling the DoCommand it * should stop after testing the command and return with that result. */ return false; } -AITestMode::AITestMode() +ScriptTestMode::ScriptTestMode() { this->last_mode = this->GetDoCommandMode(); this->last_instance = this->GetDoCommandModeInstance(); - this->SetDoCommandMode(&AITestMode::ModeProc, this); + this->SetDoCommandMode(&ScriptTestMode::ModeProc, this); } -AITestMode::~AITestMode() +ScriptTestMode::~ScriptTestMode() { if (this->GetDoCommandModeInstance() != this) { /* Ignore this error if the AI already died. */ - if (!AIObject::GetActiveInstance()->IsDead()) { + if (!ScriptObject::GetActiveInstance()->IsDead()) { throw AI_FatalError("AITestmode object was removed while it was not the latest AI*Mode object created."); } } diff --git a/src/script/api/script_testmode.hpp b/src/script/api/script_testmode.hpp index a6a3c8da8..6954146a9 100644 --- a/src/script/api/script_testmode.hpp +++ b/src/script/api/script_testmode.hpp @@ -23,10 +23,10 @@ * system only checks if it would be able to execute your requests, and what * the cost would be. */ -class AITestMode : public AIObject { +class ScriptTestMode : public ScriptObject { private: AIModeProc *last_mode; ///< The previous mode we were in. - AIObject *last_instance; ///< The previous instace of the mode. + ScriptObject *last_instance; ///< The previous instace of the mode. protected: /** @@ -40,13 +40,13 @@ public: * @note When the instance is destroyed, he restores the mode that was * current when the instance was created! */ - AITestMode(); + ScriptTestMode(); /** * Destroying this instance reset the building mode to the mode it was * in when the instance was created. */ - ~AITestMode(); + ~ScriptTestMode(); }; #endif /* SCRIPT_TESTMODE_HPP */ diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index c395aa516..b898b9c15 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -7,7 +7,7 @@ * 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 script_tile.cpp Implementation of AITile. */ +/** @file script_tile.cpp Implementation of ScriptTile. */ #include "../../stdafx.h" #include "script_tile.hpp" @@ -23,7 +23,7 @@ #include "../../landscape.h" #include "../../economy_func.h" -/* static */ bool AITile::IsBuildable(TileIndex tile) +/* static */ bool ScriptTile::IsBuildable(TileIndex tile) { if (!::IsValidTile(tile)) return false; @@ -44,30 +44,30 @@ } } -/* static */ bool AITile::IsBuildableRectangle(TileIndex tile, uint width, uint height) +/* static */ bool ScriptTile::IsBuildableRectangle(TileIndex tile, uint width, uint height) { uint tx, ty; - tx = AIMap::GetTileX(tile); - ty = AIMap::GetTileY(tile); + tx = ScriptMap::GetTileX(tile); + ty = ScriptMap::GetTileY(tile); for (uint x = tx; x < width + tx; x++) { for (uint y = ty; y < height + ty; y++) { - if (!IsBuildable(AIMap::GetTileIndex(x, y))) return false; + if (!IsBuildable(ScriptMap::GetTileIndex(x, y))) return false; } } return true; } -/* static */ bool AITile::IsWaterTile(TileIndex tile) +/* static */ bool ScriptTile::IsWaterTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_WATER) && !::IsCoast(tile); } -/* static */ bool AITile::IsCoastTile(TileIndex tile) +/* static */ bool ScriptTile::IsCoastTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; @@ -75,98 +75,98 @@ (::IsTileType(tile, MP_TREES) && ::GetTreeGround(tile) == TREE_GROUND_SHORE); } -/* static */ bool AITile::IsStationTile(TileIndex tile) +/* static */ bool ScriptTile::IsStationTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_STATION); } -/* static */ bool AITile::IsSteepSlope(Slope slope) +/* static */ bool ScriptTile::IsSteepSlope(Slope slope) { if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false; return ::IsSteepSlope((::Slope)slope); } -/* static */ bool AITile::IsHalftileSlope(Slope slope) +/* static */ bool ScriptTile::IsHalftileSlope(Slope slope) { if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false; return ::IsHalftileSlope((::Slope)slope); } -/* static */ bool AITile::HasTreeOnTile(TileIndex tile) +/* static */ bool ScriptTile::HasTreeOnTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTileType(tile, MP_TREES); } -/* static */ bool AITile::IsFarmTile(TileIndex tile) +/* static */ bool ScriptTile::IsFarmTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_FIELDS)); } -/* static */ bool AITile::IsRockTile(TileIndex tile) +/* static */ bool ScriptTile::IsRockTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return (::IsTileType(tile, MP_CLEAR) && ::GetRawClearGround(tile) == ::CLEAR_ROCKS); } -/* static */ bool AITile::IsRoughTile(TileIndex tile) +/* static */ bool ScriptTile::IsRoughTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return (::IsTileType(tile, MP_CLEAR) && ::GetRawClearGround(tile) == ::CLEAR_ROUGH); } -/* static */ bool AITile::IsSnowTile(TileIndex tile) +/* static */ bool ScriptTile::IsSnowTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return (::IsTileType(tile, MP_CLEAR) && ::IsSnowTile(tile)); } -/* static */ bool AITile::IsDesertTile(TileIndex tile) +/* static */ bool ScriptTile::IsDesertTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_DESERT)); } -/* static */ AITile::Slope AITile::GetSlope(TileIndex tile) +/* static */ ScriptTile::Slope ScriptTile::GetSlope(TileIndex tile) { if (!::IsValidTile(tile)) return SLOPE_INVALID; return (Slope)::GetTileSlope(tile); } -/* static */ AITile::Slope AITile::GetComplementSlope(Slope slope) +/* static */ ScriptTile::Slope ScriptTile::GetComplementSlope(Slope slope) { if ((slope & ~SLOPE_ELEVATED) != 0) return SLOPE_INVALID; return (Slope)::ComplementSlope((::Slope)slope); } -/* static */ int32 AITile::GetMinHeight(TileIndex tile) +/* static */ int32 ScriptTile::GetMinHeight(TileIndex tile) { if (!::IsValidTile(tile)) return -1; return ::GetTileZ(tile); } -/* static */ int32 AITile::GetMaxHeight(TileIndex tile) +/* static */ int32 ScriptTile::GetMaxHeight(TileIndex tile) { if (!::IsValidTile(tile)) return -1; return ::GetTileMaxZ(tile); } -/* static */ int32 AITile::GetCornerHeight(TileIndex tile, Corner corner) +/* static */ int32 ScriptTile::GetCornerHeight(TileIndex tile, Corner corner) { if (!::IsValidTile(tile) || !::IsValidCorner((::Corner)corner)) return -1; @@ -175,114 +175,114 @@ return (z + ::GetSlopeZInCorner(slope, (::Corner)corner)); } -/* static */ AICompany::CompanyID AITile::GetOwner(TileIndex tile) +/* static */ ScriptCompany::CompanyID ScriptTile::GetOwner(TileIndex tile) { - if (!::IsValidTile(tile)) return AICompany::COMPANY_INVALID; - if (::IsTileType(tile, MP_HOUSE)) return AICompany::COMPANY_INVALID; - if (::IsTileType(tile, MP_INDUSTRY)) return AICompany::COMPANY_INVALID; + if (!::IsValidTile(tile)) return ScriptCompany::COMPANY_INVALID; + if (::IsTileType(tile, MP_HOUSE)) return ScriptCompany::COMPANY_INVALID; + if (::IsTileType(tile, MP_INDUSTRY)) return ScriptCompany::COMPANY_INVALID; - return AICompany::ResolveCompanyID((AICompany::CompanyID)(byte)::GetTileOwner(tile)); + return ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)(byte)::GetTileOwner(tile)); } -/* static */ bool AITile::HasTransportType(TileIndex tile, TransportType transport_type) +/* static */ bool ScriptTile::HasTransportType(TileIndex tile, TransportType transport_type) { if (!::IsValidTile(tile)) return false; return ::TrackStatusToTrackdirBits(::GetTileTrackStatus(tile, (::TransportType)transport_type, UINT32_MAX)) != TRACKDIR_BIT_NONE; } -/* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius) +/* static */ int32 ScriptTile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1; CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return acceptance[cargo_type]; } -/* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius) +/* static */ int32 ScriptTile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1; CargoArray produced = ::GetProductionAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return produced[cargo_type]; } -/* static */ int32 AITile::GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to) +/* static */ int32 ScriptTile::GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to) { - return AIMap::DistanceManhattan(tile_from, tile_to); + return ScriptMap::DistanceManhattan(tile_from, tile_to); } -/* static */ int32 AITile::GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to) +/* static */ int32 ScriptTile::GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to) { - return AIMap::DistanceSquare(tile_from, tile_to); + return ScriptMap::DistanceSquare(tile_from, tile_to); } -/* static */ bool AITile::RaiseTile(TileIndex tile, int32 slope) +/* static */ bool ScriptTile::RaiseTile(TileIndex tile, int32 slope) { EnforcePrecondition(false, tile < ::MapSize()); - return AIObject::DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND); + return ScriptObject::DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND); } -/* static */ bool AITile::LowerTile(TileIndex tile, int32 slope) +/* static */ bool ScriptTile::LowerTile(TileIndex tile, int32 slope) { EnforcePrecondition(false, tile < ::MapSize()); - return AIObject::DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND); + return ScriptObject::DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND); } -/* static */ bool AITile::LevelTiles(TileIndex start_tile, TileIndex end_tile) +/* static */ bool ScriptTile::LevelTiles(TileIndex start_tile, TileIndex end_tile) { EnforcePrecondition(false, start_tile < ::MapSize()); EnforcePrecondition(false, end_tile < ::MapSize()); - return AIObject::DoCommand(end_tile, start_tile, LM_LEVEL << 1, CMD_LEVEL_LAND); + return ScriptObject::DoCommand(end_tile, start_tile, LM_LEVEL << 1, CMD_LEVEL_LAND); } -/* static */ bool AITile::DemolishTile(TileIndex tile) +/* static */ bool ScriptTile::DemolishTile(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } -/* static */ bool AITile::PlantTree(TileIndex tile) +/* static */ bool ScriptTile::PlantTree(TileIndex tile) { EnforcePrecondition(false, ::IsValidTile(tile)); - return AIObject::DoCommand(tile, TREE_INVALID, tile, CMD_PLANT_TREE); + return ScriptObject::DoCommand(tile, TREE_INVALID, tile, CMD_PLANT_TREE); } -/* static */ bool AITile::PlantTreeRectangle(TileIndex tile, uint width, uint height) +/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, uint width, uint height) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, width >= 1 && width <= 20); EnforcePrecondition(false, height >= 1 && height <= 20); TileIndex end_tile = tile + ::TileDiffXY(width - 1, height - 1); - return AIObject::DoCommand(tile, TREE_INVALID, end_tile, CMD_PLANT_TREE); + return ScriptObject::DoCommand(tile, TREE_INVALID, end_tile, CMD_PLANT_TREE); } -/* static */ bool AITile::IsWithinTownInfluence(TileIndex tile, TownID town_id) +/* static */ bool ScriptTile::IsWithinTownInfluence(TileIndex tile, TownID town_id) { - return AITown::IsWithinTownInfluence(town_id, tile); + return ScriptTown::IsWithinTownInfluence(town_id, tile); } -/* static */ TownID AITile::GetTownAuthority(TileIndex tile) +/* static */ TownID ScriptTile::GetTownAuthority(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority)->index; } -/* static */ TownID AITile::GetClosestTown(TileIndex tile) +/* static */ TownID ScriptTile::GetClosestTown(TileIndex tile) { if (!::IsValidTile(tile)) return INVALID_TOWN; return ::ClosestTownFromTile(tile, UINT_MAX)->index; } -/* static */ Money AITile::GetBuildCost(BuildType build_type) +/* static */ Money ScriptTile::GetBuildCost(BuildType build_type) { switch (build_type) { case BT_FOUNDATION: return ::GetPrice(PR_BUILD_FOUNDATION, 1, NULL); diff --git a/src/script/api/script_tile.hpp b/src/script/api/script_tile.hpp index 0e9205d3c..38ec6a55e 100644 --- a/src/script/api/script_tile.hpp +++ b/src/script/api/script_tile.hpp @@ -18,7 +18,7 @@ /** * Class that handles all tile related functions. */ -class AITile : public AIObject { +class ScriptTile : public ScriptObject { public: /** * Error messages related to modifying tiles. @@ -26,7 +26,7 @@ public: enum ErrorMessages { /** Base for tile related errors */ - ERR_TILE_BASE = AIError::ERR_CAT_TILE << AIError::ERR_CAT_BIT_SIZE, + ERR_TILE_BASE = ScriptError::ERR_CAT_TILE << ScriptError::ERR_CAT_BIT_SIZE, /** Tile can't be raised any higher */ ERR_TILE_TOO_HIGH, // [STR_ERROR_ALREADY_AT_SEA_LEVEL] @@ -118,11 +118,11 @@ public: * Check if this tile is buildable, i.e. no things on it that needs * demolishing. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if it is buildable, false if not. - * @note For trams you also might want to check for AIRoad::IsRoad(), + * @note For trams you also might want to check for ScriptRoad::IsRoad(), * as you can build tram-rails on road-tiles. - * @note For rail you also might want to check for AIRoad::IsRoad(), + * @note For rail you also might want to check for ScriptRoad::IsRoad(), * as in some cases you can build rails on road-tiles. */ static bool IsBuildable(TileIndex tile); @@ -133,7 +133,7 @@ public: * @param tile The tile to check on. * @param width The width of the rectangle. * @param height The height of the rectangle. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if it is buildable, false if not. */ static bool IsBuildableRectangle(TileIndex tile, uint width, uint height); @@ -141,7 +141,7 @@ public: /** * Checks whether the given tile is actually a water tile. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is a water tile. */ static bool IsWaterTile(TileIndex tile); @@ -149,7 +149,7 @@ public: /** * Checks whether the given tile is actually a coast tile. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is a coast tile. * @note Building on coast tiles in general is more expensive. This is not * true if there are also trees on the tile, see #HasTreeOnTile. @@ -159,7 +159,7 @@ public: /** * Checks whether the given tile is a station tile of any station. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is a station tile. */ static bool IsStationTile(TileIndex tile); @@ -186,7 +186,7 @@ public: /** * Check if the tile has any tree on it. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if there is a tree on the tile. */ static bool HasTreeOnTile(TileIndex tile); @@ -194,7 +194,7 @@ public: /** * Check if the tile is a farmland tile. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is farmland. */ static bool IsFarmTile(TileIndex tile); @@ -202,7 +202,7 @@ public: /** * Check if the tile is a rock tile. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is rock tile. */ static bool IsRockTile(TileIndex tile); @@ -210,7 +210,7 @@ public: /** * Check if the tile is a rough tile. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is rough tile. */ static bool IsRoughTile(TileIndex tile); @@ -218,7 +218,7 @@ public: /** * Check if the tile is a snow tile. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is snow tile. */ static bool IsSnowTile(TileIndex tile); @@ -226,7 +226,7 @@ public: /** * Check if the tile is a desert tile. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is desert tile. */ static bool IsDesertTile(TileIndex tile); @@ -235,7 +235,7 @@ public: * Get the slope of a tile. * This is the slope of the bare tile. A possible foundation on the tile does not influence this slope. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return Bit mask encoding the slope. See #Slope for a description of the returned values. */ static Slope GetSlope(TileIndex tile); @@ -255,7 +255,7 @@ public: * Get the minimal height on a tile. * The returned height is the height of the bare tile. A possible foundation on the tile does not influence this height. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The height of the lowest corner of the tile, ranging from 0 to 15. */ static int32 GetMinHeight(TileIndex tile); @@ -264,7 +264,7 @@ public: * Get the maximal height on a tile. * The returned height is the height of the bare tile. A possible foundation on the tile does not influence this height. * @param tile The tile to check on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The height of the highest corner of the tile, ranging from 0 to 15. */ static int32 GetMaxHeight(TileIndex tile); @@ -274,7 +274,7 @@ public: * The returned height is the height of the bare tile. A possible foundation on the tile does not influence this height. * @param tile The tile to check on. * @param corner The corner to query. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The height of the lowest corner of the tile, ranging from 0 to 15. */ static int32 GetCornerHeight(TileIndex tile, Corner corner); @@ -282,24 +282,24 @@ public: /** * Get the owner of the tile. * @param tile The tile to get the owner from. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The CompanyID of the owner of the tile, or COMPANY_INVALID if * there is no owner (grass/industry/water tiles, etc.). */ - static AICompany::CompanyID GetOwner(TileIndex tile); + static ScriptCompany::CompanyID GetOwner(TileIndex tile); /** * Checks whether the given tile contains parts suitable for the given * TransportType. * @param tile The tile to check. * @param transport_type The TransportType to check against. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre transport_type != TRANSPORT_AIR. * @note Returns false on tiles with roadworks and on road tiles with only * a single piece of road as these tiles cannot be used to transport * anything on. It furthermore returns true on some coast tile for * TRANSPORT_WATER because ships can navigate over them. - * @note Use AIAirport.IsAirportTile to check for airport tiles. Aircraft + * @note Use ScriptAirport.IsAirportTile to check for airport tiles. Aircraft * can fly over every tile on the map so using HasTransportType * doesn't make sense for TRANSPORT_AIR. * @return True if and only if the tile has the given TransportType. @@ -315,8 +315,8 @@ public: * @param width The width of the station. * @param height The height of the station. * @param radius The radius of the station. - * @pre AIMap::IsValidTile(tile). - * @pre AICargo::IsValidCargo(cargo_type) + * @pre ScriptMap::IsValidTile(tile). + * @pre ScriptCargo::IsValidCargo(cargo_type) * @pre width > 0. * @pre height > 0. * @pre radius >= 0. @@ -332,8 +332,8 @@ public: * @param width The width of the station. * @param height The height of the station. * @param radius The radius of the station. - * @pre AIMap::IsValidTile(tile). - * @pre AICargo::IsValidCargo(cargo_type) + * @pre ScriptMap::IsValidTile(tile). + * @pre ScriptCargo::IsValidCargo(cargo_type) * @pre width > 0. * @pre height > 0. * @pre radius >= 0. @@ -365,10 +365,10 @@ public: * multiple corners may result in changing some corners by multiple steps. * @param tile The tile to raise. * @param slope Corners to raise (SLOPE_xxx). - * @pre tile < AIMap::GetMapSize(). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_TOO_CLOSE_TO_EDGE - * @exception AITile::ERR_TILE_TOO_HIGH + * @pre tile < ScriptMap::GetMapSize(). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_TOO_CLOSE_TO_EDGE + * @exception ScriptTile::ERR_TILE_TOO_HIGH * @return 0 means failed, 1 means success. */ static bool RaiseTile(TileIndex tile, int32 slope); @@ -381,10 +381,10 @@ public: * multiple corners may result in changing some corners by multiple steps. * @param tile The tile to lower. * @param slope Corners to lower (SLOPE_xxx). - * @pre tile < AIMap::GetMapSize(). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_TOO_CLOSE_TO_EDGE - * @exception AITile::ERR_TILE_TOO_LOW + * @pre tile < ScriptMap::GetMapSize(). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_TOO_CLOSE_TO_EDGE + * @exception ScriptTile::ERR_TILE_TOO_LOW * @return 0 means failed, 1 means success. */ static bool LowerTile(TileIndex tile, int32 slope); @@ -392,26 +392,26 @@ public: /** * Level all tiles in the rectangle between start_tile and end_tile so they * are at the same height. All tiles will be raised or lowered until - * they are at height AITile::GetHeight(start_tile). + * they are at height ScriptTile::GetHeight(start_tile). * @param start_tile One corner of the rectangle to level. * @param end_tile The opposite corner of the rectangle. - * @pre start_tile < AIMap::GetMapSize(). - * @pre end_tile < AIMap::GetMapSize(). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AIError::ERR_TOO_CLOSE_TO_EDGE + * @pre start_tile < ScriptMap::GetMapSize(). + * @pre end_tile < ScriptMap::GetMapSize(). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptError::ERR_TOO_CLOSE_TO_EDGE * @return True if one or more tiles were leveled. * @note Even if leveling some part fails, some other part may have been * successfully leveled already. - * @note This function may return true in AITestMode, although it fails in - * AIExecMode. + * @note This function may return true in ScriptTestMode, although it fails in + * ScriptExecMode. */ static bool LevelTiles(TileIndex start_tile, TileIndex end_tile); /** * Destroy everything on the given tile. * @param tile The tile to demolish. - * @pre AIMap::IsValidTile(tile). - * @exception AIError::ERR_AREA_NOT_CLEAR + * @pre ScriptMap::IsValidTile(tile). + * @exception ScriptError::ERR_AREA_NOT_CLEAR * @return True if and only if the tile was demolished. */ static bool DemolishTile(TileIndex tile); @@ -419,7 +419,7 @@ public: /** * Create a random tree on a tile. * @param tile The tile to build a tree on. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if a tree was added on the tile. */ static bool PlantTree(TileIndex tile); @@ -429,7 +429,7 @@ public: * @param tile The top left tile of the rectangle. * @param width The width of the rectangle. * @param height The height of the rectangle. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @pre width >= 1 && width <= 20. * @pre height >= 1 && height <= 20. * @return True if and only if a tree was added on any of the tiles in the rectangle. diff --git a/src/script/api/script_tilelist.cpp b/src/script/api/script_tilelist.cpp index 75b5c438e..d4fe9f977 100644 --- a/src/script/api/script_tilelist.cpp +++ b/src/script/api/script_tilelist.cpp @@ -7,7 +7,7 @@ * 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 script_tilelist.cpp Implementation of AITileList and friends. */ +/** @file script_tilelist.cpp Implementation of ScriptTileList and friends. */ #include "../../stdafx.h" #include "script_tilelist.hpp" @@ -15,7 +15,7 @@ #include "../../industry.h" #include "../../station_base.h" -void AITileList::AddRectangle(TileIndex t1, TileIndex t2) +void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1)) return; if (!::IsValidTile(t2)) return; @@ -24,14 +24,14 @@ void AITileList::AddRectangle(TileIndex t1, TileIndex t2) TILE_AREA_LOOP(t, ta) this->AddItem(t); } -void AITileList::AddTile(TileIndex tile) +void ScriptTileList::AddTile(TileIndex tile) { if (!::IsValidTile(tile)) return; this->AddItem(tile); } -void AITileList::RemoveRectangle(TileIndex t1, TileIndex t2) +void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1)) return; if (!::IsValidTile(t2)) return; @@ -40,16 +40,16 @@ void AITileList::RemoveRectangle(TileIndex t1, TileIndex t2) TILE_AREA_LOOP(t, ta) this->RemoveItem(t); } -void AITileList::RemoveTile(TileIndex tile) +void ScriptTileList::RemoveTile(TileIndex tile) { if (!::IsValidTile(tile)) return; this->RemoveItem(tile); } -AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_id, int radius) +ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID industry_id, int radius) { - if (!AIIndustry::IsValidIndustry(industry_id) || radius <= 0) return; + if (!ScriptIndustry::IsValidIndustry(industry_id) || radius <= 0) return; const Industry *i = ::Industry::Get(industry_id); @@ -85,9 +85,9 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i } } -AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_id, int radius) +ScriptTileList_IndustryProducing::ScriptTileList_IndustryProducing(IndustryID industry_id, int radius) { - if (!AIIndustry::IsValidIndustry(industry_id) || radius <= 0) return; + if (!ScriptIndustry::IsValidIndustry(industry_id) || radius <= 0) return; const Industry *i = ::Industry::Get(industry_id); @@ -110,20 +110,20 @@ AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_i } } -AITileList_StationType::AITileList_StationType(StationID station_id, AIStation::StationType station_type) +ScriptTileList_StationType::ScriptTileList_StationType(StationID station_id, ScriptStation::StationType station_type) { - if (!AIStation::IsValidStation(station_id)) return; + if (!ScriptStation::IsValidStation(station_id)) return; const StationRect *rect = &::Station::Get(station_id)->rect; uint station_type_value = 0; - /* Convert AIStation::StationType to ::StationType, but do it in a + /* Convert ScriptStation::StationType to ::StationType, but do it in a * bitmask, so we can scan for multiple entries at the same time. */ - if ((station_type & AIStation::STATION_TRAIN) != 0) station_type_value |= (1 << ::STATION_RAIL); - if ((station_type & AIStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << ::STATION_TRUCK); - if ((station_type & AIStation::STATION_BUS_STOP) != 0) station_type_value |= (1 << ::STATION_BUS); - if ((station_type & AIStation::STATION_AIRPORT) != 0) station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG); - if ((station_type & AIStation::STATION_DOCK) != 0) station_type_value |= (1 << ::STATION_DOCK) | (1 << ::STATION_OILRIG); + if ((station_type & ScriptStation::STATION_TRAIN) != 0) station_type_value |= (1 << ::STATION_RAIL); + if ((station_type & ScriptStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << ::STATION_TRUCK); + if ((station_type & ScriptStation::STATION_BUS_STOP) != 0) station_type_value |= (1 << ::STATION_BUS); + if ((station_type & ScriptStation::STATION_AIRPORT) != 0) station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG); + if ((station_type & ScriptStation::STATION_DOCK) != 0) station_type_value |= (1 << ::STATION_DOCK) | (1 << ::STATION_OILRIG); TileArea ta(::TileXY(rect->left, rect->top), rect->right - rect->left + 1, rect->bottom - rect->top + 1); TILE_AREA_LOOP(cur_tile, ta) { diff --git a/src/script/api/script_tilelist.hpp b/src/script/api/script_tilelist.hpp index ea0f241bb..e9daacc5d 100644 --- a/src/script/api/script_tilelist.hpp +++ b/src/script/api/script_tilelist.hpp @@ -17,23 +17,23 @@ /** * Creates an empty list, in which you can add tiles. - * @ingroup AIList + * @ingroup ScriptList */ -class AITileList : public AIList { +class ScriptTileList : public ScriptList { public: /** * Adds the rectangle between tile_from and tile_to to the to-be-evaluated tiles. * @param tile_from One corner of the tiles to add. * @param tile_to The other corner of the tiles to add. - * @pre AIMap::IsValidTile(tile_from). - * @pre AIMap::IsValidTile(tile_to). + * @pre ScriptMap::IsValidTile(tile_from). + * @pre ScriptMap::IsValidTile(tile_to). */ void AddRectangle(TileIndex tile_from, TileIndex tile_to); /** * Add a tile to the to-be-evaluated tiles. * @param tile The tile to add. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). */ void AddTile(TileIndex tile); @@ -41,15 +41,15 @@ public: * Remove the tiles inside the rectangle between tile_from and tile_to form the list. * @param tile_from One corner of the tiles to remove. * @param tile_to The other corner of the files to remove. - * @pre AIMap::IsValidTile(tile_from). - * @pre AIMap::IsValidTile(tile_to). + * @pre ScriptMap::IsValidTile(tile_from). + * @pre ScriptMap::IsValidTile(tile_to). */ void RemoveRectangle(TileIndex tile_from, TileIndex tile_to); /** * Remove a tile from the list. * @param tile The tile to remove. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). */ void RemoveTile(TileIndex tile); }; @@ -57,47 +57,47 @@ public: /** * Creates a list of tiles that will accept cargo for the given industry. * @note If a simular industry is close, it might happen that this industry receives the cargo. - * @ingroup AIList + * @ingroup ScriptList */ -class AITileList_IndustryAccepting : public AITileList { +class ScriptTileList_IndustryAccepting : public ScriptTileList { public: /** - * @param industry_id The industry to create the AITileList around. + * @param industry_id The industry to create the ScriptTileList around. * @param radius The radius of the station you will be using. - * @pre AIIndustry::IsValidIndustry(industry_id). + * @pre ScriptIndustry::IsValidIndustry(industry_id). * @pre radius > 0. */ - AITileList_IndustryAccepting(IndustryID industry_id, int radius); + ScriptTileList_IndustryAccepting(IndustryID industry_id, int radius); }; /** * Creates a list of tiles which the industry checks to see if a station is * there to receive cargo produced by this industry. - * @ingroup AIList + * @ingroup ScriptList */ -class AITileList_IndustryProducing : public AITileList { +class ScriptTileList_IndustryProducing : public ScriptTileList { public: /** - * @param industry_id The industry to create the AITileList around. + * @param industry_id The industry to create the ScriptTileList around. * @param radius The radius of the station you will be using. - * @pre AIIndustry::IsValidIndustry(industry_id). + * @pre ScriptIndustry::IsValidIndustry(industry_id). * @pre radius > 0. */ - AITileList_IndustryProducing(IndustryID industry_id, int radius); + ScriptTileList_IndustryProducing(IndustryID industry_id, int radius); }; /** * Creates a list of tiles which have the requested StationType of the * StationID. - * @ingroup AIList + * @ingroup ScriptList */ -class AITileList_StationType : public AITileList { +class ScriptTileList_StationType : public ScriptTileList { public: /** - * @param station_id The station to create the AITileList for. - * @param station_type The StationType to create the AIList for. + * @param station_id The station to create the ScriptTileList for. + * @param station_type The StationType to create the ScriptList for. */ - AITileList_StationType(StationID station_id, AIStation::StationType station_type); + ScriptTileList_StationType(StationID station_id, ScriptStation::StationType station_type); }; #endif /* SCRIPT_TILELIST_HPP */ diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index acde58e18..554d5f7ae 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -7,7 +7,7 @@ * 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 script_town.cpp Implementation of AITown. */ +/** @file script_town.cpp Implementation of ScriptTown. */ #include "../../stdafx.h" #include "script_town.hpp" @@ -21,17 +21,17 @@ #include "../../landscape.h" #include "table/strings.h" -/* static */ int32 AITown::GetTownCount() +/* static */ int32 ScriptTown::GetTownCount() { return (int32)::Town::GetNumItems(); } -/* static */ bool AITown::IsValidTown(TownID town_id) +/* static */ bool ScriptTown::IsValidTown(TownID town_id) { return ::Town::IsValidID(town_id); } -/* static */ char *AITown::GetName(TownID town_id) +/* static */ char *ScriptTown::GetName(TownID town_id) { if (!IsValidTown(town_id)) return NULL; static const int len = 64; @@ -43,70 +43,70 @@ return town_name; } -/* static */ int32 AITown::GetPopulation(TownID town_id) +/* static */ int32 ScriptTown::GetPopulation(TownID town_id) { if (!IsValidTown(town_id)) return -1; const Town *t = ::Town::Get(town_id); return t->population; } -/* static */ int32 AITown::GetHouseCount(TownID town_id) +/* static */ int32 ScriptTown::GetHouseCount(TownID town_id) { if (!IsValidTown(town_id)) return -1; const Town *t = ::Town::Get(town_id); return t->num_houses; } -/* static */ TileIndex AITown::GetLocation(TownID town_id) +/* static */ TileIndex ScriptTown::GetLocation(TownID town_id) { if (!IsValidTown(town_id)) return INVALID_TILE; const Town *t = ::Town::Get(town_id); return t->xy; } -/* static */ int32 AITown::GetLastMonthProduction(TownID town_id, CargoID cargo_id) +/* static */ int32 ScriptTown::GetLastMonthProduction(TownID town_id, CargoID cargo_id) { if (!IsValidTown(town_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; const Town *t = ::Town::Get(town_id); return t->supplied[cargo_id].old_max; } -/* static */ int32 AITown::GetLastMonthSupplied(TownID town_id, CargoID cargo_id) +/* static */ int32 ScriptTown::GetLastMonthSupplied(TownID town_id, CargoID cargo_id) { if (!IsValidTown(town_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; const Town *t = ::Town::Get(town_id); return t->supplied[cargo_id].old_act; } -/* static */ int32 AITown::GetLastMonthTransportedPercentage(TownID town_id, CargoID cargo_id) +/* static */ int32 ScriptTown::GetLastMonthTransportedPercentage(TownID town_id, CargoID cargo_id) { if (!IsValidTown(town_id)) return -1; - if (!AICargo::IsValidCargo(cargo_id)) return -1; + if (!ScriptCargo::IsValidCargo(cargo_id)) return -1; const Town *t = ::Town::Get(town_id); return ::ToPercent8(t->GetPercentTransported(cargo_id)); } -/* static */ int32 AITown::GetLastMonthReceived(TownID town_id, AICargo::TownEffect towneffect_id) +/* static */ int32 ScriptTown::GetLastMonthReceived(TownID town_id, ScriptCargo::TownEffect towneffect_id) { if (!IsValidTown(town_id)) return -1; - if (!AICargo::IsValidTownEffect(towneffect_id)) return -1; + if (!ScriptCargo::IsValidTownEffect(towneffect_id)) return -1; const Town *t = ::Town::Get(town_id); return t->received[towneffect_id].old_act; } -/* static */ uint32 AITown::GetCargoGoal(TownID town_id, AICargo::TownEffect towneffect_id) +/* static */ uint32 ScriptTown::GetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id) { if (!IsValidTown(town_id)) return -1; - if (!AICargo::IsValidTownEffect(towneffect_id)) return -1; + if (!ScriptCargo::IsValidTownEffect(towneffect_id)) return -1; const Town *t = ::Town::Get(town_id); @@ -123,7 +123,7 @@ } } -/* static */ int32 AITown::GetGrowthRate(TownID town_id) +/* static */ int32 ScriptTown::GetGrowthRate(TownID town_id) { if (!IsValidTown(town_id)) return false; @@ -132,17 +132,17 @@ return (t->growth_rate * TOWN_GROWTH_TICKS + DAY_TICKS) / DAY_TICKS; } -/* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile) +/* static */ int32 ScriptTown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile) { - return AIMap::DistanceManhattan(tile, GetLocation(town_id)); + return ScriptMap::DistanceManhattan(tile, GetLocation(town_id)); } -/* static */ int32 AITown::GetDistanceSquareToTile(TownID town_id, TileIndex tile) +/* static */ int32 ScriptTown::GetDistanceSquareToTile(TownID town_id, TileIndex tile) { - return AIMap::DistanceSquare(tile, GetLocation(town_id)); + return ScriptMap::DistanceSquare(tile, GetLocation(town_id)); } -/* static */ bool AITown::IsWithinTownInfluence(TownID town_id, TileIndex tile) +/* static */ bool ScriptTown::IsWithinTownInfluence(TownID town_id, TileIndex tile) { if (!IsValidTown(town_id)) return false; @@ -150,61 +150,61 @@ return ((uint32)GetDistanceSquareToTile(town_id, tile) <= t->squared_town_zone_radius[0]); } -/* static */ bool AITown::HasStatue(TownID town_id) +/* static */ bool ScriptTown::HasStatue(TownID town_id) { if (!IsValidTown(town_id)) return false; return ::HasBit(::Town::Get(town_id)->statues, _current_company); } -/* static */ bool AITown::IsCity(TownID town_id) +/* static */ bool ScriptTown::IsCity(TownID town_id) { if (!IsValidTown(town_id)) return false; return ::Town::Get(town_id)->larger_town; } -/* static */ int AITown::GetRoadReworkDuration(TownID town_id) +/* static */ int ScriptTown::GetRoadReworkDuration(TownID town_id) { if (!IsValidTown(town_id)) return -1; return ::Town::Get(town_id)->road_build_months; } -/* static */ AICompany::CompanyID AITown::GetExclusiveRightsCompany(TownID town_id) +/* static */ ScriptCompany::CompanyID ScriptTown::GetExclusiveRightsCompany(TownID town_id) { - if (!IsValidTown(town_id)) return AICompany::COMPANY_INVALID; + if (!IsValidTown(town_id)) return ScriptCompany::COMPANY_INVALID; - return (AICompany::CompanyID)(int8)::Town::Get(town_id)->exclusivity; + return (ScriptCompany::CompanyID)(int8)::Town::Get(town_id)->exclusivity; } -/* static */ int32 AITown::GetExclusiveRightsDuration(TownID town_id) +/* static */ int32 ScriptTown::GetExclusiveRightsDuration(TownID town_id) { if (!IsValidTown(town_id)) return -1; return ::Town::Get(town_id)->exclusive_counter; } -/* static */ bool AITown::IsActionAvailable(TownID town_id, TownAction town_action) +/* static */ bool ScriptTown::IsActionAvailable(TownID town_id, TownAction town_action) { if (!IsValidTown(town_id)) return false; return HasBit(::GetMaskOfTownActions(NULL, _current_company, ::Town::Get(town_id)), town_action); } -/* static */ bool AITown::PerformTownAction(TownID town_id, TownAction town_action) +/* static */ bool ScriptTown::PerformTownAction(TownID town_id, TownAction town_action) { EnforcePrecondition(false, IsValidTown(town_id)); EnforcePrecondition(false, IsActionAvailable(town_id, town_action)); - return AIObject::DoCommand(::Town::Get(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION); + return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION); } -/* static */ AITown::TownRating AITown::GetRating(TownID town_id, AICompany::CompanyID company_id) +/* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id) { if (!IsValidTown(town_id)) return TOWN_RATING_INVALID; - AICompany::CompanyID company = AICompany::ResolveCompanyID(company_id); - if (company == AICompany::COMPANY_INVALID) return TOWN_RATING_INVALID; + ScriptCompany::CompanyID company = ScriptCompany::ResolveCompanyID(company_id); + if (company == ScriptCompany::COMPANY_INVALID) return TOWN_RATING_INVALID; const Town *t = ::Town::Get(town_id); if (!HasBit(t->have_ratings, company)) { @@ -228,7 +228,7 @@ } } -/* static */ int AITown::GetAllowedNoise(TownID town_id) +/* static */ int ScriptTown::GetAllowedNoise(TownID town_id) { if (!IsValidTown(town_id)) return -1; @@ -245,9 +245,9 @@ return max(0, 2 - num); } -/* static */ AITown::RoadLayout AITown::GetRoadLayout(TownID town_id) +/* static */ ScriptTown::RoadLayout ScriptTown::GetRoadLayout(TownID town_id) { if (!IsValidTown(town_id)) return ROAD_LAYOUT_INVALID; - return (AITown::RoadLayout)((TownLayout)::Town::Get(town_id)->layout); + return (ScriptTown::RoadLayout)((TownLayout)::Town::Get(town_id)->layout); } diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp index e2efb2888..ceddacaca 100644 --- a/src/script/api/script_town.hpp +++ b/src/script/api/script_town.hpp @@ -18,7 +18,7 @@ /** * Class that handles all town related functions. */ -class AITown : public AIObject { +class ScriptTown : public ScriptObject { public: /** * Actions that one can perform on a town. @@ -151,7 +151,7 @@ public: * @param town_id The index of the town. * @param cargo_id The index of the cargo. * @pre IsValidTown(town_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return The last month's production of the given cargo for this town. */ static int32 GetLastMonthProduction(TownID town_id, CargoID cargo_id); @@ -161,7 +161,7 @@ public: * @param town_id The index of the town. * @param cargo_id The index of the cargo. * @pre IsValidTown(town_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return The amount of cargo supplied for transport from this town last month. */ static int32 GetLastMonthSupplied(TownID town_id, CargoID cargo_id); @@ -171,7 +171,7 @@ public: * @param town_id The index of the town. * @param cargo_id The index of the cargo. * @pre IsValidTown(town_id). - * @pre AICargo::IsValidCargo(cargo_id). + * @pre ScriptCargo::IsValidCargo(cargo_id). * @return The percentage of given cargo transported from this town last month. */ static int32 GetLastMonthTransportedPercentage(TownID town_id, CargoID cargo_id); @@ -181,10 +181,10 @@ public: * @param town_id The index of the town. * @param towneffect_id The index of the cargo. * @pre IsValidTown(town_id). - * @pre AICargo::IsValidTownEffect(cargo_id). + * @pre ScriptCargo::IsValidTownEffect(cargo_id). * @return The amount of cargo received by this town last month for this cargo effect. */ - static int32 GetLastMonthReceived(TownID town_id, AICargo::TownEffect towneffect_id); + static int32 GetLastMonthReceived(TownID town_id, ScriptCargo::TownEffect towneffect_id); /** * Get the amount of cargo that needs to be delivered (per TownEffect) for a @@ -192,12 +192,12 @@ public: * @param town_id The index of the town. * @param towneffect_id The index of the towneffect. * @pre IsValidTown(town_id). - * @pre AICargo::IsValidTownEffect(cargo_id). + * @pre ScriptCargo::IsValidTownEffect(cargo_id). * @return The goal of the cargo. * @note Goals can change over time. For example with a changing snowline, or * with a growing town. */ - static uint32 GetCargoGoal(TownID town_id, AICargo::TownEffect towneffect_id); + static uint32 GetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id); /** * Get the amount of days between town growth. @@ -209,7 +209,7 @@ public: static int32 GetGrowthRate(TownID town_id); /** - * Get the manhattan distance from the tile to the AITown::GetLocation() + * Get the manhattan distance from the tile to the ScriptTown::GetLocation() * of the town. * @param town_id The town to get the distance to. * @param tile The tile to get the distance to. @@ -219,7 +219,7 @@ public: static int32 GetDistanceManhattanToTile(TownID town_id, TileIndex tile); /** - * Get the square distance from the tile to the AITown::GetLocation() + * Get the square distance from the tile to the ScriptTown::GetLocation() * of the town. * @param town_id The town to get the distance to. * @param tile The tile to get the distance to. @@ -269,10 +269,10 @@ public: * @param town_id The town to check. * @pre IsValidTown(town_id). * @return The company that has the exclusive rights. The value - * AICompany::COMPANY_INVALID means that there are currently no + * ScriptCompany::COMPANY_INVALID means that there are currently no * exclusive rights given out to anyone. */ - static AICompany::CompanyID GetExclusiveRightsCompany(TownID town_id); + static ScriptCompany::CompanyID GetExclusiveRightsCompany(TownID town_id); /** * Find out how long the town is under influence of the exclusive rights. @@ -308,10 +308,10 @@ public: * @param town_id The town to get the rating for. * @param company_id The company to get the rating for. * @pre IsValidTown(town_id). - * @pre AICompany.ResolveCompanyID(company) != AICompany::COMPANY_INVALID. + * @pre ScriptCompany.ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID. * @return The rating as shown to humans. */ - static TownRating GetRating(TownID town_id, AICompany::CompanyID company_id); + static TownRating GetRating(TownID town_id, ScriptCompany::CompanyID company_id); /** * Get the maximum level of noise that still can be added by airports diff --git a/src/script/api/script_townlist.cpp b/src/script/api/script_townlist.cpp index 749555722..33a3fc070 100644 --- a/src/script/api/script_townlist.cpp +++ b/src/script/api/script_townlist.cpp @@ -7,13 +7,13 @@ * 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 script_townlist.cpp Implementation of AITownList and friends. */ +/** @file script_townlist.cpp Implementation of ScriptTownList and friends. */ #include "../../stdafx.h" #include "script_townlist.hpp" #include "../../town.h" -AITownList::AITownList() +ScriptTownList::ScriptTownList() { Town *t; FOR_ALL_TOWNS(t) { @@ -21,7 +21,7 @@ AITownList::AITownList() } } -AITownEffectList::AITownEffectList() +ScriptTownEffectList::ScriptTownEffectList() { for (int i = TE_BEGIN; i < TE_END; i++) { this->AddItem(i); diff --git a/src/script/api/script_townlist.hpp b/src/script/api/script_townlist.hpp index 6b3ba4ebc..4923df8de 100644 --- a/src/script/api/script_townlist.hpp +++ b/src/script/api/script_townlist.hpp @@ -16,20 +16,20 @@ /** * Creates a list of towns that are currently on the map. - * @ingroup AIList + * @ingroup ScriptList */ -class AITownList : public AIList { +class ScriptTownList : public ScriptList { public: - AITownList(); + ScriptTownList(); }; /** * Creates a list of all TownEffects known in the game. - * @ingroup AIList + * @ingroup ScriptList */ -class AITownEffectList : public AIList { +class ScriptTownEffectList : public ScriptList { public: - AITownEffectList(); + ScriptTownEffectList(); }; #endif /* SCRIPT_TOWNLIST_HPP */ diff --git a/src/script/api/script_tunnel.cpp b/src/script/api/script_tunnel.cpp index 1d03eae79..98407bf59 100644 --- a/src/script/api/script_tunnel.cpp +++ b/src/script/api/script_tunnel.cpp @@ -7,7 +7,7 @@ * 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 script_tunnel.cpp Implementation of AITunnel. */ +/** @file script_tunnel.cpp Implementation of ScriptTunnel. */ #include "../../stdafx.h" #include "script_tunnel.hpp" @@ -16,13 +16,13 @@ #include "../../tunnel_map.h" #include "../../command_func.h" -/* static */ bool AITunnel::IsTunnelTile(TileIndex tile) +/* static */ bool ScriptTunnel::IsTunnelTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; return ::IsTunnelTile(tile); } -/* static */ TileIndex AITunnel::GetOtherTunnelEnd(TileIndex tile) +/* static */ TileIndex ScriptTunnel::GetOtherTunnelEnd(TileIndex tile) { if (!::IsValidTile(tile)) return INVALID_TILE; @@ -52,7 +52,7 @@ */ static void _DoCommandReturnBuildTunnel2(class AIInstance *instance) { - if (!AITunnel::_BuildTunnelRoad2()) { + if (!ScriptTunnel::_BuildTunnelRoad2()) { AIInstance::DoCommandReturn(instance); return; } @@ -68,7 +68,7 @@ static void _DoCommandReturnBuildTunnel2(class AIInstance *instance) */ static void _DoCommandReturnBuildTunnel1(class AIInstance *instance) { - if (!AITunnel::_BuildTunnelRoad1()) { + if (!ScriptTunnel::_BuildTunnelRoad1()) { AIInstance::DoCommandReturn(instance); return; } @@ -78,57 +78,57 @@ static void _DoCommandReturnBuildTunnel1(class AIInstance *instance) NOT_REACHED(); } -/* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start) +/* static */ bool ScriptTunnel::BuildTunnel(ScriptVehicle::VehicleType vehicle_type, TileIndex start) { EnforcePrecondition(false, ::IsValidTile(start)); - EnforcePrecondition(false, vehicle_type == AIVehicle::VT_RAIL || vehicle_type == AIVehicle::VT_ROAD); - EnforcePrecondition(false, vehicle_type != AIVehicle::VT_RAIL || AIRail::IsRailTypeAvailable(AIRail::GetCurrentRailType())); + EnforcePrecondition(false, vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_ROAD); + EnforcePrecondition(false, vehicle_type != ScriptVehicle::VT_RAIL || ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())); uint type = 0; - if (vehicle_type == AIVehicle::VT_ROAD) { + if (vehicle_type == ScriptVehicle::VT_ROAD) { type |= (TRANSPORT_ROAD << 8); - type |= ::RoadTypeToRoadTypes((::RoadType)AIObject::GetRoadType()); + type |= ::RoadTypeToRoadTypes((::RoadType)ScriptObject::GetRoadType()); } else { type |= (TRANSPORT_RAIL << 8); - type |= AIRail::GetCurrentRailType(); + type |= ScriptRail::GetCurrentRailType(); } /* For rail we do nothing special */ - if (vehicle_type == AIVehicle::VT_RAIL) { - return AIObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL); + if (vehicle_type == ScriptVehicle::VT_RAIL) { + return ScriptObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL); } - AIObject::SetCallbackVariable(0, start); - return AIObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL, NULL, &::_DoCommandReturnBuildTunnel1); + ScriptObject::SetCallbackVariable(0, start); + return ScriptObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL, NULL, &::_DoCommandReturnBuildTunnel1); } -/* static */ bool AITunnel::_BuildTunnelRoad1() +/* static */ bool ScriptTunnel::_BuildTunnelRoad1() { /* Build the piece of road on the 'start' side of the tunnel */ - TileIndex end = AIObject::GetCallbackVariable(0); - TileIndex start = AITunnel::GetOtherTunnelEnd(end); + TileIndex end = ScriptObject::GetCallbackVariable(0); + TileIndex start = ScriptTunnel::GetOtherTunnelEnd(end); DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return AIObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildTunnel2); + return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildTunnel2); } -/* static */ bool AITunnel::_BuildTunnelRoad2() +/* static */ bool ScriptTunnel::_BuildTunnelRoad2() { /* Build the piece of road on the 'end' side of the tunnel */ - TileIndex end = AIObject::GetCallbackVariable(0); - TileIndex start = AITunnel::GetOtherTunnelEnd(end); + TileIndex end = ScriptObject::GetCallbackVariable(0); + TileIndex start = ScriptTunnel::GetOtherTunnelEnd(end); DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return AIObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (AIObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD); + return ScriptObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD); } -/* static */ bool AITunnel::RemoveTunnel(TileIndex tile) +/* static */ bool ScriptTunnel::RemoveTunnel(TileIndex tile) { EnforcePrecondition(false, IsTunnelTile(tile)); - return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); + return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); } diff --git a/src/script/api/script_tunnel.hpp b/src/script/api/script_tunnel.hpp index 86def379d..3a6ec7b55 100644 --- a/src/script/api/script_tunnel.hpp +++ b/src/script/api/script_tunnel.hpp @@ -17,7 +17,7 @@ /** * Class that handles all tunnel related functions. */ -class AITunnel : public AIObject { +class ScriptTunnel : public ScriptObject { public: /** * All tunnel related errors. @@ -25,7 +25,7 @@ public: enum ErrorMessages { /** Base for bridge related errors */ - ERR_TUNNEL_BASE = AIError::ERR_CAT_TUNNEL << AIError::ERR_CAT_BIT_SIZE, + ERR_TUNNEL_BASE = ScriptError::ERR_CAT_TUNNEL << ScriptError::ERR_CAT_BIT_SIZE, /** Can't build tunnels on water */ ERR_TUNNEL_CANNOT_BUILD_ON_WATER, // [STR_ERROR_CAN_T_BUILD_ON_WATER] @@ -43,7 +43,7 @@ public: /** * Check whether the tile is an entrance to a tunnel. * @param tile The tile to check. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return True if and only if the tile is the beginning or end of a tunnel. */ static bool IsTunnelTile(TileIndex tile); @@ -51,13 +51,13 @@ public: /** * Get the tile that exits on the other end of a (would be) tunnel starting * at tile. If there is no 'simple' inclined slope at the start tile, - * this function will return AIMap::TILE_INVALID. + * this function will return ScriptMap::TILE_INVALID. * @param tile The tile that is an entrance to a tunnel or the tile where you may want to build a tunnel. - * @pre AIMap::IsValidTile(tile). + * @pre ScriptMap::IsValidTile(tile). * @return The TileIndex that is the other end of the (would be) tunnel, or - * AIMap::TILE_INVALID if no other end was found (can't build tunnel). + * ScriptMap::TILE_INVALID if no other end was found (can't build tunnel). * @note Even if this function returns a valid tile, that is no guarantee - * that building a tunnel will succeed. Use BuildTunnel in AITestMode to + * that building a tunnel will succeed. Use BuildTunnel in ScriptTestMode to * check whether a tunnel can actually be build. */ static TileIndex GetOtherTunnelEnd(TileIndex tile); @@ -77,32 +77,32 @@ public: /** * Builds a tunnel starting at start. The direction of the tunnel depends * on the slope of the start tile. Tunnels can be created for either - * rails or roads; use the appropriate AIVehicle::VehicleType. + * rails or roads; use the appropriate ScriptVehicle::VehicleType. * As an extra for road, this functions builds two half-pieces of road on * each end of the tunnel, making it easier for you to connect it to your * network. * @param start Where to start the tunnel. * @param vehicle_type The vehicle-type of tunnel to build. - * @pre AIMap::IsValidTile(start). - * @pre vehicle_type == AIVehicle::VT_ROAD || (vehicle_type == AIVehicle::VT_RAIL && - * AIRail::IsRailTypeAvailable(AIRail::GetCurrentRailType())). - * @exception AIError::ERR_AREA_NOT_CLEAR - * @exception AITunnel::ERR_TUNNEL_CANNOT_BUILD_ON_WATER - * @exception AITunnel::ERR_TUNNEL_START_SITE_UNSUITABLE - * @exception AITunnel::ERR_TUNNEL_ANOTHER_TUNNEL_IN_THE_WAY - * @exception AITunnel::ERR_TUNNEL_END_SITE_UNSUITABLE + * @pre ScriptMap::IsValidTile(start). + * @pre vehicle_type == ScriptVehicle::VT_ROAD || (vehicle_type == ScriptVehicle::VT_RAIL && + * ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())). + * @exception ScriptError::ERR_AREA_NOT_CLEAR + * @exception ScriptTunnel::ERR_TUNNEL_CANNOT_BUILD_ON_WATER + * @exception ScriptTunnel::ERR_TUNNEL_START_SITE_UNSUITABLE + * @exception ScriptTunnel::ERR_TUNNEL_ANOTHER_TUNNEL_IN_THE_WAY + * @exception ScriptTunnel::ERR_TUNNEL_END_SITE_UNSUITABLE * @return Whether the tunnel has been/can be build or not. - * @note The slope of a tile can be determined by AITile::GetSlope(TileIndex). + * @note The slope of a tile can be determined by ScriptTile::GetSlope(TileIndex). * @note No matter if the road pieces were build or not, if building the * tunnel succeeded, this function returns true. */ - static bool BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start); + static bool BuildTunnel(ScriptVehicle::VehicleType vehicle_type, TileIndex start); /** * Remove the tunnel whose entrance is located at tile. * @param tile The tile that is an entrance to a tunnel. - * @pre AIMap::IsValidTile(tile) && IsTunnelTile(tile). - * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY + * @pre ScriptMap::IsValidTile(tile) && IsTunnelTile(tile). + * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return Whether the tunnel has been/can be removed or not. */ static bool RemoveTunnel(TileIndex tile); diff --git a/src/script/api/script_types.hpp b/src/script/api/script_types.hpp index a797d3e29..1cce06571 100644 --- a/src/script/api/script_types.hpp +++ b/src/script/api/script_types.hpp @@ -100,7 +100,7 @@ typedef uint16 TownID; ///< The ID of a town. typedef uint32 VehicleID; ///< The ID of a vehicle. /* Types we defined ourself, as the OpenTTD core doesn't have them (yet) */ -typedef uint AIErrorType; ///< The types of errors inside the NoAI framework. +typedef uint ScriptErrorType; ///< The types of errors inside the NoAI framework. typedef BridgeType BridgeID; ///< The ID of a bridge. #endif /* SCRIPT_TYPES_HPP */ diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index e1b997252..216d4cf60 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -7,7 +7,7 @@ * 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 script_vehicle.cpp Implementation of AIVehicle. */ +/** @file script_vehicle.cpp Implementation of ScriptVehicle. */ #include "../../stdafx.h" #include "script_engine.hpp" @@ -24,13 +24,13 @@ #include "../../vehicle_func.h" #include "table/strings.h" -/* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::IsValidVehicle(VehicleID vehicle_id) { const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id); return v != NULL && v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon())); } -/* static */ int32 AIVehicle::GetNumWagons(VehicleID vehicle_id) +/* static */ int32 ScriptVehicle::GetNumWagons(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; @@ -44,7 +44,7 @@ return num; } -/* static */ int AIVehicle::GetLength(VehicleID vehicle_id) +/* static */ int ScriptVehicle::GetLength(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; @@ -52,31 +52,31 @@ return v->IsGroundVehicle() ? v->GetGroundVehicleCache()->cached_total_length : -1; } -/* static */ VehicleID AIVehicle::BuildVehicle(TileIndex depot, EngineID engine_id) +/* static */ VehicleID ScriptVehicle::BuildVehicle(TileIndex depot, EngineID engine_id) { - EnforcePrecondition(VEHICLE_INVALID, AIEngine::IsBuildable(engine_id)); + EnforcePrecondition(VEHICLE_INVALID, ScriptEngine::IsBuildable(engine_id)); ::VehicleType type = ::Engine::Get(engine_id)->type; - EnforcePreconditionCustomError(VEHICLE_INVALID, !AIGameSettings::IsDisabledVehicleType((AIVehicle::VehicleType)type), AIVehicle::ERR_VEHICLE_BUILD_DISABLED); + EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED); - if (!AIObject::DoCommand(depot, engine_id, 0, ::GetCmdBuildVeh(type), NULL, &AIInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID; + if (!ScriptObject::DoCommand(depot, engine_id, 0, ::GetCmdBuildVeh(type), NULL, &AIInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID; /* In case of test-mode, we return VehicleID 0 */ return 0; } -/* static */ VehicleID AIVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders) +/* static */ VehicleID ScriptVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders) { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); - if (!AIObject::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, &AIInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID; /* In case of test-mode, we return VehicleID 0 */ return 0; } -/* static */ bool AIVehicle::_MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon) +/* static */ bool ScriptVehicle::_MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon) { EnforcePrecondition(false, IsValidVehicle(source_vehicle_id) && source_wagon < GetNumWagons(source_vehicle_id)); EnforcePrecondition(false, dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id))); @@ -91,45 +91,45 @@ while (dest_wagon-- > 0) w = w->GetNextUnit(); } - return AIObject::DoCommand(0, v->index | (move_attached_wagons ? 1 : 0) << 20, w == NULL ? ::INVALID_VEHICLE : w->index, CMD_MOVE_RAIL_VEHICLE); + return ScriptObject::DoCommand(0, v->index | (move_attached_wagons ? 1 : 0) << 20, w == NULL ? ::INVALID_VEHICLE : w->index, CMD_MOVE_RAIL_VEHICLE); } -/* static */ bool AIVehicle::MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon) +/* static */ bool ScriptVehicle::MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon) { return _MoveWagonInternal(source_vehicle_id, source_wagon, false, dest_vehicle_id, dest_wagon); } -/* static */ bool AIVehicle::MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon) +/* static */ bool ScriptVehicle::MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon) { return _MoveWagonInternal(source_vehicle_id, source_wagon, true, dest_vehicle_id, dest_wagon); } -/* static */ int AIVehicle::GetRefitCapacity(VehicleID vehicle_id, CargoID cargo) +/* static */ int ScriptVehicle::GetRefitCapacity(VehicleID vehicle_id, CargoID cargo) { if (!IsValidVehicle(vehicle_id)) return -1; - if (!AICargo::IsValidCargo(cargo)) return -1; + if (!ScriptCargo::IsValidCargo(cargo)) return -1; CommandCost res = ::DoCommand(0, vehicle_id, cargo, DC_QUERY_COST, GetCmdRefitVeh(::Vehicle::Get(vehicle_id))); return res.Succeeded() ? _returned_refit_capacity : -1; } -/* static */ bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo) +/* static */ bool ScriptVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo) { - EnforcePrecondition(false, IsValidVehicle(vehicle_id) && AICargo::IsValidCargo(cargo)); + EnforcePrecondition(false, IsValidVehicle(vehicle_id) && ScriptCargo::IsValidCargo(cargo)); - return AIObject::DoCommand(0, vehicle_id, cargo, GetCmdRefitVeh(::Vehicle::Get(vehicle_id))); + return ScriptObject::DoCommand(0, vehicle_id, cargo, GetCmdRefitVeh(::Vehicle::Get(vehicle_id))); } -/* static */ bool AIVehicle::SellVehicle(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::SellVehicle(VehicleID vehicle_id) { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); const Vehicle *v = ::Vehicle::Get(vehicle_id); - return AIObject::DoCommand(0, vehicle_id | (v->type == VEH_TRAIN ? 1 : 0) << 20, 0, GetCmdSellVeh(v)); + return ScriptObject::DoCommand(0, vehicle_id | (v->type == VEH_TRAIN ? 1 : 0) << 20, 0, GetCmdSellVeh(v)); } -/* static */ bool AIVehicle::_SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons) +/* static */ bool ScriptVehicle::_SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons) { EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id)); EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN); @@ -137,74 +137,74 @@ const Train *v = ::Train::Get(vehicle_id); while (wagon-- > 0) v = v->GetNextUnit(); - return AIObject::DoCommand(0, v->index | (sell_attached_wagons ? 1 : 0) << 20, 0, CMD_SELL_VEHICLE); + return ScriptObject::DoCommand(0, v->index | (sell_attached_wagons ? 1 : 0) << 20, 0, CMD_SELL_VEHICLE); } -/* static */ bool AIVehicle::SellWagon(VehicleID vehicle_id, int wagon) +/* static */ bool ScriptVehicle::SellWagon(VehicleID vehicle_id, int wagon) { return _SellWagonInternal(vehicle_id, wagon, false); } -/* static */ bool AIVehicle::SellWagonChain(VehicleID vehicle_id, int wagon) +/* static */ bool ScriptVehicle::SellWagonChain(VehicleID vehicle_id, int wagon) { return _SellWagonInternal(vehicle_id, wagon, true); } -/* static */ bool AIVehicle::SendVehicleToDepot(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::SendVehicleToDepot(VehicleID vehicle_id) { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); - return AIObject::DoCommand(0, vehicle_id, 0, GetCmdSendToDepot(::Vehicle::Get(vehicle_id))); + return ScriptObject::DoCommand(0, vehicle_id, 0, GetCmdSendToDepot(::Vehicle::Get(vehicle_id))); } -/* static */ bool AIVehicle::SendVehicleToDepotForServicing(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::SendVehicleToDepotForServicing(VehicleID vehicle_id) { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); - return AIObject::DoCommand(0, vehicle_id | DEPOT_SERVICE, 0, GetCmdSendToDepot(::Vehicle::Get(vehicle_id))); + return ScriptObject::DoCommand(0, vehicle_id | DEPOT_SERVICE, 0, GetCmdSendToDepot(::Vehicle::Get(vehicle_id))); } -/* static */ bool AIVehicle::IsInDepot(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::IsInDepot(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return false; return ::Vehicle::Get(vehicle_id)->IsInDepot(); } -/* static */ bool AIVehicle::IsStoppedInDepot(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::IsStoppedInDepot(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return false; return ::Vehicle::Get(vehicle_id)->IsStoppedInDepot(); } -/* static */ bool AIVehicle::StartStopVehicle(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::StartStopVehicle(VehicleID vehicle_id) { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); - return AIObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_VEHICLE); + return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_VEHICLE); } -/* static */ bool AIVehicle::ReverseVehicle(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::ReverseVehicle(VehicleID vehicle_id) { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_ROAD || ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN); switch (::Vehicle::Get(vehicle_id)->type) { - case VEH_ROAD: return AIObject::DoCommand(0, vehicle_id, 0, CMD_TURN_ROADVEH); - case VEH_TRAIN: return AIObject::DoCommand(0, vehicle_id, 0, CMD_REVERSE_TRAIN_DIRECTION); + case VEH_ROAD: return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_TURN_ROADVEH); + case VEH_TRAIN: return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_REVERSE_TRAIN_DIRECTION); default: NOT_REACHED(); } } -/* static */ bool AIVehicle::SetName(VehicleID vehicle_id, const char *name) +/* static */ bool ScriptVehicle::SetName(VehicleID vehicle_id, const char *name) { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_VEHICLE_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return AIObject::DoCommand(0, vehicle_id, 0, CMD_RENAME_VEHICLE, name); + return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_RENAME_VEHICLE, name); } -/* static */ TileIndex AIVehicle::GetLocation(VehicleID vehicle_id) +/* static */ TileIndex ScriptVehicle::GetLocation(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return INVALID_TILE; @@ -218,14 +218,14 @@ return v->tile; } -/* static */ EngineID AIVehicle::GetEngineType(VehicleID vehicle_id) +/* static */ EngineID ScriptVehicle::GetEngineType(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE; return ::Vehicle::Get(vehicle_id)->engine_type; } -/* static */ EngineID AIVehicle::GetWagonEngineType(VehicleID vehicle_id, int wagon) +/* static */ EngineID ScriptVehicle::GetWagonEngineType(VehicleID vehicle_id, int wagon) { if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE; if (wagon >= GetNumWagons(vehicle_id)) return INVALID_ENGINE; @@ -237,14 +237,14 @@ return v->engine_type; } -/* static */ int32 AIVehicle::GetUnitNumber(VehicleID vehicle_id) +/* static */ int32 ScriptVehicle::GetUnitNumber(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->unitnumber; } -/* static */ char *AIVehicle::GetName(VehicleID vehicle_id) +/* static */ char *ScriptVehicle::GetName(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return NULL; @@ -256,14 +256,14 @@ return vehicle_name; } -/* static */ int32 AIVehicle::GetAge(VehicleID vehicle_id) +/* static */ int32 ScriptVehicle::GetAge(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->age; } -/* static */ int32 AIVehicle::GetWagonAge(VehicleID vehicle_id, int wagon) +/* static */ int32 ScriptVehicle::GetWagonAge(VehicleID vehicle_id, int wagon) { if (!IsValidVehicle(vehicle_id)) return -1; if (wagon >= GetNumWagons(vehicle_id)) return -1; @@ -275,71 +275,71 @@ return v->age; } -/* static */ int32 AIVehicle::GetMaxAge(VehicleID vehicle_id) +/* static */ int32 ScriptVehicle::GetMaxAge(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->max_age; } -/* static */ int32 AIVehicle::GetAgeLeft(VehicleID vehicle_id) +/* static */ int32 ScriptVehicle::GetAgeLeft(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age; } -/* static */ int32 AIVehicle::GetCurrentSpeed(VehicleID vehicle_id) +/* static */ int32 ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->GetDisplaySpeed(); // km-ish/h } -/* static */ AIVehicle::VehicleState AIVehicle::GetState(VehicleID vehicle_id) +/* static */ ScriptVehicle::VehicleState ScriptVehicle::GetState(VehicleID vehicle_id) { - if (!IsValidVehicle(vehicle_id)) return AIVehicle::VS_INVALID; + if (!IsValidVehicle(vehicle_id)) return ScriptVehicle::VS_INVALID; const Vehicle *v = ::Vehicle::Get(vehicle_id); byte vehstatus = v->vehstatus; - if (vehstatus & ::VS_CRASHED) return AIVehicle::VS_CRASHED; - if (v->breakdown_ctr != 0) return AIVehicle::VS_BROKEN; - if (v->IsStoppedInDepot()) return AIVehicle::VS_IN_DEPOT; - if (vehstatus & ::VS_STOPPED) return AIVehicle::VS_STOPPED; - if (v->current_order.IsType(OT_LOADING)) return AIVehicle::VS_AT_STATION; - return AIVehicle::VS_RUNNING; + if (vehstatus & ::VS_CRASHED) return ScriptVehicle::VS_CRASHED; + if (v->breakdown_ctr != 0) return ScriptVehicle::VS_BROKEN; + if (v->IsStoppedInDepot()) return ScriptVehicle::VS_IN_DEPOT; + if (vehstatus & ::VS_STOPPED) return ScriptVehicle::VS_STOPPED; + if (v->current_order.IsType(OT_LOADING)) return ScriptVehicle::VS_AT_STATION; + return ScriptVehicle::VS_RUNNING; } -/* static */ Money AIVehicle::GetRunningCost(VehicleID vehicle_id) +/* static */ Money ScriptVehicle::GetRunningCost(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->GetRunningCost() >> 8; } -/* static */ Money AIVehicle::GetProfitThisYear(VehicleID vehicle_id) +/* static */ Money ScriptVehicle::GetProfitThisYear(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->GetDisplayProfitThisYear(); } -/* static */ Money AIVehicle::GetProfitLastYear(VehicleID vehicle_id) +/* static */ Money ScriptVehicle::GetProfitLastYear(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->GetDisplayProfitLastYear(); } -/* static */ Money AIVehicle::GetCurrentValue(VehicleID vehicle_id) +/* static */ Money ScriptVehicle::GetCurrentValue(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return -1; return ::Vehicle::Get(vehicle_id)->value; } -/* static */ AIVehicle::VehicleType AIVehicle::GetVehicleType(VehicleID vehicle_id) +/* static */ ScriptVehicle::VehicleType ScriptVehicle::GetVehicleType(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return VT_INVALID; @@ -352,18 +352,18 @@ } } -/* static */ AIRoad::RoadType AIVehicle::GetRoadType(VehicleID vehicle_id) +/* static */ ScriptRoad::RoadType ScriptVehicle::GetRoadType(VehicleID vehicle_id) { - if (!IsValidVehicle(vehicle_id)) return AIRoad::ROADTYPE_INVALID; - if (GetVehicleType(vehicle_id) != VT_ROAD) return AIRoad::ROADTYPE_INVALID; + if (!IsValidVehicle(vehicle_id)) return ScriptRoad::ROADTYPE_INVALID; + if (GetVehicleType(vehicle_id) != VT_ROAD) return ScriptRoad::ROADTYPE_INVALID; - return (AIRoad::RoadType)(::RoadVehicle::Get(vehicle_id))->roadtype; + return (ScriptRoad::RoadType)(::RoadVehicle::Get(vehicle_id))->roadtype; } -/* static */ int32 AIVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo) +/* static */ int32 ScriptVehicle::GetCapacity(VehicleID vehicle_id, CargoID cargo) { if (!IsValidVehicle(vehicle_id)) return -1; - if (!AICargo::IsValidCargo(cargo)) return -1; + if (!ScriptCargo::IsValidCargo(cargo)) return -1; uint32 amount = 0; for (const Vehicle *v = ::Vehicle::Get(vehicle_id); v != NULL; v = v->Next()) { @@ -373,10 +373,10 @@ return amount; } -/* static */ int32 AIVehicle::GetCargoLoad(VehicleID vehicle_id, CargoID cargo) +/* static */ int32 ScriptVehicle::GetCargoLoad(VehicleID vehicle_id, CargoID cargo) { if (!IsValidVehicle(vehicle_id)) return -1; - if (!AICargo::IsValidCargo(cargo)) return -1; + if (!ScriptCargo::IsValidCargo(cargo)) return -1; uint32 amount = 0; for (const Vehicle *v = ::Vehicle::Get(vehicle_id); v != NULL; v = v->Next()) { @@ -386,14 +386,14 @@ return amount; } -/* static */ GroupID AIVehicle::GetGroupID(VehicleID vehicle_id) +/* static */ GroupID ScriptVehicle::GetGroupID(VehicleID vehicle_id) { - if (!IsValidVehicle(vehicle_id)) return AIGroup::GROUP_INVALID; + if (!IsValidVehicle(vehicle_id)) return ScriptGroup::GROUP_INVALID; return ::Vehicle::Get(vehicle_id)->group_id; } -/* static */ bool AIVehicle::IsArticulated(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::IsArticulated(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return false; if (GetVehicleType(vehicle_id) != VT_ROAD && GetVehicleType(vehicle_id) != VT_RAIL) return false; @@ -406,7 +406,7 @@ } } -/* static */ bool AIVehicle::HasSharedOrders(VehicleID vehicle_id) +/* static */ bool ScriptVehicle::HasSharedOrders(VehicleID vehicle_id) { if (!IsValidVehicle(vehicle_id)) return false; @@ -414,7 +414,7 @@ return v->orders.list != NULL && v->orders.list->GetNumVehicles() > 1; } -/* static */ int AIVehicle::GetReliability(VehicleID vehicle_id) +/* static */ int ScriptVehicle::GetReliability(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 e9b403f54..168bac437 100644 --- a/src/script/api/script_vehicle.hpp +++ b/src/script/api/script_vehicle.hpp @@ -17,14 +17,14 @@ /** * Class that handles all vehicle related functions. */ -class AIVehicle : public AIObject { +class ScriptVehicle : public ScriptObject { public: /** * All vehicle related error messages. */ enum ErrorMessages { /** Base for vehicle related errors */ - ERR_VEHICLE_BASE = AIError::ERR_CAT_VEHICLE << AIError::ERR_CAT_BIT_SIZE, + ERR_VEHICLE_BASE = ScriptError::ERR_CAT_VEHICLE << ScriptError::ERR_CAT_BIT_SIZE, /** Too many vehicles in the game, can't build any more. */ ERR_VEHICLE_TOO_MANY, // [STR_ERROR_TOO_MANY_VEHICLES_IN_GAME] @@ -117,7 +117,7 @@ public: * @pre IsValidVehicle(vehicle_id). * @pre 'name' must have at least one character. * @pre 'name' must have at most 30 characters. - * @exception AIError::ERR_NAME_IS_NOT_UNIQUE + * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ static bool SetName(VehicleID vehicle_id, const char *name); @@ -227,7 +227,7 @@ public: * @pre IsValidVehicle(vehicle_id). * @return The running cost of the vehicle per year. * @note Cost is per year; divide by 365 to get per day. - * @note This is not equal to AIEngine::GetRunningCost for Trains, because + * @note This is not equal to ScriptEngine::GetRunningCost for Trains, because * wagons and second engines can add up in the calculation too. */ static Money GetRunningCost(VehicleID vehicle_id); @@ -264,7 +264,7 @@ public: * @pre IsValidVehicle(vehicle_id). * @return The vehicle type. */ - static AIVehicle::VehicleType GetVehicleType(VehicleID vehicle_id); + static ScriptVehicle::VehicleType GetVehicleType(VehicleID vehicle_id); /** * Get the RoadType of the vehicle. @@ -273,7 +273,7 @@ public: * @pre GetVehicleType(vehicle_id) == VT_ROAD. * @return The RoadType the vehicle has. */ - static AIRoad::RoadType GetRoadType(VehicleID vehicle_id); + static ScriptRoad::RoadType GetRoadType(VehicleID vehicle_id); /** * Check if a vehicle is in a depot. @@ -297,10 +297,10 @@ public: * @param engine_id The engine to use for this vehicle. * @pre The tile at depot has a depot that can build the engine and * is owned by you. - * @pre AIEngine::IsBuildable(engine_id). - * @exception AIVehicle::ERR_VEHICLE_TOO_MANY - * @exception AIVehicle::ERR_VEHICLE_BUILD_DISABLED - * @exception AIVehicle::ERR_VEHICLE_WRONG_DEPOT + * @pre ScriptEngine::IsBuildable(engine_id). + * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY + * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED + * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT * @return The VehicleID of the new vehicle, or an invalid VehicleID when * it failed. Check the return value using IsValidVehicle. In test-mode * 0 is returned if it was successful; any other value indicates failure. @@ -317,9 +317,9 @@ public: * @param share_orders Should the orders be copied or shared? * @pre The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles. * @pre IsValidVehicle(vehicle_id). - * @exception AIVehicle::ERR_VEHICLE_TOO_MANY - * @exception AIVehicle::ERR_VEHICLE_BUILD_DISABLED - * @exception AIVehicle::ERR_VEHICLE_WRONG_DEPOT + * @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY + * @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED + * @exception ScriptVehicle::ERR_VEHICLE_WRONG_DEPOT * @return The VehicleID of the new vehicle, or an invalid VehicleID when * it failed. Check the return value using IsValidVehicle. In test-mode * 0 is returned if it was successful; any other value indicates failure. @@ -361,7 +361,7 @@ public: * @param vehicle_id The vehicle to refit. * @param cargo The cargo to refit to. * @pre IsValidVehicle(vehicle_id). - * @pre AICargo::IsValidCargo(cargo). + * @pre ScriptCargo::IsValidCargo(cargo). * @pre You must own the vehicle. * @pre The vehicle must be stopped in the depot. * @return The capacity the vehicle will have when refited. @@ -373,12 +373,12 @@ public: * @param vehicle_id The vehicle to refit. * @param cargo The cargo to refit to. * @pre IsValidVehicle(vehicle_id). - * @pre AICargo::IsValidCargo(cargo). + * @pre ScriptCargo::IsValidCargo(cargo). * @pre You must own the vehicle. * @pre The vehicle must be stopped in the depot. - * @exception AIVehicle::ERR_VEHICLE_CANNOT_REFIT - * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED - * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT + * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_REFIT + * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED + * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT * @return True if and only if the refit succeeded. */ static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo); @@ -389,8 +389,8 @@ public: * @pre IsValidVehicle(vehicle_id). * @pre You must own the vehicle. * @pre The vehicle must be stopped in the depot. - * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED - * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT + * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED + * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT * @return True if and only if the vehicle has been sold. */ static bool SellVehicle(VehicleID vehicle_id); @@ -403,8 +403,8 @@ public: * @pre wagon < GetNumWagons(vehicle_id). * @pre You must own the vehicle. * @pre The vehicle must be stopped in the depot. - * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED - * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT + * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED + * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT * @return True if and only if the wagon has been sold. */ static bool SellWagon(VehicleID vehicle_id, int wagon); @@ -417,8 +417,8 @@ public: * @pre wagon < GetNumWagons(vehicle_id). * @pre You must own the vehicle. * @pre The vehicle must be stopped in the depot. - * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED - * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT + * @exception ScriptVehicle::ERR_VEHICLE_IS_DESTROYED + * @exception ScriptVehicle::ERR_VEHICLE_NOT_IN_DEPOT * @return True if and only if the wagons have been sold. */ static bool SellWagonChain(VehicleID vehicle_id, int wagon); @@ -428,7 +428,7 @@ public: * sent to a depot it continues with its normal orders instead. * @param vehicle_id The vehicle to send to a depot. * @pre IsValidVehicle(vehicle_id). - * @exception AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT + * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT * @return True if the current order was changed. */ static bool SendVehicleToDepot(VehicleID vehicle_id); @@ -438,7 +438,7 @@ public: * already been sent to a depot it continues with its normal orders instead. * @param vehicle_id The vehicle to send to a depot for servicing. * @pre IsValidVehicle(vehicle_id). - * @exception AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT + * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT * @return True if the current order was changed. */ static bool SendVehicleToDepotForServicing(VehicleID vehicle_id); @@ -447,9 +447,9 @@ public: * Starts or stops the given vehicle depending on the current state. * @param vehicle_id The vehicle to start/stop. * @pre IsValidVehicle(vehicle_id). - * @exception AIVehicle::ERR_VEHICLE_CANNOT_START_STOP - * @exception (For aircraft only): AIVehicle::ERR_VEHICLE_IN_FLIGHT - * @exception (For trains only): AIVehicle::ERR_VEHICLE_NO_POWER + * @exception ScriptVehicle::ERR_VEHICLE_CANNOT_START_STOP + * @exception (For aircraft only): ScriptVehicle::ERR_VEHICLE_IN_FLIGHT + * @exception (For trains only): ScriptVehicle::ERR_VEHICLE_NO_POWER * @return True if and only if the vehicle has been started or stopped. */ static bool StartStopVehicle(VehicleID vehicle_id); @@ -470,7 +470,7 @@ public: * @param vehicle_id The vehicle to get the capacity of. * @param cargo The cargo to get the capacity for. * @pre IsValidVehicle(vehicle_id). - * @pre AICargo::IsValidCargo(cargo). + * @pre ScriptCargo::IsValidCargo(cargo). * @return The maximum amount of the given cargo the vehicle can transport. */ static int32 GetCapacity(VehicleID vehicle_id, CargoID cargo); @@ -489,7 +489,7 @@ public: * @param vehicle_id The vehicle to get the load amount of. * @param cargo The cargo to get the load amount for. * @pre IsValidVehicle(vehicle_id). - * @pre AICargo::IsValidCargo(cargo). + * @pre ScriptCargo::IsValidCargo(cargo). * @return The amount of the given cargo the vehicle currently transports. */ static int32 GetCargoLoad(VehicleID vehicle_id, CargoID cargo); diff --git a/src/script/api/script_vehiclelist.cpp b/src/script/api/script_vehiclelist.cpp index dde717e30..a8eae5be8 100644 --- a/src/script/api/script_vehiclelist.cpp +++ b/src/script/api/script_vehiclelist.cpp @@ -7,7 +7,7 @@ * 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 script_vehiclelist.cpp Implementation of AIVehicleList and friends. */ +/** @file script_vehiclelist.cpp Implementation of ScriptVehicleList and friends. */ #include "../../stdafx.h" #include "script_vehiclelist.hpp" @@ -18,7 +18,7 @@ #include "../../depot_map.h" #include "../../vehicle_base.h" -AIVehicleList::AIVehicleList() +ScriptVehicleList::ScriptVehicleList() { const Vehicle *v; FOR_ALL_VEHICLES(v) { @@ -26,9 +26,9 @@ AIVehicleList::AIVehicleList() } } -AIVehicleList_Station::AIVehicleList_Station(StationID station_id) +ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id) { - if (!AIBaseStation::IsValidBaseStation(station_id)) return; + if (!ScriptBaseStation::IsValidBaseStation(station_id)) return; const Vehicle *v; FOR_ALL_VEHICLES(v) { @@ -45,9 +45,9 @@ AIVehicleList_Station::AIVehicleList_Station(StationID station_id) } } -AIVehicleList_Depot::AIVehicleList_Depot(TileIndex tile) +ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile) { - if (!AIMap::IsValidTile(tile)) return; + if (!ScriptMap::IsValidTile(tile)) return; DestinationID dest; VehicleType type; @@ -96,18 +96,18 @@ AIVehicleList_Depot::AIVehicleList_Depot(TileIndex tile) } } -AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(VehicleID vehicle_id) +ScriptVehicleList_SharedOrders::ScriptVehicleList_SharedOrders(VehicleID vehicle_id) { - if (!AIVehicle::IsValidVehicle(vehicle_id)) return; + if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return; for (const Vehicle *v = Vehicle::Get(vehicle_id)->FirstShared(); v != NULL; v = v->NextShared()) { this->AddItem(v->index); } } -AIVehicleList_Group::AIVehicleList_Group(GroupID group_id) +ScriptVehicleList_Group::ScriptVehicleList_Group(GroupID group_id) { - if (!AIGroup::IsValidGroup((AIGroup::GroupID)group_id)) return; + if (!ScriptGroup::IsValidGroup((ScriptGroup::GroupID)group_id)) return; const Vehicle *v; FOR_ALL_VEHICLES(v) { @@ -117,14 +117,14 @@ AIVehicleList_Group::AIVehicleList_Group(GroupID group_id) } } -AIVehicleList_DefaultGroup::AIVehicleList_DefaultGroup(AIVehicle::VehicleType vehicle_type) +ScriptVehicleList_DefaultGroup::ScriptVehicleList_DefaultGroup(ScriptVehicle::VehicleType vehicle_type) { - if (vehicle_type < AIVehicle::VT_RAIL || vehicle_type > AIVehicle::VT_AIR) return; + if (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR) return; const Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->owner == _current_company && v->IsPrimaryVehicle()) { - if (v->type == vehicle_type && v->group_id == AIGroup::GROUP_DEFAULT) this->AddItem(v->index); + if (v->type == vehicle_type && v->group_id == ScriptGroup::GROUP_DEFAULT) this->AddItem(v->index); } } } diff --git a/src/script/api/script_vehiclelist.hpp b/src/script/api/script_vehiclelist.hpp index 059041f3b..b4f0204ea 100644 --- a/src/script/api/script_vehiclelist.hpp +++ b/src/script/api/script_vehiclelist.hpp @@ -17,24 +17,24 @@ /** * Creates a list of vehicles of which you are the owner. - * @ingroup AIList + * @ingroup ScriptList */ -class AIVehicleList : public AIList { +class ScriptVehicleList : public ScriptList { public: - AIVehicleList(); + ScriptVehicleList(); }; /** * Creates a list of vehicles that have orders to a given station. - * @ingroup AIList + * @ingroup ScriptList */ -class AIVehicleList_Station : public AIList { +class ScriptVehicleList_Station : public ScriptList { public: /** * @param station_id The station to get the list of vehicles from, which have orders to it. - * @pre AIBaseStation::IsValidBaseStation(station_id) + * @pre ScriptBaseStation::IsValidBaseStation(station_id) */ - AIVehicleList_Station(StationID station_id); + ScriptVehicleList_Station(StationID station_id); }; /** @@ -43,50 +43,50 @@ public: * aircraft having a depot order on a hangar of that airport will be * returned. For all other vehicle types the tile has to be a depot or * an empty list will be returned. - * @ingroup AIList + * @ingroup ScriptList */ -class AIVehicleList_Depot : public AIList { +class ScriptVehicleList_Depot : public ScriptList { public: /** * @param tile The tile of the depot to get the list of vehicles from, which have orders to it. */ - AIVehicleList_Depot(TileIndex tile); + ScriptVehicleList_Depot(TileIndex tile); }; /** * Creates a list of vehicles that share orders. - * @ingroup AIList + * @ingroup ScriptList */ -class AIVehicleList_SharedOrders : public AIList { +class ScriptVehicleList_SharedOrders : public ScriptList { public: /** * @param vehicle_id The vehicle that the rest shared orders with. */ - AIVehicleList_SharedOrders(VehicleID vehicle_id); + ScriptVehicleList_SharedOrders(VehicleID vehicle_id); }; /** * Creates a list of vehicles that are in a group. - * @ingroup AIList + * @ingroup ScriptList */ -class AIVehicleList_Group : public AIList { +class ScriptVehicleList_Group : public ScriptList { public: /** * @param group_id The ID of the group the vehicles are in. */ - AIVehicleList_Group(GroupID group_id); + ScriptVehicleList_Group(GroupID group_id); }; /** * Creates a list of vehicles that are in the default group. - * @ingroup AIList + * @ingroup ScriptList */ -class AIVehicleList_DefaultGroup : public AIList { +class ScriptVehicleList_DefaultGroup : public ScriptList { public: /** * @param vehicle_type The VehicleType to get the list of vehicles for. */ - AIVehicleList_DefaultGroup(AIVehicle::VehicleType vehicle_type); + ScriptVehicleList_DefaultGroup(ScriptVehicle::VehicleType vehicle_type); }; #endif /* SCRIPT_VEHICLELIST_HPP */ diff --git a/src/script/api/script_waypoint.cpp b/src/script/api/script_waypoint.cpp index 29357cd1d..86dd11649 100644 --- a/src/script/api/script_waypoint.cpp +++ b/src/script/api/script_waypoint.cpp @@ -7,7 +7,7 @@ * 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 script_waypoint.cpp Implementation of AIWaypoint. */ +/** @file script_waypoint.cpp Implementation of ScriptWaypoint. */ #include "../../stdafx.h" #include "script_waypoint.hpp" @@ -16,20 +16,20 @@ #include "../../company_func.h" #include "../../waypoint_base.h" -/* static */ bool AIWaypoint::IsValidWaypoint(StationID waypoint_id) +/* static */ bool ScriptWaypoint::IsValidWaypoint(StationID waypoint_id) { const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id); return wp != NULL && (wp->owner == _current_company || wp->owner == OWNER_NONE); } -/* static */ StationID AIWaypoint::GetWaypointID(TileIndex tile) +/* static */ StationID ScriptWaypoint::GetWaypointID(TileIndex tile) { - if (!AIRail::IsRailWaypointTile(tile) && !AIMarine::IsBuoyTile(tile)) return STATION_INVALID; + if (!ScriptRail::IsRailWaypointTile(tile) && !ScriptMarine::IsBuoyTile(tile)) return STATION_INVALID; return ::GetStationIndex(tile); } -/* static */ bool AIWaypoint::HasWaypointType(StationID waypoint_id, WaypointType waypoint_type) +/* static */ bool ScriptWaypoint::HasWaypointType(StationID waypoint_id, WaypointType waypoint_type) { if (!IsValidWaypoint(waypoint_id)) return false; if (!HasExactlyOneBit(waypoint_type)) return false; diff --git a/src/script/api/script_waypoint.hpp b/src/script/api/script_waypoint.hpp index b42c33487..e0224fa7b 100644 --- a/src/script/api/script_waypoint.hpp +++ b/src/script/api/script_waypoint.hpp @@ -17,7 +17,7 @@ /** * Class that handles all waypoint related functions. */ -class AIWaypoint : public AIBaseStation { +class ScriptWaypoint : public ScriptBaseStation { public: /** * Type of waypoints known in the game. @@ -34,7 +34,7 @@ public: */ enum ErrorMessages { /** Base for waypoint related errors */ - ERR_WAYPOINT_BASE = AIError::ERR_CAT_WAYPOINT << AIError::ERR_CAT_BIT_SIZE, + ERR_WAYPOINT_BASE = ScriptError::ERR_CAT_WAYPOINT << ScriptError::ERR_CAT_BIT_SIZE, /** The waypoint is build too close to another waypoint */ ERR_WAYPOINT_TOO_CLOSE_TO_ANOTHER_WAYPOINT, // [STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT] @@ -53,7 +53,7 @@ public: /** * Get the StationID of a tile. * @param tile The tile to find the StationID of. - * @pre AIRail::IsRailWaypointTile(tile). + * @pre ScriptRail::IsRailWaypointTile(tile). * @return StationID of the waypoint. */ static StationID GetWaypointID(TileIndex tile); @@ -67,6 +67,6 @@ public: static bool HasWaypointType(StationID waypoint_id, WaypointType waypoint_type); }; -DECLARE_ENUM_AS_BIT_SET(AIWaypoint::WaypointType) +DECLARE_ENUM_AS_BIT_SET(ScriptWaypoint::WaypointType) #endif /* SCRIPT_WAYPOINT_HPP */ diff --git a/src/script/api/script_waypointlist.cpp b/src/script/api/script_waypointlist.cpp index 83db15cb3..11ab6b951 100644 --- a/src/script/api/script_waypointlist.cpp +++ b/src/script/api/script_waypointlist.cpp @@ -7,7 +7,7 @@ * 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 script_waypointlist.cpp Implementation of AIWaypointList and friends. */ +/** @file script_waypointlist.cpp Implementation of ScriptWaypointList and friends. */ #include "../../stdafx.h" #include "script_waypointlist.hpp" @@ -16,7 +16,7 @@ #include "../../vehicle_base.h" #include "../../waypoint_base.h" -AIWaypointList::AIWaypointList(AIWaypoint::WaypointType waypoint_type) +ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type) { const Waypoint *wp; FOR_ALL_WAYPOINTS(wp) { @@ -25,9 +25,9 @@ AIWaypointList::AIWaypointList(AIWaypoint::WaypointType waypoint_type) } } -AIWaypointList_Vehicle::AIWaypointList_Vehicle(VehicleID vehicle_id) +ScriptWaypointList_Vehicle::ScriptWaypointList_Vehicle(VehicleID vehicle_id) { - if (!AIVehicle::IsValidVehicle(vehicle_id)) return; + if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return; const Vehicle *v = ::Vehicle::Get(vehicle_id); diff --git a/src/script/api/script_waypointlist.hpp b/src/script/api/script_waypointlist.hpp index 9bbbd2731..8670879cb 100644 --- a/src/script/api/script_waypointlist.hpp +++ b/src/script/api/script_waypointlist.hpp @@ -17,26 +17,26 @@ /** * Creates a list of waypoints of which you are the owner. - * @ingroup AIList + * @ingroup ScriptList */ -class AIWaypointList : public AIList { +class ScriptWaypointList : public ScriptList { public: /** * @param waypoint_type The type of waypoint to make a list of waypoints for. */ - AIWaypointList(AIWaypoint::WaypointType waypoint_type); + ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type); }; /** * Creates a list of waypoints which the vehicle has in its orders. - * @ingroup AIList + * @ingroup ScriptList */ -class AIWaypointList_Vehicle : public AIList { +class ScriptWaypointList_Vehicle : public ScriptList { public: /** * @param vehicle_id The vehicle to get the list of waypoints he has in its orders from. */ - AIWaypointList_Vehicle(VehicleID vehicle_id); + ScriptWaypointList_Vehicle(VehicleID vehicle_id); }; #endif /* SCRIPT_WAYPOINTLIST_HPP */ |