/*************************************************************************** zen.cpp - description ------------------- project : OpenCity codename : ZeN server begin : november 26th, 2006 copyright : (C) 2006-2008 by Duong Khang NGUYEN email : neoneurone @ gmail com $Id: zen.cpp 375 2008-10-28 14:47:15Z neoneurone $ ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * any later version. * * * ***************************************************************************/ // Useful enumerations #include "opencity_direction.h" #include "opencity_structure_type.h" // OpenCity headers #include "zen.h" #include "city.h" // The heart of the project #include "conf.h" // Parser for .conf file #include "agentpolice.h" // MAS testing #include "agentdemonstrator.h" // Global settings #include "globalvar.h" extern GlobalVar gVars; // Libraries headers #include "SDL_image.h" #include "binreloc.h" // BinReloc routines from AutoPackage #include "tinyxml.h" #include "SimpleOpt.h" // Simple command line argument parser // Standard headers #include // For log10 #include // For getenv #include // For time /*=====================================================================*/ /* LOCAL MACROS */ /*=====================================================================*/ #ifndef __WIN32__ #include // mkdir #else // Win32 specifics #include // Windows shell technologies #define DATADIR "C:/Program Files" #define SYSCONFDIR DATADIR #endif // Window's settings #define OC_WINDOW_POS_X 20 #define OC_WINDOW_POS_Y 20 #define OC_WINDOW_WIDTH 750 #define OC_WINDOW_HEIGHT 560 #define OC_WINDOW_BPP_DEFAULT 32 // OC uses this by default #define OC_WINDOW_BPP_16 16 #define OC_FULLSCREEN_WIDTH 1024 #define OC_FULLSCREEN_HEIGHT 768 // Exit code #define OC_CONFIG_NOT_FOUND -1 #define OC_CONFIG_PARSE_ERROR -2 // Settings file #define OC_CONFIG_FILE_FILENAME "config/opencity.xml" // Others macros #define OC_WINDOW_NAME PACKAGE VERSION #define OC_PROGRAM_NAME "OpenCity ZeN server application" /*=====================================================================*/ /* LOCAL VARIABLES */ /*=====================================================================*/ /// The current user interface is pointed by this pointer static UI* uipCurrentUI = NULL; /// Set to true when the user request to quit the program static bool boolQuit = false; static bool bRestart = false; /// Static so that the others can not access this static string sDataDir = ""; static string sSaveDir = ""; static string sConfigDir = ""; /*=====================================================================*/ void ocActive( const SDL_ActiveEvent & e) { OPENCITY_DEBUG( "Active event received" ); if (e.state & SDL_APPACTIVE) { gVars.gboolActive = (e.gain == 1); } } /*=====================================================================*/ void ocQuit( const int quit_code ) { cout << "Quit requested, quit code is : " << quit_code << endl << "Bye bye !" << endl; boolQuit = true; } /*=====================================================================*/ void ocRestart() { cout << "Restart with a new city from scratch. " << endl; bRestart = true; } /*=====================================================================*/ void ocProcessSDLEvents( void ) { static SDL_Event event; // Grab all the events off the queue. while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_ACTIVEEVENT: ocActive( event.active ); break; case SDL_QUIT: // Handle quit requests (like Ctrl-c). cout << "Quit requested, stoping " << OC_PROGRAM_NAME << "..." << endl; boolQuit = true; break; } } } /*=====================================================================*/ void ocSetNewUI( UI * pcNewUI) { uipCurrentUI = pcNewUI; } /*=====================================================================*/ string formatPath(const string& rcsPath) { string result = rcsPath; if (result.size() > 0) { // Delete all quotes " string::size_type pos; while ( (pos = result.find( '\"' )) != result.npos ) { result.erase( pos ); } // Append the "/" to path if (result[ result.size()-1 ] != '/') result += '/'; } else { result = "/"; } return result; } /*=====================================================================*/ void parseArg(int argc, char *argv[]) { enum { OPT_DATADIR, OPT_CONFDIR, OPT_HELP }; CSimpleOpt::SOption g_rgOptions[] = { { OPT_DATADIR, (char*)"--datadir", SO_REQ_SEP }, { OPT_DATADIR, (char*)"-dd", SO_REQ_SEP }, { OPT_CONFDIR, (char*)"--confdir", SO_REQ_SEP }, { OPT_CONFDIR, (char*)"-cd", SO_REQ_SEP }, { OPT_HELP, (char*)"--help", SO_NONE }, { OPT_HELP, (char*)"-h", SO_NONE }, SO_END_OF_OPTIONS // END }; CSimpleOpt args(argc, argv, g_rgOptions, SO_O_EXACT | SO_O_NOSLASH | SO_O_SHORTARG | SO_O_CLUMP ); while (args.Next()) { switch (args.LastError()) { case SO_OPT_INVALID: cout << "