Update: Translations from eints
[openttd-github.git] / src / script / api / script_infrastructure.cpp
bloba8d0e0551018cf33f7166dbbe104622d6d689193
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file script_infrastructure.cpp Implementation of ScriptInfrastructure. */
10 #include "../../stdafx.h"
11 #include "script_infrastructure.hpp"
12 #include "../../company_base.h"
13 #include "../../rail.h"
14 #include "../../road_func.h"
15 #include "../../water.h"
16 #include "../../station_func.h"
18 #include "../../safeguards.h"
21 /* static */ SQInteger ScriptInfrastructure::GetRailPieceCount(ScriptCompany::CompanyID company, ScriptRail::RailType railtype)
23 company = ScriptCompany::ResolveCompanyID(company);
24 if (company == ScriptCompany::COMPANY_INVALID || (::RailType)railtype >= RAILTYPE_END) return 0;
26 return ::Company::Get((::CompanyID)company)->infrastructure.rail[railtype];
29 /* static */ SQInteger ScriptInfrastructure::GetRoadPieceCount(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype)
31 company = ScriptCompany::ResolveCompanyID(company);
32 if (company == ScriptCompany::COMPANY_INVALID || (::RoadType)roadtype >= ROADTYPE_END) return 0;
34 return ::Company::Get((::CompanyID)company)->infrastructure.road[roadtype];
37 /* static */ SQInteger ScriptInfrastructure::GetInfrastructurePieceCount(ScriptCompany::CompanyID company, Infrastructure infra_type)
39 company = ScriptCompany::ResolveCompanyID(company);
40 if (company == ScriptCompany::COMPANY_INVALID) return 0;
42 const ::Company *c = ::Company::Get((::CompanyID)company);
43 switch (infra_type) {
44 case INFRASTRUCTURE_RAIL:
45 return c->infrastructure.GetRailTotal();
47 case INFRASTRUCTURE_SIGNALS:
48 return c->infrastructure.signal;
50 case INFRASTRUCTURE_ROAD:
51 return c->infrastructure.GetRoadTotal() + c->infrastructure.GetTramTotal();
53 case INFRASTRUCTURE_CANAL:
54 return c->infrastructure.water;
56 case INFRASTRUCTURE_STATION:
57 return c->infrastructure.station;
59 case INFRASTRUCTURE_AIRPORT:
60 return c->infrastructure.airport;
62 default:
63 return 0;
67 /* static */ Money ScriptInfrastructure::GetMonthlyRailCosts(ScriptCompany::CompanyID company, ScriptRail::RailType railtype)
69 company = ScriptCompany::ResolveCompanyID(company);
70 if (company == ScriptCompany::COMPANY_INVALID || (::RailType)railtype >= RAILTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0;
72 const ::Company *c = ::Company::Get((::CompanyID)company);
73 return ::RailMaintenanceCost((::RailType)railtype, c->infrastructure.rail[railtype], c->infrastructure.GetRailTotal());
76 /* static */ Money ScriptInfrastructure::GetMonthlyRoadCosts(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype)
78 company = ScriptCompany::ResolveCompanyID(company);
79 if (company == ScriptCompany::COMPANY_INVALID || (::RoadType)roadtype >= ROADTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0;
81 const ::Company *c = ::Company::Get((::CompanyID)company);
82 return ::RoadMaintenanceCost((::RoadType)roadtype, c->infrastructure.road[roadtype], RoadTypeIsRoad((::RoadType)roadtype) ? c->infrastructure.GetRoadTotal() : c->infrastructure.GetTramTotal());
85 /* static */ Money ScriptInfrastructure::GetMonthlyInfrastructureCosts(ScriptCompany::CompanyID company, Infrastructure infra_type)
87 company = ScriptCompany::ResolveCompanyID(company);
88 if (company == ScriptCompany::COMPANY_INVALID || !_settings_game.economy.infrastructure_maintenance) return 0;
90 const ::Company *c = ::Company::Get((::CompanyID)company);
91 switch (infra_type) {
92 case INFRASTRUCTURE_RAIL: {
93 Money cost;
94 uint32_t rail_total = c->infrastructure.GetRailTotal();
95 for (::RailType rt = ::RAILTYPE_BEGIN; rt != ::RAILTYPE_END; rt++) {
96 cost += RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total);
98 return cost;
101 case INFRASTRUCTURE_SIGNALS:
102 return SignalMaintenanceCost(c->infrastructure.signal);
104 case INFRASTRUCTURE_ROAD: {
105 Money cost;
106 uint32_t road_total = c->infrastructure.GetRoadTotal();
107 for (::RoadType rt = ::ROADTYPE_BEGIN; rt != ::ROADTYPE_END; rt++) {
108 cost += RoadMaintenanceCost(rt, c->infrastructure.road[rt], road_total);
110 return cost;
113 case INFRASTRUCTURE_CANAL:
114 return CanalMaintenanceCost(c->infrastructure.water);
116 case INFRASTRUCTURE_STATION:
117 return StationMaintenanceCost(c->infrastructure.station);
119 case INFRASTRUCTURE_AIRPORT:
120 return AirportMaintenanceCost(c->index);
122 default:
123 return 0;