ai_vehiclelist.cpp

Go to the documentation of this file.
00001 /* $Id: ai_vehiclelist.cpp 15614 2009-03-04 22:37:25Z yexo $ */
00002 
00005 #include "ai_vehiclelist.hpp"
00006 #include "ai_group.hpp"
00007 #include "ai_station.hpp"
00008 #include "ai_vehicle.hpp"
00009 #include "../../company_func.h"
00010 #include "../../vehicle_base.h"
00011 
00012 AIVehicleList::AIVehicleList()
00013 {
00014   const Vehicle *v;
00015   FOR_ALL_VEHICLES(v) {
00016     if (v->owner == _current_company && v->IsPrimaryVehicle()) this->AddItem(v->index);
00017   }
00018 }
00019 
00020 AIVehicleList_Station::AIVehicleList_Station(StationID station_id)
00021 {
00022   if (!AIStation::IsValidStation(station_id)) return;
00023 
00024   const Vehicle *v;
00025   FOR_ALL_VEHICLES(v) {
00026     if (v->owner == _current_company && v->IsPrimaryVehicle()) {
00027       const Order *order;
00028 
00029       FOR_VEHICLE_ORDERS(v, order) {
00030         if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == station_id) {
00031           this->AddItem(v->index);
00032           break;
00033         }
00034       }
00035     }
00036   }
00037 }
00038 
00039 AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(VehicleID vehicle_id)
00040 {
00041   if (!AIVehicle::IsValidVehicle(vehicle_id)) return;
00042 
00043   for (const Vehicle *v = GetVehicle(vehicle_id)->FirstShared(); v != NULL; v = v->NextShared()) {
00044     this->AddItem(v->index);
00045   }
00046 }
00047 
00048 AIVehicleList_Group::AIVehicleList_Group(GroupID group_id)
00049 {
00050   if (!AIGroup::IsValidGroup((AIGroup::GroupID)group_id)) return;
00051 
00052   const Vehicle *v;
00053   FOR_ALL_VEHICLES(v) {
00054     if (v->owner == _current_company && v->IsPrimaryVehicle()) {
00055       if (v->group_id == group_id) this->AddItem(v->index);
00056     }
00057   }
00058 }
00059 
00060 AIVehicleList_DefaultGroup::AIVehicleList_DefaultGroup(AIVehicle::VehicleType vehicle_type)
00061 {
00062   if (vehicle_type < AIVehicle::VT_RAIL || vehicle_type > AIVehicle::VT_AIR) return;
00063 
00064   const Vehicle *v;
00065   FOR_ALL_VEHICLES(v) {
00066     if (v->owner == _current_company && v->IsPrimaryVehicle()) {
00067       if (v->type == vehicle_type && v->group_id == AIGroup::GROUP_DEFAULT) this->AddItem(v->index);
00068     }
00069   }
00070 }

Generated on Thu Oct 1 11:03:12 2009 for OpenTTD by  doxygen 1.5.6