-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mission.cpp
174 lines (165 loc) · 4.39 KB
/
Mission.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "Mission.h"
#include "StringFuncs.h"
#include <iostream>
Mission::Mission() : m_intel(NULL)
{
}
void Mission::DeserializeSQM(std::istream &in)
{
SeekToPhrase("class Mission", in);
SeekToPhrase("{", in);
while(!in.eof())
{
std::string strLine;
std::getline(in, strLine);
strLine = StringReplace(strLine, "\x09", "");
strLine = StringReplace(strLine, "\r", "");
strLine = StringReplace(strLine, "\n", "");
//prepare for the madness
if(strLine == "addOns[]=")
{
while(RemoveWhitespace(strLine) != "};") //skip it for now
{
std::getline(in, strLine);
}
}
else if(strLine == "addOnsAuto[]=")
{
while(RemoveWhitespace(strLine) != "};") //same thing
{
std::getline(in, strLine);
}
}
else if(strLine == "class Intel")
{
if(m_intel != NULL)
{
std::cout << "WARNING: DUPLICATE INTEL";
}
else
{
m_intel = new Intel;
}
m_intel->DeserializeSQM(in);
}
else if(strLine == "class Groups")
{
//parser-ception
std::getline(in, strLine);//{
std::getline(in, strLine);
strLine = StringReplace(strLine, "\x09", "");
strLine = StringReplace(strLine, "items=", "");
strLine = StringReplace(strLine, ";", "");
m_groups.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)
{
m_groups.resize(m_groups.size()+1);
static unsigned short id = 0;
Group *group = new Group(id);
id++;
group->DeserializeSQM(in);
m_groups[m_groups.size()-1] = group;
}
}
}
else if(strLine == "class Vehicles")
{
std::getline(in, strLine);//{
std::getline(in, strLine);
strLine = StringReplace(strLine, "\x09", "");
strLine = StringReplace(strLine, "items=", "");
strLine = StringReplace(strLine, ";", "");
m_vehicles.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)
{
m_vehicles.resize(m_vehicles.size()+1);
static unsigned short id = 0;
Vehicle *vehicle = new Vehicle(id);
id++;
vehicle->DeserializeSQM(in);
m_vehicles[m_vehicles.size()-1] = vehicle;
}
}
}
else if(strLine == "class Markers")
{
std::getline(in, strLine);//{
std::getline(in, strLine);
strLine = StringReplace(strLine, "\x09", "");
strLine = StringReplace(strLine, "items=", "");
strLine = StringReplace(strLine, ";", "");
m_markers.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)
{
m_markers.resize(m_markers.size()+1);
static unsigned short id = 0;
Marker *marker = new Marker(id);
id++;
marker->DeserializeSQM(in);
m_markers[m_markers.size()-1] = marker;
}
}
}
}
}
void Mission::SerializeBiEdi(std::ostream &out)
{
out << "class _prefix_0" << std::endl << "{" << std::endl << " objectType=\"prefix\";"
<< std::endl << " class Arguments" << std::endl << " {" << std::endl
<< " };" << std::endl << "};" << std::endl;
if(m_intel != NULL)
{
m_intel->SerializeBiEdi(out);
}
for(size_t i = 0; i < Center::GetCenters().size(); i++)
{
out << "class _center_" << i << std::endl
<< "{" << std::endl
<< " objectType=\"center\";" << std::endl
<< " class Arguments" << std::endl
<< " {" << std::endl
<< " SIDE=\"" << Center::GetCenters()[i]->GetSide() << "\";" << std::endl
<< " };" << std::endl
<< "};" << std::endl;
}
for(size_t i = 0; i < m_groups.size(); i++)
{
m_groups[i]->SerializeBiEdi(out);
}
for(size_t i = 0; i < m_vehicles.size(); i++)
{
m_vehicles[i]->SerializeBiEdi(out);
}
for(size_t i = 0; i < m_markers.size(); i++)
{
m_markers[i]->SerializeBiEdi(out);
}
out << "class _postfix_0" << std::endl
<< "{" << std::endl
<< " objectType=\"postfix\";" << std::endl
<< " class Arguments" << std::endl
<< " {" << std::endl
<< " };" << std::endl
<< "};" << std::endl;
}