src/group.h
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6868 7eb395287b3d
child 6878 7d1ff2f621c7
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     4 
     4 
     5 #ifndef GROUP_H
     5 #ifndef GROUP_H
     6 #define GROUP_H
     6 #define GROUP_H
     7 
     7 
     8 #include "oldpool.h"
     8 #include "oldpool.h"
       
     9 #include "player_type.h"
       
    10 #include "vehicle_type.h"
       
    11 #include "engine.h"
     9 
    12 
    10 enum {
    13 enum {
    11 	ALL_GROUP     = 0xFFFD,
    14 	ALL_GROUP     = 0xFFFD,
    12 	DEFAULT_GROUP = 0xFFFE,
    15 	DEFAULT_GROUP = 0xFFFE,
    13 	INVALID_GROUP = 0xFFFF,
    16 	INVALID_GROUP = 0xFFFF,
    15 
    18 
    16 struct Group;
    19 struct Group;
    17 DECLARE_OLD_POOL(Group, Group, 5, 2047)
    20 DECLARE_OLD_POOL(Group, Group, 5, 2047)
    18 
    21 
    19 struct Group : PoolItem<Group, GroupID, &_Group_pool> {
    22 struct Group : PoolItem<Group, GroupID, &_Group_pool> {
    20 	StringID string_id;                     ///< Group Name
    23 	char *name;                             ///< Group Name
    21 
    24 
    22 	uint16 num_vehicle;                     ///< Number of vehicles wich belong to the group
    25 	uint16 num_vehicle;                     ///< Number of vehicles wich belong to the group
    23 	PlayerID owner;                         ///< Group Owner
    26 	PlayerID owner;                         ///< Group Owner
    24 	VehicleTypeByte vehicle_type;           ///< Vehicle type of the group
    27 	VehicleTypeByte vehicle_type;           ///< Vehicle type of the group
    25 
    28 
    26 	bool replace_protection;                ///< If set to true, the global autoreplace have no effect on the group
    29 	bool replace_protection;                ///< If set to true, the global autoreplace have no effect on the group
    27 	uint16 num_engines[TOTAL_NUM_ENGINES];  ///< Caches the number of engines of each type the player owns (no need to save this)
    30 	uint16 num_engines[TOTAL_NUM_ENGINES];  ///< Caches the number of engines of each type the player owns (no need to save this)
    28 
    31 
    29 	Group(StringID str = STR_NULL);
    32 	Group(PlayerID owner = INVALID_PLAYER);
    30 	virtual ~Group();
    33 	virtual ~Group();
    31 
    34 
    32 	bool IsValid() const;
    35 	bool IsValid() const;
    33 };
    36 };
    34 
    37 
    74  * id_g
    77  * id_g
    75  * @param id_g The GroupID of the group used
    78  * @param id_g The GroupID of the group used
    76  * @param id_e The EngineID of the engine to count
    79  * @param id_e The EngineID of the engine to count
    77  * @return The number of engines with EngineID id_e in the group
    80  * @return The number of engines with EngineID id_e in the group
    78  */
    81  */
    79 static inline uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e)
    82 uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e);
    80 {
       
    81 	if (IsValidGroupID(id_g)) return GetGroup(id_g)->num_engines[id_e];
       
    82 
       
    83 	uint num = GetPlayer(p)->num_engines[id_e];
       
    84 	if (!IsDefaultGroupID(id_g)) return num;
       
    85 
       
    86 	const Group *g;
       
    87 	FOR_ALL_GROUPS(g) {
       
    88 		if (g->owner == p) num -= g->num_engines[id_e];
       
    89 	}
       
    90 	return num;
       
    91 }
       
    92 
    83 
    93 static inline void IncreaseGroupNumVehicle(GroupID id_g)
    84 static inline void IncreaseGroupNumVehicle(GroupID id_g)
    94 {
    85 {
    95 	if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++;
    86 	if (IsValidGroupID(id_g)) GetGroup(id_g)->num_vehicle++;
    96 }
    87 }
   103 
    94 
   104 void InitializeGroup();
    95 void InitializeGroup();
   105 void SetTrainGroupID(Vehicle *v, GroupID grp);
    96 void SetTrainGroupID(Vehicle *v, GroupID grp);
   106 void UpdateTrainGroupID(Vehicle *v);
    97 void UpdateTrainGroupID(Vehicle *v);
   107 void RemoveVehicleFromGroup(const Vehicle *v);
    98 void RemoveVehicleFromGroup(const Vehicle *v);
   108 void RemoveAllGroupsForPlayer(const Player *p);
    99 void RemoveAllGroupsForPlayer(const PlayerID p);
   109 
   100 
   110 #endif /* GROUP_H */
   101 #endif /* GROUP_H */