OpenXcom  1.0
Open-source clone of the original X-Com
Texture.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 "../fmath.h"
21 #include <string>
22 #include <vector>
23 #include <yaml-cpp/yaml.h>
24 
25 namespace OpenXcom
26 {
27 
29 {
30  std::string name;
31  int weight;
32  double lonMin, lonMax, latMin, latMax;
33  TerrainCriteria() : weight(1), lonMin(0.0), lonMax(360.0), latMin(-90.0), latMax(90.0) {};
34 };
35 
36 class Target;
37 
42 class Texture
43 {
44 private:
45  int _id;
46  std::map<std::string, int> _deployments;
47  std::vector<TerrainCriteria> _terrain;
48 public:
50  Texture(int id);
52  ~Texture();
54  void load(const YAML::Node& node);
56  std::vector<TerrainCriteria> *getTerrain();
58  std::string getRandomTerrain(Target *target) const;
60  const std::map<std::string, int> &getDeployments() const;
62  std::string getRandomDeployment() const;
63 };
64 
65 }
66 
67 namespace YAML
68 {
69  template<>
70  struct convert < OpenXcom::TerrainCriteria >
71  {
72  static Node encode(const OpenXcom::TerrainCriteria& rhs)
73  {
74  Node node;
75  node["name"] = rhs.name;
76  node["weight"] = rhs.weight;
77  std::vector<double> area;
78  area.push_back(rhs.lonMin);
79  area.push_back(rhs.lonMax);
80  area.push_back(rhs.latMin);
81  area.push_back(rhs.latMax);
82  node["area"] = area;
83  return node;
84  }
85 
86  static bool decode(const Node& node, OpenXcom::TerrainCriteria& rhs)
87  {
88  if (!node.IsMap())
89  return false;
90 
91  rhs.name = node["name"].as<std::string>(rhs.name);
92  rhs.weight = node["weight"].as<int>(rhs.weight);
93  if (node["area"])
94  {
95  std::vector<double> area = node["area"].as< std::vector<double> >();
96  rhs.lonMin = Deg2Rad(area[0]);
97  rhs.lonMax = Deg2Rad(area[1]);
98  rhs.latMin = Deg2Rad(area[2]);
99  rhs.latMax = Deg2Rad(area[3]);
100  }
101  return true;
102  }
103  };
104 }
const std::map< std::string, int > & getDeployments() const
Gets the alien deployment for this texture.
Definition: Texture.cpp:101
~Texture()
Cleans up the texture.
Definition: Texture.cpp:37
void load(const YAML::Node &node)
Loads the texture from YAML.
Definition: Texture.cpp:45
std::string getRandomDeployment() const
Gets a random deployment.
Definition: Texture.cpp:111
std::vector< TerrainCriteria > * getTerrain()
Gets the list of terrain criteria.
Definition: Texture.cpp:57
Definition: Texture.h:28
Definition: Position.h:81
Represents the relations between a Geoscape texture and the corresponding Battlescape mission attribu...
Definition: Texture.h:42
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:35
std::string getRandomTerrain(Target *target) const
Gets a random texture terrain for a given target.
Definition: Texture.cpp:68
Texture(int id)
Creates a new texture with mission data.
Definition: Texture.cpp:30
Definition: BaseInfoState.cpp:40