-
Notifications
You must be signed in to change notification settings - Fork 2
/
Group.cpp
141 lines (124 loc) · 3.02 KB
/
Group.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
131
132
133
134
135
136
137
138
139
140
141
#include "Group.h"
#include <string>
#include <cassert>
#include "StringFuncs.h"
#include "Unit.h"
#include "Waypoint.h"
std::vector<Center*> centerList;
Center::Center(std::string strSide, unsigned short id) : m_strSide(strSide), m_id(id)
{
}
Center* Center::GetCenter(std::string strSide)
{
for(unsigned char i = 0; i < centerList.size(); i++)
{
if(centerList[i]->m_strSide == strSide)
{
return centerList[i];
}
}
Center *center = new Center(strSide, centerList.size());
centerList.resize(centerList.size()+1);
centerList[centerList.size()-1] = center;
return center;
}
std::string Center::GetSide()
{
return m_strSide;
}
const std::vector<Center*> Center::GetCenters()
{
return centerList;
}
const unsigned short Center::GetID()
{
return m_id;
}
Group::Group(unsigned short ID) : m_units(), m_ID(ID), m_center(NULL)
{
}
void Group::DeserializeSQM(std::istream &in)
{
std::string strLine;
std::getline(in, strLine);
assert(strLine != "{");
std::getline(in, strLine);
strLine = StringReplace(strLine, "\x09", "");
strLine = StringReplace(strLine, "side=\"", "");
strLine = StringReplace(strLine, "\";", "");
if(strLine == "WEST")
{
m_center = Center::GetCenter("WEST");
}
else if(strLine == "EAST")
{
m_center = Center::GetCenter("EAST");
}
else if(strLine == "GUER")
{
m_center = Center::GetCenter("GUER");
}
else if(strLine == "CIV")
{
m_center = Center::GetCenter("CIV");
}
else if(strLine == "LOGIC")
{
m_center = Center::GetCenter("LOGIC");
}
else if(strLine == "ENEMY")
{
m_center = Center::GetCenter("ENEMY");
}
std::getline(in, strLine);//class Vehicles
std::getline(in, strLine);//{
std::getline(in, strLine);//items=bla
strLine = StringReplace(strLine, "\x09", "");
strLine = StringReplace(strLine, "items=", "");
strLine = StringReplace(strLine, ";", "");
m_units.reserve(atoi(strLine.c_str()));
unsigned int scope = 2;
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)
{
m_units.resize(m_units.size()+1);
static unsigned short id = 0;
Unit *unit = new Unit(this, id);
id++;
unit->DeserializeSQM(in);
m_units[m_units.size()-1] = unit;
}
if(strLine.find("class Waypoints") != std::string::npos)//Waypoints are inside class Vehicles in sqm? what the fuck?
{
m_waypoints = Waypoint::DeserializeWaypoints(in, this);
}
}
}
void Group::SerializeBiEdi(std::ostream &out)
{
out << "class _group_" << m_ID << std::endl
<< "{" << std::endl
<< " objectType=\"group\";" << std::endl
<< " class Arguments" << std::endl
<< " {" << std::endl
<< " CENTER=\"_center_" << m_center->GetID() << "\";" << std::endl
<< " };" << std::endl
<< "};" << std::endl;
for(size_t i = 0; i < m_units.size(); i++)
{
m_units[i]->SerializeBiEdi(out);
}
for(size_t i = 0; i < m_waypoints.size(); i++)
{
m_waypoints[i]->SerializeBiEdi(out);
}
}
const unsigned short Group::GetID()
{
return m_ID;
}