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