Debian Codegraph @

src/buildinglayer.h

raw symbols SCIP
1 /***************************************************************************
2 buildinglayer.h - description
3 -------------------
4 begin : september 20th, 2003
5 copyright : (C) 2003-2008 by Duong Khang NGUYEN
6 email : neoneurone @ gmail com
7
8 $Id: buildinglayer.h 375 2008-10-28 14:47:15Z neoneurone $
9 ***************************************************************************/
10
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * any later version. *
17 * *
18 ***************************************************************************/
19
20 #ifndef _OPENCITY_BUILDINGLAYER_H_
21 #define _OPENCITY_BUILDINGLAYER_H_ 1
22
23 #include "main.h"
24 #include "layer.h"
25
26
27 class City;
28
29
30 //========================================================================
31 /** This class contains all the buildings added by the player
32 */
33 class BuildingLayer : public Layer {
34 public:
35 //constructor, should not be used. Call the constructor with parameters instead.
36 //BuildingLayer();
37
38 virtual ~BuildingLayer(); //dtor
39
40 BuildingLayer( const City & rcCity ); //ctor with parameters
41
42
43 //========================================================================
44 /** Save the data to the specified fstream
45 \param rfs A reference to a file stream which is ready for writing
46 \see Persistence
47 */
48 void
49 SaveTo( std::fstream& rfs );
50
51
52 //========================================================================
53 /** Load the data from the specified stream
54 \param rfs A reference to a file stream which is ready for reading
55 \see Persistence
56 */
57 void
58 LoadFrom( std::fstream& rfs );
59
60
61 //========================================================================
62 /** Is the specified area constructive ?
63 Can we build the specified structure on it ?
64 \param W1,W2 = OpenGL Ox
65 \param L1,L2 = OpenGL Oz
66 \param enumStructCode = The code of the structure that we're going to build
67 \return True or False
68 */
69 const bool
70 IsConstructive(
71 uint W1, uint L1,
72 uint W2, uint L2,
73 const OPENCITY_STRUCTURE_CODE & enumStructCode ) const;
74
75
76 //========================================================================
77 /** see "layer.h" for more informations
78 \sa Layer::BuildPreview()
79 */
80 const OPENCITY_ERR_CODE
81 BuildPreview(
82 const uint & W,
83 const uint & L,
84 const OPENCITY_STRUCTURE_CODE & enumStructCode,
85 OPENCITY_GRAPHIC_CODE & enumGraphicCode ) const;
86
87
88 //========================================================================
89 /** see "layer.h" for more informations
90 \see Layer
91 */
92 const OPENCITY_ERR_CODE
93 BuildStructure(
94 const uint & W1,
95 const uint & L1,
96 const uint & W2,
97 const uint & L2,
98 const OPENCITY_STRUCTURE_CODE & enumStructCode,
99 uint& rCost );
100
101
102 //========================================================================
103 /** Find the main structure WL coordinates of the given structure pointer
104 \param pstruct The structure pointer to search for
105 \param w,l The WL coordinates of pstruct
106 \return True if found, false otherwise
107 */
108 const bool
109 GetMainWL (
110 const Structure* const pstruct,
111 uint & w,
112 uint & l
113 ) const;
114
115
116 //========================================================================
117 /** Resize the surface used by the structure to the new surface thanks to
118 its new GraphicCode.
119 \param w,l = The structure's map coordinates
120 \param oldGC = The old graphic code of the structure
121 */
122 const OPENCITY_ERR_CODE
123 ResizeStructure(
124 const uint & w,
125 const uint & l,
126 const OPENCITY_GRAPHIC_CODE & oldGC );
127
128
129 //========================================================================
130 /** Destroy all the structures built on the specified surface
131 \param W1,W2 = OpenGL Ox
132 \param L1,L2 = OpenGL Oz
133 \param rCost = the cost needed to clean up the specified surface
134 \return Error code
135 */
136 const OPENCITY_ERR_CODE
137 DestroyStructure(
138 uint W1, uint L1,
139 uint W2, uint L2,
140 uint& rCost );
141
142
143 //========================================================================
144 /** Returns a pointer to a structure indexed by its linear index. The
145 linear index of a structure is calculated by this formula:
146 index = W + (H * city width)
147 \param cuiLinearIndex = linear index of the structure to retrieve
148 \return A pointer to a structure if it exists NULL otherwise
149 */
150 Structure*
151 GetLinearStructure( const uint cuiLinearIndex ) const;
152
153
154 Structure*
155 GetStructure(
156 const uint & w,
157 const uint & l ) const;
158
159
160 Structure*
161 GetRandomStructure(
162 uint & w,
163 uint & l,
164 const OPENCITY_STRUCTURE_CODE & enumStructCode = OC_STRUCTURE_UNDEFINED ) const;
165
166
167 const uint
168 GetNumberStructure() const;
169
170
171 //========================================================================
172 /** Set all the structures contained by this layer to the specified status.
173 \param status = The new status of the structures
174 */
175 void
176 StructureSet( const OC_BYTE& status );
177
178
179 //========================================================================
180 /** Unset the specified status of all the structures contained
181 by this layer.
182 \param status = The status of the structures to be unset
183 */
184 void
185 StructureUnset( const OC_BYTE& status );
186
187
188 //========================================================================
189 /** see "layer.h" for more informations
190 */
191 const bool
192 ContainStructure(
193 const uint & W1,
194 const uint & L1,
195 const uint & W2,
196 const uint & L2,
197 const OPENCITY_STRUCTURE_CODE & enumStructCode ) const;
198
199
200 //========================================================================
201 /** see "layer.h" for more informations
202 */
203 const bool
204 ContainStructureOnly(
205 const uint & W1,
206 const uint & L1,
207 const uint & W2,
208 const uint & L2,
209 const OPENCITY_STRUCTURE_CODE & enumStructCode ) const;
210
211
212 //========================================================================
213 /** see "layer.h" for more informations
214 */
215 GUIContainer* const
216 QueryStructure(
217 const uint & w,
218 const uint & l ) const;
219
220
221 //========================================================================
222 // Inherited methods from UI
223 //========================================================================
224 void Keyboard( const SDL_KeyboardEvent& rcEvent );
225 void MouseMotion( const SDL_MouseMotionEvent& rcEvent );
226 void MouseButton( const SDL_MouseButtonEvent& rcEvent );
227 void Expose( const SDL_ExposeEvent& rcEvent );
228 void Resize( const SDL_ResizeEvent& rcEvent );
229
230
231 private:
232 /** All the buildings are here */
233 Structure** _tabpStructure;
234
235
236
237
238
239 /*=====================================================================*/
240 /* PRIVATE METHODS */
241 /*=====================================================================*/
242 const bool
243 _IsPathConstructive(
244 const uint & w,
245 const uint & h,
246 const OPENCITY_STRUCTURE_CODE & enumStructCode ) const;
247
248
249 //========================================================================
250 /** Called internally by other methods, don't touch it
251 */
252 const OPENCITY_ERR_CODE
253 _BuildPathStructure(
254 uint W1, uint L1,
255 uint W2, uint L2,
256 const OPENCITY_STRUCTURE_CODE & enumStructCode,
257 uint& rCost );
258
259
260 //========================================================================
261 /** Build a path structure at the specified coordinates
262 \note If there's already a structure at the specified coordinates, this
263 method returns without generating any error
264 \param w,h The coordinates
265 \param linearIndex The index of the structure in the structure array
266 \param enumStructCode The structure code (=STRUCTURE_ROAD)
267 \param rCost The cost of the construction
268 */
269 void
270 _BuildPathStructure(
271 const uint & w,
272 const uint & h,
273 const uint & linearIndex,
274 const OPENCITY_STRUCTURE_CODE & enumStructCode,
275 uint& rCost );
276
277
278 const OPENCITY_ERR_CODE
279 _BuildRCIStructure(
280 uint W1, uint L1,
281 uint W2, uint L2,
282 const OPENCITY_STRUCTURE_CODE & enumStructCode,
283 uint& rCost );
284
285
286 const OPENCITY_ERR_CODE
287 _BuildFloraStructure(
288 uint W1, uint L1,
289 uint W2, uint L2,
290 const OPENCITY_STRUCTURE_CODE & enumStructCode,
291 uint& rCost );
292
293
294 const OPENCITY_ERR_CODE
295 _BuildWEGStructure(
296 uint W1, uint L1,
297 const OPENCITY_STRUCTURE_CODE & enumStructCode,
298 uint& rCost );
299
300
301 void
302 _BuildWEGStructure(
303 uint W1, uint L1,
304 uint W2, uint L2,
305 const OPENCITY_STRUCTURE_CODE & enumStructCode,
306 uint& rCost );
307
308
309 //========================================================================
310 /** Fast load a structure at the specified coordinates. If the
311 structure is bigger than 1x1, then extra structures part will be built
312 automatically. There is not any "Constructive" test.
313 \note If there's already a structure at the specified coordinates, this
314 method returns without generating any error
315 \param w1,l1 The structure upper-left map coordinates
316 \param pStruct The pointer to the structure which will be deleted
317 automatically when the program ends
318 */
319 void
320 _LoadStructure(
321 const uint & w1,
322 const uint & l1,
323 Structure* pStruct );
324
325
326 //========================================================================
327 /** Destroy the structure built at the specified coordinates
328 \param w = OpenGL Ox
329 \param l = OpenGL Oz
330 \param rCost = the cost needed to clean up the specified cell
331 \return Error code
332 */
333 const OPENCITY_ERR_CODE
334 _DestroyStructure(
335 const uint & w,
336 const uint & l,
337 uint& rCost );
338
339
340 const OPENCITY_ERR_CODE
341 _DestroyPathStructure(
342 uint w, uint l,
343 const OPENCITY_STRUCTURE_CODE & enumStructCode );
344 };
345
346 #endif
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371