group.h

Go to the documentation of this file.
00001 /* $Id: group.h 17570 2009-09-19 09:51:14Z rubidium $ */
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 #ifndef GROUP_H
00013 #define GROUP_H
00014 
00015 #include "group_type.h"
00016 #include "core/pool_type.hpp"
00017 #include "company_type.h"
00018 #include "vehicle_type.h"
00019 #include "engine_type.h"
00020 
00021 typedef Pool<Group, GroupID, 16, 64000> GroupPool;
00022 extern GroupPool _group_pool;
00023 
00024 struct Group : GroupPool::PoolItem<&_group_pool> {
00025   char *name;                             
00026 
00027   uint16 num_vehicle;                     
00028   OwnerByte owner;                        
00029   VehicleTypeByte vehicle_type;           
00030 
00031   bool replace_protection;                
00032   uint16 *num_engines;                    
00033 
00034   Group(CompanyID owner = INVALID_COMPANY);
00035   ~Group();
00036 };
00037 
00038 
00039 static inline bool IsDefaultGroupID(GroupID index)
00040 {
00041   return index == DEFAULT_GROUP;
00042 }
00043 
00049 static inline bool IsAllGroupID(GroupID id_g)
00050 {
00051   return id_g == ALL_GROUP;
00052 }
00053 
00054 #define FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start)
00055 #define FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0)
00056 
00060 static inline uint GetGroupArraySize()
00061 {
00062   const Group *g;
00063   uint num = 0;
00064 
00065   FOR_ALL_GROUPS(g) num++;
00066 
00067   return num;
00068 }
00069 
00078 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
00079 
00080 static inline void IncreaseGroupNumVehicle(GroupID id_g)
00081 {
00082   Group *g = Group::GetIfValid(id_g);
00083   if (g != NULL) g->num_vehicle++;
00084 }
00085 
00086 static inline void DecreaseGroupNumVehicle(GroupID id_g)
00087 {
00088   Group *g = Group::GetIfValid(id_g);
00089   if (g != NULL) g->num_vehicle--;
00090 }
00091 
00092 
00093 void InitializeGroup();
00094 void SetTrainGroupID(Train *v, GroupID grp);
00095 void UpdateTrainGroupID(Train *v);
00096 void RemoveVehicleFromGroup(const Vehicle *v);
00097 void RemoveAllGroupsForCompany(const CompanyID company);
00098 
00099 extern GroupID _new_group_id;
00100 
00101 #endif /* GROUP_H */

Generated on Sat Apr 17 23:24:48 2010 for OpenTTD by  doxygen 1.6.1