Fixes to creatures
This commit is contained in:
parent
a88e9f9e0f
commit
26e20da938
|
@ -51,10 +51,10 @@ void Creatures::loadMonsters(const std::string& file)
|
||||||
|
|
||||||
void Creatures::loadSingleCreature(const std::string& file)
|
void Creatures::loadSingleCreature(const std::string& file)
|
||||||
{
|
{
|
||||||
return loadCreatureBuffer(g_resources.loadFile(file));
|
loadCreatureBuffer(g_resources.loadFile(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creatures::loadNpcs(const std::string &folder)
|
void Creatures::loadNpcs(const std::string& folder)
|
||||||
{
|
{
|
||||||
boost::filesystem::path npcPath(folder);
|
boost::filesystem::path npcPath(folder);
|
||||||
if(!boost::filesystem::exists(npcPath))
|
if(!boost::filesystem::exists(npcPath))
|
||||||
|
@ -77,14 +77,14 @@ void Creatures::loadCreatureBuffer(const std::string &buffer)
|
||||||
stdext::throw_exception(stdext::format("cannot load creature buffer: %s", doc.ErrorDesc()));
|
stdext::throw_exception(stdext::format("cannot load creature buffer: %s", doc.ErrorDesc()));
|
||||||
|
|
||||||
TiXmlElement* root = doc.FirstChildElement();
|
TiXmlElement* root = doc.FirstChildElement();
|
||||||
if(!root || root->ValueStr() != "npc")
|
if(!root || (root->ValueStr() != "monster" && root->ValueStr() != "npc"))
|
||||||
stdext::throw_exception("invalid root tag name");
|
stdext::throw_exception("invalid root tag name");
|
||||||
|
|
||||||
|
CreatureTypePtr newType(new CreatureType(stdext::trim(stdext::tolower(root->Attribute("name")))));
|
||||||
for(TiXmlElement* attrib = root->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) {
|
for(TiXmlElement* attrib = root->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) {
|
||||||
if(attrib->ValueStr() != "npc" && attrib->ValueStr() != "monster")
|
if(attrib->ValueStr() != "look")
|
||||||
stdext::throw_exception(stdext::format("invalid attribute '%s'", attrib->ValueStr()));
|
continue;
|
||||||
|
|
||||||
CreatureTypePtr newType(nullptr);
|
|
||||||
if(m_loadCreatureBuffer(attrib, newType))
|
if(m_loadCreatureBuffer(attrib, newType))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -92,26 +92,20 @@ void Creatures::loadCreatureBuffer(const std::string &buffer)
|
||||||
doc.Clear();
|
doc.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Creatures::m_loadCreatureBuffer(TiXmlElement* attrib, CreatureTypePtr& m)
|
bool Creatures::m_loadCreatureBuffer(TiXmlElement* attrib, const CreatureTypePtr& m)
|
||||||
{
|
{
|
||||||
if(m || std::find(m_creatures.begin(), m_creatures.end(), m) != m_creatures.end())
|
if(std::find(m_creatures.begin(), m_creatures.end(), m) != m_creatures.end())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
m = CreatureTypePtr(new CreatureType(stdext::trim(stdext::tolower(attrib->Attribute("name")))));
|
|
||||||
Outfit out;
|
Outfit out;
|
||||||
|
|
||||||
int32 type;
|
int32 type;
|
||||||
bool isTypeEx=false;
|
|
||||||
if(!attrib->Attribute("type").empty())
|
if(!attrib->Attribute("type").empty())
|
||||||
type = attrib->readType<int32>("type");
|
type = attrib->readType<int32>("type");
|
||||||
else {
|
else
|
||||||
type = attrib->readType<int32>("typeex");
|
type = attrib->readType<int32>("typeex");
|
||||||
isTypeEx = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.setId(type);
|
out.setId(type);
|
||||||
|
{
|
||||||
if(!isTypeEx) {
|
|
||||||
out.setHead(attrib->readType<int>(("head")));
|
out.setHead(attrib->readType<int>(("head")));
|
||||||
out.setBody(attrib->readType<int>(("body")));
|
out.setBody(attrib->readType<int>(("body")));
|
||||||
out.setLegs(attrib->readType<int>(("legs")));
|
out.setLegs(attrib->readType<int>(("legs")));
|
||||||
|
@ -119,9 +113,9 @@ bool Creatures::m_loadCreatureBuffer(TiXmlElement* attrib, CreatureTypePtr& m)
|
||||||
out.setAddons(attrib->readType<int>(("addons")));
|
out.setAddons(attrib->readType<int>(("addons")));
|
||||||
out.setMount(attrib->readType<int>(("mount")));
|
out.setMount(attrib->readType<int>(("mount")));
|
||||||
}
|
}
|
||||||
|
|
||||||
m->setOutfit(out);
|
m->setOutfit(out);
|
||||||
m_creatures.push_back(m);
|
m_creatures.push_back(m);
|
||||||
|
|
||||||
return type >= 0;
|
return type >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +125,3 @@ CreatureTypePtr Creatures::getCreature(const std::string& name)
|
||||||
[=] (const CreatureTypePtr& m) -> bool { return m->getName() == stdext::trim(stdext::tolower(name)); });
|
[=] (const CreatureTypePtr& m) -> bool { return m->getName() == stdext::trim(stdext::tolower(name)); });
|
||||||
return it != m_creatures.end() ? *it : nullptr;
|
return it != m_creatures.end() ? *it : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureTypePtr Creatures::getCreature(const Position& pos)
|
|
||||||
{
|
|
||||||
auto it = std::find_if(m_creatures.begin(), m_creatures.end(),
|
|
||||||
[=] (const CreatureTypePtr& m) -> bool { return m->getPos() == pos; });
|
|
||||||
return it != m_creatures.end() ? *it : nullptr;
|
|
||||||
}
|
|
||||||
|
|
|
@ -42,13 +42,11 @@ public:
|
||||||
CreatureType() { }
|
CreatureType() { }
|
||||||
CreatureType(const std::string& name) { setName(name); }
|
CreatureType(const std::string& name) { setName(name); }
|
||||||
|
|
||||||
void setPos(const Position& pos) { m_attribs.set(CreatureAttrPosition, pos); }
|
|
||||||
void setName(const std::string& name) { m_attribs.set(CreatureAttrName, name); }
|
void setName(const std::string& name) { m_attribs.set(CreatureAttrName, name); }
|
||||||
void setOutfit(const Outfit& o) { m_attribs.set(CreatureAttrOutfit, o); }
|
void setOutfit(const Outfit& o) { m_attribs.set(CreatureAttrOutfit, o); }
|
||||||
void setSpawnTime(int spawnTime) { m_attribs.set(CreatureAttrSpawnTime, spawnTime); }
|
void setSpawnTime(int spawnTime) { m_attribs.set(CreatureAttrSpawnTime, spawnTime); }
|
||||||
|
|
||||||
std::string getName() { return m_attribs.get<std::string>(CreatureAttrName); }
|
std::string getName() { return m_attribs.get<std::string>(CreatureAttrName); }
|
||||||
Position getPos() { return m_attribs.get<Position>(CreatureAttrPosition); }
|
|
||||||
Outfit getOutfit() { return m_attribs.get<Outfit>(CreatureAttrOutfit); }
|
Outfit getOutfit() { return m_attribs.get<Outfit>(CreatureAttrOutfit); }
|
||||||
int getSpawnTime() { return m_attribs.get<int>(CreatureAttrSpawnTime); }
|
int getSpawnTime() { return m_attribs.get<int>(CreatureAttrSpawnTime); }
|
||||||
|
|
||||||
|
@ -67,12 +65,10 @@ public:
|
||||||
void loadCreatureBuffer(const std::string& buffer);
|
void loadCreatureBuffer(const std::string& buffer);
|
||||||
|
|
||||||
CreatureTypePtr getCreature(const std::string& name);
|
CreatureTypePtr getCreature(const std::string& name);
|
||||||
CreatureTypePtr getCreature(const Position& pos);
|
|
||||||
|
|
||||||
bool isLoaded() const { return m_loaded; }
|
bool isLoaded() const { return m_loaded; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_loadCreatureBuffer(TiXmlElement* elem, CreatureTypePtr& m);
|
bool m_loadCreatureBuffer(TiXmlElement* elem, const CreatureTypePtr& m);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<CreatureTypePtr> m_creatures;
|
std::vector<CreatureTypePtr> m_creatures;
|
||||||
|
|
|
@ -305,11 +305,9 @@ void OTClient::registerLuaFunctions()
|
||||||
|
|
||||||
g_lua.registerClass<CreatureType>();
|
g_lua.registerClass<CreatureType>();
|
||||||
g_lua.bindClassStaticFunction<CreatureType>("create", []{ return CreatureTypePtr(new CreatureType); });
|
g_lua.bindClassStaticFunction<CreatureType>("create", []{ return CreatureTypePtr(new CreatureType); });
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("setPos", &CreatureType::setPos);
|
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("setName", &CreatureType::setName);
|
g_lua.bindClassMemberFunction<CreatureType>("setName", &CreatureType::setName);
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("setOutfit", &CreatureType::setOutfit);
|
g_lua.bindClassMemberFunction<CreatureType>("setOutfit", &CreatureType::setOutfit);
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("setSpawnTime", &CreatureType::setSpawnTime);
|
g_lua.bindClassMemberFunction<CreatureType>("setSpawnTime", &CreatureType::setSpawnTime);
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("getPos", &CreatureType::getPos);
|
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("getName", &CreatureType::getName);
|
g_lua.bindClassMemberFunction<CreatureType>("getName", &CreatureType::getName);
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("getOutfit", &CreatureType::getOutfit);
|
g_lua.bindClassMemberFunction<CreatureType>("getOutfit", &CreatureType::getOutfit);
|
||||||
g_lua.bindClassMemberFunction<CreatureType>("getSpawnTime", &CreatureType::getSpawnTime);
|
g_lua.bindClassMemberFunction<CreatureType>("getSpawnTime", &CreatureType::getSpawnTime);
|
||||||
|
|
|
@ -403,22 +403,26 @@ void Map::loadSpawns(const std::string &fileName)
|
||||||
if(!root || root->ValueStr() != "spawns")
|
if(!root || root->ValueStr() != "spawns")
|
||||||
stdext::throw_exception("malformed spawns file");
|
stdext::throw_exception("malformed spawns file");
|
||||||
|
|
||||||
|
CreatureTypePtr cType(nullptr);
|
||||||
for(TiXmlElement* node = root->FirstChildElement(); node; node = node->NextSiblingElement()) {
|
for(TiXmlElement* node = root->FirstChildElement(); node; node = node->NextSiblingElement()) {
|
||||||
if(node->ValueTStr() != "spawn")
|
if(node->ValueTStr() != "spawn")
|
||||||
stdext::throw_exception("invalid spawn node");
|
stdext::throw_exception("invalid spawn node");
|
||||||
|
|
||||||
Position centerPos = node->readPos("center");
|
Position centerPos = node->readPos("center");
|
||||||
for(TiXmlElement* mType = node->FirstChildElement(); mType; mType = mType->NextSiblingElement()) {
|
for(TiXmlElement* cNode = node->FirstChildElement(); cNode; cNode = cNode->NextSiblingElement()) {
|
||||||
if(mType->ValueStr() != "monster" && mType->ValueStr() != "npc")
|
if(cNode->ValueStr() != "monster" && cNode->ValueStr() != "npc")
|
||||||
stdext::throw_exception(stdext::format("invalid spawn-subnode %s", mType->ValueStr()));
|
stdext::throw_exception(stdext::format("invalid spawn-subnode %s", cNode->ValueStr()));
|
||||||
|
|
||||||
std::string mName = mType->Attribute("name");
|
std::string cName = stdext::trim(stdext::tolower(cNode->Attribute("name")));
|
||||||
CreatureTypePtr m = getCreature(mName);
|
if (!(cType = m_creatures.getCreature(cName)))
|
||||||
if (!m)
|
continue;
|
||||||
stdext::throw_exception(stdext::format("unkown monster '%s'", stdext::trim(stdext::tolower(mName))));
|
|
||||||
|
|
||||||
m->setPos(centerPos + mType->readPoint());
|
cType->setSpawnTime(cNode->readType<int>("spawntime"));
|
||||||
m->setSpawnTime(mType->readType<int>("spawntime"));
|
CreaturePtr creature(new Creature);
|
||||||
|
creature->setOutfit(cType->getOutfit());
|
||||||
|
creature->setName(cType->getName());
|
||||||
|
|
||||||
|
addThing(creature, centerPos + cNode->readPoint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,52 @@ enum OTBM_NodeTypes_t
|
||||||
OTBM_WAYPOINT = 16
|
OTBM_WAYPOINT = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum clientVersion_t
|
||||||
|
{
|
||||||
|
CLIENT_VERSION_750 = 1,
|
||||||
|
CLIENT_VERSION_755 = 2,
|
||||||
|
CLIENT_VERSION_760 = 3,
|
||||||
|
CLIENT_VERSION_770 = 3,
|
||||||
|
CLIENT_VERSION_780 = 4,
|
||||||
|
CLIENT_VERSION_790 = 5,
|
||||||
|
CLIENT_VERSION_792 = 6,
|
||||||
|
CLIENT_VERSION_800 = 7,
|
||||||
|
CLIENT_VERSION_810 = 8,
|
||||||
|
CLIENT_VERSION_811 = 9,
|
||||||
|
CLIENT_VERSION_820 = 10,
|
||||||
|
CLIENT_VERSION_830 = 11,
|
||||||
|
CLIENT_VERSION_840 = 12,
|
||||||
|
CLIENT_VERSION_841 = 13,
|
||||||
|
CLIENT_VERSION_842 = 14,
|
||||||
|
CLIENT_VERSION_850 = 15,
|
||||||
|
CLIENT_VERSION_854_OLD = 16,
|
||||||
|
CLIENT_VERSION_854 = 17,
|
||||||
|
CLIENT_VERSION_855 = 18,
|
||||||
|
CLIENT_VERSION_860_OLD = 19,
|
||||||
|
CLIENT_VERSION_860 = 20,
|
||||||
|
CLIENT_VERSION_861 = 21,
|
||||||
|
CLIENT_VERSION_862 = 22,
|
||||||
|
CLIENT_VERSION_870 = 23,
|
||||||
|
CLIENT_VERSION_871 = 24,
|
||||||
|
CLIENT_VERSION_872 = 25,
|
||||||
|
CLIENT_VERSION_873 = 26,
|
||||||
|
CLIENT_VERSION_900 = 27,
|
||||||
|
CLIENT_VERSION_910 = 28,
|
||||||
|
CLIENT_VERSION_920 = 29,
|
||||||
|
CLIENT_VERSION_940 = 30,
|
||||||
|
CLIENT_VERSION_944_V1 = 31,
|
||||||
|
CLIENT_VERSION_944_V2 = 32,
|
||||||
|
CLIENT_VERSION_944_V3 = 33,
|
||||||
|
CLIENT_VERSION_944_V4 = 34,
|
||||||
|
CLIENT_VERSION_946 = 35,
|
||||||
|
CLIENT_VERSION_950 = 36,
|
||||||
|
CLIENT_VERSION_952 = 37,
|
||||||
|
CLIENT_VERSION_953 = 38,
|
||||||
|
CLIENT_VERSION_954 = 39,
|
||||||
|
CLIENT_VERSION_960 = 40
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OTCM_SIGNATURE = 0x4D43544F,
|
OTCM_SIGNATURE = 0x4D43544F,
|
||||||
OTCM_VERSION = 1
|
OTCM_VERSION = 1
|
||||||
|
|
Loading…
Reference in New Issue