Go to the documentation of this file.
32 static bool isInZone(
const Position& pos,
38 return ((pos.
x >= centerPos.
x - radius) && (pos.
x <= centerPos.
x + radius) &&
39 (pos.
y >= centerPos.
y - radius) && (pos.
y <= centerPos.
y + radius)
47 m_nullCreature =
nullptr;
53 centerPos.
x = node->
readType<
int>(
"centerx");
54 centerPos.
y = node->
readType<
int>(
"centery");
55 centerPos.
z = node->
readType<
int>(
"centerz");
62 if(cNode->ValueStr() !=
"monster" && cNode->ValueStr() !=
"npc")
65 std::string cName = cNode->Attribute(
"name");
75 int16 dir_ = cNode->readType<
int16>(
"direction");
81 placePos.
x = centerPos.
x + cNode->readType<
int>(
"x");
82 placePos.
y = centerPos.
y + cNode->readType<
int>(
"y");
83 placePos.
z = cNode->readType<
int>(
"z");
101 for(
const auto& pair : m_creatures) {
110 const Position& placePos = pair.first;
125 if(!isInZone(placePos, centerPos, m_radius)) {
134 m_creatures.insert(std::make_pair(placePos, cType));
139 auto iterator = m_creatures.find(pos);
140 if(iterator != m_creatures.end()) {
141 assert(iterator->first.isValid());
143 m_creatures.erase(iterator);
149 std::vector<CreatureTypePtr> creatures;
150 for (
auto p : m_creatures)
151 creatures.push_back(p.second);
177 for(
auto pair : m_spawns)
178 pair.second->clear();
190 if(!root || root->
ValueStr() !=
"monsters")
194 std::string fname = file.substr(0, file.find_last_of(
'/')) +
'/' + monster->Attribute(
"file");
195 if(fname.substr(fname.length() - 4) !=
".xml")
212 std::string tmp = folder;
220 for(
const std::string& file : fileList)
243 if(!root || root->
ValueStr() !=
"spawns")
247 if(node->ValueTStr() !=
"spawn")
252 m_spawns.insert(std::make_pair(spawn->getCenterPos(), spawn));
255 m_spawnLoaded =
true;
256 }
catch(std::exception& e) {
273 for(
auto pair : m_spawns) {
275 pair.second->save(elem);
281 }
catch(std::exception& e) {
289 doc.
Parse(buffer.c_str());
297 std::string cName = root->
Attribute(
"name");
304 if(attrib->ValueStr() !=
"look")
316 if(std::find(m_creatures.begin(), m_creatures.end(), m) != m_creatures.end())
340 m_creatures.push_back(m);
348 auto it = std::find_if(m_creatures.begin(), m_creatures.end(),
349 [=] (
const CreatureTypePtr& m) ->
bool { return m->getName() == name; });
350 if(it != m_creatures.end())
353 return m_nullCreature;
360 const Outfit& o = c->getOutfit();
363 auto it = std::find_if(m_creatures.begin(), m_creatures.end(), findFun);
364 if(it != m_creatures.end())
367 return m_nullCreature;
372 auto it = m_spawns.find(centerPos);
373 if(it != m_spawns.end())
381 for (
const auto& pair : m_spawns) {
382 const Position& centerPos = pair.first;
383 const SpawnPtr& spawn = pair.second;
385 if (isInZone(pos, centerPos, spawn->getRadius()))
394 auto iter = m_spawns.find(centerPos);
395 if(iter != m_spawns.end()) {
396 if(iter->second->getRadius() != radius)
397 iter->second->setRadius(radius);
403 ret->setRadius(radius);
404 ret->setCenterPos(centerPos);
406 m_spawns.insert(std::make_pair(centerPos, ret));
412 const Position& centerPos = spawn->getCenterPos();
413 auto it = m_spawns.find(centerPos);
414 if(it != m_spawns.end())
420 std::vector<SpawnPtr> spawns;
421 for (
auto p : m_spawns)
422 spawns.push_back(p.second);
std::list< std::string > listDirectoryFiles(const std::string &directoryPath="")
const CreatureTypePtr & getCreatureByLook(int look)
void setRace(CreatureRace race)
const TiXmlElement * NextSiblingElement() const
const CreatureTypePtr & getCreatureByName(std::string name)
void setAddons(int addons)
const std::string & ValueStr() const
void setDirection(Otc::Direction dir)
void ucwords(std::string &str)
void setDirection(Otc::Direction direction)
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
bool directoryExists(const std::string &directoryName)
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)
void error(const std::string &what)
void setCategory(ThingCategory category)
void addCreature(const Position &placePos, const CreatureTypePtr &cType)
void setSpawnTime(int32 spawnTime)
void setCenterPos(const Position &pos)
void deleteSpawn(const SpawnPtr &spawn)
CreatureManager g_creatures
std::string Attribute(const std::string &name) const
void SetTabSize(int _tabsize)
ResourceManager g_resources
void saveSpawns(const std::string &fileName)
void Clear()
Delete all the children of this node. Does not affect 'this'.
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
void addThing(const ThingPtr &thing, const Position &pos, int stackPos=-1)
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
std::vector< SpawnPtr > getSpawns()
void setName(const std::string &name)
void loadNpcs(const std::string &folder)
stdext::shared_object_ptr< CreatureType > CreatureTypePtr
void save(TiXmlElement *node)
void loadCreatureBuffer(const std::string &buffer)
void SetAttribute(const std::string &name, const std::string &_value)
void setOutfit(const Outfit &o)
void trim(std::string &str)
std::vector< CreatureTypePtr > getCreatures()
T readType(const std::string &str) const
void throw_exception(const std::string &what)
Throws a generic exception.
bool ends_with(const std::string &str, const std::string &test)
std::string readFileContents(const std::string &fileName)
std::string to_string(const T &t)
void loadSpawns(const std::string &fileName)
SpawnPtr getSpawnForPlacePos(const Position &pos)
void debug(const std::string &what)
void loadMonsters(const std::string &file)
Otc::Direction getDirection()
bool removeThingByPos(const Position &pos, int stackPos)
SpawnPtr getSpawn(const Position ¢erPos)
void loadSingleCreature(const std::string &file)
void internalLoadCreatureBuffer(TiXmlElement *attrib, const CreatureTypePtr &m)
void tolower(std::string &str)
void setOutfit(const Outfit &outfit)
void removeCreature(const Position &pos)
void load(TiXmlElement *node)
SpawnPtr addSpawn(const Position ¢erPos, int radius)
void warning(const std::string &what)