Debian Codegraph @

engine/include/patch_type.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name patch_type.h - The patch type header. */
11 //
12 // (c) Copyright 2008-2010 by Jimmy Salmon
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27
28 #ifndef _PATCH_TYPE_H_
29 #define _PATCH_TYPE_H_
30
31 //@{
32
33 #include "video.h"
34
35
36 class CPatchType
37 {
38 public:
39 /**
40 ** Patch type constructor
41 */
42 CPatchType(const std::string &name, const std::string &file,
43 int tileWidth, int tileHeight, unsigned short *flags, bool customPatch, const std::string &theme = "") :
44 name(name), file(file), graphic(NULL), tileWidth(tileWidth), tileHeight(tileHeight), customPatch(customPatch), theme(theme)
45 {
46 this->flags = new unsigned short[this->tileWidth * this->tileHeight];
47 memcpy(this->flags, flags, this->tileWidth * this->tileHeight * sizeof(unsigned short));
48 }
49
50 /**
51 ** Patch type destructor
52 */
53 ~CPatchType()
54 {
55 CGraphic::Free(this->graphic);
56 delete[] this->flags;
57 }
58
59 /**
60 ** Load the patch type
61 */
62 void load()
63 {
64 if (!this->graphic) {
65 this->graphic = CGraphic::New(this->file);
66 this->graphic->Load();
67 }
68 }
69
70 /**
71 ** Clean the allocated memory
72 */
73 void clean()
74 {
75 CGraphic::Free(this->graphic);
76 this->graphic = NULL;
77 }
78
79 /**
80 ** Get the name
81 */
82 inline const std::string &getName() const { return this->name; }
83
84 /**
85 ** Get the file name
86 */
87 inline const std::string &getFile() const { return this->file; }
88
89 /**
90 ** Get the graphic
91 */
92 inline const CGraphic *getGraphic() const { return this->graphic; }
93
94 /**
95 ** Get the tile width of the patch
96 */
97 inline int getTileWidth() const { return this->tileWidth; }
98
99 /**
100 ** Get the tile height of the patch
101 */
102 inline int getTileHeight() const { return this->tileHeight; }
103
104 /**
105 ** Get the tile flag at a tile location
106 */
107 unsigned short getFlag(int x, int y) const
108 {
109 Assert(0 <= x && x < this->tileWidth && 0 <= y && y < this->tileHeight);
110 return flags[y * this->tileWidth + x];
111 }
112
113 /**
114 ** Set the tile flag at a tile location
115 */
116 void setFlag(int x, int y, unsigned short flag)
117 {
118 Assert(0 <= x && x < this->tileWidth && 0 <= y && y < this->tileHeight);
119 flags[y * this->tileWidth + x] = flag;
120 }
121
122 /**
123 ** Get all of the tile flags
124 */
125 inline unsigned short *getFlags()
126 {
127 return this->flags;
128 }
129
130 /**
131 ** Set custom patch
132 */
133 inline void setCustomPatch(bool customPatch)
134 {
135 this->customPatch = customPatch;
136 }
137
138 /**
139 ** Is this a custom patch
140 */
141 inline bool isCustomPatch()
142 {
143 return this->customPatch;
144 }
145
146 /**
147 ** Get the theme
148 */
149 inline const std::string &getTheme() const { return this->theme; }
150
151 private:
152 std::string name;
153 std::string file;
154 CGraphic *graphic;
155 int tileWidth;
156 int tileHeight;
157 unsigned short *flags;
158 bool customPatch;
159 std::string theme;
160 };
161
162 //@}
163
164 #endif /* _PATCH_TYPE_H_ */
165