| 1 | /*************************************************************************** |
| 2 | layer.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: layer.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_LAYER_H_ |
| 21 | #define _OPENCITY_LAYER_H_ 1 |
| 22 | |
| 23 | #include "main.h" |
| 24 | |
| 25 | #include "persistence.h" |
| 26 | #include "ui.h" |
| 27 | |
| 28 | class Structure; |
| 29 | class GUIContainer; |
| 30 | class GUIButton; |
| 31 | |
| 32 | |
| 33 | //======================================================================== |
| 34 | /** This is the interface of all other layer classes. A layer is |
| 35 | persistent and should handle the user interface commands. |
| 36 | */ |
| 37 | class Layer : public Persistence, public UI |
| 38 | { |
| 39 | public: |
| 40 | Layer( ); |
| 41 | |
| 42 | virtual |
| 43 | ~Layer( ); |
| 44 | |
| 45 | |
| 46 | //======================================================================== |
| 47 | /** Is the surface ( w1, l1, w2, l2 ) constructive ? |
| 48 | Is there something built on it already ? |
| 49 | */ |
| 50 | virtual const bool |
| 51 | IsConstructive( |
| 52 | uint W1, uint L1, |
| 53 | uint W2, uint L2, |
| 54 | const OPENCITY_STRUCTURE_CODE & enumStructCode ) const = 0; |
| 55 | |
| 56 | |
| 57 | //======================================================================== |
| 58 | /** Preview the structure which is about to be built on the specified |
| 59 | surface. |
| 60 | \param W,L The upper left corner of the surface which will be used |
| 61 | to build the bulding. |
| 62 | \param enumGraphicCode Will contain the OC graphic code of the building |
| 63 | \param enumStructCode Contain the structure code |
| 64 | \sa IsConstructive() |
| 65 | \sa BuildStructure() |
| 66 | */ |
| 67 | virtual const OPENCITY_ERR_CODE |
| 68 | BuildPreview( |
| 69 | const uint & W, |
| 70 | const uint & L, |
| 71 | const OPENCITY_STRUCTURE_CODE & enumStructCode, |
| 72 | OPENCITY_GRAPHIC_CODE & enumGraphicCode ) const = 0; |
| 73 | |
| 74 | |
| 75 | //======================================================================== |
| 76 | /** Build the specified structure on the surface |
| 77 | Precondition: the specified surface must be "constructive". This is |
| 78 | checked by the method "IsConstructive()" |
| 79 | \sa IsConstructive() |
| 80 | */ |
| 81 | virtual const OPENCITY_ERR_CODE |
| 82 | BuildStructure( |
| 83 | const uint & W1, |
| 84 | const uint & L1, |
| 85 | const uint & W2, |
| 86 | const uint & L2, |
| 87 | const OPENCITY_STRUCTURE_CODE & enumStructCode, |
| 88 | uint& rCost ) = 0; |
| 89 | |
| 90 | |
| 91 | //======================================================================== |
| 92 | /** Resize the surface used by the structure to the new surface thanks to |
| 93 | its new GraphicCode. |
| 94 | \param w,l The NorthWest (top left) coordinates of the structure |
| 95 | \param oldGC The old graphic code |
| 96 | */ |
| 97 | virtual const OPENCITY_ERR_CODE |
| 98 | ResizeStructure( |
| 99 | const uint & w, |
| 100 | const uint & l, |
| 101 | const OPENCITY_GRAPHIC_CODE & oldGC ) = 0; |
| 102 | |
| 103 | |
| 104 | //======================================================================== |
| 105 | /** Destroy _all_ the structures built on the surface. If the specified |
| 106 | surface is a part of a bigger structure, the big main structure is |
| 107 | also destroyed. |
| 108 | */ |
| 109 | virtual const OPENCITY_ERR_CODE |
| 110 | DestroyStructure( |
| 111 | uint W1, uint L1, |
| 112 | uint W2, uint L2, |
| 113 | uint& rCost ) = 0; |
| 114 | |
| 115 | |
| 116 | //======================================================================== |
| 117 | /** Fast access to the structure by its internal linear index. There's |
| 118 | no error checking. |
| 119 | \param cuiLinearIndex The linear index of the structure to access. |
| 120 | It starts from 0. |
| 121 | */ |
| 122 | virtual Structure* |
| 123 | GetLinearStructure( const uint cuiLinearIndex ) const = 0; |
| 124 | |
| 125 | |
| 126 | //======================================================================== |
| 127 | /** Access to the structure specified by its WL coordinates |
| 128 | \param w,l The structure NorthWest (top left) coordinates |
| 129 | */ |
| 130 | virtual Structure* |
| 131 | GetStructure( |
| 132 | const uint & w, |
| 133 | const uint & l ) const = 0; |
| 134 | |
| 135 | |
| 136 | //======================================================================== |
| 137 | /** Random access to the structure of the specified type |
| 138 | \param w,l The structure NorthWest (top left) coordinates |
| 139 | \param enumStructCode The structure code |
| 140 | \return The randomly selected structure pointer |
| 141 | */ |
| 142 | virtual Structure* |
| 143 | GetRandomStructure( |
| 144 | uint & w, |
| 145 | uint & l, |
| 146 | const OPENCITY_STRUCTURE_CODE & enumStructCode = OC_STRUCTURE_UNDEFINED ) const = 0; |
| 147 | |
| 148 | |
| 149 | //======================================================================== |
| 150 | /** Get the number of the structures built on the layer |
| 151 | */ |
| 152 | virtual const uint |
| 153 | GetNumberStructure() const = 0; |
| 154 | |
| 155 | |
| 156 | const uint |
| 157 | GetMaxLinear() const; |
| 158 | |
| 159 | |
| 160 | //======================================================================== |
| 161 | /** Get the layer size. |
| 162 | \note This method is obsolete |
| 163 | \see GlobalVar |
| 164 | */ |
| 165 | void |
| 166 | GetLayerSize( uint& w, uint& l) const; |
| 167 | |
| 168 | |
| 169 | //======================================================================== |
| 170 | /** Set the status of all structures |
| 171 | \param status The new status of the structures |
| 172 | */ |
| 173 | virtual void |
| 174 | StructureSet( const OC_BYTE& status ) = 0; |
| 175 | |
| 176 | |
| 177 | //======================================================================== |
| 178 | /** Unset the status of all structures |
| 179 | \param status The status to unset |
| 180 | */ |
| 181 | virtual void |
| 182 | StructureUnset( const OC_BYTE& status ) = 0; |
| 183 | |
| 184 | |
| 185 | //======================================================================== |
| 186 | /** Does the specified surface contain _at least_ one required structure ? |
| 187 | */ |
| 188 | virtual const bool |
| 189 | ContainStructure( |
| 190 | const uint & W1, |
| 191 | const uint & L1, |
| 192 | const uint & W2, |
| 193 | const uint & L2, |
| 194 | const OPENCITY_STRUCTURE_CODE & enumStructCode ) const = 0; |
| 195 | |
| 196 | |
| 197 | //======================================================================== |
| 198 | /** Does the specified surface contain _only_ the required structure or |
| 199 | nothing ? |
| 200 | */ |
| 201 | virtual const bool |
| 202 | ContainStructureOnly( |
| 203 | const uint & W1, |
| 204 | const uint & L1, |
| 205 | const uint & W2, |
| 206 | const uint & L2, |
| 207 | const OPENCITY_STRUCTURE_CODE & enumStructCode ) const = 0; |
| 208 | |
| 209 | |
| 210 | //======================================================================== |
| 211 | /** This methods returns a pointer to a container which contains the |
| 212 | queried informations. The user must call "delete pointer" to destroy |
| 213 | that pointer once he/she've done with it. |
| 214 | \see _CreateQueryContainer(), _DeleteQueryContainer() |
| 215 | */ |
| 216 | virtual GUIContainer* const |
| 217 | QueryStructure( |
| 218 | const uint & w, |
| 219 | const uint & l ) const = 0; |
| 220 | |
| 221 | |
| 222 | protected: |
| 223 | uint _uiLayerWidth; |
| 224 | uint _uiLayerLength; |
| 225 | |
| 226 | |
| 227 | //======================================================================== |
| 228 | /** Used by the "Query" function |
| 229 | these controls are shared by all the derived layers |
| 230 | */ |
| 231 | static GUIContainer* pctrQ; ///< The query container |
| 232 | static GUIButton* pbtnQRo, *pbtnQRf; ///< Residential query button |
| 233 | static GUIButton* pbtnQCo, *pbtnQCf; ///< Commercial query button |
| 234 | static GUIButton* pbtnQIo, *pbtnQIf; ///< Industrial query button |
| 235 | static GUIButton* pbtnQWo, *pbtnQWf; ///< Water query button |
| 236 | static GUIButton* pbtnQEo, *pbtnQEf; ///< Electricity query button |
| 237 | static GUIButton* pbtnQGo, *pbtnQGf; ///< Gas query button |
| 238 | static GUIButton* pbtnQP; ///< Path query button |
| 239 | |
| 240 | |
| 241 | private: |
| 242 | /*=====================================================================*/ |
| 243 | /* PRIVATE STATIC ATTRIBUTES */ |
| 244 | /*=====================================================================*/ |
| 245 | |
| 246 | /// Total derived classes |
| 247 | static uint _uiNumberLayer; |
| 248 | |
| 249 | //======================================================================== |
| 250 | void _CreateQueryContainer(); |
| 251 | void _DeleteQueryContainer(); |
| 252 | }; |
| 253 | |
| 254 | #endif |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 |