Eliminated some problems resulting from last merge
[openstranded.git] / src / kingdom.hh
blobde9ce00be0e6460de7231842a3696ffc261bb397
1 /*
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
27 #include <string>
28 #include <map>
29 #include "entity.hh"
30 #include "type.hh"
32 class Kingdom;
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.
47 class Kingdom
49 private:
50 std::string name;
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;
62 ID highestEntityID;
64 public:
66 * The constructor, with the kingdom name as argument
68 Kingdom (const char *name);
71 * Entities and Types are most likely to be allocated on the heap,
72 * so this destructor is used to free them again
74 virtual
75 ~Kingdom ();
78 * Looks up a certain entity from the kingdom's list by its ID
80 Entity*
81 getEntity (ID index);
84 * Looks up a certain type from the kingdom's list by its ID
86 Type*
87 getType (ID index);
90 * Checks whether an entity with a certain ID exists
92 bool
93 entityExists (ID entity);
96 * Checks whether a type with a certain ID exists
98 bool
99 typeExists (ID type);
102 * Append an entity to the list, automatically assigning an ID
103 * which is by 1 higher than the currently highest entity ID
105 Entity*
106 appendEntity (ID type);
109 * Insert an entity into a specific position of the list, assigning
110 * the specified ID to it
112 Entity*
113 insertEntity (ID type, ID entity);
116 * TypeIDs need to be certain and definite towards the outside,
117 * so there is only an insertType method defining a certain ID
119 Type*
120 insertType (const char* name, ID type);
122 Type*
123 insertType (ID type);
126 * These are some virtual functions used by other methods.
127 * They differ from kingdom to kingdom.
128 * Basically, they should just implement the
129 * entity's and type's constructors/destructors for this kingdom
131 virtual Entity*
132 createEntity (ID type);
134 virtual void
135 destroyEntity (Entity *entity);
137 virtual Type*
138 createType (const char* name);
140 virtual void
141 destroyType (Type *type);
144 * Static class members
147 static std::map <ID, Kingdom*> kingdomList;
149 static void
150 initKingdomList ();
152 static void
153 uninitKingdomList ();
156 #endif /* STRANDED_KINGDOM_HH */