Skip to content
Permalink
Browse files

Add: New RoadType API functions.

  • Loading branch information...
PeterN authored and michicc committed Apr 6, 2019
1 parent c02ef3e commit 3293f08e0b1aa94319c29e7391eb2f5d6d4c5a17
@@ -1092,6 +1092,7 @@
<ClInclude Include="..\src\script\api\script_rail.hpp" />
<ClInclude Include="..\src\script\api\script_railtypelist.hpp" />
<ClInclude Include="..\src\script\api\script_road.hpp" />
<ClInclude Include="..\src\script\api\script_roadtypelist.hpp" />
<ClInclude Include="..\src\script\api\script_sign.hpp" />
<ClInclude Include="..\src\script\api\script_signlist.hpp" />
<ClInclude Include="..\src\script\api\script_station.hpp" />
@@ -1158,6 +1159,7 @@
<ClCompile Include="..\src\script\api\script_rail.cpp" />
<ClCompile Include="..\src\script\api\script_railtypelist.cpp" />
<ClCompile Include="..\src\script\api\script_road.cpp" />
<ClCompile Include="..\src\script\api\script_roadtypelist.cpp" />
<ClCompile Include="..\src\script\api\script_sign.cpp" />
<ClCompile Include="..\src\script\api\script_signlist.cpp" />
<ClCompile Include="..\src\script\api\script_station.cpp" />
@@ -2364,6 +2364,9 @@
<ClInclude Include="..\src\script\api\script_road.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_roadtypelist.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_sign.hpp">
<Filter>Script API</Filter>
</ClInclude>
@@ -2562,6 +2565,9 @@
<ClCompile Include="..\src\script\api\script_road.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_roadtypelist.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_sign.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
@@ -1092,6 +1092,7 @@
<ClInclude Include="..\src\script\api\script_rail.hpp" />
<ClInclude Include="..\src\script\api\script_railtypelist.hpp" />
<ClInclude Include="..\src\script\api\script_road.hpp" />
<ClInclude Include="..\src\script\api\script_roadtypelist.hpp" />
<ClInclude Include="..\src\script\api\script_sign.hpp" />
<ClInclude Include="..\src\script\api\script_signlist.hpp" />
<ClInclude Include="..\src\script\api\script_station.hpp" />
@@ -1158,6 +1159,7 @@
<ClCompile Include="..\src\script\api\script_rail.cpp" />
<ClCompile Include="..\src\script\api\script_railtypelist.cpp" />
<ClCompile Include="..\src\script\api\script_road.cpp" />
<ClCompile Include="..\src\script\api\script_roadtypelist.cpp" />
<ClCompile Include="..\src\script\api\script_sign.cpp" />
<ClCompile Include="..\src\script\api\script_signlist.cpp" />
<ClCompile Include="..\src\script\api\script_station.cpp" />
@@ -2364,6 +2364,9 @@
<ClInclude Include="..\src\script\api\script_road.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_roadtypelist.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_sign.hpp">
<Filter>Script API</Filter>
</ClInclude>
@@ -2562,6 +2565,9 @@
<ClCompile Include="..\src\script\api\script_road.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_roadtypelist.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_sign.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
@@ -1092,6 +1092,7 @@
<ClInclude Include="..\src\script\api\script_rail.hpp" />
<ClInclude Include="..\src\script\api\script_railtypelist.hpp" />
<ClInclude Include="..\src\script\api\script_road.hpp" />
<ClInclude Include="..\src\script\api\script_roadtypelist.hpp" />
<ClInclude Include="..\src\script\api\script_sign.hpp" />
<ClInclude Include="..\src\script\api\script_signlist.hpp" />
<ClInclude Include="..\src\script\api\script_station.hpp" />
@@ -1158,6 +1159,7 @@
<ClCompile Include="..\src\script\api\script_rail.cpp" />
<ClCompile Include="..\src\script\api\script_railtypelist.cpp" />
<ClCompile Include="..\src\script\api\script_road.cpp" />
<ClCompile Include="..\src\script\api\script_roadtypelist.cpp" />
<ClCompile Include="..\src\script\api\script_sign.cpp" />
<ClCompile Include="..\src\script\api\script_signlist.cpp" />
<ClCompile Include="..\src\script\api\script_station.cpp" />
@@ -2364,6 +2364,9 @@
<ClInclude Include="..\src\script\api\script_road.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_roadtypelist.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_sign.hpp">
<Filter>Script API</Filter>
</ClInclude>
@@ -2562,6 +2565,9 @@
<ClCompile Include="..\src\script\api\script_road.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_roadtypelist.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_sign.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
@@ -825,6 +825,7 @@ script/api/script_order.hpp
script/api/script_rail.hpp
script/api/script_railtypelist.hpp
script/api/script_road.hpp
script/api/script_roadtypelist.hpp
script/api/script_sign.hpp
script/api/script_signlist.hpp
script/api/script_station.hpp
@@ -893,6 +894,7 @@ script/api/script_order.cpp
script/api/script_rail.cpp
script/api/script_railtypelist.cpp
script/api/script_road.cpp
script/api/script_roadtypelist.cpp
script/api/script_sign.cpp
script/api/script_signlist.cpp
script/api/script_station.cpp
@@ -62,6 +62,7 @@
#include "../script/api/ai/ai_rail.hpp.sq"
#include "../script/api/ai/ai_railtypelist.hpp.sq"
#include "../script/api/ai/ai_road.hpp.sq"
#include "../script/api/ai/ai_roadtypelist.hpp.sq"
#include "../script/api/ai/ai_sign.hpp.sq"
#include "../script/api/ai/ai_signlist.hpp.sq"
#include "../script/api/ai/ai_station.hpp.sq"
@@ -167,6 +168,7 @@ void AIInstance::RegisterAPI()
SQAIRail_Register(this->engine);
SQAIRailTypeList_Register(this->engine);
SQAIRoad_Register(this->engine);
SQAIRoadTypeList_Register(this->engine);
SQAISign_Register(this->engine);
SQAISignList_Register(this->engine);
SQAIStation_Register(this->engine);
@@ -64,6 +64,7 @@
#include "../script/api/game/game_rail.hpp.sq"
#include "../script/api/game/game_railtypelist.hpp.sq"
#include "../script/api/game/game_road.hpp.sq"
#include "../script/api/game/game_roadtypelist.hpp.sq"
#include "../script/api/game/game_sign.hpp.sq"
#include "../script/api/game/game_signlist.hpp.sq"
#include "../script/api/game/game_station.hpp.sq"
@@ -174,6 +175,7 @@ void GameInstance::RegisterAPI()
SQGSRail_Register(this->engine);
SQGSRailTypeList_Register(this->engine);
SQGSRoad_Register(this->engine);
SQGSRoadTypeList_Register(this->engine);
SQGSSign_Register(this->engine);
SQGSSignList_Register(this->engine);
SQGSStation_Register(this->engine);
@@ -41,6 +41,8 @@ void SQAIEngine_Register(Squirrel *engine)
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::IsWagon, "IsWagon", 2, ".i");
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::CanRunOnRail, "CanRunOnRail", 3, ".ii");
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::HasPowerOnRail, "HasPowerOnRail", 3, ".ii");
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::CanRunOnRoad, "CanRunOnRoad", 3, ".ii");
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::HasPowerOnRoad, "HasPowerOnRoad", 3, ".ii");
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::GetRoadType, "GetRoadType", 2, ".i");
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::GetRailType, "GetRailType", 2, ".i");
SQAIEngine.DefSQStaticMethod(engine, &ScriptEngine::IsArticulated, "IsArticulated", 2, ".i");
@@ -31,6 +31,8 @@ void SQAIRoad_Register(Squirrel *engine)
SQAIRoad.DefSQConst(engine, ScriptRoad::ROADTYPE_ROAD, "ROADTYPE_ROAD");
SQAIRoad.DefSQConst(engine, ScriptRoad::ROADTYPE_TRAM, "ROADTYPE_TRAM");
SQAIRoad.DefSQConst(engine, ScriptRoad::ROADTYPE_INVALID, "ROADTYPE_INVALID");
SQAIRoad.DefSQConst(engine, ScriptRoad::ROADTRAMTYPES_ROAD, "ROADTRAMTYPES_ROAD");
SQAIRoad.DefSQConst(engine, ScriptRoad::ROADTRAMTYPES_TRAM, "ROADTRAMTYPES_TRAM");
SQAIRoad.DefSQConst(engine, ScriptRoad::ROADVEHTYPE_BUS, "ROADVEHTYPE_BUS");
SQAIRoad.DefSQConst(engine, ScriptRoad::ROADVEHTYPE_TRUCK, "ROADVEHTYPE_TRUCK");
SQAIRoad.DefSQConst(engine, ScriptRoad::BT_ROAD, "BT_ROAD");
@@ -86,6 +88,7 @@ void SQAIRoad_Register(Squirrel *engine)
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadDepot, "RemoveRoadDepot", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadStation, "RemoveRoadStation", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::GetBuildCost, "GetBuildCost", 3, ".ii");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::GetRoadTramType, "GetRoadTramType", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::GetMaxSpeed, "GetMaxSpeed", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i");

@@ -0,0 +1,25 @@
/* $Id$ */

/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* 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/>.
*/

/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */

#include "../script_roadtypelist.hpp"
#include "../template/template_roadtypelist.hpp.sq"


template <> const char *GetClassName<ScriptRoadTypeList, ST_AI>() { return "AIRoadTypeList"; }

void SQAIRoadTypeList_Register(Squirrel *engine)
{
DefSQClass<ScriptRoadTypeList, ST_AI> SQAIRoadTypeList("AIRoadTypeList");
SQAIRoadTypeList.PreRegister(engine, "AIList");
SQAIRoadTypeList.AddConstructor<void (ScriptRoadTypeList::*)(ScriptRoad::RoadTramTypes rtts), 2>(engine, "xi");

SQAIRoadTypeList.PostRegister(engine);
}
@@ -31,6 +31,9 @@
* \li AIRoad::RoadVehHasPowerOnRoad
* \li AIRoad::ConvertRoadType
* \li AIRoad::GetMaxSpeed
* \li AIEngine::CanRunOnRoad
* \li AIEngine::HasPowerOnRoad
* \li AIRoadTypeList::RoadTypeList
*
* \b 1.9.0
*
@@ -41,6 +41,8 @@ void SQGSEngine_Register(Squirrel *engine)
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::IsWagon, "IsWagon", 2, ".i");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::CanRunOnRail, "CanRunOnRail", 3, ".ii");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::HasPowerOnRail, "HasPowerOnRail", 3, ".ii");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::CanRunOnRoad, "CanRunOnRoad", 3, ".ii");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::HasPowerOnRoad, "HasPowerOnRoad", 3, ".ii");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetRoadType, "GetRoadType", 2, ".i");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetRailType, "GetRailType", 2, ".i");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::IsArticulated, "IsArticulated", 2, ".i");
@@ -31,6 +31,8 @@ void SQGSRoad_Register(Squirrel *engine)
SQGSRoad.DefSQConst(engine, ScriptRoad::ROADTYPE_ROAD, "ROADTYPE_ROAD");
SQGSRoad.DefSQConst(engine, ScriptRoad::ROADTYPE_TRAM, "ROADTYPE_TRAM");
SQGSRoad.DefSQConst(engine, ScriptRoad::ROADTYPE_INVALID, "ROADTYPE_INVALID");
SQGSRoad.DefSQConst(engine, ScriptRoad::ROADTRAMTYPES_ROAD, "ROADTRAMTYPES_ROAD");
SQGSRoad.DefSQConst(engine, ScriptRoad::ROADTRAMTYPES_TRAM, "ROADTRAMTYPES_TRAM");
SQGSRoad.DefSQConst(engine, ScriptRoad::ROADVEHTYPE_BUS, "ROADVEHTYPE_BUS");
SQGSRoad.DefSQConst(engine, ScriptRoad::ROADVEHTYPE_TRUCK, "ROADVEHTYPE_TRUCK");
SQGSRoad.DefSQConst(engine, ScriptRoad::BT_ROAD, "BT_ROAD");
@@ -86,6 +88,7 @@ void SQGSRoad_Register(Squirrel *engine)
SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadDepot, "RemoveRoadDepot", 2, ".i");
SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadStation, "RemoveRoadStation", 2, ".i");
SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetBuildCost, "GetBuildCost", 3, ".ii");
SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetRoadTramType, "GetRoadTramType", 2, ".i");
SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetMaxSpeed, "GetMaxSpeed", 2, ".i");
SQGSRoad.DefSQStaticMethod(engine, &ScriptRoad::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i");

@@ -0,0 +1,25 @@
/* $Id$ */

/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* 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/>.
*/

/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */

#include "../script_roadtypelist.hpp"
#include "../template/template_roadtypelist.hpp.sq"


template <> const char *GetClassName<ScriptRoadTypeList, ST_GS>() { return "GSRoadTypeList"; }

void SQGSRoadTypeList_Register(Squirrel *engine)
{
DefSQClass<ScriptRoadTypeList, ST_GS> SQGSRoadTypeList("GSRoadTypeList");
SQGSRoadTypeList.PreRegister(engine, "GSList");
SQGSRoadTypeList.AddConstructor<void (ScriptRoadTypeList::*)(ScriptRoad::RoadTramTypes rtts), 2>(engine, "xi");

SQGSRoadTypeList.PostRegister(engine);
}
@@ -15,6 +15,7 @@
#include "../../company_base.h"
#include "../../strings_func.h"
#include "../../rail.h"
#include "../../road.h"
#include "../../engine_base.h"
#include "../../engine_func.h"
#include "../../articulated_vehicles.h"
@@ -219,6 +220,20 @@
return ::HasPowerOnRail((::RailType)::RailVehInfo(engine_id)->railtype, (::RailType)track_rail_type);
}

/* static */ bool ScriptEngine::CanRunOnRoad(EngineID engine_id, ScriptRoad::RoadType road_type)
{
return HasPowerOnRoad(engine_id, road_type);
}

/* static */ bool ScriptEngine::HasPowerOnRoad(EngineID engine_id, ScriptRoad::RoadType road_type)
{
if (!IsValidEngine(engine_id)) return false;
if (GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return false;
if (!ScriptRoad::IsRoadTypeAvailable(road_type)) return false;

return ::HasPowerOnRoad((::RoadType)::RoadVehInfo(engine_id)->roadtype, (::RoadType)road_type);
}

/* static */ ScriptRoad::RoadType ScriptEngine::GetRoadType(EngineID engine_id)
{
if (!IsValidEngine(engine_id)) return ScriptRoad::ROADTYPE_INVALID;
@@ -217,6 +217,28 @@ class ScriptEngine : public ScriptObject {
*/
static bool HasPowerOnRail(EngineID engine_id, ScriptRail::RailType track_rail_type);

/**
* Check if a road vehicle can run on a RoadType.
* @param engine_id The engine to check.
* @param road_type Another RoadType.
* @pre IsValidEngine(engine_id).
* @pre GetVehicleType(engine_id) == ScriptVehicle::VT_ROAD.
* @pre ScriptRoad::IsRoadTypeAvailable(road_type).
* @return Whether an engine of type 'engine_id' can run on 'road_type'.
*/
static bool CanRunOnRoad(EngineID engine_id, ScriptRoad::RoadType road_type);

/**
* Check if a road vehicle has power on a RoadType.
* @param engine_id The engine to check.
* @param road_type Another RoadType.
* @pre IsValidEngine(engine_id).
* @pre GetVehicleType(engine_id) == ScriptVehicle::VT_ROAD.
* @pre ScriptRoad::IsRoadTypeAvailable(road_type).
* @return Whether an engine of type 'engine_id' has power on 'road_type'.
*/
static bool HasPowerOnRoad(EngineID engine_id, ScriptRoad::RoadType road_type);

/**
* Get the RoadType of the engine.
* @param engine_id The engine to get the RoadType of.
@@ -97,7 +97,7 @@
{
if (!ScriptMap::IsValidTile(tile)) return false;
if (!IsRoadTypeAvailable(road_type)) return false;
return ::GetAnyRoadBits(tile, GetRoadTramType((::RoadType)road_type), false) != ROAD_NONE;
return ::GetAnyRoadBits(tile, ::GetRoadTramType((::RoadType)road_type), false) != ROAD_NONE;
}

/* static */ bool ScriptRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2)
@@ -109,7 +109,7 @@
/* Tiles not neighbouring */
if ((abs((int)::TileX(t1) - (int)::TileX(t2)) + abs((int)::TileY(t1) - (int)::TileY(t2))) != 1) return false;

RoadTramType rtt = GetRoadTramType(ScriptObject::GetRoadType());
RoadTramType rtt = ::GetRoadTramType(ScriptObject::GetRoadType());
RoadBits r1 = ::GetAnyRoadBits(t1, rtt); // TODO
RoadBits r2 = ::GetAnyRoadBits(t2, rtt); // TODO

@@ -627,6 +627,11 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
}
}

/* static */ ScriptRoad::RoadTramTypes ScriptRoad::GetRoadTramType(RoadType roadtype)
{
return (RoadTramTypes)(1 << ::GetRoadTramType((::RoadType)roadtype));
}

/* static */ int32 ScriptRoad::GetMaxSpeed(RoadType road_type)
{
if (!ScriptRoad::IsRoadTypeAvailable(road_type)) return 0;
@@ -13,6 +13,7 @@
#define SCRIPT_ROAD_HPP

#include "script_tile.hpp"
#include "../../../road.h"

/**
* Class that handles all road related functions.
@@ -58,6 +59,14 @@ class ScriptRoad : public ScriptObject {
ROADTYPE_INVALID = -1, ///< Invalid RoadType.
};

/**
* Road/tram types
*/
enum RoadTramTypes {
ROADTRAMTYPES_ROAD = ::RTTB_ROAD, ///< Road road types.
ROADTRAMTYPES_TRAM = ::RTTB_TRAM, ///< Tram road types.
};

/**
* Type of road station.
*/
@@ -537,6 +546,13 @@ class ScriptRoad : public ScriptObject {
*/
static Money GetBuildCost(RoadType roadtype, BuildType build_type);

/**
* Test if a road type is for road or trams.
* @param roadtype the roadtype to test.
* @return RoadTramTypes of the road types.
*/
static RoadTramTypes GetRoadTramType(RoadType roadtype);

/**
* Get the maximum speed of road vehicles running on this roadtype.
* @param road_type The roadtype to get the maximum speed of.
Oops, something went wrong.

0 comments on commit 3293f08

Please sign in to comment.
You can’t perform that action at this time.