2 * This file includes the base class definition for entity kingdoms.
3 * Kingdoms group entities roughly by their most basic similiarities.
4 * The name 'Kingdom' is derived from the biological term.
6 * Copyright (C) 2008 Hermann Walth
8 * This file is part of OpenStranded
10 * OpenStranded is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * OpenStranded is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef STRANDED_KINGDOM_HH
25 #define STRANDED_KINGDOM_HH
34 typedef unsigned int ID
;
38 * This is a base class for all kingdoms.
39 * Originally implemented kingdoms were, roughly summarized, the following:
40 * Units as the only mobile and intelligent (or controllable) entities,
41 * Items as storable tools or resources,
42 * Objects as immobile structures, flora, rocks or similiar, and
43 * Infos as meta-information for technical purposes
44 * The OpenStranded Kingdom system is, however, designed to make it possible
45 * to implement new kingdoms at will.
53 * Kingdoms manage all their entities and types
54 * with pointers in local lists (STL Maps)
55 * where they are mapped to certain IDs.
56 * Using pointers may not be optimal OOP,
57 * but other methods aren't as efficient here.
59 std::map
<ID
, Entity
*> entityList
;
60 std::map
<ID
, Type
*> typeList
;
67 * @param name The name of the kingdom
69 Kingdom (const char *name
);
73 * Entities and Types are most likely to be allocated on the heap,
74 * so this destructor is used to free them again
80 * Looks up a certain entity from the kingdom's list by its ID.
81 * @param index The ID of the desired entity
82 * @return A pointer to the entity, NULL if none is found
88 * Looks up a certain type from the kingdom's list by its ID
89 * @param index The ID of the desired type
90 * @return A pointer to the type, NULL if none is found
96 * Checks whether an entity with a certain ID exists
97 * @param entity ID of the entity
98 * @return true if the entity exists, false if not
101 entityExists (ID entity
);
104 * Checks whether a type with a certain ID exists
105 * @param type ID of the type
106 * @return true if the type exists, false if not
109 typeExists (ID type
);
112 * Append an entity to the list.
113 * This method automatically assigns an ID which is by
114 * one higher than the currently highest entity ID
115 * @param type The ID of the type of the entity
116 * @return A pointer to the appended entity
119 appendEntity (ID type
);
122 * Insert an entity into a specific position of the list.
123 * This method assigns the specified ID to the entity.
124 * @param type The ID of the type of the entity
125 * @param entity The desired ID of the entity in the kingdom
126 * @return A pointer to the inserted entity
129 insertEntity (ID type
, ID entity
);
133 * TypeIDs need to be certain and definite towards the outside,
134 * so there is only an insertType method defining a certain ID.
135 * @param name The name of the type
136 * @param type The desired ID of the type
137 * @return A pointer to the inserted type
140 insertType (const char* name
, ID type
);
143 * Insert a type without a name.
144 * @param type The desired ID of the type
145 * @return A pointer to the inserted type
148 insertType (ID type
);
151 * These are some virtual functions used by other methods.
152 * They differ from kingdom to kingdom.
153 * Basically, they should just implement the
154 * entity's and type's constructors/destructors for this kingdom
158 createEntity (ID type
);
161 destroyEntity (Entity
*entity
);
164 createType (const char* name
);
167 destroyType (Type
*type
);
172 // Static class members
175 static std::map
<ID
, Kingdom
*> kingdomList
;
178 initKingdomList (std::string mod
= "Stranded II");
181 uninitKingdomList ();
184 parseEntityTypes(std::string mod
, std::string name
);
187 #endif /* STRANDED_KINGDOM_HH */