-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPlanet.cpp
195 lines (169 loc) · 3.65 KB
/
Planet.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "Planet.h"
#include "Galaxy.h"
#include <QMap>
Planet::Planet(QTextStream &stream, Galaxy &galaxy, unsigned id, unsigned starId):_id(id),_starId(starId)
{
const static QMap<QString,int> planetOptions={
{"PlanetName",0},
{"Owner",1},
{"Race",2},
{"Economy",3},
{"Goverment",4},
{"ISize",5},
{"RelationToPlayer",6},
{"IMainTechLevel",7},
{"OrbitCnt",8},
{"ShopGoods",9},
{"ShopGoodsSale",10},
{"ShopGoodsBuy",11},
{"WaterSpace",12},
{"LandSpace",13},
{"HillSpace",14},
{"WaterComplate",15},
{"LandComplate",16},
{"HillComplate",17},
{"EqShop ^{",18},
{"Storage ^{",19},
{"Treasure ^{",20},
{"Garrison ^{",21},
{"TechLevels",22},
{"CurrentInvention",23},
{"CurrentInventionPoints",24}
};
int nesting=0;
QString line = stream.readLine().trimmed();;
while (!line.isNull())
{
nesting+=line.contains('{');
nesting-=line.contains('}');
if(line.startsWith("PlanetId"))
{
nesting-=1;
QStringRef idRef(&line,6,line.indexOf(' ')-6);
_id=idRef.toInt();
}
if(nesting<0)
{
break;
}
QString varname=line.section('=',0,0);
QString value=line.section('=',-1);
switch(planetOptions.value(varname,-1))
{
case 0://PlanetName
_name=value;
break;
case 1://Owner
_owner=value;
break;
case 2://Race
_race=value;
break;
case 3://Economy
_economy=value;
break;
case 4://Goverment
_government=value;
break;
case 5://ISize
_size=value.toInt();
break;
case 6://RelationToPlayer
_relation=value.toInt();
break;
case 7://IMainTechLevel
_techLevel=value.toInt();
break;
case 8://OrbitCnt
_orbitCount=value.toInt();
break;
case 9://ShopGoods
_goodsShopQuantity=GoodsArr(value);
break;
case 10://ShopGoodsSale
_goodsSale=GoodsArr(value);
break;
case 11://ShopGoodsBuy
_goodsBuy=GoodsArr(value);
break;
case 12://WaterSpace
_waterSpace=value.toInt();
break;
case 13://LandSpace
_landSpace=value.toInt();
break;
case 14://HillSpace
_hillSpace=value.toInt();
break;
case 15://WaterComplate
_waterComplete=value.toInt();
break;
case 16://LandComplate
_landComplete=value.toInt();
break;
case 17://HillComplate
_hillComplete=value.toInt();
break;
case 18://EqShop ^{
if(_owner=="None") {
break;
}
{
auto eqListAppend=readEqlist(stream, galaxy,Equipment::kPlanetShop,_id);
_eqIdList.insert(eqListAppend.begin(),eqListAppend.end());
--nesting;
}
break;
case 19://Storage ^{
{
auto eqListAppend=readEqlist(stream, galaxy,Equipment::kPlanetStorage,_id);
_eqIdList.insert(eqListAppend.begin(),eqListAppend.end());
--nesting;
}
break;
case 20://Treasure ^{
{
auto eqListAppend=readEqlist(stream, galaxy,Equipment::kPlanetTreasure,_id);
_eqIdList.insert(eqListAppend.begin(),eqListAppend.end());
--nesting;
}
break;
case 21://Garrison ^{
readShiplist(stream,galaxy,_starId);
--nesting;
break;
case 22://TechLevels ^{
readTechLevels(value);
break;
case 23://CurrentInvention ^{
_currentInvention=value.toUInt();
break;
case 24://CurrentInventionPoints ^{
_currentInventionPoints=value.toFloat();
break;
default:
//skip record
break;
}
line = stream.readLine().trimmed();
}
galaxy.addPlanet(std::move(*this));
}
void readPlanets(QTextStream &stream, Galaxy &galaxy, unsigned starId)
{
QString line = stream.readLine().trimmed();;
while (!line.isNull())
{
if(line.contains("PlanetId"))
{
QStringRef idRef(&line,8,line.indexOf(' ')-8);
unsigned id=idRef.toInt();
Planet(stream, galaxy, id,starId);
}
else if(line.contains('}'))
{
break;
}
line = stream.readLine().trimmed();
}
}