| 1 | /*************************************************************************** |
| 2 | structure.cpp - description |
| 3 | ------------------- |
| 4 | begin : june 16th, 2003 |
| 5 | copyright : (C) 2003-2007 by Duong Khang NGUYEN |
| 6 | email : neoneurone @ gmail com |
| 7 | |
| 8 | $Id: structure.cpp 462 2011-07-03 15:49:40Z 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 | // Useful enumerations |
| 21 | #include "opencity_direction.h" |
| 22 | #include "opencity_structure_type.h" |
| 23 | |
| 24 | // OpenCity header |
| 25 | #include "structure.h" |
| 26 | |
| 27 | // Global settings |
| 28 | #include "globalvar.h" |
| 29 | extern GlobalVar gVars; |
| 30 | |
| 31 | |
| 32 | uint Structure::uiNumberStructure = 0; ///< Number of structures created so far |
| 33 | |
| 34 | |
| 35 | /*======================================================================*/ |
| 36 | const uint & |
| 37 | Structure::GetNumber() |
| 38 | { |
| 39 | return Structure::uiNumberStructure; |
| 40 | } |
| 41 | |
| 42 | |
| 43 | /*======================================================================*/ |
| 44 | void |
| 45 | Structure::SetNumber( const uint & rcuiNb ) |
| 46 | { |
| 47 | Structure::uiNumberStructure = rcuiNb; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /*======================================================================*/ |
| 52 | Structure::Structure(): |
| 53 | _eGC( OC_EMPTY ), |
| 54 | _eSC( OC_STRUCTURE_UNDEFINED ), |
| 55 | _eType( OC_TYPE_UNDEFINED ), |
| 56 | _uiStatus( 0 ), |
| 57 | _uiLevel( OC_STRUCTURE_LEVEL_START ), |
| 58 | _pstructureMain( NULL ) |
| 59 | { |
| 60 | OPENCITY_DEBUG( "ctor 0" ); |
| 61 | uiNumberStructure++; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /*======================================================================*/ |
| 66 | Structure::Structure |
| 67 | ( |
| 68 | const OPENCITY_STRUCTURE_CODE enumStructCode |
| 69 | ): |
| 70 | _eGC( OC_EMPTY ), |
| 71 | _eSC( enumStructCode ), |
| 72 | _uiStatus( 0 ), |
| 73 | _uiLevel( OC_STRUCTURE_LEVEL_START ), |
| 74 | _pstructureMain( NULL ) |
| 75 | { |
| 76 | OPENCITY_DEBUG( "ctor 1" ); |
| 77 | |
| 78 | _eType = gVars.gpPropertyMgr->GetST( enumStructCode ); |
| 79 | uiNumberStructure++; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /*======================================================================*/ |
| 84 | Structure::Structure |
| 85 | ( |
| 86 | const OPENCITY_STRUCTURE_CODE enumStructCode, |
| 87 | Structure* pMain |
| 88 | ): |
| 89 | _eGC( OC_EMPTY ), |
| 90 | _eSC( enumStructCode ), |
| 91 | _uiStatus( 0 ), |
| 92 | _uiLevel( OC_STRUCTURE_LEVEL_START ), |
| 93 | _pstructureMain( pMain ) |
| 94 | { |
| 95 | OPENCITY_DEBUG( "ctor 2" ); |
| 96 | |
| 97 | _eType = gVars.gpPropertyMgr->GetST( enumStructCode ); |
| 98 | uiNumberStructure++; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /*======================================================================*/ |
| 103 | Structure::~Structure( ) |
| 104 | { |
| 105 | OPENCITY_DEBUG( "Structure dtor" ); |
| 106 | |
| 107 | uiNumberStructure--; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /*=====================================================================*/ |
| 112 | void |
| 113 | Structure::SaveTo( std::fstream& rfs ) |
| 114 | { |
| 115 | OPENCITY_DEBUG( __PRETTY_FUNCTION__ << "saving" ); |
| 116 | |
| 117 | rfs << _eGC << std::ends; |
| 118 | rfs << _eSC << std::ends; |
| 119 | rfs << _eType << std::ends; |
| 120 | rfs << _uiStatus << std::ends; |
| 121 | rfs << _uiLevel << std::ends; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /*=====================================================================*/ |
| 126 | void |
| 127 | Structure::LoadFrom( std::fstream& rfs ) |
| 128 | { |
| 129 | OPENCITY_DEBUG( __PRETTY_FUNCTION__ << "loading" ); |
| 130 | uint t = 0; |
| 131 | |
| 132 | rfs >> t; rfs.ignore(); _eGC = (OPENCITY_GRAPHIC_CODE)t; |
| 133 | rfs >> t; rfs.ignore(); _eSC = (OPENCITY_STRUCTURE_CODE)t; |
| 134 | rfs >> t; rfs.ignore(); _eType= (OPENCITY_STRUCTURE_TYPE)t; |
| 135 | rfs >> _uiStatus; rfs.ignore(); |
| 136 | rfs >> _uiLevel; rfs.ignore(); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /*======================================================================*/ |
| 141 | void |
| 142 | Structure::Set( |
| 143 | const uint wegBit ) |
| 144 | { |
| 145 | _uiStatus |= wegBit; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | /*======================================================================*/ |
| 150 | void |
| 151 | Structure::Unset( |
| 152 | const uint wegBit ) |
| 153 | { |
| 154 | _uiStatus &= ~wegBit; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /*======================================================================*/ |
| 159 | const bool |
| 160 | Structure::IsSet( |
| 161 | const uint wegBit ) const |
| 162 | { |
| 163 | if ((_uiStatus & wegBit) == wegBit) |
| 164 | return true; |
| 165 | else |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | /*======================================================================*/ |
| 171 | const OPENCITY_GRAPHIC_CODE |
| 172 | Structure::GetGraphicCode() const |
| 173 | { |
| 174 | return _eGC; |
| 175 | } |
| 176 | |
| 177 | |
| 178 | /*======================================================================*/ |
| 179 | const OPENCITY_GRAPHIC_CODE |
| 180 | Structure::GetBaseGraphicCode() const |
| 181 | { |
| 182 | OPENCITY_GRAPHIC_CODE tempGC = OC_EMPTY; |
| 183 | |
| 184 | switch (_eSC) { |
| 185 | case OC_STRUCTURE_RES: |
| 186 | tempGC = OC_RES_ZONE0; |
| 187 | break; |
| 188 | |
| 189 | case OC_STRUCTURE_COM: |
| 190 | tempGC = OC_COM_ZONE0; |
| 191 | break; |
| 192 | |
| 193 | case OC_STRUCTURE_IND: |
| 194 | tempGC = OC_IND_ZONE0; |
| 195 | break; |
| 196 | |
| 197 | default: |
| 198 | OPENCITY_DEBUG("Unrecognized graphic code enumeration."); |
| 199 | assert(0); |
| 200 | break; |
| 201 | } |
| 202 | |
| 203 | return tempGC; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /*======================================================================*/ |
| 208 | const OPENCITY_GRAPHIC_CODE |
| 209 | Structure::GetNextLevelGraphicCode() const |
| 210 | { |
| 211 | // OPENCITY_DEBUG("WARNING: Inside Structure"); |
| 212 | // WARNING: we don't have such information in a general structure |
| 213 | return _eGC; |
| 214 | } |
| 215 | |
| 216 | |
| 217 | /*======================================================================*/ |
| 218 | const OPENCITY_GRAPHIC_CODE |
| 219 | Structure::GetPreviousLevelGraphicCode() const |
| 220 | { |
| 221 | // WARNING: we don't have such information in a general structure |
| 222 | return _eGC; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | /*======================================================================*/ |
| 227 | const OPENCITY_STRUCTURE_CODE |
| 228 | Structure::GetCode() const |
| 229 | { |
| 230 | return _eSC; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /*======================================================================*/ |
| 235 | Structure* |
| 236 | Structure::GetMain() const |
| 237 | { |
| 238 | return _pstructureMain; |
| 239 | } |
| 240 | |
| 241 | |
| 242 | /*======================================================================*/ |
| 243 | void |
| 244 | Structure::SetMain( Structure* const pstruct ) |
| 245 | { |
| 246 | _pstructureMain = pstruct; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | /*======================================================================*/ |
| 251 | const bool |
| 252 | Structure::LevelUp( ) |
| 253 | { |
| 254 | // OPENCITY_DEBUG("WARNING: Inside Structure"); |
| 255 | if (_uiLevel < OC_STRUCTURE_LEVEL_MAX) { |
| 256 | _uiLevel++; |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | |
| 264 | /*======================================================================*/ |
| 265 | const bool |
| 266 | Structure::LevelDown( ) |
| 267 | { |
| 268 | if (_uiLevel > OC_STRUCTURE_LEVEL_MIN) { |
| 269 | _uiLevel--; |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | /*======================================================================*/ |
| 278 | const uint |
| 279 | Structure::GetLevel() const |
| 280 | { |
| 281 | return _uiLevel; |
| 282 | } |
| 283 | |
| 284 | |
| 285 | /*======================================================================*/ |
| 286 | void |
| 287 | Structure::SetLevel( |
| 288 | const uint uiLevel ) |
| 289 | { |
| 290 | _uiLevel = uiLevel; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | /*======================================================================*/ |
| 295 | const OPENCITY_STRUCTURE_TYPE |
| 296 | Structure::GetType() const |
| 297 | { |
| 298 | return _eType; |
| 299 | } |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 |