-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWaypoint.cpp
130 lines (117 loc) · 3.55 KB
/
Waypoint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "Waypoint.h"
#include "Group.h"
#include "StringFuncs.h"
std::vector<Waypoint*> Waypoint::DeserializeWaypoints(std::istream &in, Group *group)
{
std::vector<Waypoint*> ret;
std::string strLine;
std::getline(in, strLine);
std::getline(in, strLine);
strLine = StringReplace(strLine, "\x09", "");
strLine = StringReplace(strLine, "items=", "");
strLine = StringReplace(strLine, ";", "");
ret.reserve(atoi(strLine.c_str()));
unsigned int scope = 1;
while(scope != 0)
{
std::getline(in, strLine);
scope += CharCount(strLine, '{');
scope -= CharCount(strLine, '}');
strLine = StringReplace(strLine, "\x09", "");
if(strLine.find("class Item") != std::string::npos)
{
ret.resize(ret.size()+1);
static unsigned short id = 0;
Waypoint *wp = new Waypoint(group, id);
id++;
wp->DeserializeSQM(in);
ret[ret.size()-1] = wp;
}
}
return ret;
}
Waypoint::Waypoint(Group *grp, unsigned short ID): m_grp(grp), m_ID(ID), m_dX(0), m_dY(0), m_dZ(0), m_strCombatMode(),
m_strFormation(), m_strSpeed(), m_strCombat(), m_strShowWP(), m_strType()
{
}
void Waypoint::DeserializeSQM(std::istream &in)
{
std::string strLine;
std::getline(in, strLine);
unsigned short scope = 1;
while(scope != 0)
{
std::getline(in, strLine);
scope += CharCount(strLine, '{');
scope -= CharCount(strLine, '}');
size_t eqPos = strLine.find('=');
std::string strCmd = RemoveWhitespace(strLine.substr(0, eqPos));
std::string strArg = strLine.substr(eqPos+1, strLine.size()-1);
if(strCmd == "position[]")
{
strArg = StringReplace(strArg, "{", "");
size_t commaPos = strArg.find(',');
m_dX = atof(strArg.substr(0, commaPos).c_str());
strArg = strArg.substr(commaPos+1, strArg.length());
commaPos = strArg.find(',');
m_dZ = atof(strArg.substr(0, commaPos).c_str());
strArg = strArg.substr(commaPos+1, strArg.length());
commaPos = strArg.find("};");
m_dY = atof(strArg.substr(0, commaPos).c_str());
}
else if(strCmd == "combatMode")
{
m_strCombatMode = strArg.substr(1, strArg.length()-3);
}
else if(strCmd == "formation")
{
m_strFormation = strArg.substr(1, strArg.length()-3);;
}
else if(strCmd == "speed")
{
m_strSpeed = strArg.substr(1, strArg.length()-3);;
}
else if(strCmd == "combat")
{
m_strCombat = strArg.substr(1, strArg.length()-3);;
}
else if(strCmd == "showWP")
{
m_strShowWP = strArg.substr(1, strArg.length()-3);;
}
else if(strCmd == "classEffects")
{
SeekToPhrase("{", in);// skip for now
SeekToPhrase("};", in);
}
else if(strCmd == "type")
{
m_strType = strArg.substr(1, strArg.length()-3);;
}
//TODO: Mess around with all options and fill in the rest
}
}
void Waypoint::SerializeBiEdi(std::ostream &out)
{
out << "class _waypoint_" << m_ID << std::endl
<< "{" << std::endl
<< " objectType=\"waypoint\";" << std::endl
<< " class Arguments" << std::endl
<< " {" << std::endl
<< " POSITION=\"[" << m_dX << "," << m_dY << "]\";" << std::endl
<< " GROUP=\"_group_" << m_grp->GetID() << "\";" << std::endl;
if(m_strType != "")
out << " TYPE=\"" << m_strType << "\";" << std::endl;
if(m_strFormation != "")
out << " FORMATION=\"" << m_strFormation << "\";" << std::endl;
if(m_strSpeed != "")
out << " SPEED=\"" << m_strSpeed << "\";" << std::endl;
if(m_strCombat != "")
out << " COMBAT=\"" << m_strCombat << "\";" << std::endl;
if(m_strCombatMode != "")
out << " COMBAT_MODE=\"" << m_strCombatMode << "\";" << std::endl;
if(m_strShowWP != "")
out << " SHOW=\"" << m_strShowWP << "\";" << std::endl;
out << " };" << std::endl
<< "};" << std::endl;
}