(svn r23416) -Add: [NoAI] API for querying infrastructure costs.

This commit is contained in:
michi_cc 2011-12-03 23:40:57 +00:00
parent fc8633e1ac
commit 351da038eb
20 changed files with 362 additions and 0 deletions

View File

@ -886,6 +886,7 @@
<ClInclude Include="..\src\script\api\script_industrytype.hpp" /> <ClInclude Include="..\src\script\api\script_industrytype.hpp" />
<ClInclude Include="..\src\script\api\script_industrytypelist.hpp" /> <ClInclude Include="..\src\script\api\script_industrytypelist.hpp" />
<ClInclude Include="..\src\script\api\script_info_docs.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_list.hpp" />
<ClInclude Include="..\src\script\api\script_log.hpp" /> <ClInclude Include="..\src\script\api\script_log.hpp" />
<ClInclude Include="..\src\script\api\script_map.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_industrylist.cpp" />
<ClCompile Include="..\src\script\api\script_industrytype.cpp" /> <ClCompile Include="..\src\script\api\script_industrytype.cpp" />
<ClCompile Include="..\src\script\api\script_industrytypelist.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_list.cpp" />
<ClCompile Include="..\src\script\api\script_log.cpp" /> <ClCompile Include="..\src\script\api\script_log.cpp" />
<ClCompile Include="..\src\script\api\script_map.cpp" /> <ClCompile Include="..\src\script\api\script_map.cpp" />

View File

@ -1881,6 +1881,9 @@
<ClInclude Include="..\src\script\api\script_info_docs.hpp"> <ClInclude Include="..\src\script\api\script_info_docs.hpp">
<Filter>Script API</Filter> <Filter>Script API</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\script\api\script_infrastructure.hpp">
<Filter>Script API</Filter>
</ClInclude>
<ClInclude Include="..\src\script\api\script_list.hpp"> <ClInclude Include="..\src\script\api\script_list.hpp">
<Filter>Script API</Filter> <Filter>Script API</Filter>
</ClInclude> </ClInclude>
@ -2034,6 +2037,9 @@
<ClCompile Include="..\src\script\api\script_industrytypelist.cpp"> <ClCompile Include="..\src\script\api\script_industrytypelist.cpp">
<Filter>Script API Implementation</Filter> <Filter>Script API Implementation</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\script\api\script_infrastructure.cpp">
<Filter>Script API Implementation</Filter>
</ClCompile>
<ClCompile Include="..\src\script\api\script_list.cpp"> <ClCompile Include="..\src\script\api\script_list.cpp">
<Filter>Script API Implementation</Filter> <Filter>Script API Implementation</Filter>
</ClCompile> </ClCompile>

View File

@ -2870,6 +2870,10 @@
RelativePath=".\..\src\script\api\script_info_docs.hpp" RelativePath=".\..\src\script\api\script_info_docs.hpp"
> >
</File> </File>
<File
RelativePath=".\..\src\script\api\script_infrastructure.hpp"
>
</File>
<File <File
RelativePath=".\..\src\script\api\script_list.hpp" RelativePath=".\..\src\script\api\script_list.hpp"
> >
@ -3078,6 +3082,10 @@
RelativePath=".\..\src\script\api\script_industrytypelist.cpp" RelativePath=".\..\src\script\api\script_industrytypelist.cpp"
> >
</File> </File>
<File
RelativePath=".\..\src\script\api\script_infrastructure.cpp"
>
</File>
<File <File
RelativePath=".\..\src\script\api\script_list.cpp" RelativePath=".\..\src\script\api\script_list.cpp"
> >

View File

@ -2867,6 +2867,10 @@
RelativePath=".\..\src\script\api\script_info_docs.hpp" RelativePath=".\..\src\script\api\script_info_docs.hpp"
> >
</File> </File>
<File
RelativePath=".\..\src\script\api\script_infrastructure.hpp"
>
</File>
<File <File
RelativePath=".\..\src\script\api\script_list.hpp" RelativePath=".\..\src\script\api\script_list.hpp"
> >
@ -3075,6 +3079,10 @@
RelativePath=".\..\src\script\api\script_industrytypelist.cpp" RelativePath=".\..\src\script\api\script_industrytypelist.cpp"
> >
</File> </File>
<File
RelativePath=".\..\src\script\api\script_infrastructure.cpp"
>
</File>
<File <File
RelativePath=".\..\src\script\api\script_list.cpp" RelativePath=".\..\src\script\api\script_list.cpp"
> >

View File

@ -660,6 +660,7 @@ script/api/script_industrylist.hpp
script/api/script_industrytype.hpp script/api/script_industrytype.hpp
script/api/script_industrytypelist.hpp script/api/script_industrytypelist.hpp
script/api/script_info_docs.hpp script/api/script_info_docs.hpp
script/api/script_infrastructure.hpp
script/api/script_list.hpp script/api/script_list.hpp
script/api/script_log.hpp script/api/script_log.hpp
script/api/script_map.hpp script/api/script_map.hpp
@ -713,6 +714,7 @@ script/api/script_industry.cpp
script/api/script_industrylist.cpp script/api/script_industrylist.cpp
script/api/script_industrytype.cpp script/api/script_industrytype.cpp
script/api/script_industrytypelist.cpp script/api/script_industrytypelist.cpp
script/api/script_infrastructure.cpp
script/api/script_list.cpp script/api/script_list.cpp
script/api/script_log.cpp script/api/script_log.cpp
script/api/script_map.cpp script/api/script_map.cpp

View File

@ -53,6 +53,7 @@
#include "../script/api/ai/ai_industrylist.hpp.sq" #include "../script/api/ai/ai_industrylist.hpp.sq"
#include "../script/api/ai/ai_industrytype.hpp.sq" #include "../script/api/ai/ai_industrytype.hpp.sq"
#include "../script/api/ai/ai_industrytypelist.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_list.hpp.sq"
#include "../script/api/ai/ai_log.hpp.sq" #include "../script/api/ai/ai_log.hpp.sq"
#include "../script/api/ai/ai_map.hpp.sq" #include "../script/api/ai/ai_map.hpp.sq"
@ -153,6 +154,7 @@ void AIInstance::RegisterAPI()
SQAIIndustryList_CargoProducing_Register(this->engine); SQAIIndustryList_CargoProducing_Register(this->engine);
SQAIIndustryType_Register(this->engine); SQAIIndustryType_Register(this->engine);
SQAIIndustryTypeList_Register(this->engine); SQAIIndustryTypeList_Register(this->engine);
SQAIInfrastructure_Register(this->engine);
SQAILog_Register(this->engine); SQAILog_Register(this->engine);
SQAIMap_Register(this->engine); SQAIMap_Register(this->engine);
SQAIMarine_Register(this->engine); SQAIMarine_Register(this->engine);

View File

@ -51,6 +51,7 @@ void SQAIAirport_Register(Squirrel *engine)
SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetAirportType, "GetAirportType", 2, ".i"); SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetAirportType, "GetAirportType", 2, ".i");
SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, ".ii"); SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetNoiseLevelIncrease, "GetNoiseLevelIncrease", 3, ".ii");
SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetNearestTown, "GetNearestTown", 3, ".ii"); SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetNearestTown, "GetNearestTown", 3, ".ii");
SQAIAirport.DefSQStaticMethod(engine, &ScriptAirport::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i");
SQAIAirport.PostRegister(engine); SQAIAirport.PostRegister(engine);
} }

View File

@ -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);
}

View File

@ -91,6 +91,7 @@ void SQAIRail_Register(Squirrel *engine)
SQAIRail.DefSQStaticMethod(engine, &ScriptRail::RemoveSignal, "RemoveSignal", 3, ".ii"); SQAIRail.DefSQStaticMethod(engine, &ScriptRail::RemoveSignal, "RemoveSignal", 3, ".ii");
SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetBuildCost, "GetBuildCost", 3, ".ii"); SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetBuildCost, "GetBuildCost", 3, ".ii");
SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetMaxSpeed, "GetMaxSpeed", 2, ".i"); SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetMaxSpeed, "GetMaxSpeed", 2, ".i");
SQAIRail.DefSQStaticMethod(engine, &ScriptRail::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i");
SQAIRail.PostRegister(engine); SQAIRail.PostRegister(engine);
} }

View File

@ -74,6 +74,7 @@ void SQAIRoad_Register(Squirrel *engine)
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadDepot, "RemoveRoadDepot", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadDepot, "RemoveRoadDepot", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadStation, "RemoveRoadStation", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::RemoveRoadStation, "RemoveRoadStation", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::GetBuildCost, "GetBuildCost", 3, ".ii"); SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::GetBuildCost, "GetBuildCost", 3, ".ii");
SQAIRoad.DefSQStaticMethod(engine, &ScriptRoad::GetMaintenanceCostFactor, "GetMaintenanceCostFactor", 2, ".i");
SQAIRoad.PostRegister(engine); SQAIRoad.PostRegister(engine);
} }

View File

@ -21,6 +21,7 @@
* *
* API additions: * API additions:
* *
* \li AIAirport::GetMaintenanceCostFactor
* \li AICargo::CT_AUTO_REFIT * \li AICargo::CT_AUTO_REFIT
* \li AICargo::CT_NO_REFIT * \li AICargo::CT_NO_REFIT
* \li AICargo::IsValidTownEffect * \li AICargo::IsValidTownEffect
@ -32,9 +33,12 @@
* \li AICompany::GetQuarterlyCompanyValue * \li AICompany::GetQuarterlyCompanyValue
* \li AIController::GetOpsTillSuspend * \li AIController::GetOpsTillSuspend
* \li AIInfo::CONFIG_DEVELOPER * \li AIInfo::CONFIG_DEVELOPER
* \li AIInfrastructure
* \li AIOrder::GetOrderRefit * \li AIOrder::GetOrderRefit
* \li AIOrder::IsRefitOrder * \li AIOrder::IsRefitOrder
* \li AIOrder::SetOrderRefit * \li AIOrder::SetOrderRefit
* \li AIRail::GetMaintenanceCostFactor
* \li AIRoad::GetMaintenanceCostFactor
* \li AITown::GetCargoGoal * \li AITown::GetCargoGoal
* \li AITown::GetGrowthRate * \li AITown::GetGrowthRate
* \li AITown::GetLastMonthReceived * \li AITown::GetLastMonthReceived

View File

@ -151,3 +151,10 @@
return AirportGetNearestTown(AirportSpec::Get(type), tile)->index; 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;
}

View File

@ -193,6 +193,14 @@ public:
* @return The TownID of the town closest to the tile. * @return The TownID of the town closest to the tile.
*/ */
static TownID GetNearestTown(TileIndex tile, AirportType type); 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 */ #endif /* SCRIPT_AIRPORT_HPP */

View File

@ -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;
}
}

View File

@ -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 */

View File

@ -492,3 +492,10 @@ static bool IsValidSignalType(int signal_type)
return ::GetRailTypeInfo((::RailType)railtype)->max_speed; return ::GetRailTypeInfo((::RailType)railtype)->max_speed;
} }
/* static */ uint16 ScriptRail::GetMaintenanceCostFactor(RailType railtype)
{
if (!ScriptRail::IsRailTypeAvailable(railtype)) return 0;
return ::GetRailTypeInfo((::RailType)railtype)->maintenance_multiplier;
}

View File

@ -464,6 +464,14 @@ public:
* To get km/h multiply this number by 1.00584. * To get km/h multiply this number by 1.00584.
*/ */
static int32 GetMaxSpeed(RailType railtype); 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 */ #endif /* SCRIPT_RAIL_HPP */

View File

@ -581,3 +581,10 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
default: return -1; default: return -1;
} }
} }
/* static */ uint16 ScriptRoad::GetMaintenanceCostFactor(RoadType roadtype)
{
if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return 0;
return roadtype == ROADTYPE_TRAM ? 3 : 2;
}

View File

@ -471,6 +471,14 @@ public:
*/ */
static Money GetBuildCost(RoadType roadtype, BuildType build_type); 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: private:
/** /**

View File

@ -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