Go to the documentation of this file.
45 m_contentRevision = 0;
46 m_otbMinorVersion = 0;
47 m_otbMajorVersion = 0;
51 for(
auto &m_thingType: m_thingTypes)
52 m_thingType.resize(1, m_nullThingType);
53 m_itemTypes.resize(1, m_nullItemType);
58 for(
auto &m_thingType: m_thingTypes)
61 m_reverseItemTypes.clear();
62 m_nullThingType =
nullptr;
63 m_nullItemType =
nullptr;
78 fin->
addU32(m_datSignature);
80 for(
auto &m_thingType: m_thingTypes)
81 fin->
addU16(m_thingType.size() - 1);
88 for(
uint16 id = firstId;
id < m_thingTypes[category].size(); ++id)
89 m_thingTypes[category][
id]->serialize(fin);
95 }
catch(std::exception& e) {
104 m_contentRevision = 0;
110 m_datSignature = fin->
getU32();
111 m_contentRevision =
static_cast<uint16_t
>(m_datSignature);
113 for(
auto &m_thingType: m_thingTypes) {
114 int count = fin->
getU16() + 1;
116 m_thingType.resize(count, m_nullThingType);
123 for(
uint16 id = firstId;
id < m_thingTypes[category].size(); ++id) {
126 m_thingTypes[category][id] = type;
147 if(node->tag() ==
"creatures")
149 else if(node->tag() ==
"items")
151 else if(node->tag() ==
"effects")
153 else if(node->tag() ==
"missiles")
160 uint16 id = stdext::safe_cast<uint16>(node2->tag());
168 }
catch(std::exception& e) {
186 signature = root->getU32();
190 uint8 rootAttr = root->getU8();
191 if(rootAttr == 0x01) {
192 uint16 size = root->getU16();
193 if(size != 4 + 4 + 4 + 128)
196 m_otbMajorVersion = root->getU32();
197 m_otbMinorVersion = root->getU32();
203 m_reverseItemTypes.clear();
204 m_itemTypes.resize(children.size() + 1, m_nullItemType);
205 m_reverseItemTypes.resize(children.size() + 1, m_nullItemType);
213 if(
unlikely(clientId >= m_reverseItemTypes.size()))
214 m_reverseItemTypes.resize(clientId + 1);
215 m_reverseItemTypes[clientId] = itemType;
220 }
catch(std::exception& e) {
237 if(!root || root->
ValueTStr() !=
"items")
241 if(
unlikely(element->ValueTStr() !=
"item"))
246 std::vector<std::string> s_ids =
stdext::split(element->Attribute(
"id"),
";");
247 for(
const std::string& s : s_ids) {
248 std::vector<int32> ids = stdext::split<int32>(s,
"-");
257 std::vector<int32> begin = stdext::split<int32>(element->Attribute(
"fromid"),
";");
258 std::vector<int32> end = stdext::split<int32>(element->Attribute(
"toid"),
";");
259 if(begin[0] && begin.size() == end.size()) {
260 size_t size = begin.size();
261 for(
size_t i = 0; i < size; ++i)
262 while(begin[i] <= end[i])
271 }
catch(std::exception& e) {
284 s = serverId > 20000 && serverId < 20100;
287 s = serverId > 30000 && serverId < 30100;
301 std::string key = attrib->Attribute(
"key");
306 if(key ==
"description")
307 itemType->
setDesc(attrib->Attribute(
"value"));
308 else if(key ==
"weapontype")
310 else if(key ==
"ammotype")
312 else if(key ==
"armor")
314 else if(key ==
"charges")
316 else if(key ==
"type") {
317 std::string value = attrib->Attribute(
"value");
322 else if(value ==
"magicfield")
324 else if(value ==
"teleport")
326 else if(value ==
"door")
335 if(
unlikely(
id >= m_itemTypes.size()))
336 m_itemTypes.resize(
id + 1, m_nullItemType);
337 m_itemTypes[id] = itemType;
342 if(
id == 0 ||
id >= m_reverseItemTypes.size())
343 return m_nullItemType;
345 if(m_reverseItemTypes[
id])
346 return m_reverseItemTypes[id];
348 return m_nullItemType;
354 if(it->getName() == name)
356 return m_nullItemType;
363 if(it->getName() == name)
372 if(it->getName().find(name) != std::string::npos)
381 return m_nullThingType;
383 return m_thingTypes[category][id];
388 if(
id >= m_itemTypes.size() || m_itemTypes[
id] == m_nullItemType) {
390 return m_nullItemType;
392 return m_itemTypes[id];
399 if(type->hasAttr(attr))
408 if(type->getCategory() == category)
418 return m_thingTypes[category];
std::vector< ItemTypePtr > ItemTypeList
bool loadDat(std::string file)
ItemTypeList findItemTypesByString(std::string name)
void unserialize(const BinaryTreePtr &node)
const TiXmlElement * NextSiblingElement() const
All OTML errors throw this exception.
const ItemTypePtr & findItemTypeByName(std::string name)
bool loadOtml(std::string file)
static OTMLDocumentPtr parse(const std::string &fileName)
Parse OTML from a file.
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
const TIXML_STRING & ValueTStr() const
void callGlobalField(const std::string &global, const std::string &field, const T &... args)
stdext::shared_object_ptr< ItemType > ItemTypePtr
void error(const std::string &what)
const ItemTypePtr & getItemType(uint16 id)
void unserializeOtml(const OTMLNodePtr &node)
void setDesc(const std::string &desc)
const ThingTypeList & getThingTypes(ThingCategory category)
void setServerId(uint16 serverId)
std::string Attribute(const std::string &name) const
void loadXml(const std::string &file)
void unserialize(uint16 clientId, ThingCategory category, const FileStreamPtr &fin)
ResourceManager g_resources
void Clear()
Delete all the children of this node. Does not affect 'this'.
BinaryTreePtr getBinaryTree()
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
const ItemTypePtr & findItemTypeByClientId(uint16 id)
ItemTypeList findItemTypeByCategory(ItemCategory category)
const ThingTypePtr & getThingType(uint16 id, ThingCategory category)
void setName(const std::string &name)
stdext::shared_object_ptr< ThingType > ThingTypePtr
void throw_exception(const std::string &what)
Throws a generic exception.
FileStreamPtr openFile(const std::string &fileName)
std::string readFileContents(const std::string &fileName)
std::vector< std::string > split(const std::string &str, const std::string &separators)
virtual const char * what() const
void setCategory(ItemCategory category)
void debug(const std::string &what)
void loadOtb(const std::string &file)
std::vector< BinaryTreePtr > BinaryTreeVec
std::vector< ThingTypePtr > ThingTypeList
void addItemType(const ItemTypePtr &itemType)
void parseItemType(uint16 id, TiXmlElement *elem)
ThingTypeList findThingTypeByAttr(ThingAttr attr, ThingCategory category)
ItemTypeList findItemTypesByName(std::string name)
FileStreamPtr createFile(const std::string &fileName)
void saveDat(std::string fileName)
void tolower(std::string &str)
ThingTypeManager g_things
std::string guessFilePath(const std::string &filename, const std::string &type)