group.h

Go to the documentation of this file.
00001 /* $Id: group.h 21845 2011-01-18 22:31:06Z 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 
00070 uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
00071 
00072 static inline void IncreaseGroupNumVehicle(GroupID id_g)
00073 {
00074   Group *g = Group::GetIfValid(id_g);
00075   if (g != NULL) g->num_vehicle++;
00076 }
00077 
00078 static inline void DecreaseGroupNumVehicle(GroupID id_g)
00079 {
00080   Group *g = Group::GetIfValid(id_g);
00081   if (g != NULL) g->num_vehicle--;
00082 }
00083 
00084 
00085 void InitializeGroup();
00086 void SetTrainGroupID(Train *v, GroupID grp);
00087 void UpdateTrainGroupID(Train *v);
00088 void RemoveVehicleFromGroup(const Vehicle *v);
00089 void RemoveAllGroupsForCompany(const CompanyID company);
00090 
00091 extern GroupID _new_group_id;
00092 
00093 #endif /* GROUP_H */

Generated on Sun May 15 19:20:08 2011 for OpenTTD by  doxygen 1.6.1