OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RuleRegion.h
1 /*
2  * Copyright 2010-2014 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 #ifndef OPENXCOM_RULEREGION_H
20 #define OPENXCOM_RULEREGION_H
21 
22 #include <string>
23 #include <vector>
24 #include <yaml-cpp/yaml.h>
25 #include "../fmath.h"
26 #include "../Savegame/WeightedOptions.h"
27 
28 namespace OpenXcom
29 {
30 
36 {
37  double lonMin, lonMax, latMin, latMax;
38 
39  bool operator== (const MissionArea& ma) const
40  {
41  return AreSame(lonMax, ma.lonMax) && AreSame(lonMin, ma.lonMin) && AreSame(latMax, ma.latMax) && AreSame(latMin, ma.latMin);
42  }
43 };
44 
49 {
50  std::vector<MissionArea> areas;
51 
52  void swap(MissionZone &other)
53  {
54  areas.swap(other.areas);
55  }
56 };
57 
58 class City;
59 
66 {
67 private:
68  std::string _type;
69  int _cost;
70  std::vector<double> _lonMin, _lonMax, _latMin, _latMax;
71  std::vector<City*> _cities;
73  WeightedOptions _missionWeights;
75  size_t _regionWeight;
77  std::vector<MissionZone> _missionZones;
79  std::string _missionRegion;
80 public:
81  static const int CITY_MISSION_ZONE = 3;
82  static const int ALIEN_BASE_ZONE = 4;
84  RuleRegion(const std::string &type);
86  ~RuleRegion();
88  void load(const YAML::Node& node);
90  std::string getType() const;
92  int getBaseCost() const;
94  bool insideRegion(double lon, double lat) const;
96  std::vector<City*> *getCities();
98  size_t getWeight() const;
100  const WeightedOptions &getAvailableMissions() const { return _missionWeights; }
102  const std::string &getMissionRegion() const { return _missionRegion; }
104  std::pair<double, double> getRandomPoint(size_t site) const;
106  const std::vector<double> &getLonMax() const { return _lonMax; }
108  const std::vector<double> &getLonMin() const { return _lonMin; }
110  const std::vector<double> &getLatMax() const { return _latMax; }
112  const std::vector<double> &getLatMin() const { return _latMin; }
113  const std::vector<MissionZone> &getMissionZones() const;
114 };
115 
116 }
117 
118 namespace YAML
119 {
120  template<>
121  struct convert<OpenXcom::MissionArea>
122  {
123  static Node encode(const OpenXcom::MissionArea& rhs)
124  {
125  Node node;
126  node.push_back(rhs.lonMin);
127  node.push_back(rhs.lonMax);
128  node.push_back(rhs.latMin);
129  node.push_back(rhs.latMax);
130  return node;
131  }
132 
133  static bool decode(const Node& node, OpenXcom::MissionArea& rhs)
134  {
135  if (!node.IsSequence() || node.size() != 4)
136  return false;
137 
138  rhs.lonMin = node[0].as<double>();
139  rhs.lonMax = node[1].as<double>();
140  rhs.latMin = node[2].as<double>();
141  rhs.latMax = node[3].as<double>();
142  return true;
143  }
144  };
145 
146  template<>
147  struct convert<OpenXcom::MissionZone>
148  {
149  static Node encode(const OpenXcom::MissionZone& rhs)
150  {
151  Node node;
152  node = rhs.areas;
153  return node;
154  }
155 
156  static bool decode(const Node& node, OpenXcom::MissionZone& rhs)
157  {
158  if (!node.IsSequence())
159  return false;
160 
161  rhs.areas = node.as< std::vector<OpenXcom::MissionArea> >(rhs.areas);
162  return true;
163  }
164  };
165 }
166 
167 #endif
std::vector< City * > * getCities()
Gets the cities in this region.
Definition: RuleRegion.cpp:168
RuleRegion(const std::string &type)
Creates a blank region ruleset.
Definition: RuleRegion.cpp:34
const WeightedOptions & getAvailableMissions() const
Gets the weighted list of missions for this region.
Definition: RuleRegion.h:100
Defines a rectangle in polar coordinates.
Definition: RuleRegion.h:35
const std::vector< double > & getLonMin() const
Gets the minimum longitude.
Definition: RuleRegion.h:108
const std::string & getMissionRegion() const
Gets the substitute mission region.
Definition: RuleRegion.h:102
bool insideRegion(double lon, double lat) const
Checks if a point is inside the region.
Definition: RuleRegion.cpp:145
A zone (set of areas) on the globe.
Definition: RuleRegion.h:48
int getBaseCost() const
Gets the region's base cost.
Definition: RuleRegion.cpp:134
const std::vector< double > & getLatMax() const
Gets the maximum latitude.
Definition: RuleRegion.h:110
const std::vector< double > & getLatMin() const
Gets the minimum latitude.
Definition: RuleRegion.h:112
std::string getType() const
Gets the region's type.
Definition: RuleRegion.cpp:125
const std::vector< double > & getLonMax() const
Gets the maximum longitude.
Definition: RuleRegion.h:106
Represents a city of the world.
Definition: City.h:32
Holds pairs of relative weights and IDs.
Definition: WeightedOptions.h:34
void load(const YAML::Node &node)
Loads the region from YAML.
Definition: RuleRegion.cpp:53
Represents a specific region of the world.
Definition: RuleRegion.h:65
~RuleRegion()
Cleans up the region ruleset.
Definition: RuleRegion.cpp:41
std::pair< double, double > getRandomPoint(size_t site) const
Gets a random point inside a mission site.
Definition: RuleRegion.cpp:189
size_t getWeight() const
Gets the weight of this region for mission selection.
Definition: RuleRegion.cpp:178