2 * See kingdom.hh for a brief description of kingdoms.
4 * Copyright (C) 2008 Hermann Walth
6 * This file is part of OpenStranded
8 * OpenStranded is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * OpenStranded is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
27 std::map
<ID
, Kingdom
*> Kingdom::kingdomList
;
30 Kingdom::Kingdom (const char *name
):
31 name (std::string (name
))
39 std::map
<ID
, Type
*>::iterator type
;
40 for (type
= typeList
.begin (); type
!= typeList
.end (); type
++)
41 destroyType (type
->second
);
43 std::map
<ID
, Entity
*>::iterator entity
;
44 for (entity
= entityList
.begin (); entity
!= entityList
.end (); entity
++)
45 destroyEntity (entity
->second
);
50 Kingdom::getEntity (ID index
)
52 if (entityExists (index
))
53 return entityList
[index
];
60 Kingdom::getType (ID index
)
62 if (typeExists (index
))
63 return typeList
[index
];
70 Kingdom::entityExists (ID entity
)
72 if (entityList
.find (entity
) != entityList
.end ())
80 Kingdom::typeExists (ID type
)
82 if (typeList
.find (type
) != typeList
.end ())
90 Kingdom::appendEntity (ID type
)
92 return entityList
[++highestEntityID
] = createEntity (type
);
97 Kingdom::insertEntity (ID type
, ID entity
)
99 if (!entityExists (entity
))
100 entityList
[entity
] = createEntity (type
);
102 if (entity
> highestEntityID
)
103 highestEntityID
= entity
;
105 return entityList
[entity
];
110 Kingdom::insertType (const char* name
, ID type
)
112 if (!typeExists (type
))
113 typeList
[type
] = createType (name
);
114 return typeList
[type
];
119 Kingdom::insertType (ID type
)
121 return this->insertType ("", type
);
126 Kingdom::createEntity (ID type
)
128 return new Entity (type
);
133 Kingdom::destroyEntity (Entity
*entity
)
140 Kingdom::createType (const char* name
)
142 return new Type (name
);
147 Kingdom::destroyType (Type
*type
)
154 * Functions for the kingdomList
155 * TODO: In terms of beauty and modularity,
156 * these functions should be outsourced into another file
159 Kingdom::initKingdomList ()
161 kingdomList
[S2_OBJECT
] = new ObjectKingdom
;
162 kingdomList
[S2_UNIT
] = new UnitKingdom
;
163 kingdomList
[S2_ITEM
] = new ItemKingdom
;
168 Kingdom::uninitKingdomList ()
170 std::map
<ID
, Kingdom
*>::iterator iter
;
171 for (iter
= kingdomList
.begin (); iter
!= kingdomList
.end (); iter
++)
172 delete (iter
->second
);