Files
mod-playerbots/src/strategy/values/PositionValue.cpp
2024-08-04 10:23:36 +08:00

66 lines
1.7 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it
* and/or modify it under version 2 of the License, or (at your option), any later version.
*/
#include "PositionValue.h"
#include "Playerbots.h"
PositionValue::PositionValue(PlayerbotAI* botAI, std::string const name)
: ManualSetValue<PositionMap&>(botAI, positions, name)
{
}
std::string const PositionValue::Save()
{
std::ostringstream out;
bool first = true;
for (PositionMap::iterator i = value.begin(); i != value.end(); ++i)
{
std::string const name = i->first;
PositionInfo pos = i->second;
if (pos.isSet())
{
if (!first)
out << "^";
else
first = false;
out << name << "=" << pos.x << "," << pos.y << "," << pos.z << "," << pos.mapId;
}
}
return out.str();
}
bool PositionValue::Load(std::string const text)
{
value.clear();
std::vector<std::string> ss = split(text, '^');
for (std::vector<std::string>::iterator i = ss.begin(); i != ss.end(); ++i)
{
std::vector<std::string> s1 = split(*i, '=');
if (s1.size() != 2)
continue;
std::string const name = s1[0];
std::vector<std::string> s2 = split(s1[1], ',');
if (s2.size() != 4)
continue;
double x = atof(s2[0].c_str());
double y = atof(s2[1].c_str());
double z = atof(s2[2].c_str());
uint32 mapId = atoi(s2[3].c_str());
value[name].Set(x, y, z, mapId);
}
return true;
}
WorldPosition CurrentPositionValue::Calculate() { return WorldPosition(bot); }