1 /*************************************************************************** 2 city.h - description 3 ------------------- 4 begin : may 28th, 2003 5 copyright : (C) 2003-2007 by Duong Khang NGUYEN 6 email : neoneurone @ gmail com 7 8 $Id: city.h 448 2010-05-09 15:18:32Z 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_CITY_H_ 21 #define _OPENCITY_CITY_H_ 1 22 23 #include "main.h" 24 25 #include "persistence.h" 26 #include "ui.h" 27 28 #include <deque> 29 30 #define OC_MAX_RESSOURCE_RECORD 20 31 32 33 class PathFinder; // testing pathfinding 34 class Vehicle; 35 class MovementManager; 36 37 class MainSim; // main simulator which handles the micro simulators 38 39 class Layer; 40 class BuildingLayer; 41 42 class GUIBar; // GUI, toolcircle 43 class GUIButton; 44 class GUILabel; 45 class GUIContainer; 46 47 48 //======================================================================== 49 /** This structure is used to keep track of city ressources 50 */ 51 struct Ressource { 52 OC_LINT fund; ///< Money, money, money ! 53 uint population; ///< Number of "oczens" 54 uint r, c, i; ///< RCI values 55 uint w, e, g; ///< WEG values 56 }; 57 58 59 //======================================================================== 60 /** The game is here ! This class controls all other classes. 61 */ 62 class City : public Persistence, public UI 63 { 64 public: 65 City( 66 const uint width = OC_CITY_W, 67 const uint length = OC_CITY_L, 68 const bool bGUIEnabled = true ); 69 70 ~City(); 71 72 73 //======================================================================== 74 /** Save the data to the specified fstream 75 \param rfs A reference to a file stream which is ready for writing 76 */ 77 void SaveTo( std::fstream& rfs ); 78 79 80 //======================================================================== 81 /** Load the data from the specified stream 82 \param rfs A reference to a file stream which is ready for reading 83 */ 84 void LoadFrom( std::fstream& rfs ); 85 86 87 //======================================================================== 88 void SetCurrentLayer( OPENCITY_CITY_LAYER enumNewLayer ); 89 90 91 //======================================================================== 92 /** Process the city's task 93 */ 94 void Run(); 95 96 97 //======================================================================== 98 /** Update the display 99 */ 100 void Display(); 101 102 103 Layer* GetLayer( OPENCITY_CITY_LAYER enumLayer ) const; 104 105 106 const void GetWL( uint & w, uint & l ) const; 107 108 109 //======================================================================== 110 // Inherited methods from UI 111 //======================================================================== 112 void Keyboard( const SDL_KeyboardEvent& rcEvent ); 113 void MouseMotion( const SDL_MouseMotionEvent& rcEvent ); 114 void MouseButton( const SDL_MouseButtonEvent& rcEvent ); 115 void Expose( const SDL_ExposeEvent& rcEvent ); 116 void Resize( const SDL_ResizeEvent& rcEvent ); 117 118 119 private: 120 // City's informations 121 bool _bGUIEnabled; ///< GUI mode ? 122 bool _bStatusVisible; ///< Is the status bar visible ? 123 124 uint _uiIncome; ///< Monthly income accumulator 125 OC_LINT _liCityFund; ///< Money, money, money ! 126 uint _uiPopulation; ///< Number of "oczens" 127 std::deque<Ressource> _dqRessource; ///< Store the last city ressources 128 129 uint _uiDay; ///< The game date 130 uint _uiMonth; 131 uint _uiYear; 132 133 uint _uiWidth; ///< City's width, length 134 uint _uiLength; 135 136 int _iWinWidth; ///< Windows' width, height 137 int _iWinHeight; 138 139 // Dragging mode and mouse click 140 bool _bLMBPressed; ///< Is the left mouse button pressed ? 141 uint _uiMapW1; 142 uint _uiMapL1; 143 uint _uiMapW2; 144 uint _uiMapL2; 145 146 // Handle pressed keyboards 147 bool _abKeyPressed[KEY_NUMBER]; 148 149 // Current city's layer 150 OPENCITY_CITY_LAYER _eCurrentLayer; 151 152 // Current city's speed 153 OPENCITY_CITY_SPEED _eSpeed; 154 155 // Current active tool 156 OPENCITY_TOOL_CODE _eCurrentTool; 157 GUIButton* _apbtnCurrentTool[OC_TOOL_NUMBER]; 158 159 // Others classes 160 Layer* _apLayer[4]; // The array of our 4 differents layer 161 162 // Testing pathfinder, TODO maybe we need to move it to main.cpp 163 bool boolPathGo; 164 uint uiPathStartW, uiPathStartH; 165 uint uiPathStopW, uiPathStopH; 166 GUIContainer*_pctrPath; 167 GUIButton* pbtnPathStart; 168 GUIButton* pbtnPathStop1; 169 GUIButton* pbtnPathStop2; 170 GUIButton* pbtnTestBuilding; // Used by graphists 171 Vehicle* pvehicle; 172 uint uiVehicleType; 173 174 // Testing MAS 175 GUIContainer*_pctrMAS; 176 GUIButton* pbtnMAS; 177 GUIButton* pbtnMASPolice; 178 GUIButton* pbtnMASDemonstrator; 179 GUIButton* pbtnMASRobber; 180 181 // Simulator 182 MainSim* _pMSim; 183 SDL_Thread* _pthreadMSim; 184 185 // The main menu 186 GUIContainer* _pctrMenu; // The main menu container 187 GUIButton* _pbtnMenuNew; // new button 188 GUIButton* _pbtnMenuLoad; // load button 189 GUIButton* _pbtnMenuSave; // save button 190 GUIButton* _pbtnMenuQuit; // quit button 191 192 // The status bar 193 GUIContainer* _pctrStatus; ///< The main status bar container 194 GUILabel* _plblFund; ///< The fund label 195 GUILabel* _plblPopulation; ///< The population label 196 GUILabel* _plblDate; ///< The date label 197 GUIBar* _pbarResidence; ///< The residence bar 198 GUIBar* _pbarCommerce; ///< The commerce bar 199 GUIBar* _pbarIndustry; ///< The industry bar 200 GUIBar* _pbarPower; ///< The power bar 201 GUIButton* _pbtnPause; ///< Pause button 202 GUIButton* _pbtnPlay; ///< Play button 203 204 // GUI containers for main, zone, eLectric and Terrain toolcircles 205 GUIContainer* _pctr; 206 GUIContainer* _pctrMain; 207 GUIContainer* _pctrL; // electricic tool 208 GUIContainer* _pctrT; // terrain tool 209 GUIContainer* _pctrQ; // query tool 210 GUIContainer* _pctrZ; // zone tool 211 GUIContainer* _pctrG; // Government tool circle 212 GUIContainer* _pctrN; // Nature tool circle 213 GUIContainer* _pctrS; // Save tool circle 214 215 // Main container, Z, LPX buttons 216 GUIButton* pbtnZ; // RCI zoning tools 217 GUIButton* pbtnS; // save/load tools 218 GUIButton* pbtnL; // electric Line 219 GUIButton* pbtnP; // Path 220 GUIButton* pbtnX; // Xestroy 221 GUIButton* pbtnG; // Government tool 222 223 // RCI buttons 224 GUIButton* pbtnZB; // Back button 225 GUIButton* pbtnZR; // Residential 226 GUIButton* pbtnZC; // Commercial 227 GUIButton* pbtnZI; // Industrial 228 229 // EL buttons 230 GUIButton* pbtnLB; // Back button 231 GUIButton* pbtnLL; // Electric lines 232 GUIButton* pbtnLN; // Nuclear power plant 233 GUIButton* pbtnLC; // Coal power plant 234 235 // (U)p / (D)own buttons 236 GUIButton* pbtnTB; // Back button 237 GUIButton* pbtnTU; // Raise terrain 238 GUIButton* pbtnTD; // Lower terrain 239 GUIButton* pbtnTX; // Destroy tool 240 GUIButton* pbtnTQ; // query button 241 242 // (P)ark buttons 243 GUIButton* pbtnGB; // Back button 244 GUIButton* pbtnGP; // Build a park 245 GUIButton* pbtnGE; // Education department 246 GUIButton* pbtnGH; // Hospital 247 GUIButton* pbtnGL; // Police department 248 GUIButton* pbtnGF; // Fire department 249 250 // Nature buttons 251 GUIButton* pbtnNB; // Back button 252 GUIButton* pbtnNP; // Park 253 GUIButton* pbtnNT; // Tree 254 255 // Save buttons 256 GUIButton* pbtnSB; // Back button 257 GUIButton* pbtnSS; // Save 258 GUIButton* pbtnSL; // Load 259 260 261 /*=====================================================================*/ 262 /* PRIVATE METHODS */ 263 /*=====================================================================*/ 264 265 //======================================================================== 266 /** Create few trees on the map according to the density map 267 */ 268 void _CreateTree(); 269 270 271 //======================================================================== 272 /** Create all the threads which handle the simulation aspect 273 \sa _DeleteSimulator() 274 */ 275 void _CreateSimulator(); 276 277 278 //======================================================================== 279 /** Wait for the simulation thread's exit 280 \sa _CreateSimulator() 281 */ 282 void _DeleteSimulator(); 283 284 285 //======================================================================== 286 /** Create the Graphic User Interface or ToolCircle 287 \sa _DeleteGUI() 288 */ 289 void _CreateGUI(); 290 291 292 //======================================================================== 293 /** Free the memory used by the GUI 294 \sa _CreateGUI() 295 */ 296 void _DeleteGUI(); 297 298 void _LoadMenu(); 299 void _CenterMenu(); 300 void _UnloadMenu(); 301 302 void _SetCurrentTool( const OPENCITY_TOOL_CODE& tool ); 303 void _DoTool( const SDL_MouseButtonEvent& sdlMBEvent ); 304 305 bool _HandleKeyPressed(); 306 307 //======================================================================== 308 /** Save the ressource record to the queue 309 */ 310 void _RecordRessource(); 311 312 void _DoBill( const OPENCITY_PROPERTY_CODE& ); 313 314 void _HandleMenuClick(); 315 316 void _HandleStatusClick(); 317 318 void _HandleGUIClick(); 319 320 void _HandleMouseXY(); 321 322 void _TestPathfinding(); 323 324 void _BuildPreview(); 325 326 327 //======================================================================== 328 /** Save the game 329 \return true if everything goes fine, false otherwise 330 */ 331 bool 332 _Save( const string& strFilename ); 333 334 //======================================================================== 335 /** Save the game 336 \return true if everything goes fine, false otherwise 337 */ 338 bool 339 _Load( const string& strFilename ); 340 341 }; 342 343 #endif 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363