(svn r10751) -Codechange: make the group struct use the pool item class as super class.

This commit is contained in:
rubidium
2007-08-02 12:51:57 +00:00
parent dd666a80d5
commit 87ad3df284
3 changed files with 43 additions and 57 deletions

View File

@@ -13,40 +13,31 @@ enum {
INVALID_GROUP = 0xFFFF,
};
struct Group {
struct Group;
DECLARE_OLD_POOL(Group, Group, 5, 2047)
struct Group : PoolItem<Group, GroupID, &_Group_pool> {
StringID string_id; ///< Group Name
uint16 num_vehicle; ///< Number of vehicles wich belong to the group
PlayerID owner; ///< Group Owner
GroupID index; ///< Array index
VehicleTypeByte vehicle_type; ///< Vehicle type of the group
bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group
uint16 num_engines[TOTAL_NUM_ENGINES]; ///< Caches the number of engines of each type the player owns (no need to save this)
Group(StringID str = STR_NULL);
virtual ~Group();
void QuickFree();
bool IsValid() const;
};
DECLARE_OLD_POOL(Group, Group, 5, 2047)
static inline bool IsValidGroup(const Group *g)
{
return g->string_id != STR_NULL;
}
static inline void DestroyGroup(Group *g)
{
DeleteName(g->string_id);
}
static inline void DeleteGroup(Group *g)
{
DestroyGroup(g);
g->string_id = STR_NULL;
}
static inline bool IsValidGroupID(GroupID index)
{
return index < GetGroupPoolSize() && IsValidGroup(GetGroup(index));
return index < GetGroupPoolSize() && GetGroup(index)->IsValid();
}
static inline bool IsDefaultGroupID(GroupID index)
@@ -64,7 +55,7 @@ static inline bool IsAllGroupID(GroupID id_g)
return id_g == ALL_GROUP;
}
#define FOR_ALL_GROUPS_FROM(g, start) for (g = GetGroup(start); g != NULL; g = (g->index + 1U < GetGroupPoolSize()) ? GetGroup(g->index + 1) : NULL) if (IsValidGroup(g))
#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())
#define FOR_ALL_GROUPS(g) FOR_ALL_GROUPS_FROM(g, 0)
/**