2007-05-19 09:40:18 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file group.h Base class from groups. */
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
#ifndef GROUP_H
|
|
|
|
#define GROUP_H
|
|
|
|
|
2008-03-28 16:34:50 +00:00
|
|
|
#include "group_type.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "oldpool.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_type.h"
|
2008-01-12 14:10:35 +00:00
|
|
|
#include "vehicle_type.h"
|
2008-03-31 00:17:39 +00:00
|
|
|
#include "engine_type.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2007-08-02 12:51:57 +00:00
|
|
|
DECLARE_OLD_POOL(Group, Group, 5, 2047)
|
|
|
|
|
|
|
|
struct Group : PoolItem<Group, GroupID, &_Group_pool> {
|
2008-01-12 19:58:06 +00:00
|
|
|
char *name; ///< Group Name
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
uint16 num_vehicle; ///< Number of vehicles wich belong to the group
|
2008-09-30 20:39:50 +00:00
|
|
|
OwnerByte owner; ///< Group Owner
|
2007-05-19 09:40:18 +00:00
|
|
|
VehicleTypeByte vehicle_type; ///< Vehicle type of the group
|
|
|
|
|
|
|
|
bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group
|
2008-09-30 20:39:50 +00:00
|
|
|
uint16 *num_engines; ///< Caches the number of engines of each type the company owns (no need to save this)
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
Group(CompanyID owner = INVALID_COMPANY);
|
2007-08-02 12:51:57 +00:00
|
|
|
virtual ~Group();
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2007-08-02 12:51:57 +00:00
|
|
|
bool IsValid() const;
|
|
|
|
};
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
static inline bool IsDefaultGroupID(GroupID index)
|
|
|
|
{
|
2007-07-14 23:10:27 +00:00
|
|
|
return index == DEFAULT_GROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Checks if a GroupID stands for all vehicles of a company
|
2007-07-14 23:10:27 +00:00
|
|
|
* @param id_g The GroupID to check
|
|
|
|
* @return true is id_g is identical to ALL_GROUP
|
|
|
|
*/
|
|
|
|
static inline bool IsAllGroupID(GroupID id_g)
|
|
|
|
{
|
|
|
|
return id_g == ALL_GROUP;
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2009-05-16 23:44:36 +00:00
|
|
|
#define FOR_ALL_GROUPS_FROM(g, start) for (g = Group::Get(start); g != NULL; g = (g->index + 1U < Group::GetPoolSize()) ? Group::Get(g->index + 1) : NULL) if (g->IsValid())
|
2007-05-19 09:40:18 +00:00
|
|
|
#define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current size of the GroupPool
|
|
|
|
*/
|
2009-05-21 22:43:25 +00:00
|
|
|
static inline uint GetGroupArraySize()
|
2007-05-19 09:40:18 +00:00
|
|
|
{
|
|
|
|
const Group *g;
|
|
|
|
uint num = 0;
|
|
|
|
|
|
|
|
FOR_ALL_GROUPS(g) num++;
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2007-07-14 23:10:27 +00:00
|
|
|
/**
|
|
|
|
* Get the number of engines with EngineID id_e in the group with GroupID
|
|
|
|
* id_g
|
|
|
|
* @param id_g The GroupID of the group used
|
|
|
|
* @param id_e The EngineID of the engine to count
|
|
|
|
* @return The number of engines with EngineID id_e in the group
|
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
|
2007-07-14 23:10:27 +00:00
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
static inline void IncreaseGroupNumVehicle(GroupID id_g)
|
|
|
|
{
|
2009-05-18 16:21:28 +00:00
|
|
|
Group *g = Group::GetIfValid(id_g);
|
|
|
|
if (g != NULL) g->num_vehicle++;
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void DecreaseGroupNumVehicle(GroupID id_g)
|
|
|
|
{
|
2009-05-18 16:21:28 +00:00
|
|
|
Group *g = Group::GetIfValid(id_g);
|
|
|
|
if (g != NULL) g->num_vehicle--;
|
2007-05-19 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitializeGroup();
|
|
|
|
void SetTrainGroupID(Vehicle *v, GroupID grp);
|
|
|
|
void UpdateTrainGroupID(Vehicle *v);
|
|
|
|
void RemoveVehicleFromGroup(const Vehicle *v);
|
2008-09-30 20:39:50 +00:00
|
|
|
void RemoveAllGroupsForCompany(const CompanyID company);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
extern GroupID _new_group_id;
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
#endif /* GROUP_H */
|