Mercurial > hg > openttd
changeset 18571:820ed7ca5fcc draft
(svn r23416) -Add: [NoAI] API for querying infrastructure costs.
author | michi_cc <michi_cc@openttd.org> |
---|---|
date | Sat, 03 Dec 2011 23:40:57 +0000 |
parents | bbdb2c13eb92 |
children | b74c52ca03cd |
files | projects/openttd_vs100.vcxproj projects/openttd_vs100.vcxproj.filters projects/openttd_vs80.vcproj projects/openttd_vs90.vcproj source.list src/ai/ai_instance.cpp src/script/api/ai/ai_airport.hpp.sq src/script/api/ai/ai_infrastructure.hpp.sq src/script/api/ai/ai_rail.hpp.sq src/script/api/ai/ai_road.hpp.sq src/script/api/ai_changelog.hpp src/script/api/script_airport.cpp src/script/api/script_airport.hpp src/script/api/script_infrastructure.cpp src/script/api/script_infrastructure.hpp src/script/api/script_rail.cpp src/script/api/script_rail.hpp src/script/api/script_road.cpp src/script/api/script_road.hpp src/script/api/template/template_infrastructure.hpp.sq |
diffstat | 20 files changed, 362 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -886,6 +886,7 @@ <ClInclude Include="..\src\script\api\script_industrytype.hpp" /> <ClInclude Include="..\src\script\api\script_industrytypelist.hpp" /> <ClInclude Include="..\src\script\api\script_info_docs.hpp" /> + <ClInclude Include="..\src\script\api\script_infrastructure.hpp" /> <ClInclude Include="..\src\script\api\script_list.hpp" /> <ClInclude Include="..\src\script\api\script_log.hpp" /> <ClInclude Include="..\src\script\api\script_map.hpp" /> @@ -937,6 +938,7 @@ <ClCompile Include="..\src\script\api\script_industrylist.cpp" /> <ClCompile Include="..\src\script\api\script_industrytype.cpp" /> <ClCompile Include="..\src\script\api\script_industrytypelist.cpp" /> + <ClCompile Include="..\src\script\api\script_infrastructure.cpp" /> <ClCompile Include="..\src\script\api\script_list.cpp" /> <ClCompile Include="..\src\script\api\script_log.cpp" /> <ClCompile Include="..\src\script\api\script_map.cpp" />
--- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -1881,6 +1881,9 @@ <ClInclude Include="..\src\script\api\script_info_docs.hpp"> <Filter>Script API</Filter> </ClInclude> + <ClInclude Include="..\src\script\api\script_infrastructure.hpp"> + <Filter>Script API</Filter> + </ClInclude> <ClInclude Include="..\src\script\api\script_list.hpp"> <Filter>Script API</Filter> </ClInclude> @@ -2034,6 +2037,9 @@ <ClCompile Include="..\src\script\api\script_industrytypelist.cpp"> <Filter>Script API Implementation</Filter> </ClCompile> + <ClCompile Include="..\src\script\api\script_infrastructure.cpp"> + <Filter>Script API Implementation</Filter> + </ClCompile> <ClCompile Include="..\src\script\api\script_list.cpp"> <Filter>Script API Implementation</Filter> </ClCompile>
--- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -2871,6 +2871,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_infrastructure.hpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_list.hpp" > </File> @@ -3079,6 +3083,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_infrastructure.cpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_list.cpp" > </File>
--- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -2868,6 +2868,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_infrastructure.hpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_list.hpp" > </File> @@ -3076,6 +3080,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_infrastructure.cpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_list.cpp" > </File>
--- a/source.list +++ b/source.list @@ -660,6 +660,7 @@ script/api/script_industrytype.hpp script/api/script_industrytypelist.hpp script/api/script_info_docs.hpp +script/api/script_infrastructure.hpp script/api/script_list.hpp script/api/script_log.hpp script/api/script_map.hpp @@ -713,6 +714,7 @@ script/api/script_industrylist.cpp script/api/script_industrytype.cpp script/api/script_industrytypelist.cpp +script/api/script_infrastructure.cpp script/api/script_list.cpp script/api/script_log.cpp script/api/script_map.cpp
--- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -53,6 +53,7 @@ #include "../script/api/ai/ai_industrylist.hpp.sq" #include "../script/api/ai/ai_industrytype.hpp.sq" #include "../script/api/ai/ai_industrytypelist.hpp.sq" +#include "../script/api/ai/ai_infrastructure.hpp.sq" #include "../script/api/ai/ai_list.hpp.sq" #include "../script/api/ai/ai_log.hpp.sq" #include "../script/api/ai/ai_map.hpp.sq" @@ -153,6 +154,7 @@ SQAIIndustryList_CargoProducing_Register(this->engine); SQAIIndustryType_Register(this->engine); SQAIIndustryTypeList_Register(this->engine); + SQAIInfrastructure_Register(this->engine); SQAILog_Register(this->engine); SQAIMap_Register(this->engine); SQAIMarine_Register(this->engine);
--- a/src/script/api/ai/ai_airport.hpp.sq +++ b/src/script/api/ai/ai_airport.hpp.sq @@ -51,6 +51,7 @@ SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetAirportType, "GetAirportType", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, ".ii"); SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetNearestTown, "GetNearestTown", 3, ".ii"); + SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i"); SQAIAirport.PostRegister(engine); }
new file mode 100644 --- /dev/null +++ b/src/script/api/ai/ai_infrastructure.hpp.sq @@ -0,0 +1,39 @@ +/* $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_infrastructure.hpp" +#include "../template/template_infrastructure.hpp.sq" + + +template <> const char *GetClassName<ScriptInfrastructure, ST_AI>() { return "AIInfrastructure"; } + +void SQAIInfrastructure_Register(Squirrel *engine) +{ + DefSQClass<ScriptInfrastructure, ST_AI> SQAIInfrastructure("AIInfrastructure"); + SQAIInfrastructure.PreRegister(engine); + SQAIInfrastructure.AddConstructor<void (ScriptInfrastructure::*)(), 1>(engine, "x"); + + SQAIInfrastructure.DefSQConst(engine, ScriptInfrastructure::INFRASTRUCTURE_RAIL, "INFRASTRUCTURE_RAIL"); + SQAIInfrastructure.DefSQConst(engine, ScriptInfrastructure::INFRASTRUCTURE_SIGNALS, "INFRASTRUCTURE_SIGNALS"); + SQAIInfrastructure.DefSQConst(engine, ScriptInfrastructure::INFRASTRUCTURE_ROAD, "INFRASTRUCTURE_ROAD"); + SQAIInfrastructure.DefSQConst(engine, ScriptInfrastructure::INFRASTRUCTURE_CANAL, "INFRASTRUCTURE_CANAL"); + SQAIInfrastructure.DefSQConst(engine, ScriptInfrastructure::INFRASTRUCTURE_STATION, "INFRASTRUCTURE_STATION"); + SQAIInfrastructure.DefSQConst(engine, ScriptInfrastructure::INFRASTRUCTURE_AIRPORT, "INFRASTRUCTURE_AIRPORT"); + + SQAIInfrastructure.DefSQStaticMethod(engine, &ScriptInfrastructure::GetRailPieceCount, "GetRailPieceCount", 3, ".ii"); + SQAIInfrastructure.DefSQStaticMethod(engine, &ScriptInfrastructure::GetRoadPieceCount, "GetRoadPieceCount", 3, ".ii"); + SQAIInfrastructure.DefSQStaticMethod(engine, &ScriptInfrastructure::GetInfrastructurePieceCount, "GetInfrastructurePieceCount", 3, ".ii"); + SQAIInfrastructure.DefSQStaticMethod(engine, &ScriptInfrastructure::GetMonthlyRailCosts, "GetMonthlyRailCosts", 3, ".ii"); + SQAIInfrastructure.DefSQStaticMethod(engine, &ScriptInfrastructure::GetMonthlyRoadCosts, "GetMonthlyRoadCosts", 3, ".ii"); + SQAIInfrastructure.DefSQStaticMethod(engine, &ScriptInfrastructure::GetMonthlyInfrastructureCosts, "GetMonthlyInfrastructureCosts", 3, ".ii"); + + SQAIInfrastructure.PostRegister(engine); +}
--- a/src/script/api/ai/ai_rail.hpp.sq +++ b/src/script/api/ai/ai_rail.hpp.sq @@ -91,6 +91,7 @@ SQAIRail.DefSQStaticMethod(engine, &ScriptRail::RemoveSignal, "RemoveSignal", 3, ".ii"); SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetBuildCost, "GetBuildCost", 3, ".ii"); SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetMaxSpeed, "GetMaxSpeed", 2, ".i"); + SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i"); SQAIRail.PostRegister(engine); }
--- a/src/script/api/ai/ai_road.hpp.sq +++ b/src/script/api/ai/ai_road.hpp.sq @@ -74,6 +74,7 @@ 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::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i"); SQAIRoad.PostRegister(engine); }
--- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -21,6 +21,7 @@ * * API additions: * + * \li AIAirport::GetMaintenanceCostFactor * \li AICargo::CT_AUTO_REFIT * \li AICargo::CT_NO_REFIT * \li AICargo::IsValidTownEffect @@ -32,9 +33,12 @@ * \li AICompany::GetQuarterlyCompanyValue * \li AIController::GetOpsTillSuspend * \li AIInfo::CONFIG_DEVELOPER + * \li AIInfrastructure * \li AIOrder::GetOrderRefit * \li AIOrder::IsRefitOrder * \li AIOrder::SetOrderRefit + * \li AIRail::GetMaintenanceCostFactor + * \li AIRoad::GetMaintenanceCostFactor * \li AITown::GetCargoGoal * \li AITown::GetGrowthRate * \li AITown::GetLastMonthReceived
--- a/src/script/api/script_airport.cpp +++ b/src/script/api/script_airport.cpp @@ -151,3 +151,10 @@ return AirportGetNearestTown(AirportSpec::Get(type), tile)->index; } + +/* static */ uint16 ScriptAirport::GetMaintenanceCostFactor(AirportType type) +{ + if (!IsAirportInformationAvailable(type)) return INVALID_TOWN; + + return AirportSpec::Get(type)->maintenance_cost; +}
--- a/src/script/api/script_airport.hpp +++ b/src/script/api/script_airport.hpp @@ -193,6 +193,14 @@ * @return The TownID of the town closest to the tile. */ static TownID GetNearestTown(TileIndex tile, AirportType type); + + /** + * Get the maintenance cost factor of an airport type. + * @param type The airport type to get the maintenance factor of. + * @pre IsAirportInformationAvailable(type) + * @return Maintenance cost factor of the airport type. + */ + static uint16 GetMaintenanceCostFactor(AirportType type); }; #endif /* SCRIPT_AIRPORT_HPP */
new file mode 100644 --- /dev/null +++ b/src/script/api/script_infrastructure.cpp @@ -0,0 +1,132 @@ +/* $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/>. + */ + +/** @file script_infrastructure.cpp Implementation of ScriptInfrastructure. */ + +#include "../../stdafx.h" +#include "script_infrastructure.hpp" +#include "../../settings_func.h" +#include "../../company_base.h" +#include "../../rail.h" +#include "../../road_func.h" +#include "../../water.h" +#include "../../station_func.h" + + +/* static */ uint32 ScriptInfrastructure::GetRailPieceCount(ScriptCompany::CompanyID company, ScriptRail::RailType railtype) +{ + company = ScriptCompany::ResolveCompanyID(company); + if (company == ScriptCompany::COMPANY_INVALID || (::RailType)railtype >= RAILTYPE_END) return 0; + + return ::Company::Get((::CompanyID)company)->infrastructure.rail[railtype]; +} + +/* static */ uint32 ScriptInfrastructure::GetRoadPieceCount(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype) +{ + company = ScriptCompany::ResolveCompanyID(company); + if (company == ScriptCompany::COMPANY_INVALID || (::RoadType)roadtype >= ROADTYPE_END) return 0; + + return ::Company::Get((::CompanyID)company)->infrastructure.road[roadtype]; +} + +/* static */ uint32 ScriptInfrastructure::GetInfrastructurePieceCount(ScriptCompany::CompanyID company, Infrastructure infra_type) +{ + company = ScriptCompany::ResolveCompanyID(company); + if (company == ScriptCompany::COMPANY_INVALID) return 0; + + ::Company *c = ::Company::Get((::CompanyID)company); + switch (infra_type) { + case INFRASTRUCTURE_RAIL: { + uint32 count = 0; + for (::RailType rt = ::RAILTYPE_BEGIN; rt != ::RAILTYPE_END; rt++) { + count += c->infrastructure.rail[rt]; + } + return count; + } + + case INFRASTRUCTURE_SIGNALS: + return c->infrastructure.signal; + + case INFRASTRUCTURE_ROAD: { + uint32 count = 0; + for (::RoadType rt = ::ROADTYPE_BEGIN; rt != ::ROADTYPE_END; rt++) { + count += c->infrastructure.road[rt]; + } + return count; + } + + case INFRASTRUCTURE_CANAL: + return c->infrastructure.water; + + case INFRASTRUCTURE_STATION: + return c->infrastructure.station; + + case INFRASTRUCTURE_AIRPORT: + return c->infrastructure.airport; + + default: + return 0; + } +} + +/* static */ Money ScriptInfrastructure::GetMonthlyRailCosts(ScriptCompany::CompanyID company, ScriptRail::RailType railtype) +{ + company = ScriptCompany::ResolveCompanyID(company); + if (company == ScriptCompany::COMPANY_INVALID || (::RailType)railtype >= RAILTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0; + + return ::RailMaintenanceCost((::RailType)railtype, ::Company::Get((::CompanyID)company)->infrastructure.rail[railtype]); +} + +/* static */ Money ScriptInfrastructure::GetMonthlyRoadCosts(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype) +{ + company = ScriptCompany::ResolveCompanyID(company); + if (company == ScriptCompany::COMPANY_INVALID || (::RoadType)roadtype >= ROADTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0; + + return ::RoadMaintenanceCost((::RoadType)roadtype, ::Company::Get((::CompanyID)company)->infrastructure.road[roadtype]); +} + +/* static */ Money ScriptInfrastructure::GetMonthlyInfrastructureCosts(ScriptCompany::CompanyID company, Infrastructure infra_type) +{ + company = ScriptCompany::ResolveCompanyID(company); + if (company == ScriptCompany::COMPANY_INVALID || !_settings_game.economy.infrastructure_maintenance) return 0; + + ::Company *c = ::Company::Get((::CompanyID)company); + switch (infra_type) { + case INFRASTRUCTURE_RAIL: { + Money cost; + for (::RailType rt = ::RAILTYPE_BEGIN; rt != ::RAILTYPE_END; rt++) { + cost += RailMaintenanceCost(rt, c->infrastructure.rail[rt]); + } + return cost; + } + + case INFRASTRUCTURE_SIGNALS: + return SignalMaintenanceCost(c->infrastructure.signal); + + case INFRASTRUCTURE_ROAD: { + Money cost; + for (::RoadType rt = ::ROADTYPE_BEGIN; rt != ::ROADTYPE_END; rt++) { + cost += RoadMaintenanceCost(rt, c->infrastructure.road[rt]); + } + return cost; + } + + case INFRASTRUCTURE_CANAL: + return CanalMaintenanceCost(c->infrastructure.water); + + case INFRASTRUCTURE_STATION: + return StationMaintenanceCost(c->infrastructure.station); + + case INFRASTRUCTURE_AIRPORT: + return AirportMaintenanceCost(c->index); + + default: + return 0; + } +}
new file mode 100644 --- /dev/null +++ b/src/script/api/script_infrastructure.hpp @@ -0,0 +1,86 @@ +/* $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/>. + */ + +/** @file script_infrastructure.hpp Everything to query a company's infrastructure. */ + +#ifndef SCRIPT_INFRASTRUCTURE_HPP +#define SCRIPT_INFRASTRUCTURE_HPP + +#include "script_object.hpp" +#include "script_road.hpp" +#include "script_rail.hpp" + +/** + * Class that handles all company infrastructure related functions. + * @api ai + */ +class ScriptInfrastructure : public ScriptObject { +public: + /** Infrastructure categories. */ + enum Infrastructure { + INFRASTRUCTURE_RAIL, ///< Rail infrastructure. + INFRASTRUCTURE_SIGNALS, ///< Signal infrastructure. + INFRASTRUCTURE_ROAD, ///< Road infrastructure. + INFRASTRUCTURE_CANAL, ///< Canal infrastructure. + INFRASTRUCTURE_STATION, ///< Station infrastructure. + INFRASTRUCTURE_AIRPORT, ///< Airport infrastructure. + }; + + /** + * Return the number of rail pieces of a specific rail type for a company. + * @param company The company to get the count for. + * @param railtype Rail type to get the count of. + * @return Count for the rail type. + */ + static uint32 GetRailPieceCount(ScriptCompany::CompanyID company, ScriptRail::RailType railtype); + + /** + * Return the number of road pieces of a specific road type for a company. + * @param company The company to get the count for. + * @param roadtype Road type to get the count of. + * @return Count for the road type. + */ + static uint32 GetRoadPieceCount(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype); + + /** + * Return the number of pieces of an infrastructure category for a company. + * @param company The company to get the count for. + * @param infra_type Infrastructure category to get the cost of. + * @return Count for the wanted category. + * @note #INFRASTRUCTURE_RAIL and #INFRASTRUCTURE_ROAD return the total count for all rail/road types. + */ + static uint32 GetInfrastructurePieceCount(ScriptCompany::CompanyID company, Infrastructure infra_type); + + /** + * Return the monthly maintenance costs of a specific rail type for a company. + * @param company The company to get the monthly cost for. + * @param railtype Rail type to get the cost of. + * @return Monthly maintenance cost for the rail type. + */ + static Money GetMonthlyRailCosts(ScriptCompany::CompanyID company, ScriptRail::RailType railtype); + + /** + * Return the monthly maintenance costs of a specific road type for a company. + * @param company The company to get the monthly cost for. + * @param roadtype Road type to get the cost of. + * @return Monthly maintenance cost for the road type. + */ + static Money GetMonthlyRoadCosts(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype); + + /** + * Return the monthly maintenance costs of an infrastructure category for a company. + * @param company The company to get the monthly cost for. + * @param infra_type Infrastructure category to get the cost of. + * @return Monthly maintenance cost for the wanted category. + * @note #INFRASTRUCTURE_RAIL and #INFRASTRUCTURE_ROAD return the total cost for all rail/road types. + */ + static Money GetMonthlyInfrastructureCosts(ScriptCompany::CompanyID company, Infrastructure infra_type); +}; + +#endif /* SCRIPT_INFRASTRUCTURE_HPP */
--- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -492,3 +492,10 @@ return ::GetRailTypeInfo((::RailType)railtype)->max_speed; } + +/* static */ uint16 ScriptRail::GetMaintenanceCostFactor(RailType railtype) +{ + if (!ScriptRail::IsRailTypeAvailable(railtype)) return 0; + + return ::GetRailTypeInfo((::RailType)railtype)->maintenance_multiplier; +}
--- a/src/script/api/script_rail.hpp +++ b/src/script/api/script_rail.hpp @@ -464,6 +464,14 @@ * To get km/h multiply this number by 1.00584. */ static int32 GetMaxSpeed(RailType railtype); + + /** + * Get the maintenance cost factor of a railtype. + * @param railtype The railtype to get the maintenance factor of. + * @pre IsRailTypeAvailable(railtype) + * @return Maintenance cost factor of the railtype. + */ + static uint16 GetMaintenanceCostFactor(RailType railtype); }; #endif /* SCRIPT_RAIL_HPP */
--- a/src/script/api/script_road.cpp +++ b/src/script/api/script_road.cpp @@ -581,3 +581,10 @@ default: return -1; } } + +/* static */ uint16 ScriptRoad::GetMaintenanceCostFactor(RoadType roadtype) +{ + if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return 0; + + return roadtype == ROADTYPE_TRAM ? 3 : 2; +}
--- a/src/script/api/script_road.hpp +++ b/src/script/api/script_road.hpp @@ -471,6 +471,14 @@ */ static Money GetBuildCost(RoadType roadtype, BuildType build_type); + /** + * Get the maintenance cost factor of a roadtype. + * @param railtype The roadtype to get the maintenance factor of. + * @pre IsRoadTypeAvailable(roadtype) + * @return Maintenance cost factor of the roadtype. + */ + static uint16 GetMaintenanceCostFactor(RoadType roadtype); + private: /**
new file mode 100644 --- /dev/null +++ b/src/script/api/template/template_infrastructure.hpp.sq @@ -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_infrastructure.hpp" + +namespace SQConvert { + /* Allow enums to be used as Squirrel parameters */ + template <> inline ScriptInfrastructure::Infrastructure GetParam(ForceType<ScriptInfrastructure::Infrastructure>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptInfrastructure::Infrastructure)tmp; } + template <> inline int Return<ScriptInfrastructure::Infrastructure>(HSQUIRRELVM vm, ScriptInfrastructure::Infrastructure res) { sq_pushinteger(vm, (int32)res); return 1; } + + /* Allow ScriptInfrastructure to be used as Squirrel parameter */ + template <> inline ScriptInfrastructure *GetParam(ForceType<ScriptInfrastructure *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptInfrastructure *)instance; } + template <> inline ScriptInfrastructure &GetParam(ForceType<ScriptInfrastructure &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptInfrastructure *)instance; } + template <> inline const ScriptInfrastructure *GetParam(ForceType<const ScriptInfrastructure *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptInfrastructure *)instance; } + template <> inline const ScriptInfrastructure &GetParam(ForceType<const ScriptInfrastructure &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptInfrastructure *)instance; } + template <> inline int Return<ScriptInfrastructure *>(HSQUIRRELVM vm, ScriptInfrastructure *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Infrastructure", res, NULL, DefSQDestructorCallback<ScriptInfrastructure>, true); return 1; } +} // namespace SQConvert