Pyrogenesis  trunk
TerrainProperties.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19 ///////////////////////////////////////////////
20  CTerrainProperties
21 
22  Basically represents a set of terrain attributes loaded from XML. These
23  objects are organized in an inheritance tree, determined at load time.
24 
25 */
26 
27 #ifndef INCLUDED_TERRAINPROPERTIES
28 #define INCLUDED_TERRAINPROPERTIES
29 
30 #include <memory>
31 
32 #include "ps/CStr.h"
33 #include "lib/file/vfs/vfs_path.h"
34 
35 class CTerrainGroup;
36 class XMBElement;
37 class CXeromyces;
39 
40 typedef shared_ptr<CTerrainProperties> CTerrainPropertiesPtr;
41 
43 {
44 public:
45  typedef std::vector<CTerrainGroup *> GroupVector;
46 
47 private:
49 
50  // BGRA color of topmost mipmap level, for coloring minimap, or a color
51  // manually specified in the Terrain XML (or by any parent)
52  // ..Valid is true if the base color is specified in this terrain XML
53  // No caching here, since ideally, a saved XML file of an object should
54  // produce be equivalent to the source file
57 
59 
60  // Orientation of texture (in radians) (default pi/4 = 45 degrees)
62 
63  // Size of texture in metres (default 32m = 8 tiles)
65 
66  // All terrain type groups we're a member of
67  GroupVector m_Groups;
68 
69 public:
71 
72  // Create a new object and load the XML file specified. Returns NULL upon
73  // failure
74  // The parent pointer may be NULL, for the "root" terrainproperties object.
75  static CTerrainPropertiesPtr FromXML(const CTerrainPropertiesPtr& parent, const VfsPath& pathname);
76 
77  void LoadXml(XMBElement node, CXeromyces *pFile, const VfsPath& pathname);
78 
79  // Save the object to an XML file. Implement when needed! ;-)
80  // bool WriteXML(const CStr& path);
81 
83  {
84  return m_pParent;
85  }
86 
87  // Return true if this property object or any of its parents has a basecolor
88  // override (mmap attribute in the XML file)
89  bool HasBaseColor();
90  // Return the minimap color specified in this property object or in any of
91  // its parents. If no minimap color is specified, return garbage.
92  // Use HasBaseColor() to see if the value is valid.
93  // The color value is in BGRA format
94  u32 GetBaseColor();
95 
97  {
98  return m_TextureAngle;
99  }
100 
102  {
103  return m_TextureSize;
104  }
105 
106  CStr GetMovementClass() const
107  {
108  return m_MovementClass;
109  }
110 
111  const GroupVector &GetGroups() const
112  {
113  return m_Groups;
114  }
115 };
116 
117 #endif
shared_ptr< CTerrainProperties > CTerrainPropertiesPtr
Definition: TerrainProperties.h:38
CTerrainPropertiesPtr m_pParent
Definition: TerrainProperties.h:48
CStr m_MovementClass
Definition: TerrainProperties.h:58
float GetTextureSize()
Definition: TerrainProperties.h:101
std::vector< CTerrainGroup * > GroupVector
Definition: TerrainProperties.h:45
float m_TextureAngle
Definition: TerrainProperties.h:61
Definition: XeroXMB.h:160
void LoadXml(XMBElement node, CXeromyces *pFile, const VfsPath &pathname)
Definition: TerrainProperties.cpp:92
static CTerrainPropertiesPtr FromXML(const CTerrainPropertiesPtr &parent, const VfsPath &pathname)
Definition: TerrainProperties.cpp:46
CTerrainProperties(CTerrainPropertiesPtr parent)
Definition: TerrainProperties.cpp:34
uint32_t u32
Definition: types.h:39
float m_TextureSize
Definition: TerrainProperties.h:64
Definition: path.h:77
Definition: TerrainProperties.h:42
u32 GetBaseColor()
Definition: TerrainProperties.cpp:152
bool HasBaseColor()
Definition: TerrainProperties.cpp:147
float GetTextureAngle()
Definition: TerrainProperties.h:96
bool m_HasBaseColor
Definition: TerrainProperties.h:56
GroupVector m_Groups
Definition: TerrainProperties.h:67
Definition: Xeromyces.h:42
CStr GetMovementClass() const
Definition: TerrainProperties.h:106
Definition: TerrainTextureManager.h:43
u32 m_BaseColor
Definition: TerrainProperties.h:55
const GroupVector & GetGroups() const
Definition: TerrainProperties.h:111
CTerrainPropertiesPtr GetParent() const
Definition: TerrainProperties.h:82