script_infrastructure.cpp

Go to the documentation of this file.
00001 /* $Id: script_infrastructure.cpp 23416 2011-12-03 23:40:57Z michi_cc $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #include "../../stdafx.h"
00013 #include "script_infrastructure.hpp"
00014 #include "../../settings_func.h"
00015 #include "../../company_base.h"
00016 #include "../../rail.h"
00017 #include "../../road_func.h"
00018 #include "../../water.h"
00019 #include "../../station_func.h"
00020 
00021 
00022 /* static */ uint32 ScriptInfrastructure::GetRailPieceCount(ScriptCompany::CompanyID company, ScriptRail::RailType railtype)
00023 {
00024   company = ScriptCompany::ResolveCompanyID(company);
00025   if (company == ScriptCompany::COMPANY_INVALID || (::RailType)railtype >= RAILTYPE_END) return 0;
00026 
00027   return ::Company::Get((::CompanyID)company)->infrastructure.rail[railtype];
00028 }
00029 
00030 /* static */ uint32 ScriptInfrastructure::GetRoadPieceCount(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype)
00031 {
00032   company = ScriptCompany::ResolveCompanyID(company);
00033   if (company == ScriptCompany::COMPANY_INVALID || (::RoadType)roadtype >= ROADTYPE_END) return 0;
00034 
00035   return ::Company::Get((::CompanyID)company)->infrastructure.road[roadtype];
00036 }
00037 
00038 /* static */ uint32 ScriptInfrastructure::GetInfrastructurePieceCount(ScriptCompany::CompanyID company, Infrastructure infra_type)
00039 {
00040   company = ScriptCompany::ResolveCompanyID(company);
00041   if (company == ScriptCompany::COMPANY_INVALID) return 0;
00042 
00043 	::Company *c = ::Company::Get((::CompanyID)company);
00044   switch (infra_type) {
00045     case INFRASTRUCTURE_RAIL: {
00046       uint32 count = 0;
00047       for (::RailType rt = ::RAILTYPE_BEGIN; rt != ::RAILTYPE_END; rt++) {
00048         count += c->infrastructure.rail[rt];
00049       }
00050       return count;
00051     }
00052 
00053     case INFRASTRUCTURE_SIGNALS:
00054       return c->infrastructure.signal;
00055 
00056     case INFRASTRUCTURE_ROAD: {
00057       uint32 count = 0;
00058       for (::RoadType rt = ::ROADTYPE_BEGIN; rt != ::ROADTYPE_END; rt++) {
00059         count += c->infrastructure.road[rt];
00060       }
00061       return count;
00062     }
00063 
00064     case INFRASTRUCTURE_CANAL:
00065       return c->infrastructure.water;
00066 
00067     case INFRASTRUCTURE_STATION:
00068       return c->infrastructure.station;
00069 
00070     case INFRASTRUCTURE_AIRPORT:
00071       return c->infrastructure.airport;
00072 
00073     default:
00074       return 0;
00075   }
00076 }
00077 
00078 /* static */ Money ScriptInfrastructure::GetMonthlyRailCosts(ScriptCompany::CompanyID company, ScriptRail::RailType railtype)
00079 {
00080   company = ScriptCompany::ResolveCompanyID(company);
00081   if (company == ScriptCompany::COMPANY_INVALID || (::RailType)railtype >= RAILTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0;
00082 
00083   return ::RailMaintenanceCost((::RailType)railtype, ::Company::Get((::CompanyID)company)->infrastructure.rail[railtype]);
00084 }
00085 
00086 /* static */ Money ScriptInfrastructure::GetMonthlyRoadCosts(ScriptCompany::CompanyID company, ScriptRoad::RoadType roadtype)
00087 {
00088   company = ScriptCompany::ResolveCompanyID(company);
00089   if (company == ScriptCompany::COMPANY_INVALID || (::RoadType)roadtype >= ROADTYPE_END || !_settings_game.economy.infrastructure_maintenance) return 0;
00090 
00091   return ::RoadMaintenanceCost((::RoadType)roadtype, ::Company::Get((::CompanyID)company)->infrastructure.road[roadtype]);
00092 }
00093 
00094 /* static */ Money ScriptInfrastructure::GetMonthlyInfrastructureCosts(ScriptCompany::CompanyID company, Infrastructure infra_type)
00095 {
00096   company = ScriptCompany::ResolveCompanyID(company);
00097   if (company == ScriptCompany::COMPANY_INVALID || !_settings_game.economy.infrastructure_maintenance) return 0;
00098 
00099 	::Company *c = ::Company::Get((::CompanyID)company);
00100   switch (infra_type) {
00101     case INFRASTRUCTURE_RAIL: {
00102       Money cost;
00103       for (::RailType rt = ::RAILTYPE_BEGIN; rt != ::RAILTYPE_END; rt++) {
00104         cost += RailMaintenanceCost(rt, c->infrastructure.rail[rt]);
00105       }
00106       return cost;
00107     }
00108 
00109     case INFRASTRUCTURE_SIGNALS:
00110       return SignalMaintenanceCost(c->infrastructure.signal);
00111 
00112     case INFRASTRUCTURE_ROAD: {
00113       Money cost;
00114       for (::RoadType rt = ::ROADTYPE_BEGIN; rt != ::ROADTYPE_END; rt++) {
00115         cost += RoadMaintenanceCost(rt, c->infrastructure.road[rt]);
00116       }
00117       return cost;
00118     }
00119 
00120     case INFRASTRUCTURE_CANAL:
00121       return CanalMaintenanceCost(c->infrastructure.water);
00122 
00123     case INFRASTRUCTURE_STATION:
00124       return StationMaintenanceCost(c->infrastructure.station);
00125 
00126     case INFRASTRUCTURE_AIRPORT:
00127       return AirportMaintenanceCost(c->index);
00128 
00129     default:
00130       return 0;
00131   }
00132 }