summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-06-27 14:15:48 +0000
committerrubidium <rubidium@openttd.org>2007-06-27 14:15:48 +0000
commit1cff4725010b20d39cbf5781dd3251112a004e8c (patch)
treeeaa49e95c6bd9507f25d0920157782b69f1e373f /src/vehicle.cpp
parentf603383eb9a11b6b951910933fcab305c6c1fe68 (diff)
downloadopenttd-1cff4725010b20d39cbf5781dd3251112a004e8c.tar.xz
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index a97c027d2..9ed457f18 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2615,6 +2615,50 @@ UnitID GetFreeUnitNumber(VehicleType type)
}
+/**
+ * Check whether we can build infrastructure for the given
+ * vehicle type. This to disable building stations etc. when
+ * you are not allowed/able to have the vehicle type yet.
+ * @param type the vehicle type to check this for
+ * @return true if there is any reason why you may build
+ * the infrastructure for the given vehicle type
+ */
+bool CanBuildVehicleInfrastructure(VehicleType type)
+{
+ assert(IsPlayerBuildableVehicleType(type));
+
+ if (_patches.always_build_infrastructure) return true;
+
+ UnitID max;
+ switch (type) {
+ case VEH_TRAIN: max = _patches.max_trains; break;
+ case VEH_ROAD: max = _patches.max_roadveh; break;
+ case VEH_SHIP: max = _patches.max_ships; break;
+ case VEH_AIRCRAFT: max = _patches.max_aircraft; break;
+ default: NOT_REACHED();
+ }
+
+ /* We can build vehicle infrastructure when we may build the vehicle type */
+ if (max > 0) {
+
+ /* Can we actually build the vehicle type? */
+ EngineID e;
+ FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
+ if (HASBIT(GetEngine(e)->player_avail, _local_player)) return true;
+ }
+ return false;
+ }
+
+ /* We should be able to build infrastructure when we have the actual vehicle type */
+ const Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ if (v->owner == _local_player && v->type == type) return true;
+ }
+
+ return false;
+}
+
+
const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v)
{
const Player *p = GetPlayer(player);