(svn r23416) -Add: [NoAI] API for querying infrastructure costs.
parent
fc8633e1ac
commit
351da038eb
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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 */
|
@ -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
|
Loading…
Reference in New Issue