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"
|
2009-05-22 15:39:22 +00:00
|
|
|
#include "core/pool_type.hpp"
|
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
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
typedef Pool<Group, GroupID, 16, 64000> GroupPool;
|
|
|
|
extern GroupPool _group_pool;
|
2007-08-02 12:51:57 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
struct Group : GroupPool::PoolItem<&_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);
|
2009-05-22 15:13:50 +00:00
|
|
|
~Group();
|
2007-08-02 12:51:57 +00:00
|
|
|
};
|
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-22 14:23:36 +00:00
|
|
|
#define FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start)
|
|
|
|
#define FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0)
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
2009-07-01 22:22:01 +00:00
|
|
|
void SetTrainGroupID(Train *v, GroupID grp);
|
|
|
|
void UpdateTrainGroupID(Train *v);
|
2007-05-19 09:40:18 +00:00
|
|
|
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 */
|