Debian Codegraph @

engine/include/patch_manager.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.h - The patch manager 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_MANAGER_H_
29 #define _PATCH_MANAGER_H_
30
31 //@{
32
33 #include <list>
34 #include <map>
35 #include <vector>
36 #include <string>
37
38 class CPatchType;
39 class CPatch;
40 class CFile;
41
42
43 class CPatchManager
44 {
45 public:
46 /**
47 ** Patch manager constructor
48 */
49 CPatchManager();
50
51 /**
52 ** Patch manager destructor
53 */
54 ~CPatchManager();
55
56 /**
57 ** Create a new patch of type typeName at location x, y
58 */
59 CPatch *add(const std::string &typeName, int x, int y);
60
61 /**
62 ** Remove a patch
63 */
64 void remove(CPatch *patch);
65
66 /**
67 ** Move a patch's location
68 */
69 void move(CPatch *patch, int x, int y);
70
71 /**
72 ** Move a patch to the top
73 */
74 void moveToTop(CPatch *patch);
75
76 /**
77 ** Move a patch to the bottom
78 */
79 void moveToBottom(CPatch *patch);
80
81 /**
82 ** Get the patch at location x, y
83 */
84 CPatch *getPatch(int x, int y, int *xOffset = NULL, int *yOffset = NULL) const;
85
86 /**
87 ** Get all of the patches
88 */
89 const std::list<CPatch *> &getPatches() const;
90
91 /**
92 ** Get all of the patch names
93 */
94 std::vector<std::string> getPatchTypeNames() const;
95
96 /**
97 ** Get the names of the patch types that use the graphic in
98 ** the specified file.
99 */
100 std::vector<std::string> getPatchTypeNamesUsingGraphic(
101 const std::string &graphicFile) const;
102
103 /**
104 ** Get all of the patch themes
105 */
106 std::vector<std::string> getPatchTypeThemes() const;
107
108 /**
109 ** Load the patches used in the map
110 */
111 void load();
112
113 /**
114 ** Load all patches
115 */
116 void loadAll();
117
118 /**
119 ** Clear the patches used in the map
120 */
121 void clear();
122
123 /**
124 ** Define a new patch type.
125 ** Types should be created only once and last for the duration of the game.
126 */
127 CPatchType *newPatchType(const std::string &name, const std::string &file,
128 int tileWidth, int tileHeight, int *flags, const std::string &theme = "");
129
130 /**
131 ** Define a new patch type.
132 ** Types should be created only once and last for the duration of the game.
133 */
134 CPatchType *newPatchType(const std::string &name, const std::string &file,
135 int tileWidth, int tileHeight, unsigned short *flags, const std::string &theme = "");
136
137 /**
138 ** Get a patch type
139 */
140 CPatchType *getPatchType(const std::string &name);
141
142 /**
143 ** Save all of the patches
144 */
145 std::string savePatches(bool patchesOnly = false) const;
146
147 /**
148 ** Save a patch type
149 */
150 std::string savePatchType(CPatchType *patchType) const;
151
152 /**
153 ** Compute how large the patch type should be if one were
154 ** created for the graphic in the specified file.
155 ** This function is intended to be called from Lua.
156 */
157 bool computePatchSize(const std::string &graphicFile,
158 int *width, int *height) const;
159
160 private:
161 void updateMapFlags(int x1, int y1, int x2, int y2);
162
163 std::list<CPatch *> patches;
164 std::map<std::string, CPatchType *> patchTypesMap;
165
166 std::list<CPatch *> removedPatches;
167
168 bool loadedAll;
169 };
170
171 //@}
172
173 #endif /* _PATCH_MANAGER_H_ */
174