OpenXcom  1.0
Open-source clone of the original X-Com
MissionStatistics.h
1 /*
2 * Copyright 2010-2016 OpenXcom Developers.
3 *
4 * This file is part of OpenXcom.
5 *
6 * OpenXcom is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OpenXcom is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include <yaml-cpp/yaml.h>
20 #include <map>
21 #include <string>
22 #include <sstream>
23 #include "GameTime.h"
24 #include "../Engine/Language.h"
25 
26 namespace OpenXcom
27 {
28 
33 {
35  int id;
36  std::string markerName;
37  int markerId;
38  GameTime time;
39  std::string region, country, type, ufo;
40  bool success;
41  std::string rating;
42  int score;
43  std::string alienRace;
44  int daylight;
45  std::map<int, int> injuryList;
46  bool valiantCrux;
47  int lootValue;
48 
49  // Load
50  void load(const YAML::Node &node)
51  {
52  id = node["id"].as<int>(id);
53  markerName = node["markerName"].as<std::string>(markerName);
54  markerId = node["markerId"].as<int>(markerId);
55  time.load(node["time"]);
56  region = node["region"].as<std::string>(region);
57  country = node["country"].as<std::string>(country);
58  type = node["type"].as<std::string>(type);
59  ufo = node["ufo"].as<std::string>(ufo);
60  success = node["success"].as<bool>(success);
61  score = node["score"].as<int>(score);
62  rating = node["rating"].as<std::string>(rating);
63  alienRace = node["alienRace"].as<std::string>(alienRace);
64  daylight = node["daylight"].as<int>(daylight);
65  injuryList = node["injuryList"].as< std::map<int, int> >(injuryList);
66  valiantCrux = node["valiantCrux"].as<bool>(valiantCrux);
67  lootValue = node["lootValue"].as<int>(lootValue);
68  }
69 
70  // Save
71  YAML::Node save() const
72  {
73  YAML::Node node;
74  node["id"] = id;
75  if (!markerName.empty())
76  {
77  node["markerName"] = markerName;
78  node["markerId"] = markerId;
79  }
80  node["time"] = time.save();
81  node["region"] = region;
82  node["country"] = country;
83  node["type"] = type;
84  node["ufo"] = ufo;
85  node["success"] = success;
86  node["score"] = score;
87  node["rating"] = rating;
88  node["alienRace"] = alienRace;
89  node["daylight"] = daylight;
90  node["injuryList"] = injuryList;
91  if (valiantCrux) node["valiantCrux"] = valiantCrux;
92  if (lootValue) node["lootValue"] = lootValue;
93  return node;
94  }
95 
96  std::wstring getMissionName(Language *lang) const
97  {
98  if (!markerName.empty())
99  {
100  return lang->getString(markerName).arg(markerId);
101  }
102  else
103  {
104  return lang->getString(type);
105  }
106  }
107 
108  std::wstring getRatingString(Language *lang) const
109  {
110  std::wostringstream ss;
111  if (success)
112  {
113  ss << lang->getString("STR_VICTORY");
114  }
115  else
116  {
117  ss << lang->getString("STR_DEFEAT");
118  }
119  ss << L" - " << lang->getString(rating);
120  return ss.str();
121  }
122 
123  std::string getLocationString() const
124  {
125  if (country == "STR_UNKNOWN")
126  {
127  return region;
128  }
129  else
130  {
131  return country;
132  }
133  }
134 
135  std::string getDaylightString() const
136  {
137  if (daylight <= 5)
138  {
139  return "STR_DAY";
140  }
141  else
142  {
143  return "STR_NIGHT";
144  }
145  }
146 
147  bool isAlienBase() const
148  {
149  if (type.find("STR_ALIEN_BASE") != std::string::npos || type.find("STR_ALIEN_COLONY") != std::string::npos)
150  {
151  return true;
152  }
153  return false;
154  }
155 
156  bool isBaseDefense() const
157  {
158  if (type == "STR_BASE_DEFENSE")
159  {
160  return true;
161  }
162  return false;
163  }
164 
165  bool isUfoMission() const
166  {
167  if(ufo != "NO_UFO")
168  {
169  return true;
170  }
171  return false;
172  }
173 
174  MissionStatistics(const YAML::Node& node) : time(0, 0, 0, 0, 0, 0, 0) { load(node); }
175  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) { }
176  ~MissionStatistics() { }
177 };
178 
179 }
int id
Variables.
Definition: MissionStatistics.h:35
void load(const YAML::Node &node)
Loads the time from YAML.
Definition: GameTime.cpp:50
Contains strings used throughout the game for localization.
Definition: Language.h:39
LocalizedText arg(const std::wstring &) const OX_REQUIRED_RESULT
Replace next argument.
Definition: LocalizedText.cpp:30
const LocalizedText & getString(const std::string &id) const
Get a localized text.
Definition: Language.cpp:487
Stores the current ingame time/date according to GMT.
Definition: GameTime.h:38
Container for mission statistics.
Definition: MissionStatistics.h:32
YAML::Node save() const
Saves the time to YAML.
Definition: GameTime.cpp:65
Definition: BaseInfoState.cpp:40