glx@9624: /* $Id$ */ glx@9624: rubidium@10455: /** @file group.h Base class from groups. */ glx@9624: glx@9624: #ifndef GROUP_H glx@9624: #define GROUP_H glx@9624: rubidium@9837: #include "group_type.h" glx@9624: #include "oldpool.h" rubidium@9724: #include "player_type.h" rubidium@9724: #include "vehicle_type.h" rubidium@9837: #include "engine_type.h" glx@9624: rubidium@9694: DECLARE_OLD_POOL(Group, Group, 5, 2047) rubidium@9694: rubidium@9694: struct Group : PoolItem { rubidium@9724: char *name; ///< Group Name glx@9624: glx@9624: uint16 num_vehicle; ///< Number of vehicles wich belong to the group rubidium@9826: PlayerByte owner; ///< Group Owner glx@9624: VehicleTypeByte vehicle_type; ///< Vehicle type of the group glx@9624: glx@9624: bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group rubidium@10455: uint16 *num_engines; ///< Caches the number of engines of each type the player owns (no need to save this) rubidium@9694: rubidium@9724: Group(PlayerID owner = INVALID_PLAYER); rubidium@9694: virtual ~Group(); rubidium@9694: rubidium@9694: bool IsValid() const; glx@9624: }; glx@9624: glx@9624: glx@9624: static inline bool IsValidGroupID(GroupID index) glx@9624: { rubidium@9694: return index < GetGroupPoolSize() && GetGroup(index)->IsValid(); glx@9624: } glx@9624: glx@9624: static inline bool IsDefaultGroupID(GroupID index) glx@9624: { rubidium@9686: return index == DEFAULT_GROUP; rubidium@9686: } rubidium@9686: rubidium@9686: /** rubidium@9686: * Checks if a GroupID stands for all vehicles of a player rubidium@9686: * @param id_g The GroupID to check rubidium@9686: * @return true is id_g is identical to ALL_GROUP rubidium@9686: */ rubidium@9686: static inline bool IsAllGroupID(GroupID id_g) rubidium@9686: { rubidium@9686: return id_g == ALL_GROUP; glx@9624: } glx@9624: rubidium@9694: #define FOR_ALL_GROUPS_FROM(g, start) for (g = GetGroup(start); g != NULL; g = (g->index + 1U < GetGroupPoolSize()) ? GetGroup(g->index + 1) : NULL) if (g->IsValid()) glx@9624: #define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0) glx@9624: glx@9624: /** glx@9624: * Get the current size of the GroupPool glx@9624: */ glx@9624: static inline uint GetGroupArraySize(void) glx@9624: { glx@9624: const Group *g; glx@9624: uint num = 0; glx@9624: glx@9624: FOR_ALL_GROUPS(g) num++; glx@9624: glx@9624: return num; glx@9624: } glx@9624: rubidium@9686: /** rubidium@9686: * Get the number of engines with EngineID id_e in the group with GroupID rubidium@9686: * id_g rubidium@9686: * @param id_g The GroupID of the group used rubidium@9686: * @param id_e The EngineID of the engine to count rubidium@9686: * @return The number of engines with EngineID id_e in the group rubidium@9686: */ rubidium@9724: uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e); rubidium@9686: glx@9624: static inline void IncreaseGroupNumVehicle(GroupID id_g) glx@9624: { glx@9624: if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++; glx@9624: } glx@9624: glx@9624: static inline void DecreaseGroupNumVehicle(GroupID id_g) glx@9624: { glx@9624: if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle--; glx@9624: } glx@9624: glx@9624: glx@9624: void InitializeGroup(); glx@9624: void SetTrainGroupID(Vehicle *v, GroupID grp); glx@9624: void UpdateTrainGroupID(Vehicle *v); glx@9624: void RemoveVehicleFromGroup(const Vehicle *v); rubidium@9724: void RemoveAllGroupsForPlayer(const PlayerID p); glx@9624: glx@9624: #endif /* GROUP_H */