示例#1
0
int main(int argc, char *argv[]) {
	// init fnkdat
	if(fnkdat(NULL, NULL, 0, FNKDAT_INIT) < 0) {
      perror("Could not initialize fnkdat");
      exit(EXIT_FAILURE);
	}

	bool bShowDebug = false;
    for(int i=1; i < argc; i++) {
	    //check for overiding params
	    std::string parameter(argv[i]);

		if(parameter == "--showlog") {
		    // special parameter which does not overwrite settings
            bShowDebug = true;
		} else if((parameter == "-f") || (parameter == "--fullscreen") || (parameter == "-w") || (parameter == "--window") || (parameter.find("--PlayerName=") == 0) || (parameter.find("--ServerPort=") == 0)) {
            // normal parameter for overwriting settings
            // handle later
        } else {
            printUsage();
            exit(EXIT_FAILURE);
		}
	}

	if(bShowDebug == false) {
	    // get utf8-encoded log file path
	    std::string logfilePath = getLogFilepath();
	    const char* pLogfilePath = logfilePath.c_str();

	    #if defined (_WIN32)

        // on win32 we need an ansi-encoded filepath
        WCHAR szwLogPath[MAX_PATH];
        char szLogPath[MAX_PATH];

        if(MultiByteToWideChar(CP_UTF8, 0, pLogfilePath, -1, szwLogPath, MAX_PATH) == 0) {
            fprintf(stderr, "Conversion of logfile path from utf-8 to utf-16 failed\n");
            exit(EXIT_FAILURE);
        }

        if(WideCharToMultiByte(CP_ACP, 0, szwLogPath, -1, szLogPath, MAX_PATH, NULL, NULL) == 0) {
            fprintf(stderr, "Conversion of logfile path from utf-16 to ansi failed\n");
            exit(EXIT_FAILURE);
        }

        pLogfilePath = szLogPath;

	    #endif

        int d = open(pLogfilePath, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if(d < 0) {
            fprintf(stderr, "Opening logfile '%s' failed\n", pLogfilePath);
            exit(EXIT_FAILURE);
        }

        // Hint: fileno(stdout) != STDOUT_FILENO on Win32 (see SDL_win32_main.c)
        if(dup2(d, fileno(stdout)) < 0) {
            fprintf(stderr, "Redirecting stdout failed\n");
            exit(EXIT_FAILURE);
        }

        // Hint: fileno(stderr) != STDERR_FILENO on Win32 (see SDL_win32_main.c)
        if(dup2(d, fileno(stderr)) < 0) {
            fprintf(stderr, "Redirecting stderr failed\n");
            exit(EXIT_FAILURE);
        }
	}

	fprintf(stdout, "Starting Dune Legacy " VERSION " ...\n"); fflush(stdout);

	if(checkForExcessPrecision() == true) {
        fprintf(stdout, "WARNING: Floating point operations are internally calculated with higher precision. Network game might get async. Are you using x87-FPU? Check your compile settings!\n"); fflush(stdout);
	}

    // First check for missing files
    std::vector<std::string> missingFiles = FileManager::getMissingFiles();

    if(missingFiles.empty() == false) {
        // create data directory inside config directory
        char tmp[FILENAME_MAX];
        fnkdat("data/", tmp, FILENAME_MAX, FNKDAT_USER | FNKDAT_CREAT);

        bool cannotShowMissingScreen = false;
        fprintf(stderr,"The following files are missing:\n");
        std::vector<std::string>::const_iterator iter;
        for(iter = missingFiles.begin() ; iter != missingFiles.end(); ++iter) {
            fprintf(stderr," %s\n",iter->c_str());
            if(iter->find("LEGACY.PAK") != std::string::npos) {
                cannotShowMissingScreen = true;
            }
        }

        fprintf(stderr,"Put them in one of the following directories:\n");
        std::vector<std::string> searchPath = FileManager::getSearchPath();
        std::vector<std::string>::const_iterator searchPathIter;
        for(searchPathIter = searchPath.begin(); searchPathIter != searchPath.end(); ++searchPathIter) {
            fprintf(stderr," %s\n",searchPathIter->c_str());
        }

        if(cannotShowMissingScreen == true) {
            return EXIT_FAILURE;
        }
    }

	bool bExitGame = false;
	bool bFirstInit = true;
	bool bFirstGamestart = false;

    debug = false;
    cursorFrame = UI_CursorNormal;

	do {
		int seed = time(NULL);
		srand(seed);

        // check if configfile exists
        std::string configfilepath = getConfigFilepath();
        if(existsFile(configfilepath) == false) {
            std::string userLanguage = getUserLanguage();
            if(userLanguage.empty()) {
                userLanguage = "en";
            }

            if(missingFiles.empty() == true) {
                // if all pak files were found we can create the ini file
                bFirstGamestart = true;
                createDefaultConfigFile(configfilepath, userLanguage);
            }
        }

		INIFile myINIFile(configfilepath);

		settings.general.playIntro = myINIFile.getBoolValue("General","Play Intro",false);
		settings.general.playerName = myINIFile.getStringValue("General","Player Name","Player");
		settings.video.width = myINIFile.getIntValue("Video","Width",640);
		settings.video.height = myINIFile.getIntValue("Video","Height",480);
		settings.video.fullscreen = myINIFile.getBoolValue("Video","Fullscreen",true);
		settings.video.doubleBuffering = myINIFile.getBoolValue("Video","Double Buffering",true);
		settings.video.frameLimit = myINIFile.getBoolValue("Video","FrameLimit",true);
		settings.video.preferredZoomLevel = myINIFile.getIntValue("Video","Preferred Zoom Level", 0);
		settings.video.scaler = myINIFile.getStringValue("Video","Scaler", "scale2x");
		settings.audio.musicType = myINIFile.getStringValue("Audio","Music Type","adl");
		settings.audio.playMusic = myINIFile.getBoolValue("Audio","Play Music", true);
		settings.audio.playSFX = myINIFile.getBoolValue("Audio","Play SFX", true);
		settings.audio.frequency = myINIFile.getIntValue("Audio","Audio Frequency", 22050);

		settings.general.language = myINIFile.getStringValue("General","Language","en");

		settings.network.serverPort = myINIFile.getIntValue("Network","ServerPort",DEFAULT_PORT);
		settings.network.metaServer = myINIFile.getStringValue("Network","MetaServer",DEFAULT_METASERVER);
		settings.network.debugNetwork = myINIFile.getBoolValue("Network","Debug Network",false);

		settings.ai.campaignAI = myINIFile.getStringValue("AI","Campaign AI",DEFAULTAIPLAYERCLASS);

        settings.gameOptions.gameSpeed = myINIFile.getIntValue("Game Options","Game Speed",GAMESPEED_DEFAULT);
        settings.gameOptions.concreteRequired = myINIFile.getBoolValue("Game Options","Concrete Required",true);
		settings.gameOptions.structuresDegradeOnConcrete = myINIFile.getBoolValue("Game Options","Structures Degrade On Concrete",true);
        settings.gameOptions.fogOfWar = myINIFile.getBoolValue("Game Options","Fog of War",false);
        settings.gameOptions.startWithExploredMap = myINIFile.getBoolValue("Game Options","Start with Explored Map",false);
        settings.gameOptions.instantBuild = myINIFile.getBoolValue("Game Options","Instant Build",false);
        settings.gameOptions.onlyOnePalace = myINIFile.getBoolValue("Game Options","Only One Palace",false);
        settings.gameOptions.rocketTurretsNeedPower = myINIFile.getBoolValue("Game Options","Rocket-Turrets Need Power",false);
        settings.gameOptions.sandwormsRespawn = myINIFile.getBoolValue("Game Options","Sandworms Respawn",false);
        settings.gameOptions.killedSandwormsDropSpice = myINIFile.getBoolValue("Game Options","Killed Sandworms Drop Spice",false);

        fprintf(stdout, "loading texts....."); fflush(stdout);
        pTextManager = new TextManager();
        fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

		if(FileManager::getMissingFiles().size() > 0) {
		    // set back to english
            std::vector<std::string> missingFiles = FileManager::getMissingFiles();
            fprintf(stderr,"The following files are missing for language \"%s\":\n",_("LanguageFileExtension").c_str());
            std::vector<std::string>::const_iterator iter;
            for(iter = missingFiles.begin(); iter != missingFiles.end(); ++iter) {
                fprintf(stderr," %s\n",iter->c_str());
            }
            fprintf(stderr,"Language is changed to English!\n");
            settings.general.language = "en";
		}

		for(int i=1; i < argc; i++) {
		    //check for overiding params
            std::string parameter(argv[i]);

			if((parameter == "-f") || (parameter == "--fullscreen")) {
				settings.video.fullscreen = true;
			} else if((parameter == "-w") || (parameter == "--window")) {
				settings.video.fullscreen = false;
			} else if(parameter.find("--PlayerName=") == 0) {
                settings.general.playerName = parameter.substr(strlen("--PlayerName="));
            } else if(parameter.find("--ServerPort=") == 0) {
                settings.network.serverPort = atol(argv[i] + strlen("--ServerPort="));
            }
		}

        if(bFirstInit == true) {
            fprintf(stdout, "initializing SDL..... \t\t"); fflush(stdout);
            if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) {
                fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError());
                exit(EXIT_FAILURE);
            }
            fprintf(stdout, "finished\n"); fflush(stdout);
        }

		if(bFirstGamestart == true && bFirstInit == true) {
            // detect 800x600 screen resolution
            if(SDL_VideoModeOK(800, 600, 8, SDL_HWSURFACE | SDL_FULLSCREEN) > 0) {
                settings.video.width = 800;
                settings.video.height = 600;
                settings.video.preferredZoomLevel = 1;

                myINIFile.setIntValue("Video","Width",settings.video.width);
                myINIFile.setIntValue("Video","Height",settings.video.height);
                myINIFile.setIntValue("Video","Preferred Zoom Level",1);

                myINIFile.saveChangesTo(getConfigFilepath());
            }
		}

        Scaler::setDefaultScaler(Scaler::getScalerByName(settings.video.scaler));

		SDL_EnableUNICODE(1);
		SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
		char strenv[] = "SDL_VIDEO_CENTERED=center";
        SDL_putenv(strenv);
		SDL_WM_SetCaption("Dune Legacy", "Dune Legacy");

		if(bFirstInit == true) {
			fprintf(stdout, "initializing sound..... \t");fflush(stdout);
			if( Mix_OpenAudio(settings.audio.frequency, AUDIO_S16SYS, 2, 1024) < 0 ) {
				SDL_Quit();
				fprintf(stderr,"Warning: Couldn't set %d Hz 16-bit audio\n- Reason: %s\n",settings.audio.frequency,SDL_GetError());
				exit(EXIT_FAILURE);
			} else {
				fprintf(stdout, "allocated %d channels.\n", Mix_AllocateChannels(6)); fflush(stdout);
			}
		}

        pFileManager = new FileManager( !missingFiles.empty() );

        // now we can finish loading texts
        if(missingFiles.empty()) {
            pTextManager->loadData();
        }

        if(pFileManager->exists("IBM.PAL") == true) {
            palette = LoadPalette_RW(pFileManager->openFile("IBM.PAL"), true);
        } else {
            // create dummy palette for showing missing files info
            palette = Palette(256);
            palette[115].r = 202;
            palette[115].g = 141;
            palette[115].b = 16;
            palette[255].r = 255;
            palette[255].g = 255;
            palette[255].b = 255;
        }

		screen = NULL;
		setVideoMode();


		fprintf(stdout, "loading fonts...");fflush(stdout);
		pFontManager = new FontManager();
		fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

		if(!missingFiles.empty()) {
		    // some files are missing
		    bExitGame = true;
		    printMissingFilesToScreen();
		    fprintf(stdout, "Deinitialize....."); fflush(stdout);
		} else {
		    // everything is just fine and we can start the game

            fprintf(stdout, "loading graphics..."); fflush(stdout);
            pGFXManager = new GFXManager();
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

            fprintf(stdout, "loading sounds..."); fflush(stdout);
            pSFXManager = new SFXManager();
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

            GUIStyle::setGUIStyle(new DuneStyle);

            if(bFirstInit == true) {
                fprintf(stdout, "starting sound player..."); fflush(stdout);
                soundPlayer = new SoundPlayer();
                fprintf(stdout, "\tfinished\n");

                fprintf(stdout, "starting music player...\t"); fflush(stdout);
                if(settings.audio.musicType == "directory") {
                    fprintf(stdout, "playing from music directory\n"); fflush(stdout);
                    musicPlayer = new DirectoryPlayer();
                } else if(settings.audio.musicType == "adl") {
                    fprintf(stdout, "playing ADL files\n"); fflush(stdout);
                    musicPlayer = new ADLPlayer();
                } else if(settings.audio.musicType == "xmi") {
                    fprintf(stdout, "playing XMI files\n"); fflush(stdout);
                    musicPlayer = new XMIPlayer();
                } else {
                    fprintf(stdout, "failed\n"); fflush(stdout);
                    exit(EXIT_FAILURE);
                }

                //musicPlayer->changeMusic(MUSIC_INTRO);
            }

            // Playing intro
            if(((bFirstGamestart == true) || (settings.general.playIntro == true)) && (bFirstInit==true)) {
                fprintf(stdout, "playing intro.....");fflush(stdout);
                Intro* pIntro = new Intro();
                pIntro->run();
                delete pIntro;
                fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
            }

            bFirstInit = false;

            fprintf(stdout, "starting main menu...");fflush(stdout);
            MainMenu * myMenu = new MainMenu();
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
            if(myMenu->showMenu() == MENU_QUIT_DEFAULT) {
                bExitGame = true;
            }
            delete myMenu;

            fprintf(stdout, "Deinitialize....."); fflush(stdout);

            GUIStyle::destroyGUIStyle();

            // clear everything
            if(bExitGame == true) {
                delete musicPlayer;
                delete soundPlayer;
                Mix_HaltMusic();
                Mix_CloseAudio();
            }

            delete pTextManager;
            delete pSFXManager;
            delete pGFXManager;
		}

		delete pFontManager;
		delete pFileManager;
		if(bExitGame == true) {
			SDL_Quit();
		}
		fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
	} while(bExitGame == false);

	// deinit fnkdat
	if(fnkdat(NULL, NULL, 0, FNKDAT_UNINIT) < 0) {
		perror("Could not uninitialize fnkdat");
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
	// init fnkdat
	if(fnkdat(NULL, NULL, 0, FNKDAT_INIT) < 0) {
      perror("Could not initialize fnkdat");
      exit(EXIT_FAILURE);
	}

	bool bShowDebug = false;
    for(int i=1; i < argc; i++) {
	    //check for overiding params
		if (strcmp(argv[i], "--showlog") == 0)
			bShowDebug = true;
	}

	if(bShowDebug == false) {
        int d = open(GetLogFilepath().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if(d < 0) {
            perror("Opening logfile failed");
            exit(EXIT_FAILURE);
        }

        if(dup2(d, STDOUT_FILENO) < 0) {
            perror("Redirecting stdout failed");
            exit(EXIT_FAILURE);
        }

        if(dup2(d, STDERR_FILENO) < 0) {
            perror("Redirecting stderr failed");
            exit(EXIT_FAILURE);
        }
	}

    // First check for missing files
    std::vector<std::string> MissingFiles = FileManager::getMissingFiles(LNG_ENG);

    if(MissingFiles.size() > 0) {
        // create data directory inside config directory
        char tmp[FILENAME_MAX];
        fnkdat("data/", tmp, FILENAME_MAX, FNKDAT_USER | FNKDAT_CREAT);

        bool cannotShowMissingScreen = false;
        fprintf(stderr,"The following files are missing:\n");
        std::vector<std::string>::const_iterator iter;
        for(iter = MissingFiles.begin() ; iter != MissingFiles.end(); ++iter) {
            fprintf(stderr," %s\n",iter->c_str());
            if(iter->find("LEGACY.PAK") != std::string::npos) {
                cannotShowMissingScreen = true;
            }
        }

        fprintf(stderr,"Put them in one of the following directories:\n");
        std::vector<std::string> searchPath = FileManager::getSearchPath();
        std::vector<std::string>::const_iterator searchPathIter;
        for(searchPathIter = searchPath.begin(); searchPathIter != searchPath.end(); ++searchPathIter) {
            fprintf(stderr," %s\n",searchPathIter->c_str());
        }

        if(cannotShowMissingScreen == true) {
            return EXIT_FAILURE;
        }
    }

	bool ExitGame = false;
	bool FirstInit = true;
	bool FirstGamestart = false;

    debug = false;
    cursorFrame = UI_CursorNormal;

	do {
		int seed = time(NULL);
		srand(seed);

        // check if configfile exists
        std::string configfilepath = GetConfigFilepath();
        if(ExistsFile(configfilepath) == false) {
            int UserLanguage = GetUserLanguage();
            if(UserLanguage == LNG_UNKNOWN) {
                UserLanguage = LNG_ENG;
            }

            if(MissingFiles.empty() == true) {
                // if all pak files were found we can create the ini file
                FirstGamestart = true;
                CreateDefaultConfigFile(configfilepath, UserLanguage);
            }
        }

		INIFile myINIFile(configfilepath);

		settings.General.PlayIntro = myINIFile.getBoolValue("General","Play Intro",false);
		settings.General.ConcreteRequired = myINIFile.getBoolValue("General","Concrete Required",true);
        settings.General.FogOfWar = myINIFile.getBoolValue("General","Fog of War",false);
		settings.General.PlayerName = myINIFile.getStringValue("General","Player Name","Player");
		settings.Video.Width = myINIFile.getIntValue("Video","Width",640);
		settings.Video.Height = myINIFile.getIntValue("Video","Height",480);
		settings.Video.Fullscreen = myINIFile.getBoolValue("Video","Fullscreen",true);
		settings.Video.DoubleBuffering = myINIFile.getBoolValue("Video","Double Buffering",true);
		settings.Video.FrameLimit = myINIFile.getBoolValue("Video","FrameLimit",true);
		settings.Audio.MusicType = myINIFile.getStringValue("Audio","Music Type","adl");
		std::string Lng = myINIFile.getStringValue("General","Language","en");
		if(Lng == "en") {
			settings.General.setLanguage(LNG_ENG);
		} else if (Lng == "fr") {
			settings.General.setLanguage(LNG_FRE);
		} else if (Lng == "de") {
			settings.General.setLanguage(LNG_GER);
		} else {
			fprintf(stderr,"INI-File: Invalid Language \"%s\"! Default Language (en) is used.\n",Lng.c_str());
			settings.General.setLanguage(LNG_ENG);
		}

		if(FileManager::getMissingFiles(settings.General.Language).size() > 0) {
		    // set back to english
            std::vector<std::string> MissingFiles = FileManager::getMissingFiles(settings.General.Language);
            fprintf(stderr,"The following files are missing for language \"%s\":\n",settings.General.LanguageExt.c_str());
            std::vector<std::string>::const_iterator iter;
            for(iter = MissingFiles.begin() ; iter != MissingFiles.end(); ++iter) {
                fprintf(stderr," %s\n",iter->c_str());
            }
            fprintf(stderr,"Language is changed to English!\n");
            settings.General.setLanguage(LNG_ENG);
		}

		lookDist[0] = 10;lookDist[1] = 10;lookDist[2] = 9;lookDist[3] = 9;lookDist[4] = 9;lookDist[5] = 8;lookDist[6] = 8;lookDist[7] = 7;lookDist[8] = 6;lookDist[9] = 4;lookDist[10] = 1;


		for(int i=1; i < argc; i++) {
		    //check for overiding params
			if((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--fullscreen") == 0))
				settings.Video.Fullscreen = true;
			else if((strcmp(argv[i], "-w") == 0) || (strcmp(argv[i], "--window") == 0))
				settings.Video.Fullscreen = false;
		}

		if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) {
			fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError());
			exit(EXIT_FAILURE);
		}

		if(FirstGamestart == true && FirstInit == true) {
            // detect 800x600 screen resolution
            if(SDL_VideoModeOK(800, 600, 8, SDL_HWSURFACE | SDL_FULLSCREEN) > 0) {
                settings.Video.Width = 800;
                settings.Video.Height = 600;

                myINIFile.setIntValue("Video","Width",settings.Video.Width);
                myINIFile.setIntValue("Video","Height",settings.Video.Height);

                myINIFile.SaveChangesTo(GetConfigFilepath());
            }
		}

		SDL_EnableUNICODE(1);
		SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
		char strenv[] = "SDL_VIDEO_CENTERED=center";
        SDL_putenv(strenv);
		SDL_WM_SetCaption("Dune Legacy", "Dune Legacy");

		if(FirstInit == true) {
			fprintf(stdout, "initialising sound..... \t");fflush(stdout);
			if( Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 1024) < 0 ) {
				SDL_Quit();
				fprintf(stderr,"Warning: Couldn't set 22050 Hz 16-bit audio\n- Reason: %s\n",SDL_GetError());
				exit(EXIT_FAILURE);
			} else {
				fprintf(stdout, "allocated %d channels.\n", Mix_AllocateChannels(4)); fflush(stdout);
			}
		}

        pFileManager = new FileManager( (MissingFiles.size() > 0) );

        if(pFileManager->exists("IBM.PAL") == true) {
            palette = LoadPalette_RW(pFileManager->OpenFile("IBM.PAL"), true);
        } else {
            // create dummy palette for showing missing files info
            palette = Palette(256);
            palette[255].r = 255;
            palette[255].g = 255;
            palette[255].b = 255;
        }

		screen = NULL;
		setVideoMode();


		fprintf(stdout, "loading fonts.....");fflush(stdout);
		pFontManager = new FontManager();

		fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

		if(MissingFiles.size() > 0) {
		    // some files are missing
		    ExitGame = true;
		    PrintMissingFilesToScreen();
		    fprintf(stdout, "Deinitialize....."); fflush(stdout);
		} else {
		    // everything is just fine and we can start the game

            //get the house palettes
            houseColor[HOUSE_ATREIDES]  =   COLOR_ATREIDES;
            houseColor[HOUSE_ORDOS]     =   COLOR_ORDOS;
            houseColor[HOUSE_HARKONNEN] =   COLOR_HARKONNEN;
            houseColor[HOUSE_SARDAUKAR] =   COLOR_SARDAUKAR;
            houseColor[HOUSE_FREMEN]    =   COLOR_FREMEN;
            houseColor[HOUSE_MERCENARY] =   COLOR_MERCENARY;

            fprintf(stdout, "loading graphics....."); fflush(stdout);
            if((pGFXManager = new GFXManager()) == NULL) {
                fprintf(stderr,"main: Cannot create GFXManager!\n");
                exit(EXIT_FAILURE);
            }
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

            fprintf(stdout, "loading sounds....."); fflush(stdout);
            if((pSFXManager = new SFXManager()) == NULL) {
                fprintf(stderr,"main: Cannot create SFXManager!\n");
                exit(EXIT_FAILURE);
            }
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

            fprintf(stdout, "loading texts....."); fflush(stdout);
            if((pTextManager = new TextManager()) == NULL) {
                fprintf(stderr,"main: Cannot create TextManager!\n");
                exit(EXIT_FAILURE);
            }
            fprintf(stdout, "\t\tfinished\n"); fflush(stdout);

            GUIStyle::SetGUIStyle(new DuneStyle);

            if(FirstInit == true) {
                fprintf(stdout, "starting sound player..."); fflush(stdout);
                soundPlayer = new SoundPlayer();
                fprintf(stdout, "\tfinished\n");

                fprintf(stdout, "starting music player...\t"); fflush(stdout);
                if(settings.Audio.MusicType == "directory") {
                    fprintf(stdout, "playing from music directory\n"); fflush(stdout);
                    musicPlayer = new DirectoryPlayer();
                } else if(settings.Audio.MusicType == "adl") {
                    fprintf(stdout, "playing ADL files\n"); fflush(stdout);
                    musicPlayer = new ADLPlayer();
                } else if(settings.Audio.MusicType == "xmi") {
                    fprintf(stdout, "playing XMI files\n"); fflush(stdout);
                    musicPlayer = new XMIPlayer();
                } else {
                    fprintf(stdout, "failed\n"); fflush(stdout);
                    exit(EXIT_FAILURE);
                }

                //musicPlayer->changeMusic(MUSIC_INTRO);
            }

            // Playing intro
            if(((FirstGamestart == true) || (settings.General.PlayIntro == true)) && (FirstInit==true)) {
                fprintf(stdout, "playing intro.....");fflush(stdout);
                Intro* pIntro = new Intro();

                pIntro->run();

                delete pIntro;
                fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
            }

            FirstInit = false;

            fprintf(stdout, "starting main menu.......");fflush(stdout);

            MainMenu * myMenu = new MainMenu();

            fprintf(stdout, "\tfinished\n"); fflush(stdout);

            if(myMenu->showMenu() == -1) {
                ExitGame = true;
            }
            delete myMenu;

            fprintf(stdout, "Deinitialize....."); fflush(stdout);

            GUIStyle::DestroyGUIStyle();

            // clear everything
            if(ExitGame == true) {
                delete musicPlayer;
                delete soundPlayer;
                Mix_HaltMusic();
                Mix_CloseAudio();
            }

            delete pTextManager;
            delete pSFXManager;
            delete pGFXManager;
		}

		delete pFontManager;
		delete pFileManager;
		if(ExitGame == true) {
			SDL_Quit();
		}
		fprintf(stdout, "\t\tfinished\n"); fflush(stdout);
	} while(ExitGame == false);

	// deinit fnkdat
	if(fnkdat(NULL, NULL, 0, FNKDAT_UNINIT) < 0) {
		perror("Could not uninitialize fnkdat");
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;
}