ai_vehiclelist.cpp

Go to the documentation of this file.
00001 /* $Id$ */
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 "ai_vehiclelist.hpp"
00014 #include "ai_group.hpp"
00015 #include "ai_map.hpp"
00016 #include "ai_station.hpp"
00017 #include "../../company_func.h"
00018 #include "../../depot_map.h"
00019 #include "../../vehicle_base.h"
00020 
00021 AIVehicleList::AIVehicleList()
00022 {
00023   const Vehicle *v;
00024   FOR_ALL_VEHICLES(v) {
00025     if (v->owner == _current_company && v->IsPrimaryVehicle()) this->AddItem(v->index);
00026   }
00027 }
00028 
00029 AIVehicleList_Station::AIVehicleList_Station(StationID station_id)
00030 {
00031   if (!AIBaseStation::IsValidBaseStation(station_id)) return;
00032 
00033   const Vehicle *v;
00034   FOR_ALL_VEHICLES(v) {
00035     if (v->owner == _current_company && v->IsPrimaryVehicle()) {
00036       const Order *order;
00037 
00038       FOR_VEHICLE_ORDERS(v, order) {
00039         if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station_id) {
00040           this->AddItem(v->index);
00041           break;
00042         }
00043       }
00044     }
00045   }
00046 }
00047 
00048 AIVehicleList_Depot::AIVehicleList_Depot(TileIndex tile)
00049 {
00050   if (!AIMap::IsValidTile(tile)) return;
00051 
00052   DestinationID dest;
00053   VehicleType type;
00054 
00055   switch (GetTileType(tile)) {
00056     case MP_STATION: // Aircraft
00057       if (!IsAirport(tile)) return;
00058       type = VEH_AIRCRAFT;
00059       dest = GetStationIndex(tile);
00060       break;
00061 
00062     case MP_RAILWAY:
00063       if (!IsRailDepot(tile)) return;
00064       type = VEH_TRAIN;
00065       dest = GetDepotIndex(tile);
00066       break;
00067 
00068     case MP_ROAD:
00069       if (!IsRoadDepot(tile)) return;
00070       type = VEH_ROAD;
00071       dest = GetDepotIndex(tile);
00072       break;
00073 
00074     case MP_WATER:
00075       if (!IsShipDepot(tile)) return;
00076       type = VEH_SHIP;
00077       dest = GetDepotIndex(tile);
00078       break;
00079 
00080     default: // No depot
00081       return;
00082   }
00083 
00084   const Vehicle *v;
00085   FOR_ALL_VEHICLES(v) {
00086     if (v->owner == _current_company && v->IsPrimaryVehicle() && v->type == type) {
00087       const Order *order;
00088 
00089       FOR_VEHICLE_ORDERS(v, order) {
00090         if (order->IsType(OT_GOTO_DEPOT) && order->GetDestination() == dest) {
00091           this->AddItem(v->index);
00092           break;
00093         }
00094       }
00095     }
00096   }
00097 }
00098 
00099 AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(VehicleID vehicle_id)
00100 {
00101   if (!AIVehicle::IsValidVehicle(vehicle_id)) return;
00102 
00103   for (const Vehicle *v = Vehicle::Get(vehicle_id)->FirstShared(); v != NULL; v = v->NextShared()) {
00104     this->AddItem(v->index);
00105   }
00106 }
00107 
00108 AIVehicleList_Group::AIVehicleList_Group(GroupID group_id)
00109 {
00110   if (!AIGroup::IsValidGroup((AIGroup::GroupID)group_id)) return;
00111 
00112   const Vehicle *v;
00113   FOR_ALL_VEHICLES(v) {
00114     if (v->owner == _current_company && v->IsPrimaryVehicle()) {
00115       if (v->group_id == group_id) this->AddItem(v->index);
00116     }
00117   }
00118 }
00119 
00120 AIVehicleList_DefaultGroup::AIVehicleList_DefaultGroup(AIVehicle::VehicleType vehicle_type)
00121 {
00122   if (vehicle_type < AIVehicle::VT_RAIL || vehicle_type > AIVehicle::VT_AIR) return;
00123 
00124   const Vehicle *v;
00125   FOR_ALL_VEHICLES(v) {
00126     if (v->owner == _current_company && v->IsPrimaryVehicle()) {
00127       if (v->type == vehicle_type && v->group_id == AIGroup::GROUP_DEFAULT) this->AddItem(v->index);
00128     }
00129   }
00130 }

Generated on Sun Jan 23 01:49:00 2011 for OpenTTD by  doxygen 1.6.1