2007-05-19 09:40:18 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-05-14 18:38:54 +00:00
|
|
|
/** @file group.h Base class for groups and group functions. */
|
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;
|
2011-05-14 18:38:54 +00:00
|
|
|
extern GroupPool _group_pool; ///< Pool of groups.
|
2007-08-02 12:51:57 +00:00
|
|
|
|
2011-05-14 18:38:54 +00:00
|
|
|
/** Group data. */
|
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
|
|
|
|
2011-05-14 18:38:54 +00:00
|
|
|
uint16 num_vehicle; ///< Number of vehicles in 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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-05-14 18:38:54 +00:00
|
|
|
/**
|
|
|
|
* Increase the number of vehicles by one in a group.
|
|
|
|
* @param id_g Group id.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2011-05-14 18:38:54 +00:00
|
|
|
/**
|
|
|
|
* Decrease the number of vehicles by one in a group.
|
|
|
|
* @param id_g Group id.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */
|