forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMissionStatistics.h
More file actions
186 lines (172 loc) · 4.18 KB
/
Copy pathMissionStatistics.h
File metadata and controls
186 lines (172 loc) · 4.18 KB
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
#pragma once
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include <yaml-cpp/yaml.h>
#include <map>
#include <string>
#include <sstream>
#include "GameTime.h"
#include "../Engine/Language.h"
#include "../Battlescape/TileEngine.h"
namespace OpenXcom
{
/**
* Container for mission statistics.
*/
struct MissionStatistics
{
// Variables
int id;
std::string markerName;
int markerId;
GameTime time;
std::string region, country, type, ufo;
bool success;
std::string rating;
int score;
std::string alienRace;
int daylight;
std::map<int, int> injuryList;
bool valiantCrux;
int lootValue;
/// Load
void load(const YAML::Node &node)
{
id = node["id"].as<int>(id);
markerName = node["markerName"].as<std::string>(markerName);
markerId = node["markerId"].as<int>(markerId);
time.load(node["time"]);
region = node["region"].as<std::string>(region);
country = node["country"].as<std::string>(country);
type = node["type"].as<std::string>(type);
ufo = node["ufo"].as<std::string>(ufo);
success = node["success"].as<bool>(success);
score = node["score"].as<int>(score);
rating = node["rating"].as<std::string>(rating);
alienRace = node["alienRace"].as<std::string>(alienRace);
daylight = node["daylight"].as<int>(daylight);
injuryList = node["injuryList"].as< std::map<int, int> >(injuryList);
valiantCrux = node["valiantCrux"].as<bool>(valiantCrux);
lootValue = node["lootValue"].as<int>(lootValue);
}
/// Save
YAML::Node save() const
{
YAML::Node node;
node["id"] = id;
if (!markerName.empty())
{
node["markerName"] = markerName;
node["markerId"] = markerId;
}
node["time"] = time.save();
node["region"] = region;
node["country"] = country;
node["type"] = type;
node["ufo"] = ufo;
node["success"] = success;
node["score"] = score;
node["rating"] = rating;
node["alienRace"] = alienRace;
node["daylight"] = daylight;
node["injuryList"] = injuryList;
if (valiantCrux) node["valiantCrux"] = valiantCrux;
if (lootValue) node["lootValue"] = lootValue;
return node;
}
std::string getMissionName(Language *lang) const
{
if (!markerName.empty())
{
return lang->getString(markerName).arg(markerId);
}
else
{
return lang->getString(type);
}
}
std::string getRatingString(Language *lang) const
{
std::ostringstream ss;
if (success)
{
ss << lang->getString("STR_VICTORY");
}
else
{
ss << lang->getString("STR_DEFEAT");
}
ss << " - " << lang->getString(rating);
return ss.str();
}
std::string getLocationString() const
{
if (country == "STR_UNKNOWN")
{
return region;
}
else
{
return country;
}
}
bool isDarkness() const
{
return daylight > TileEngine::MAX_DARKNESS_TO_SEE_UNITS;
}
std::string getDaylightString() const
{
if (isDarkness())
{
return "STR_NIGHT";
}
else
{
return "STR_DAY";
}
}
bool isAlienBase() const
{
if (type.find("STR_ALIEN_BASE") != std::string::npos || type.find("STR_ALIEN_COLONY") != std::string::npos)
{
return true;
}
return false;
}
bool isBaseDefense() const
{
if (type == "STR_BASE_DEFENSE")
{
return true;
}
return false;
}
bool isUfoMission() const
{
if(ufo != "NO_UFO")
{
return true;
}
return false;
}
MissionStatistics(const YAML::Node& node) : time(0, 0, 0, 0, 0, 0, 0) { load(node); }
MissionStatistics() : id(0), markerId(0), time(0, 0, 0, 0, 0, 0, 0), region("STR_REGION_UNKNOWN"), country("STR_UNKNOWN"), ufo("NO_UFO"), success(false), score(0), alienRace("STR_UNKNOWN"), daylight(0), valiantCrux(false), lootValue(0) { }
~MissionStatistics() { }
};
}