2010-03-13 22:10:45 +01:00
// This file is part of Glest (www.glest.org)
//
2010-03-25 01:19:49 +01:00
// Copyright (C) 2001-2008 Marti<74> o Figueroa
2010-03-13 22:10:45 +01:00
//
// You can redistribute this code 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 (at your option) any later version
// ==============================================================
# include "game.h"
# include "config.h"
# include "renderer.h"
# include "particle_renderer.h"
# include "commander.h"
# include "battle_end.h"
# include "sound_renderer.h"
# include "profiler.h"
# include "core_data.h"
# include "metrics.h"
# include "faction.h"
# include "network_manager.h"
# include "checksum.h"
# include "auto_test.h"
2010-04-24 14:22:35 +02:00
# include "FPUCheck.h"
2011-10-03 02:36:28 +02:00
# include "menu_state_keysetup.h"
2010-03-13 22:10:45 +01:00
# include "leak_dumper.h"
using namespace Shared : : Graphics ;
using namespace Shared : : Util ;
using namespace Shared : : Platform ;
namespace Glest { namespace Game {
2010-05-29 08:56:32 +02:00
Game * thisGamePtr = NULL ;
2010-03-13 22:10:45 +01:00
// =====================================================
// class Game
// =====================================================
// ===================== PUBLIC ========================
2010-10-30 05:03:44 +02:00
const float PHOTO_MODE_MAXHEIGHT = 500.0 ;
2011-09-21 08:51:28 +02:00
const int CREATE_NEW_TEAM = - 100 ;
const int CANCEL_SWITCH_TEAM = - 1 ;
2011-03-22 03:02:54 +01:00
Game : : Game ( ) : ProgramState ( NULL ) {
2011-03-28 23:04:47 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-22 03:02:54 +01:00
originalDisplayMsgCallback = NULL ;
aiInterfaces . clear ( ) ;
2011-09-01 01:10:43 +02:00
mouse2d = 0 ;
mouseX = 0 ;
mouseY = 0 ;
updateFps = 0 ;
lastUpdateFps = 0 ;
avgUpdateFps = 0 ;
totalRenderFps = 0 ;
renderFps = 0 ;
lastRenderFps = 0 ;
avgRenderFps = 0 ;
currentAvgRenderFpsTotal = 0 ;
paused = false ;
gameOver = false ;
renderNetworkStatus = false ;
showFullConsole = false ;
mouseMoved = false ;
scrollSpeed = 0 ;
camLeftButtonDown = false ;
camRightButtonDown = false ;
camUpButtonDown = false ;
camDownButtonDown = false ;
speed = sNormal ;
weatherParticleSystem = NULL ;
isFirstRender = false ;
quitTriggeredIndicator = false ;
original_updateFps = 0 ;
original_cameraFps = 0 ;
captureAvgTestStatus = false ;
updateFpsAvgTest = 0 ;
renderFpsAvgTest = 0 ;
renderExtraTeamColor = 0 ;
photoModeEnabled = false ;
visibleHUD = false ;
withRainEffect = false ;
program = NULL ;
gameStarted = false ;
2011-09-21 08:51:28 +02:00
2011-09-24 23:07:15 +02:00
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
popupMenuSwitchTeams . setEnabled ( false ) ;
popupMenuSwitchTeams . setVisible ( false ) ;
2011-09-21 08:51:28 +02:00
switchTeamConfirmMessageBox . setEnabled ( false ) ;
exitGamePopupMenuIndex = - 1 ;
joinTeamPopupMenuIndex = - 1 ;
2011-10-03 22:48:09 +02:00
pauseGamePopupMenuIndex = - 1 ;
2011-10-03 02:36:28 +02:00
keyboardSetupPopupMenuIndex = - 1 ;
2011-09-24 23:07:15 +02:00
masterserverMode = false ;
2011-10-03 02:36:28 +02:00
currentUIState = NULL ;
2011-03-22 03:02:54 +01:00
}
2011-09-24 23:07:15 +02:00
Game : : Game ( Program * program , const GameSettings * gameSettings , bool masterserverMode ) :
2010-06-24 03:23:18 +02:00
ProgramState ( program ) , lastMousePos ( 0 ) , isFirstRender ( true )
2010-03-13 22:10:45 +01:00
{
2011-03-28 23:04:47 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-01 18:54:44 +02:00
2011-09-24 23:07:15 +02:00
this - > masterserverMode = masterserverMode ;
2011-09-27 12:16:09 +02:00
if ( this - > masterserverMode = = true ) {
printf ( " Starting a new game... \n " ) ;
}
2010-10-29 18:27:22 +02:00
this - > program = program ;
2010-09-09 03:44:25 +02:00
Unit : : setGame ( this ) ;
2011-01-20 09:19:14 +01:00
gameStarted = false ;
2010-09-09 03:44:25 +02:00
2010-08-25 20:26:17 +02:00
original_updateFps = GameConstants : : updateFps ;
original_cameraFps = GameConstants : : cameraFps ;
2010-08-25 21:21:11 +02:00
GameConstants : : updateFps = 40 ;
GameConstants : : cameraFps = 100 ;
2010-09-07 23:01:22 +02:00
captureAvgTestStatus = false ;
lastRenderLog2d = 0 ;
2010-09-10 14:15:21 +02:00
totalRenderFps = 0 ;
2011-04-05 08:32:23 +02:00
lastMaxUnitCalcTime = 0 ;
2011-07-07 00:02:38 +02:00
renderExtraTeamColor = 0 ;
2010-08-25 20:26:17 +02:00
2010-12-20 21:01:14 +01:00
mouseMoved = false ;
2010-08-04 20:49:11 +02:00
quitTriggeredIndicator = false ;
2010-05-29 08:56:32 +02:00
originalDisplayMsgCallback = NULL ;
thisGamePtr = this ;
2011-09-24 23:07:15 +02:00
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
popupMenuSwitchTeams . setEnabled ( false ) ;
popupMenuSwitchTeams . setVisible ( false ) ;
2011-09-21 08:51:28 +02:00
switchTeamConfirmMessageBox . setEnabled ( false ) ;
exitGamePopupMenuIndex = - 1 ;
joinTeamPopupMenuIndex = - 1 ;
2011-10-03 22:48:09 +02:00
pauseGamePopupMenuIndex = - 1 ;
2011-10-03 02:36:28 +02:00
keyboardSetupPopupMenuIndex = - 1 ;
currentUIState = NULL ;
2011-09-21 08:51:28 +02:00
2010-03-13 22:10:45 +01:00
this - > gameSettings = * gameSettings ;
2010-03-23 03:35:55 +01:00
scrollSpeed = Config : : getInstance ( ) . getFloat ( " UiScrollSpeed " , " 1.5 " ) ;
2010-09-11 18:14:03 +02:00
photoModeEnabled = Config : : getInstance ( ) . getBool ( " PhotoMode " , " false " ) ;
2011-06-10 00:54:45 +02:00
visibleHUD = Config : : getInstance ( ) . getBool ( " VisibleHud " , " true " ) ;
2011-06-21 01:48:22 +02:00
withRainEffect = Config : : getInstance ( ) . getBool ( " RainEffect " , " true " ) ;
2010-06-15 18:27:52 +02:00
//MIN_RENDER_FPS_ALLOWED = Config::getInstance().getInt("MIN_RENDER_FPS_ALLOWED",intToStr(MIN_RENDER_FPS_ALLOWED).c_str());
2010-06-15 07:36:07 +02:00
2010-03-13 22:10:45 +01:00
mouseX = 0 ;
mouseY = 0 ;
mouse2d = 0 ;
loadingText = " " ;
weatherParticleSystem = NULL ;
updateFps = 0 ;
renderFps = 0 ;
lastUpdateFps = 0 ;
2010-06-17 02:08:27 +02:00
lastRenderFps = - 1 ;
2010-08-24 03:21:34 +02:00
avgUpdateFps = - 1 ;
avgRenderFps = - 1 ;
2010-10-02 04:17:50 +02:00
currentAvgRenderFpsTotal = 0 ;
tickCount = 0 ;
2010-03-13 22:10:45 +01:00
paused = false ;
gameOver = false ;
renderNetworkStatus = false ;
speed = sNormal ;
2010-04-14 22:49:14 +02:00
showFullConsole = false ;
2011-04-12 01:26:50 +02:00
camLeftButtonDown = false ;
camRightButtonDown = false ;
camUpButtonDown = false ;
camDownButtonDown = false ;
2010-06-01 18:54:44 +02:00
2011-02-15 05:34:19 +01:00
Object : : setStateCallback ( & gui ) ;
2011-01-11 23:09:46 +01:00
Logger & logger = Logger : : getInstance ( ) ;
logger . showProgress ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
2010-09-12 07:05:08 +02:00
Game : : ~ Game ( ) {
2011-03-28 23:04:47 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-01 18:54:44 +02:00
2011-02-15 05:34:19 +01:00
Object : : setStateCallback ( NULL ) ;
2010-07-06 07:30:34 +02:00
thisGamePtr = NULL ;
if ( originalDisplayMsgCallback ! = NULL ) {
NetworkInterface : : setDisplayMessageFunction ( originalDisplayMsgCallback ) ;
}
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-06 07:30:34 +02:00
2010-03-13 22:10:45 +01:00
Logger & logger = Logger : : getInstance ( ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
2010-12-09 21:41:11 +01:00
2010-04-05 19:43:04 +02:00
logger . loadLoadingScreen ( " " ) ;
2010-03-13 22:10:45 +01:00
logger . setState ( Lang : : getInstance ( ) . get ( " Deleting " ) ) ;
2011-03-30 23:15:20 +02:00
//logger.add("Game", true);
logger . add ( " Game " , false ) ;
2011-01-11 23:09:46 +01:00
logger . hideProgress ( ) ;
2010-03-13 22:10:45 +01:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-07 08:46:55 +02:00
2010-03-13 22:10:45 +01:00
SoundRenderer : : getInstance ( ) . stopAllSounds ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-02 04:50:20 +02:00
2010-03-13 22:10:45 +01:00
deleteValues ( aiInterfaces . begin ( ) , aiInterfaces . end ( ) ) ;
2011-01-11 23:09:46 +01:00
aiInterfaces . clear ( ) ;
2010-03-13 22:10:45 +01:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-01 18:54:44 +02:00
2010-03-13 22:10:45 +01:00
gui . end ( ) ; //selection must be cleared before deleting units
2010-07-02 04:50:20 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-02 04:50:20 +02:00
2010-03-13 22:10:45 +01:00
world . end ( ) ; //must die before selection because of referencers
2010-05-29 08:56:32 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] aiInterfaces.size() = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , aiInterfaces . size ( ) ) ;
2010-08-10 06:56:35 +02:00
2010-08-10 07:03:06 +02:00
// MUST DO THIS LAST!!!! Because objects above have pointers to things like
// unit particles and fade them out etc and this end method deletes the original
// object pointers.
2010-08-10 06:56:35 +02:00
renderer . endGame ( ) ;
2010-08-25 20:26:17 +02:00
GameConstants : : updateFps = original_updateFps ;
GameConstants : : cameraFps = original_cameraFps ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-09 03:44:25 +02:00
Unit : : setGame ( NULL ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ==== END GAME ==== getCurrentPixelByteCount() = %llu \n " , __FILE__ , __FUNCTION__ , __LINE__ , ( long long unsigned int ) renderer . getCurrentPixelByteCount ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " ==== END GAME ==== \n " ) ;
2011-01-02 01:39:13 +01:00
2010-10-29 18:27:22 +02:00
//this->program->reInitGl();
//renderer.reinitAll();
2011-03-28 23:04:47 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
2010-08-04 20:49:11 +02:00
bool Game : : quitTriggered ( ) {
return quitTriggeredIndicator ;
}
2010-08-07 06:49:06 +02:00
Stats Game : : quitAndToggleState ( ) {
//quitGame();
//Program *program = game->getProgram();
return quitGame ( ) ;
//Game::exitGameState(program, endStats);
2010-08-04 20:49:11 +02:00
}
2010-03-13 22:10:45 +01:00
// ==================== init and load ====================
2010-05-29 08:56:32 +02:00
int Game : : ErrorDisplayMessage ( const char * msg , bool exitApp ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg ) ;
2010-05-29 08:56:32 +02:00
if ( thisGamePtr ! = NULL ) {
string text = msg ;
2010-07-01 08:11:14 +02:00
thisGamePtr - > showErrorMessageBox ( text , " Error detected " , false ) ;
2010-05-29 08:56:32 +02:00
}
return 0 ;
}
2011-01-26 10:09:59 +01:00
Texture2D * Game : : findFactionLogoTexture ( const GameSettings * settings , Logger * logger , string factionLogoFilter , bool useTechDefaultIfFilterNotFound ) {
Texture2D * result = NULL ;
string logoFilename = Game : : findFactionLogoFile ( settings , logger , factionLogoFilter ) ;
if ( logoFilename = = " " & & factionLogoFilter ! = " " & & useTechDefaultIfFilterNotFound = = true ) {
logoFilename = Game : : findFactionLogoFile ( settings , logger ) ;
}
result = Renderer : : findFactionLogoTexture ( logoFilename ) ;
return result ;
}
2011-03-31 00:14:51 +02:00
string Game : : extractScenarioLogoFile ( const GameSettings * settings , string & result ,
bool & loadingImageUsed , Logger * logger , string factionLogoFilter ) {
2011-03-22 03:02:54 +01:00
string scenarioDir = " " ;
if ( settings - > getScenarioDir ( ) ! = " " ) {
2010-08-31 08:38:27 +02:00
scenarioDir = settings - > getScenarioDir ( ) ;
if ( EndsWith ( scenarioDir , " .xml " ) = = true ) {
scenarioDir = scenarioDir . erase ( scenarioDir . size ( ) - 4 , 4 ) ;
scenarioDir = scenarioDir . erase ( scenarioDir . size ( ) - settings - > getScenario ( ) . size ( ) , settings - > getScenario ( ) . size ( ) + 1 ) ;
}
2011-03-31 00:14:51 +02:00
//printf("!!! extractScenarioLogoFile scenarioDir [%s] factionLogoFilter [%s]\n",scenarioDir.c_str(),factionLogoFilter.c_str());
2010-08-31 08:38:27 +02:00
vector < string > loadScreenList ;
2010-09-01 08:05:28 +02:00
findAll ( scenarioDir + factionLogoFilter , loadScreenList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( loadScreenList . empty ( ) = = false ) {
2010-08-31 08:38:27 +02:00
string senarioLogo = scenarioDir + loadScreenList [ 0 ] ;
if ( fileExists ( senarioLogo ) = = true ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] found scenario loading screen '%s' \n " , __FILE__ , __FUNCTION__ , senarioLogo . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
result = senarioLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
}
loadingImageUsed = true ;
}
}
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , settings - > getScenarioDir ( ) . c_str ( ) , settings - > getScenario ( ) . c_str ( ) , scenarioDir . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
}
2011-03-22 03:02:54 +01:00
return scenarioDir ;
}
2010-08-31 08:38:27 +02:00
2011-03-31 00:14:51 +02:00
string Game : : extractFactionLogoFile ( bool & loadingImageUsed , string factionName ,
string scenarioDir , string techName , Logger * logger , string factionLogoFilter ) {
2011-03-22 03:02:54 +01:00
string result = " " ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Searching for faction loading screen \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-22 03:02:54 +01:00
if ( factionName = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
const string factionLogo = data_path + " data/core/misc_textures/observer.jpg " ;
//printf("In [%s::%s Line: %d] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,__LINE__,factionLogo.c_str());
if ( fileExists ( factionLogo ) = = true ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
result = factionLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
2010-08-31 08:38:27 +02:00
}
2011-03-22 03:02:54 +01:00
loadingImageUsed = true ;
2010-08-31 08:38:27 +02:00
}
}
2011-03-22 03:02:54 +01:00
//else if(settings->getFactionTypeName(i) == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
else if ( factionName = = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) {
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
const string factionLogo = data_path + " data/core/misc_textures/random.jpg " ;
if ( fileExists ( factionLogo ) = = true ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
result = factionLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
}
loadingImageUsed = true ;
}
}
else {
Config & config = Config : : getInstance ( ) ;
2010-08-31 08:38:27 +02:00
vector < string > pathList = config . getPathListForType ( ptTechs , scenarioDir ) ;
for ( int idx = 0 ; idx < pathList . size ( ) ; idx + + ) {
2011-03-13 09:23:43 +01:00
string currentPath = pathList [ idx ] ;
endPathWithSlash ( currentPath ) ;
2011-03-22 03:02:54 +01:00
//string path = currentPath + techName + "/" + "factions" + "/" + settings->getFactionTypeName(i);
string path = currentPath + techName + " / " + " factions " + " / " + factionName ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] possible loading screen dir '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , path . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
if ( isdir ( path . c_str ( ) ) = = true ) {
2011-03-13 09:23:43 +01:00
endPathWithSlash ( path ) ;
2010-08-31 08:38:27 +02:00
vector < string > loadScreenList ;
2011-03-13 09:23:43 +01:00
findAll ( path + factionLogoFilter , loadScreenList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( loadScreenList . empty ( ) = = false ) {
2011-03-13 09:23:43 +01:00
string factionLogo = path + loadScreenList [ 0 ] ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for loading screen '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
if ( fileExists ( factionLogo ) = = true ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
result = factionLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
}
loadingImageUsed = true ;
break ;
}
}
}
2011-03-22 03:02:54 +01:00
2010-08-31 08:38:27 +02:00
if ( loadingImageUsed = = true ) {
break ;
}
}
}
2011-03-22 03:02:54 +01:00
//break;
//}
//}
return result ;
}
string Game : : extractTechLogoFile ( string scenarioDir , string techName ,
2011-03-31 00:14:51 +02:00
bool & loadingImageUsed , Logger * logger , string factionLogoFilter ) {
2011-03-22 03:02:54 +01:00
string result = " " ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Searching for tech loading screen \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-22 03:02:54 +01:00
Config & config = Config : : getInstance ( ) ;
vector < string > pathList = config . getPathListForType ( ptTechs , scenarioDir ) ;
for ( int idx = 0 ; idx < pathList . size ( ) ; idx + + ) {
string currentPath = pathList [ idx ] ;
endPathWithSlash ( currentPath ) ;
string path = currentPath + techName ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] possible loading screen dir '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , path . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
if ( isdir ( path . c_str ( ) ) = = true ) {
endPathWithSlash ( path ) ;
vector < string > loadScreenList ;
findAll ( path + factionLogoFilter , loadScreenList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( loadScreenList . empty ( ) = = false ) {
2011-03-22 03:02:54 +01:00
string factionLogo = path + loadScreenList [ 0 ] ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for loading screen '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
if ( fileExists ( factionLogo ) = = true ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
result = factionLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
}
loadingImageUsed = true ;
break ;
}
}
}
if ( loadingImageUsed = = true ) {
break ;
}
}
return result ;
}
2011-06-09 02:59:03 +02:00
void Game : : loadHudTexture ( const GameSettings * settings )
{
string factionName = " " ;
string techName = settings - > getTech ( ) ;
string scenarioDir = settings - > getScenarioDir ( ) ;
for ( int i = 0 ; i < settings - > getFactionCount ( ) ; + + i ) {
if ( settings - > getFactionControl ( i ) = = ctHuman ) {
factionName = settings - > getFactionTypeName ( i ) ;
break ;
}
}
if ( factionName ! = " " ) {
Config & config = Config : : getInstance ( ) ;
vector < string > pathList = config . getPathListForType ( ptTechs , scenarioDir ) ;
for ( int idx = 0 ; idx < pathList . size ( ) ; idx + + ) {
string currentPath = pathList [ idx ] ;
endPathWithSlash ( currentPath ) ;
vector < string > hudList ;
string path = currentPath + techName + " / " + " factions " + " / " + factionName ;
endPathWithSlash ( path ) ;
findAll ( path + " hud.* " , hudList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( hudList . empty ( ) = = false ) {
2011-06-09 02:59:03 +02:00
string hudImageFileName = path + hudList [ 0 ] ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled )
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for a HUD '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , hudImageFileName . c_str ( ) ) ;
if ( fileExists ( hudImageFileName ) = = true ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled )
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found HUD image '%s' \n " , __FILE__ , __FUNCTION__ , __LINE__ , hudImageFileName . c_str ( ) ) ;
Texture2D * texture = Renderer : : findFactionLogoTexture ( hudImageFileName ) ;
gui . setHudTexture ( texture ) ;
//printf("Hud texture found! \n");
break ;
}
}
}
}
}
2011-03-31 00:14:51 +02:00
string Game : : findFactionLogoFile ( const GameSettings * settings , Logger * logger ,
string factionLogoFilter ) {
2011-03-22 03:02:54 +01:00
string result = " " ;
if ( settings = = NULL ) {
result = " " ;
}
2011-08-31 21:44:19 +02:00
else {
string mapName = settings - > getMap ( ) ;
string tilesetName = settings - > getTileset ( ) ;
string techName = settings - > getTech ( ) ;
string scenarioName = settings - > getScenario ( ) ;
bool loadingImageUsed = false ;
if ( logger ! = NULL ) {
logger - > setState ( Lang : : getInstance ( ) . get ( " Loading " ) ) ;
if ( scenarioName . empty ( ) ) {
logger - > setSubtitle ( formatString ( mapName ) + " - " +
formatString ( tilesetName ) + " - " + formatString ( techName ) ) ;
}
else {
logger - > setSubtitle ( formatString ( scenarioName ) ) ;
}
2011-03-22 03:02:54 +01:00
}
2011-08-31 21:44:19 +02:00
string scenarioDir = " " ;
bool skipCustomLoadScreen = false ;
if ( skipCustomLoadScreen = = false ) {
scenarioDir = extractScenarioLogoFile ( settings , result , loadingImageUsed ,
logger , factionLogoFilter ) ;
}
// try to use a faction related loading screen
if ( skipCustomLoadScreen = = false & & loadingImageUsed = = false ) {
for ( int i = 0 ; i < settings - > getFactionCount ( ) ; + + i ) {
if ( settings - > getFactionControl ( i ) = = ctHuman | |
( settings - > getFactionControl ( i ) = = ctNetwork & & settings - > getThisFactionIndex ( ) = = i ) ) {
result = extractFactionLogoFile ( loadingImageUsed , settings - > getFactionTypeName ( i ) ,
scenarioDir , techName , logger , factionLogoFilter ) ;
break ;
}
2011-03-22 03:02:54 +01:00
}
}
2011-08-31 21:44:19 +02:00
// try to use a tech related loading screen
if ( skipCustomLoadScreen = = false & & loadingImageUsed = = false ) {
result = extractTechLogoFile ( scenarioDir , techName ,
loadingImageUsed , logger , factionLogoFilter ) ;
}
2011-03-22 03:02:54 +01:00
}
2010-08-31 08:38:27 +02:00
return result ;
}
2011-03-22 03:02:54 +01:00
vector < Texture2D * > Game : : processTech ( string techName ) {
vector < Texture2D * > logoFiles ;
bool enableFactionTexturePreview = Config : : getInstance ( ) . getBool ( " FactionPreview " , " true " ) ;
if ( enableFactionTexturePreview ) {
string currentTechName_factionPreview = techName ;
vector < string > factions ;
vector < string > techPaths = Config : : getInstance ( ) . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
findAll ( techPath + techName + " /factions/*. " , factions , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( factions . empty ( ) = = false ) {
2011-03-22 03:02:54 +01:00
for ( unsigned int factionIdx = 0 ; factionIdx < factions . size ( ) ; + + factionIdx ) {
bool loadingImageUsed = false ;
string factionLogo = " " ;
string currentFactionName_factionPreview = factions [ factionIdx ] ;
factionLogo = Game : : extractFactionLogoFile (
loadingImageUsed ,
currentFactionName_factionPreview ,
" " ,
techName ,
2011-03-31 00:14:51 +02:00
NULL ,
2011-03-22 03:02:54 +01:00
" preview_screen.* " ) ;
if ( factionLogo = = " " ) {
factionLogo = Game : : extractFactionLogoFile (
loadingImageUsed ,
currentFactionName_factionPreview ,
" " ,
techName ,
2011-03-31 00:14:51 +02:00
NULL ,
2011-03-22 03:02:54 +01:00
" loading_screen.* " ) ;
}
if ( factionLogo ! = " " ) {
Texture2D * texture = Renderer : : preloadTexture ( factionLogo ) ;
logoFiles . push_back ( texture ) ;
}
}
}
}
}
return logoFiles ;
}
2010-09-12 07:05:08 +02:00
void Game : : load ( ) {
load ( lgt_All ) ;
}
void Game : : load ( LoadGameItem loadTypes ) {
2011-05-06 09:47:31 +02:00
std : : map < string , vector < pair < string , string > > > loadedFileList ;
2010-05-29 08:56:32 +02:00
originalDisplayMsgCallback = NetworkInterface : : getDisplayMessageFunction ( ) ;
NetworkInterface : : setDisplayMessageFunction ( ErrorDisplayMessage ) ;
2010-05-01 22:14:25 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] loadTypes = %d, gameSettings = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , loadTypes , this - > gameSettings . toString ( ) . c_str ( ) ) ;
2010-06-03 09:52:17 +02:00
2011-01-20 20:56:11 +01:00
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( ) ;
2010-08-31 08:38:27 +02:00
Config & config = Config : : getInstance ( ) ;
2010-03-13 22:10:45 +01:00
Logger & logger = Logger : : getInstance ( ) ;
2010-08-31 08:38:27 +02:00
2010-03-13 22:10:45 +01:00
string mapName = gameSettings . getMap ( ) ;
string tilesetName = gameSettings . getTileset ( ) ;
string techName = gameSettings . getTech ( ) ;
string scenarioName = gameSettings . getScenario ( ) ;
2010-08-31 08:38:27 +02:00
2010-09-12 07:05:08 +02:00
if ( ( loadTypes & lgt_FactionPreview ) = = lgt_FactionPreview ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
Game : : findFactionLogoFile ( & gameSettings , & logger ) ;
2010-03-13 22:10:45 +01:00
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2010-03-13 22:10:45 +01:00
}
2010-06-24 12:52:58 +02:00
2011-06-09 02:59:03 +02:00
loadHudTexture ( & gameSettings ) ;
2010-03-21 06:33:13 +01:00
string scenarioDir = " " ;
2010-09-12 07:05:08 +02:00
if ( gameSettings . getScenarioDir ( ) ! = " " ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-21 06:33:13 +01:00
scenarioDir = gameSettings . getScenarioDir ( ) ;
if ( EndsWith ( scenarioDir , " .xml " ) = = true ) {
scenarioDir = scenarioDir . erase ( scenarioDir . size ( ) - 4 , 4 ) ;
scenarioDir = scenarioDir . erase ( scenarioDir . size ( ) - gameSettings . getScenario ( ) . size ( ) , gameSettings . getScenario ( ) . size ( ) + 1 ) ;
}
}
2010-06-13 02:59:56 +02:00
2010-04-12 22:32:47 +02:00
//throw runtime_error("Test!");
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-03 08:25:54 +02:00
2010-03-13 22:10:45 +01:00
//tileset
2010-09-12 07:05:08 +02:00
if ( ( loadTypes & lgt_TileSet ) = = lgt_TileSet ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
world . loadTileset ( config . getPathListForType ( ptTilesets , scenarioDir ) ,
2011-03-15 16:30:28 +01:00
tilesetName , & checksum , loadedFileList ) ;
2010-09-12 07:05:08 +02:00
}
2010-03-13 22:10:45 +01:00
2010-06-12 20:27:39 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-06-25 07:05:52 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-03 08:25:54 +02:00
2010-09-12 07:05:08 +02:00
set < string > factions ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
2010-03-13 22:10:45 +01:00
for ( int i = 0 ; i < gameSettings . getFactionCount ( ) ; + + i ) {
factions . insert ( gameSettings . getFactionTypeName ( i ) ) ;
}
2010-09-12 07:05:08 +02:00
if ( ( loadTypes & lgt_TechTree ) = = lgt_TechTree ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
//tech, load before map because of resources
world . loadTech ( config . getPathListForType ( ptTechs , scenarioDir ) , techName ,
2011-03-15 16:30:28 +01:00
factions , & checksum , loadedFileList ) ;
2010-09-12 07:05:08 +02:00
// Validate the faction setup to ensure we don't have any bad associations
/*
std : : vector < std : : string > results = world . validateFactionTypes ( ) ;
if ( results . size ( ) > 0 ) {
// Display the validation errors
string errorText = " Errors were detected: \n " ;
for ( int i = 0 ; i < results . size ( ) ; + + i ) {
if ( i > 0 ) {
errorText + = " \n " ;
}
errorText + = results [ i ] ;
2010-07-30 09:51:39 +02:00
}
2010-09-12 07:05:08 +02:00
throw runtime_error ( errorText ) ;
2010-07-30 09:51:39 +02:00
}
2010-09-12 07:05:08 +02:00
*/
}
2010-07-30 09:51:39 +02:00
2010-06-12 20:27:39 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-06-25 07:05:52 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-03 08:25:54 +02:00
2010-03-13 22:10:45 +01:00
//map
2010-09-12 07:05:08 +02:00
if ( ( loadTypes & lgt_Map ) = = lgt_Map ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
world . loadMap ( Map : : getMapPath ( mapName , scenarioDir ) , & checksum ) ;
}
2010-03-13 22:10:45 +01:00
2010-06-12 20:27:39 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-06-25 07:05:52 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-03 08:25:54 +02:00
2010-03-13 22:10:45 +01:00
//scenario
2010-09-12 07:05:08 +02:00
if ( ( loadTypes & lgt_Scenario ) = = lgt_Scenario ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
if ( scenarioName . empty ( ) = = false ) {
Lang : : getInstance ( ) . loadScenarioStrings ( gameSettings . getScenarioDir ( ) , scenarioName ) ;
world . loadScenario ( gameSettings . getScenarioDir ( ) , & checksum ) ;
}
}
2010-04-24 14:22:35 +02:00
2010-06-12 20:27:39 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2010-06-25 07:05:52 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-01 22:14:25 +02:00
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
2010-03-13 22:10:45 +01:00
}
2010-09-12 07:05:08 +02:00
void Game : : init ( ) {
init ( false ) ;
}
void Game : : init ( bool initForPreviewOnly )
2010-03-13 22:10:45 +01:00
{
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] initForPreviewOnly = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , initForPreviewOnly ) ;
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
Logger & logger = Logger : : getInstance ( ) ;
CoreData & coreData = CoreData : : getInstance ( ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
Map * map = world . getMap ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-09-12 07:05:08 +02:00
if ( map = = NULL ) {
throw runtime_error ( " map == NULL " ) ;
}
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
2010-09-12 07:05:08 +02:00
if ( initForPreviewOnly = = false ) {
logger . setState ( lang . get ( " Initializing " ) ) ;
2010-03-13 22:10:45 +01:00
2010-09-12 07:05:08 +02:00
//mesage box
mainMessageBox . init ( lang . get ( " Yes " ) , lang . get ( " No " ) ) ;
mainMessageBox . setEnabled ( false ) ;
2010-07-01 08:11:14 +02:00
2010-09-12 07:05:08 +02:00
//mesage box
errorMessageBox . init ( lang . get ( " Ok " ) ) ;
errorMessageBox . setEnabled ( false ) ;
errorMessageBox . setY ( mainMessageBox . getY ( ) - mainMessageBox . getH ( ) - 10 ) ;
2010-06-12 20:27:39 +02:00
2010-09-12 07:05:08 +02:00
//init world, and place camera
commander . init ( & world ) ;
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
}
2010-06-12 20:27:39 +02:00
2010-03-13 22:10:45 +01:00
world . init ( this , gameSettings . getDefaultUnits ( ) ) ;
2010-06-12 20:27:39 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-12 20:27:39 +02:00
2010-09-12 07:05:08 +02:00
if ( initForPreviewOnly = = false ) {
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2010-09-12 07:05:08 +02:00
gui . init ( this ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
//SDL_PumpEvents();
2010-06-12 20:27:39 +02:00
2010-09-12 07:05:08 +02:00
chatManager . init ( & console , world . getThisTeamIndex ( ) ) ;
console . clearStoredLines ( ) ;
}
2010-06-24 03:23:18 +02:00
2010-03-13 22:10:45 +01:00
gameCamera . init ( map - > getW ( ) , map - > getH ( ) ) ;
2010-06-12 20:27:39 +02:00
2011-02-25 01:31:42 +01:00
// camera default height calculation
if ( map - > getCameraHeight ( ) > 0 & & gameCamera . getCalculatedDefault ( ) < map - > getCameraHeight ( ) ) {
gameCamera . setCalculatedDefault ( map - > getCameraHeight ( ) ) ;
}
else if ( gameCamera . getCalculatedDefault ( ) < map - > getMaxMapHeight ( ) + 13.0f ) {
2011-02-10 01:14:21 +01:00
gameCamera . setCalculatedDefault ( map - > getMaxMapHeight ( ) + 13.0f ) ;
}
2010-09-12 07:05:08 +02:00
if ( world . getThisFaction ( ) ! = NULL ) {
const Vec2i & v = map - > getStartLocation ( world . getThisFaction ( ) - > getStartLocationIndex ( ) ) ;
gameCamera . setPos ( Vec2f ( v . x , v . y ) ) ;
}
2010-06-12 20:27:39 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
2011-10-03 22:48:09 +02:00
NetworkRole role = nrIdle ;
2010-09-12 07:05:08 +02:00
if ( initForPreviewOnly = = false ) {
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2010-04-24 14:22:35 +02:00
2010-09-12 07:05:08 +02:00
scriptManager . init ( & world , & gameCamera ) ;
2010-03-13 22:10:45 +01:00
2010-09-12 07:05:08 +02:00
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] creating AI's \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
2010-09-14 21:10:37 +02:00
//create AIs
bool enableServerControlledAI = this - > gameSettings . getEnableServerControlledAI ( ) ;
bool isNetworkGame = this - > gameSettings . isNetworkGame ( ) ;
2011-10-03 22:48:09 +02:00
role = networkManager . getNetworkRole ( ) ;
2010-09-14 21:10:37 +02:00
2011-01-11 23:09:46 +01:00
deleteValues ( aiInterfaces . begin ( ) , aiInterfaces . end ( ) ) ;
2010-09-12 07:05:08 +02:00
aiInterfaces . resize ( world . getFactionCount ( ) ) ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
2010-09-14 21:10:37 +02:00
if ( faction - > getCpuControl ( enableServerControlledAI , isNetworkGame , role ) = = true ) {
2010-09-12 07:05:08 +02:00
aiInterfaces [ i ] = new AiInterface ( * this , i , faction - > getTeam ( ) ) ;
logger . add ( " Creating AI for faction " + intToStr ( i ) , true ) ;
}
else {
aiInterfaces [ i ] = NULL ;
}
2010-03-13 22:10:45 +01:00
}
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-12 20:27:39 +02:00
2010-09-12 07:05:08 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2011-09-16 02:34:14 +02:00
if ( world . getFactionCount ( ) = = 1 & & world . getFaction ( 0 ) - > getType ( ) - > getPersonalityType ( ) = = fpt_Observer ) {
withRainEffect = false ;
}
2011-06-21 01:48:22 +02:00
if ( withRainEffect ) {
//weather particle systems
if ( world . getTileset ( ) - > getWeather ( ) = = wRainy ) {
logger . add ( " Creating rain particle system " , true ) ;
weatherParticleSystem = new RainParticleSystem ( ) ;
weatherParticleSystem - > setSpeed ( 12.f / GameConstants : : updateFps ) ;
weatherParticleSystem - > setPos ( gameCamera . getPos ( ) ) ;
renderer . manageParticleSystem ( weatherParticleSystem , rsGame ) ;
}
else if ( world . getTileset ( ) - > getWeather ( ) = = wSnowy ) {
logger . add ( " Creating snow particle system " , true ) ;
weatherParticleSystem = new SnowParticleSystem ( 1200 ) ;
weatherParticleSystem - > setSpeed ( 1.5f / GameConstants : : updateFps ) ;
weatherParticleSystem - > setPos ( gameCamera . getPos ( ) ) ;
weatherParticleSystem - > setTexture ( coreData . getSnowTexture ( ) ) ;
renderer . manageParticleSystem ( weatherParticleSystem , rsGame ) ;
}
2010-09-12 07:05:08 +02:00
}
}
2010-03-13 22:10:45 +01:00
//init renderer state
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Initializing renderer \n " , __FILE__ , __FUNCTION__ ) ;
2010-03-13 22:10:45 +01:00
logger . add ( " Initializing renderer " , true ) ;
renderer . initGame ( this ) ;
2010-10-28 02:51:25 +02:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
if ( faction ! = NULL ) {
faction - > deletePixels ( ) ;
}
}
2010-09-12 07:05:08 +02:00
if ( initForPreviewOnly = = false ) {
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
2010-04-24 14:22:35 +02:00
2010-09-12 07:05:08 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2011-01-20 09:19:14 +01:00
Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Waiting for network \n " , __FILE__ , __FUNCTION__ ) ;
2010-09-12 07:05:08 +02:00
logger . add ( " Waiting for network players " , true ) ;
networkManager . getGameNetworkInterface ( ) - > waitUntilReady ( & checksum ) ;
2010-03-13 22:10:45 +01:00
2010-09-12 07:05:08 +02:00
//std::string worldLog = world.DumpWorldToLog(true);
2010-05-20 22:19:34 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Starting music stream \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
logger . add ( " Starting music stream " , true ) ;
2010-06-12 20:27:39 +02:00
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = false ) {
if ( world . getThisFaction ( ) = = NULL ) {
throw runtime_error ( " world.getThisFaction() = = NULL " ) ;
}
if ( world . getThisFaction ( ) - > getType ( ) = = NULL ) {
throw runtime_error ( " world.getThisFaction() - > getType ( ) = = NULL " ) ;
}
//if(world.getThisFaction()->getType()->getMusic() == NULL) {
// throw runtime_error("world.getThisFaction()->getType()->getMusic() == NULL");
//}
2010-09-12 07:05:08 +02:00
}
2010-06-12 20:27:39 +02:00
2011-01-18 05:56:42 +01:00
//sounds
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( ) ;
soundRenderer = SoundRenderer : : getInstance ( ) ;
Tileset * tileset = world . getTileset ( ) ;
AmbientSounds * ambientSounds = tileset - > getAmbientSounds ( ) ;
//rain
if ( tileset - > getWeather ( ) = = wRainy & & ambientSounds - > isEnabledRain ( ) ) {
logger . add ( " Starting ambient stream " , true ) ;
soundRenderer . playAmbient ( ambientSounds - > getRain ( ) ) ;
}
//snow
if ( tileset - > getWeather ( ) = = wSnowy & & ambientSounds - > isEnabledSnow ( ) ) {
logger . add ( " Starting ambient stream " , true ) ;
soundRenderer . playAmbient ( ambientSounds - > getSnow ( ) ) ;
}
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = false ) {
StrSound * gameMusic = world . getThisFaction ( ) - > getType ( ) - > getMusic ( ) ;
soundRenderer . playMusic ( gameMusic ) ;
}
2010-03-13 22:10:45 +01:00
2010-09-12 07:05:08 +02:00
logger . add ( " Launching game " ) ;
}
2010-03-13 22:10:45 +01:00
2011-04-02 23:17:17 +02:00
logger . setCancelLoadingEnabled ( false ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " ================ STARTING GAME ================ \n " ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugPathFinder , " ================ STARTING GAME ================ \n " ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugPathFinder , " PathFinderType: %s \n " , ( getGameSettings ( ) - > getPathFinderType ( ) ? " RoutePlanner " : " PathFinder " ) ) ;
2010-07-01 08:11:14 +02:00
2011-09-21 08:51:28 +02:00
//PopupMenu popupMenu;
std : : vector < string > menuItems ;
menuItems . push_back ( lang . get ( " ExitGame? " ) ) ;
exitGamePopupMenuIndex = menuItems . size ( ) - 1 ;
if ( ( gameSettings . getFlagTypes1 ( ) & ft1_allow_team_switching ) = = ft1_allow_team_switching ) {
menuItems . push_back ( lang . get ( " JoinOtherTeam " ) ) ;
joinTeamPopupMenuIndex = menuItems . size ( ) - 1 ;
}
2011-10-03 22:48:09 +02:00
bool allowAdminMenuItems = false ;
if ( role = = nrServer ) {
allowAdminMenuItems = true ;
}
else if ( role = = nrClient ) {
ClientInterface * clientInterface = dynamic_cast < ClientInterface * > ( networkManager . getClientInterface ( ) ) ;
if ( clientInterface ! = NULL & &
gameSettings . getMasterserver_admin ( ) = = clientInterface - > getSessionKey ( ) ) {
allowAdminMenuItems = true ;
}
}
if ( allowAdminMenuItems = = true ) {
menuItems . push_back ( lang . get ( " PauseResumeGame " ) ) ;
pauseGamePopupMenuIndex = menuItems . size ( ) - 1 ;
}
2011-10-03 02:36:28 +02:00
menuItems . push_back ( lang . get ( " Keyboardsetup " ) ) ;
keyboardSetupPopupMenuIndex = menuItems . size ( ) - 1 ;
menuItems . push_back ( lang . get ( " Cancel " ) ) ;
2011-10-04 02:50:43 +02:00
popupMenu . setW ( 100 ) ;
popupMenu . setH ( 100 ) ;
2011-09-21 08:51:28 +02:00
popupMenu . init ( lang . get ( " GameMenuTitle " ) , menuItems ) ;
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
popupMenuSwitchTeams . setEnabled ( false ) ;
popupMenuSwitchTeams . setVisible ( false ) ;
2011-01-20 09:19:14 +01:00
gameStarted = true ;
2011-09-27 12:16:09 +02:00
if ( this - > masterserverMode = = true ) {
printf ( " New game has started... \n " ) ;
}
2011-01-20 09:19:14 +01:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ==== START GAME ==== getCurrentPixelByteCount() = %llu \n " , __FILE__ , __FUNCTION__ , __LINE__ , ( long long unsigned int ) renderer . getCurrentPixelByteCount ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " ==== START GAME ==== \n " ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== update ====================
//update
2010-09-12 07:05:08 +02:00
void Game : : update ( ) {
2010-05-29 09:58:58 +02:00
try {
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > update ( ) ;
}
2010-06-15 18:27:52 +02:00
Chrono chrono ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2010-05-29 09:58:58 +02:00
// a) Updates non dependent on speed
2010-03-13 22:10:45 +01:00
2011-01-02 01:39:13 +01:00
if ( NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ! = NULL & &
NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) - > getQuit ( ) & &
mainMessageBox . getEnabled ( ) = = false & &
errorMessageBox . getEnabled ( ) = = false ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-01-02 01:39:13 +01:00
quitTriggeredIndicator = true ;
return ;
}
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = false ) {
if ( world . getThisFaction ( ) - > getFirstSwitchTeamVote ( ) ! = NULL ) {
const SwitchTeamVote * vote = world . getThisFaction ( ) - > getFirstSwitchTeamVote ( ) ;
GameSettings * settings = world . getGameSettingsPtr ( ) ;
2011-09-21 10:00:00 +02:00
2011-09-24 23:07:15 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2011-09-21 10:00:00 +02:00
2011-09-24 23:07:15 +02:00
char szBuf [ 1024 ] = " " ;
if ( lang . hasString ( " AllowPlayerJoinTeam " ) = = true ) {
sprintf ( szBuf , lang . get ( " AllowPlayerJoinTeam " ) . c_str ( ) , settings - > getNetworkPlayerName ( vote - > factionIndex ) . c_str ( ) , vote - > oldTeam , vote - > newTeam ) ;
}
else {
sprintf ( szBuf , " Allow player [%s] to join your team \n (changing from team# %d to team# %d)? " , settings - > getNetworkPlayerName ( vote - > factionIndex ) . c_str ( ) , vote - > oldTeam , vote - > newTeam ) ;
}
2011-09-21 08:51:28 +02:00
2011-09-24 23:07:15 +02:00
switchTeamConfirmMessageBox . setText ( szBuf ) ;
switchTeamConfirmMessageBox . init ( lang . get ( " Yes " ) , lang . get ( " No " ) ) ;
switchTeamConfirmMessageBox . setEnabled ( true ) ;
2011-09-21 08:51:28 +02:00
2011-09-24 23:07:15 +02:00
world . getThisFactionPtr ( ) - > setCurrentSwitchTeamVoteFactionIndex ( vote - > factionIndex ) ;
}
2011-09-21 08:51:28 +02:00
}
2010-05-29 09:58:58 +02:00
//misc
updateFps + + ;
mouse2d = ( mouse2d + 1 ) % Renderer : : maxMouse2dAnim ;
2010-03-13 22:10:45 +01:00
2010-05-29 09:58:58 +02:00
//console
console . update ( ) ;
2010-03-13 22:10:45 +01:00
2010-05-29 09:58:58 +02:00
// b) Updates depandant on speed
int updateLoops = getUpdateLoops ( ) ;
2010-03-13 22:10:45 +01:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-06-15 18:27:52 +02:00
2010-06-01 18:54:44 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-10-19 01:09:43 +02:00
bool enableServerControlledAI = this - > gameSettings . getEnableServerControlledAI ( ) ;
bool isNetworkGame = this - > gameSettings . isNetworkGame ( ) ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [before ReplaceDisconnectedNetworkPlayersWithAI] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-11-11 09:02:50 +01:00
2010-10-19 01:09:43 +02:00
// Check to see if we are playing a network game and if any players
// have disconnected?
ReplaceDisconnectedNetworkPlayersWithAI ( isNetworkGame , role ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [after ReplaceDisconnectedNetworkPlayersWithAI] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-11-11 09:02:50 +01:00
2011-10-03 22:48:09 +02:00
if ( updateLoops > 0 ) {
2011-04-10 01:25:18 +02:00
// update the frame based timer in the stats with at least one step
world . getStats ( ) - > addFramesToCalculatePlaytime ( ) ;
2010-11-11 09:02:50 +01:00
2011-10-03 22:48:09 +02:00
//update
for ( int i = 0 ; i < updateLoops ; + + i ) {
chrono . start ( ) ;
//AiInterface
for ( int j = 0 ; j < world . getFactionCount ( ) ; + + j ) {
Faction * faction = world . getFaction ( j ) ;
if ( faction - > getCpuControl ( enableServerControlledAI , isNetworkGame , role ) = = true & &
scriptManager . getPlayerModifiers ( j ) - > getAiEnabled ( ) = = true ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] [i = %d] faction = %d, factionCount = %d, took msecs: %lld [before AI updates] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , j , world . getFactionCount ( ) , chrono . getMillis ( ) ) ;
2010-09-14 21:10:37 +02:00
2011-10-03 22:48:09 +02:00
aiInterfaces [ j ] - > update ( ) ;
2010-11-07 04:27:06 +01:00
2011-10-03 22:48:09 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] [i = %d] faction = %d, factionCount = %d, took msecs: %lld [after AI updates] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , j , world . getFactionCount ( ) , chrono . getMillis ( ) ) ;
}
2010-05-29 09:58:58 +02:00
}
2010-09-14 21:10:37 +02:00
2011-10-03 22:48:09 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [AI updates] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2011-10-03 22:48:09 +02:00
//World
world . update ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [world update i = %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2011-10-03 22:48:09 +02:00
// Commander
//commander.updateNetwork();
commander . signalNetworkUpdate ( this ) ;
2011-01-11 09:45:58 +01:00
2011-10-03 22:48:09 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [commander updateNetwork i = %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2011-10-03 22:48:09 +02:00
//Gui
gui . update ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [gui updating i = %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2011-10-03 22:48:09 +02:00
//Particle systems
if ( weatherParticleSystem ! = NULL ) {
weatherParticleSystem - > setPos ( gameCamera . getPos ( ) ) ;
}
2010-05-29 09:58:58 +02:00
2011-10-03 22:48:09 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [weather particle updating i = %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-08-21 20:50:56 +02:00
2011-10-03 22:48:09 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . updateParticleManager ( rsGame , avgRenderFps ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [particle manager updating i = %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-05-29 09:58:58 +02:00
2011-10-03 22:48:09 +02:00
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
}
}
//else if(role == nrClient) {
else {
commander . signalNetworkUpdate ( this ) ;
2010-03-13 22:10:45 +01:00
}
2010-05-03 08:25:54 +02:00
2010-05-29 09:58:58 +02:00
//call the chat manager
chatManager . updateNetwork ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld [chatManager.updateNetwork] \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-04-24 14:22:35 +02:00
2010-05-29 09:58:58 +02:00
//check for quiting status
2010-07-03 13:07:37 +02:00
if ( NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ! = NULL & &
NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) - > getQuit ( ) & &
2010-07-01 08:11:14 +02:00
mainMessageBox . getEnabled ( ) = = false & &
errorMessageBox . getEnabled ( ) = = false ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-04 20:49:11 +02:00
quitTriggeredIndicator = true ;
2010-08-04 18:56:24 +02:00
return ;
2010-05-29 09:58:58 +02:00
}
2010-03-13 22:10:45 +01:00
2010-05-29 09:58:58 +02:00
//update auto test
if ( Config : : getInstance ( ) . getBool ( " AutoTest " ) ) {
AutoTest : : getInstance ( ) . updateGame ( this ) ;
}
}
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-10-06 22:22:06 +02:00
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2011-01-02 01:39:13 +01:00
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
}
2010-10-19 01:09:43 +02:00
void Game : : ReplaceDisconnectedNetworkPlayersWithAI ( bool isNetworkGame , NetworkRole role ) {
if ( role = = nrServer & & isNetworkGame = = true ) {
Logger & logger = Logger : : getInstance ( ) ;
ServerInterface * server = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
2011-02-15 04:32:14 +01:00
if ( faction - > getFactionDisconnectHandled ( ) = = false & &
( faction - > getControlType ( ) = = ctNetwork | |
2010-10-19 01:09:43 +02:00
faction - > getControlType ( ) = = ctNetworkCpuEasy | |
faction - > getControlType ( ) = = ctNetworkCpu | |
faction - > getControlType ( ) = = ctNetworkCpuUltra | |
2011-02-15 04:32:14 +01:00
faction - > getControlType ( ) = = ctNetworkCpuMega ) ) {
2010-10-22 19:29:23 +02:00
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
2010-10-19 01:09:43 +02:00
if ( aiInterfaces [ i ] = = NULL & & ( slot = = NULL | | slot - > isConnected ( ) = = false ) ) {
2011-02-15 04:32:14 +01:00
faction - > setFactionDisconnectHandled ( true ) ;
2010-10-19 01:09:43 +02:00
char szBuf [ 255 ] = " " ;
2011-02-15 04:32:14 +01:00
if ( faction - > getType ( ) - > getPersonalityType ( ) ! = fpt_Observer ) {
faction - > setControlType ( ctCpu ) ;
aiInterfaces [ i ] = new AiInterface ( * this , i , faction - > getTeam ( ) , faction - > getStartLocationIndex ( ) ) ;
logger . add ( " Creating AI for faction " + intToStr ( i ) , true ) ;
2011-04-05 16:59:48 +02:00
Lang & lang = Lang : : getInstance ( ) ;
string msg = " Player #%d [%s] has disconnected, switching player to AI mode! " ;
if ( lang . hasString ( " GameSwitchPlayerToAI " ) ) {
msg = lang . get ( " GameSwitchPlayerToAI " ) ;
}
sprintf ( szBuf , msg . c_str ( ) , i + 1 , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) ) ;
2011-02-15 04:32:14 +01:00
}
else {
2011-04-05 16:59:48 +02:00
Lang & lang = Lang : : getInstance ( ) ;
string msg = " Player #%d [%s] has disconnected, but player was only an observer! " ;
if ( lang . hasString ( " GameSwitchPlayerObserverToAI " ) ) {
msg = lang . get ( " GameSwitchPlayerObserverToAI " ) ;
}
sprintf ( szBuf , msg . c_str ( ) , i + 1 , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) ) ;
2011-02-15 04:32:14 +01:00
}
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = this - > gameSettings . getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int j = 0 ; j < languageList . size ( ) ; + + j ) {
bool localEcho = ( languageList [ j ] = = lang . getLanguage ( ) ) ;
server - > sendTextMessage ( szBuf , - 1 , localEcho , languageList [ j ] ) ;
}
2010-10-19 01:09:43 +02:00
}
}
}
}
}
2010-03-13 22:10:45 +01:00
void Game : : updateCamera ( ) {
gameCamera . update ( ) ;
}
// ==================== render ====================
//render
2010-05-06 23:29:46 +02:00
void Game : : render ( ) {
2010-06-24 03:23:18 +02:00
// Ensure the camera starts in the right position
if ( isFirstRender = = true ) {
isFirstRender = false ;
2010-06-25 02:45:46 +02:00
gameCamera . resetPosition ( ) ;
this - > restoreToStartXY ( ) ;
2010-06-24 03:23:18 +02:00
}
2011-07-01 04:50:20 +02:00
canRender ( ) ;
incrementFps ( ) ;
2010-05-07 08:46:55 +02:00
renderFps + + ;
2010-09-10 14:15:21 +02:00
totalRenderFps + + ;
2011-09-24 09:46:56 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = false ) {
2011-09-24 09:46:56 +02:00
renderWorker ( ) ;
}
else {
2011-09-24 23:07:15 +02:00
// Titi, uncomment this to watch the game on the masterserver
//renderWorker();
2011-09-24 09:46:56 +02:00
// In masterserver mode quit game if no network players left
ServerInterface * server = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
int connectedClients = 0 ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
if ( slot ! = NULL & & slot - > isConnected ( ) = = true ) {
connectedClients + + ;
}
}
if ( connectedClients = = 0 ) {
quitTriggeredIndicator = true ;
}
}
2010-05-07 08:46:55 +02:00
}
void Game : : renderWorker ( ) {
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
// Renderer &renderer= Renderer::getInstance();
// renderer.clearBuffers();
//
// //3d
// renderer.reset3dMenu();
//
// renderer.clearZBuffer();
// //renderer.loadCameraMatrix(menuBackground.getCamera());
// //renderer.renderMenuBackground(&menuBackground);
// renderer.renderParticleManager(rsMenu);
//
// //2d
// renderer.reset2d();
//
// currentUIState->render();
//
// if(renderer.isMasterserverMode() == false) {
// renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim);
// renderer.renderFPSWhenEnabled(lastFps);
// renderer.swapBuffers();
// }
currentUIState - > render ( ) ;
return ;
}
2010-08-25 09:29:35 +02:00
Chrono chrono ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) chrono . start ( ) ;
2010-05-07 08:46:55 +02:00
2010-06-15 18:27:52 +02:00
render3d ( ) ;
2010-05-03 08:25:54 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %d [render3d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-05-03 08:25:54 +02:00
2010-03-13 22:10:45 +01:00
render2d ( ) ;
2010-05-03 08:25:54 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %d [render2d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-05-03 08:25:54 +02:00
2010-03-13 22:10:45 +01:00
Renderer : : getInstance ( ) . swapBuffers ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %d [swap buffers] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== tick ====================
2010-10-02 04:17:50 +02:00
void Game : : tick ( ) {
2011-07-01 04:50:20 +02:00
ProgramState : : tick ( ) ;
2010-10-02 04:17:50 +02:00
tickCount + + ;
2010-08-24 03:21:34 +02:00
if ( avgUpdateFps = = - 1 ) {
avgUpdateFps = updateFps ;
}
else {
avgUpdateFps = ( avgUpdateFps + updateFps ) / 2 ;
}
2010-10-02 04:17:50 +02:00
currentAvgRenderFpsTotal + = renderFps ;
2010-08-24 03:21:34 +02:00
if ( avgRenderFps = = - 1 ) {
avgRenderFps = renderFps ;
}
2010-10-02 06:29:12 +02:00
// Update the average every x game ticks
const int CHECK_AVG_FPS_EVERY_X_TICKS = 15 ;
if ( tickCount % CHECK_AVG_FPS_EVERY_X_TICKS = = 0 ) {
avgRenderFps = currentAvgRenderFpsTotal / CHECK_AVG_FPS_EVERY_X_TICKS ;
2010-10-02 04:17:50 +02:00
currentAvgRenderFpsTotal = 0 ;
2010-08-24 03:21:34 +02:00
}
2010-08-28 22:52:25 +02:00
if ( captureAvgTestStatus = = true ) {
if ( updateFpsAvgTest = = - 1 ) {
updateFpsAvgTest = updateFps ;
}
else {
updateFpsAvgTest = ( updateFpsAvgTest + updateFps ) / 2 ;
}
if ( renderFpsAvgTest = = - 1 ) {
renderFpsAvgTest = renderFps ;
}
else {
renderFpsAvgTest = ( renderFpsAvgTest + renderFps ) / 2 ;
}
}
2010-03-13 22:10:45 +01:00
lastUpdateFps = updateFps ;
lastRenderFps = renderFps ;
updateFps = 0 ;
renderFps = 0 ;
//Win/lose check
checkWinner ( ) ;
gui . tick ( ) ;
}
// ==================== events ====================
2011-09-21 08:51:28 +02:00
int Game : : getFirstUnusedTeamNumber ( ) {
std : : map < int , bool > uniqueTeamNumbersUsed ;
for ( unsigned int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
uniqueTeamNumbersUsed [ faction - > getTeam ( ) ] = true ;
}
int result = - 1 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
if ( uniqueTeamNumbersUsed . find ( i ) = = uniqueTeamNumbersUsed . end ( ) ) {
result = i ;
break ;
}
}
return result ;
}
2011-01-20 09:19:14 +01:00
void Game : : mouseDownLeft ( int x , int y ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > mouseDownLeft ( x , y ) ;
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
2011-03-31 20:13:02 +02:00
Logger : : getInstance ( ) . handleMouseClick ( x , y ) ;
2011-01-20 09:19:14 +01:00
return ;
}
2010-05-29 09:58:58 +02:00
Map * map = world . getMap ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
bool messageBoxClick = false ;
2011-09-21 08:51:28 +02:00
if ( popupMenu . mouseClick ( x , y ) ) {
std : : pair < int , string > result = popupMenu . mouseClickedMenuItem ( x , y ) ;
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
// Exit game
if ( result . first = = exitGamePopupMenuIndex ) {
showMessageBox ( Lang : : getInstance ( ) . get ( " ExitGame? " ) , " " , true ) ;
}
else if ( result . first = = joinTeamPopupMenuIndex ) {
2011-09-21 10:00:00 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2011-09-21 08:51:28 +02:00
switchTeamIndexMap . clear ( ) ;
std : : map < int , bool > uniqueTeamNumbersUsed ;
std : : vector < string > menuItems ;
for ( unsigned int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
if ( uniqueTeamNumbersUsed . find ( faction - > getTeam ( ) ) = = uniqueTeamNumbersUsed . end ( ) ) {
uniqueTeamNumbersUsed [ faction - > getTeam ( ) ] = true ;
}
if ( world . getThisFaction ( ) - > getIndex ( ) ! = faction - > getIndex ( ) & &
world . getThisFaction ( ) - > getTeam ( ) ! = faction - > getTeam ( ) ) {
char szBuf [ 1024 ] = " " ;
2011-09-21 10:00:00 +02:00
if ( lang . hasString ( " JoinPlayerTeam " ) = = true ) {
sprintf ( szBuf , lang . get ( " JoinPlayerTeam " ) . c_str ( ) , faction - > getIndex ( ) , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) , faction - > getTeam ( ) ) ;
}
else {
sprintf ( szBuf , " Join player #%d - %s on Team: %d " , faction - > getIndex ( ) , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) , faction - > getTeam ( ) ) ;
}
2011-09-21 08:51:28 +02:00
menuItems . push_back ( szBuf ) ;
switchTeamIndexMap [ menuItems . size ( ) - 1 ] = faction - > getTeam ( ) ;
}
}
2011-09-21 10:00:00 +02:00
2011-09-21 08:51:28 +02:00
if ( uniqueTeamNumbersUsed . size ( ) < 8 ) {
2011-09-21 10:00:00 +02:00
menuItems . push_back ( lang . get ( " CreateNewTeam " ) ) ;
2011-09-21 08:51:28 +02:00
switchTeamIndexMap [ menuItems . size ( ) - 1 ] = CREATE_NEW_TEAM ;
}
2011-09-21 10:00:00 +02:00
menuItems . push_back ( lang . get ( " Cancel " ) ) ;
2011-09-21 08:51:28 +02:00
switchTeamIndexMap [ menuItems . size ( ) - 1 ] = CANCEL_SWITCH_TEAM ;
2011-10-04 02:50:43 +02:00
popupMenuSwitchTeams . setW ( 100 ) ;
popupMenuSwitchTeams . setH ( 100 ) ;
2011-09-21 10:00:00 +02:00
popupMenuSwitchTeams . init ( lang . get ( " SwitchTeams " ) , menuItems ) ;
2011-09-21 08:51:28 +02:00
popupMenuSwitchTeams . setEnabled ( true ) ;
popupMenuSwitchTeams . setVisible ( true ) ;
}
2011-10-03 02:36:28 +02:00
else if ( result . first = = keyboardSetupPopupMenuIndex ) {
MainMenu * newMenu = new MainMenu ( program ) ; // open keyboard shortcuts setup screen
currentUIState = newMenu ;
newMenu - > setState ( new MenuStateKeysetup ( program , newMenu , & currentUIState ) ) ; // open keyboard shortcuts setup screen
}
2011-10-03 22:48:09 +02:00
else if ( result . first = = pauseGamePopupMenuIndex ) {
//this->setPaused(!paused);
//printf("popup paused = %d\n",paused);
if ( paused = = false ) {
commander . tryPauseGame ( ) ;
}
else {
commander . tryResumeGame ( ) ;
}
}
2011-09-21 08:51:28 +02:00
}
else if ( popupMenuSwitchTeams . mouseClick ( x , y ) ) {
//popupMenuSwitchTeams
std : : pair < int , string > result = popupMenuSwitchTeams . mouseClickedMenuItem ( x , y ) ;
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
popupMenuSwitchTeams . setEnabled ( false ) ;
popupMenuSwitchTeams . setVisible ( false ) ;
bool isNetworkGame = this - > gameSettings . isNetworkGame ( ) ;
int teamIndex = switchTeamIndexMap [ result . first ] ;
switch ( teamIndex ) {
case CREATE_NEW_TEAM :
{
int newTeam = getFirstUnusedTeamNumber ( ) ;
if ( isNetworkGame = = true ) {
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeam ( faction , newTeam ) ;
}
else {
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeam ( faction , newTeam ) ;
}
}
break ;
case CANCEL_SWITCH_TEAM :
break ;
default :
if ( isNetworkGame = = true ) {
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeam ( faction , teamIndex ) ;
}
else {
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeam ( faction , teamIndex ) ;
}
break ;
}
}
if ( switchTeamConfirmMessageBox . getEnabled ( ) = = true ) {
int button = - 1 ;
if ( switchTeamConfirmMessageBox . mouseClick ( x , y , button ) ) {
switchTeamConfirmMessageBox . setEnabled ( false ) ;
SwitchTeamVote * vote = world . getThisFactionPtr ( ) - > getSwitchTeamVote ( world . getThisFaction ( ) - > getCurrentSwitchTeamVoteFactionIndex ( ) ) ;
vote - > voted = true ;
vote - > allowSwitchTeam = ( button = = 1 ) ;
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeamVote ( faction , vote ) ;
}
}
2010-05-29 09:58:58 +02:00
//scrip message box, only if the exit box is not enabled
2010-07-01 08:11:14 +02:00
if ( mainMessageBox . getEnabled ( ) = = false & &
errorMessageBox . getEnabled ( ) = = false & &
scriptManager . getMessageBox ( ) - > getEnabled ( ) ) {
2010-05-29 09:58:58 +02:00
int button = 1 ;
if ( scriptManager . getMessageBox ( ) - > mouseClick ( x , y , button ) ) {
scriptManager . onMessageBoxOk ( ) ;
messageBoxClick = true ;
}
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:58:58 +02:00
//minimap panel
2010-07-01 08:11:14 +02:00
if ( messageBoxClick = = false ) {
2010-12-18 18:18:36 +01:00
if ( metrics . isInMinimap ( x , y ) ) {
2010-05-29 09:58:58 +02:00
int xm = x - metrics . getMinimapX ( ) ;
int ym = y - metrics . getMinimapY ( ) ;
int xCell = static_cast < int > ( xm * ( static_cast < float > ( map - > getW ( ) ) / metrics . getMinimapW ( ) ) ) ;
int yCell = static_cast < int > ( map - > getH ( ) - ym * ( static_cast < float > ( map - > getH ( ) ) / metrics . getMinimapH ( ) ) ) ;
2010-03-13 22:10:45 +01:00
2011-02-25 23:13:11 +01:00
if ( map - > isInside ( xCell , yCell ) & & map - > isInsideSurface ( map - > toSurfCoords ( Vec2i ( xCell , yCell ) ) ) ) {
2010-12-18 18:18:36 +01:00
if ( gui . isSelectingPos ( ) ) {
gui . mouseDownLeftGraphics ( xCell , yCell , true ) ;
}
else
{
2010-05-29 09:58:58 +02:00
gameCamera . setPos ( Vec2f ( static_cast < float > ( xCell ) , static_cast < float > ( yCell ) ) ) ;
}
2010-03-13 22:10:45 +01:00
}
}
2010-05-29 09:58:58 +02:00
//display panel
2011-04-28 00:35:45 +02:00
else if ( metrics . isInDisplay ( x , y ) & & ! gui . isSelectingPos ( ) ) {
2010-05-29 09:58:58 +02:00
int xd = x - metrics . getDisplayX ( ) ;
int yd = y - metrics . getDisplayY ( ) ;
2011-04-28 00:35:45 +02:00
if ( gui . mouseValid ( xd , yd ) ) {
2010-05-29 09:58:58 +02:00
gui . mouseDownLeftDisplay ( xd , yd ) ;
}
2011-04-28 00:35:45 +02:00
else {
2010-12-18 18:18:36 +01:00
gui . mouseDownLeftGraphics ( x , y , false ) ;
2010-05-29 09:58:58 +02:00
}
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:58:58 +02:00
//graphics panel
2011-04-28 00:35:45 +02:00
else {
2010-12-18 18:18:36 +01:00
gui . mouseDownLeftGraphics ( x , y , false ) ;
2010-03-13 22:10:45 +01:00
}
}
2010-05-29 09:58:58 +02:00
//exit message box, has to be the last thing to do in this function
2010-07-03 13:07:37 +02:00
if ( errorMessageBox . getEnabled ( ) = = true ) {
if ( errorMessageBox . mouseClick ( x , y ) ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-03 13:07:37 +02:00
//close message box
errorMessageBox . setEnabled ( false ) ;
}
}
2010-05-29 09:58:58 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
int button = 1 ;
if ( mainMessageBox . mouseClick ( x , y , button ) ) {
if ( button = = 1 ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-08-04 20:49:11 +02:00
quitTriggeredIndicator = true ;
2010-07-30 00:08:45 +02:00
return ;
2010-05-29 09:58:58 +02:00
}
else {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-29 09:58:58 +02:00
//close message box
mainMessageBox . setEnabled ( false ) ;
}
2010-03-13 22:10:45 +01:00
}
}
}
2010-05-29 09:58:58 +02:00
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-01-20 09:19:14 +01:00
void Game : : mouseDownRight ( int x , int y ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > mouseDownRight ( x , y ) ;
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
2011-03-31 20:13:02 +02:00
Logger : : getInstance ( ) . handleMouseClick ( x , y ) ;
2011-01-20 09:19:14 +01:00
return ;
}
2010-12-18 18:18:36 +01:00
Map * map = world . getMap ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
2010-12-24 09:43:09 +01:00
2010-12-18 18:18:36 +01:00
if ( metrics . isInMinimap ( x , y ) ) {
int xm = x - metrics . getMinimapX ( ) ;
int ym = y - metrics . getMinimapY ( ) ;
int xCell = static_cast < int > ( xm * ( static_cast < float > ( map - > getW ( ) ) / metrics . getMinimapW ( ) ) ) ;
int yCell = static_cast < int > ( map - > getH ( ) - ym * ( static_cast < float > ( map - > getH ( ) ) / metrics . getMinimapH ( ) ) ) ;
2011-02-25 23:13:11 +01:00
if ( map - > isInside ( xCell , yCell ) & & map - > isInsideSurface ( map - > toSurfCoords ( Vec2i ( xCell , yCell ) ) ) ) {
2010-12-18 18:18:36 +01:00
gui . mouseDownRightGraphics ( xCell , yCell , true ) ;
}
}
2011-04-28 00:35:45 +02:00
else {
Vec2i targetPos ;
Vec2i screenPos ( x , y ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . computePosition ( screenPos , targetPos ) ;
if ( renderer . computePosition ( screenPos , targetPos ) = = true & &
map - > isInsideSurface ( map - > toSurfCoords ( targetPos ) ) = = true ) {
gui . mouseDownRightGraphics ( x , y , false ) ;
}
}
2010-05-29 09:58:58 +02:00
}
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] x = %d y = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) , x , y ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-01-20 09:19:14 +01:00
void Game : : mouseUpCenter ( int x , int y ) {
2011-10-03 02:36:28 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2011-09-26 06:26:44 +02:00
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > mouseUpCenter ( x , y ) ;
return ;
}
2011-01-20 09:19:14 +01:00
if ( mouseMoved = = false ) {
gameCamera . resetPosition ( ) ;
}
else {
mouseMoved = false ;
}
2010-12-20 21:01:14 +01:00
}
2011-01-20 09:19:14 +01:00
void Game : : mouseUpLeft ( int x , int y ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > mouseUpLeft ( x , y ) ;
return ;
}
2010-05-29 09:58:58 +02:00
gui . mouseUpLeftGraphics ( x , y ) ;
}
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-01-20 09:19:14 +01:00
void Game : : mouseDoubleClickLeft ( int x , int y ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > mouseDoubleClickLeft ( x , y ) ;
return ;
}
2011-01-20 09:19:14 +01:00
2010-05-29 09:58:58 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
//display panel
2011-02-25 23:13:11 +01:00
if ( metrics . isInDisplay ( x , y ) & & ! gui . isSelectingPos ( ) ) {
2010-05-29 09:58:58 +02:00
int xd = x - metrics . getDisplayX ( ) ;
int yd = y - metrics . getDisplayY ( ) ;
if ( gui . mouseValid ( xd , yd ) ) {
return ;
}
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:58:58 +02:00
//graphics panel
gui . mouseDoubleClickLeftGraphics ( x , y ) ;
}
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-01-20 09:19:14 +01:00
void Game : : mouseMove ( int x , int y , const MouseState * ms ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > mouseMove ( x , y , ms ) ;
return ;
}
2011-01-20 09:19:14 +01:00
2011-09-21 08:51:28 +02:00
popupMenu . mouseMove ( x , y ) ;
popupMenuSwitchTeams . mouseMove ( x , y ) ;
2010-05-29 09:58:58 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
mouseX = x ;
mouseY = y ;
if ( ms - > get ( mbCenter ) ) {
//if (input.isCtrlDown()) {
// float speed = input.isShiftDown() ? 1.f : 0.125f;
// float response = input.isShiftDown() ? 0.1875f : 0.0625f;
// gameCamera.moveForwardH((y - lastMousePos.y) * speed, response);
// gameCamera.moveSideH((x - lastMousePos.x) * speed, response);
//} else
2010-12-20 21:01:14 +01:00
mouseMoved = true ;
2010-05-29 09:58:58 +02:00
{
//float ymult = Config::getInstance().getCameraInvertYAxis() ? -0.2f : 0.2f;
//float xmult = Config::getInstance().getCameraInvertXAxis() ? -0.2f : 0.2f;
float ymult = 0.2f ;
float xmult = 0.2f ;
2010-03-23 03:35:55 +01:00
2011-04-11 02:11:52 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-30 02:25:35 +02:00
2010-05-29 09:58:58 +02:00
gameCamera . transitionVH ( - ( y - lastMousePos . y ) * ymult , ( lastMousePos . x - x ) * xmult ) ;
mouseX = lastMousePos . x ;
mouseY = lastMousePos . y ;
Window : : revertMousePos ( ) ;
2010-03-30 02:25:35 +02:00
2011-04-11 02:11:52 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-05-29 09:58:58 +02:00
return ;
2010-03-27 22:32:33 +01:00
}
2010-05-29 09:58:58 +02:00
}
else {
//main window
2011-04-09 00:49:10 +02:00
//if(Window::isKeyDown() == false)
2011-04-12 01:26:50 +02:00
if ( ! camLeftButtonDown & & ! camRightButtonDown & & ! camUpButtonDown & & ! camDownButtonDown )
2011-04-09 00:49:10 +02:00
{
2011-08-31 02:24:14 +02:00
bool mouseMoveScrollsWorld = Config : : getInstance ( ) . getBool ( " MouseMoveScrollsWorld " , " true " ) ;
if ( mouseMoveScrollsWorld = = true ) {
if ( y < 10 ) {
gameCamera . setMoveZ ( - scrollSpeed ) ;
}
else if ( y > metrics . getVirtualH ( ) - 10 ) {
gameCamera . setMoveZ ( scrollSpeed ) ;
}
else {
gameCamera . setMoveZ ( 0 ) ;
}
2010-05-29 09:58:58 +02:00
2011-08-31 02:24:14 +02:00
if ( x < 10 ) {
gameCamera . setMoveX ( - scrollSpeed ) ;
}
else if ( x > metrics . getVirtualW ( ) - 10 ) {
gameCamera . setMoveX ( scrollSpeed ) ;
}
else {
gameCamera . setMoveX ( 0 ) ;
}
2010-05-29 09:58:58 +02:00
}
2010-03-27 22:32:33 +01:00
}
2010-03-13 22:10:45 +01:00
2011-09-21 08:51:28 +02:00
if ( switchTeamConfirmMessageBox . getEnabled ( ) = = true ) {
switchTeamConfirmMessageBox . mouseMove ( x , y ) ;
}
2010-05-29 09:58:58 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
mainMessageBox . mouseMove ( x , y ) ;
2010-03-27 22:32:33 +01:00
}
2010-07-01 08:11:14 +02:00
if ( errorMessageBox . getEnabled ( ) ) {
errorMessageBox . mouseMove ( x , y ) ;
}
2010-05-29 09:58:58 +02:00
if ( scriptManager . getMessageBox ( ) - > getEnabled ( ) ) {
scriptManager . getMessageBox ( ) - > mouseMove ( x , y ) ;
2010-03-27 22:32:33 +01:00
}
2010-05-29 09:58:58 +02:00
//else if (saveBox) {
// saveBox->mouseMove(x, y);
//} else {
// //graphics
gui . mouseMoveGraphics ( x , y ) ;
//}
}
//display
2011-05-01 22:19:41 +02:00
if ( ! gui . isSelecting ( ) & & ! gui . isSelectingPos ( ) ) {
2010-05-29 09:58:58 +02:00
if ( ! gui . isSelectingPos ( ) ) {
2011-05-01 22:19:41 +02:00
if ( metrics . isInDisplay ( x , y ) ) {
gui . mouseMoveDisplay ( x - metrics . getDisplayX ( ) , y - metrics . getDisplayY ( ) ) ;
}
else {
gui . mouseMoveOutsideDisplay ( ) ;
}
2010-03-27 22:32:33 +01:00
}
2010-03-23 03:35:55 +01:00
}
2010-03-13 22:10:45 +01:00
2010-05-29 09:58:58 +02:00
lastMousePos . x = mouseX ;
lastMousePos . y = mouseY ;
}
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
2010-03-13 22:10:45 +01:00
}
2010-03-23 03:35:55 +01:00
}
2010-03-13 22:10:45 +01:00
2010-03-23 03:35:55 +01:00
void Game : : eventMouseWheel ( int x , int y , int zDelta ) {
2011-10-03 02:36:28 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
if ( currentUIState ! = NULL ) {
currentUIState - > eventMouseWheel ( x , y , zDelta ) ;
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-04-11 02:11:52 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-05-29 09:58:58 +02:00
//gameCamera.transitionXYZ(0.0f, -(float)zDelta / 30.0f, 0.0f);
gameCamera . zoom ( ( float ) zDelta / 60.0f ) ;
//gameCamera.setMoveY(1);
}
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-06-26 03:55:08 +02:00
void Game : : keyDown ( SDL_KeyboardEvent key ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-06-26 03:55:08 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = [%c] [%d] gameStarted [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key . keysym . sym , key . keysym . sym , gameStarted ) ;
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > keyDown ( key ) ;
return ;
}
2010-03-13 22:10:45 +01:00
2010-05-29 09:58:58 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2010-04-06 16:09:42 +02:00
2010-05-29 09:58:58 +02:00
//send key to the chat manager
chatManager . keyDown ( key ) ;
2010-03-13 22:10:45 +01:00
2011-07-04 20:05:02 +02:00
//printf("GAME KEYDOWN #1\n");
2010-09-11 18:14:03 +02:00
if ( chatManager . getEditEnabled ( ) = = false ) {
2011-07-04 20:05:02 +02:00
//printf("GAME KEYDOWN #2\n");
2011-06-26 03:55:08 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = [%d - %c] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key . keysym . sym , key . keysym . sym ) ;
2010-03-13 22:10:45 +01:00
2010-06-12 20:27:39 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2011-03-11 07:34:59 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] key = [%d - %c] pausegame [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key,configKeys.getCharKey("PauseGame"));
2010-06-12 20:27:39 +02:00
2011-06-26 03:55:08 +02:00
//if(key == configKeys.getCharKey("RenderNetworkStatus")) {
2011-07-04 20:05:02 +02:00
if ( isKeyPressed ( configKeys . getSDLKey ( " RenderNetworkStatus " ) , key , false ) = = true ) {
2010-06-15 07:36:07 +02:00
renderNetworkStatus = ! renderNetworkStatus ;
2010-05-29 09:58:58 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ShowFullConsole")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ShowFullConsole " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
showFullConsole = true ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("TogglePhotoMode")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " TogglePhotoMode " ) , key , false ) = = true ) {
2010-09-11 18:14:03 +02:00
photoModeEnabled = ! photoModeEnabled ;
2010-10-30 05:03:44 +02:00
if ( photoModeEnabled = = true & &
this - > gameSettings . isNetworkGame ( ) = = false ) {
gameCamera . setMaxHeight ( PHOTO_MODE_MAXHEIGHT ) ;
}
else if ( photoModeEnabled = = false ) {
gameCamera . setMaxHeight ( - 1 ) ;
}
2010-09-11 18:14:03 +02:00
}
2010-08-28 05:41:17 +02:00
//Toggle music
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ToggleMusic")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ToggleMusic " ) , key , false ) = = true ) {
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = false ) {
Config & config = Config : : getInstance ( ) ;
StrSound * gameMusic = world . getThisFaction ( ) - > getType ( ) - > getMusic ( ) ;
if ( gameMusic ! = NULL ) {
float configVolume = ( config . getInt ( " SoundVolumeMusic " ) / 100.f ) ;
float currentVolume = gameMusic - > getVolume ( ) ;
if ( currentVolume > 0 ) {
gameMusic - > setVolume ( 0 ) ;
console . addLine ( lang . get ( " GameMusic " ) + " " + lang . get ( " Off " ) ) ;
}
else {
//If the config says zero, use the default music volume
gameMusic - > setVolume ( configVolume ? configVolume : 0.9 ) ;
console . addLine ( lang . get ( " GameMusic " ) ) ;
}
2010-08-28 05:41:17 +02:00
}
}
}
2010-05-29 09:58:58 +02:00
//move camera left
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeLeft")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeLeft " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveX ( - 1 ) ;
2011-04-12 01:26:50 +02:00
camLeftButtonDown = true ;
2010-05-29 09:58:58 +02:00
}
//move camera right
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeRight")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeRight " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveX ( 1 ) ;
2011-04-12 01:26:50 +02:00
camRightButtonDown = true ;
2010-05-29 09:58:58 +02:00
}
//move camera up
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeUp")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeUp " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveZ ( 1 ) ;
2011-04-12 01:26:50 +02:00
camUpButtonDown = true ;
2010-05-29 09:58:58 +02:00
}
//move camera down
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeDown")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeDown " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveZ ( - 1 ) ;
2011-04-12 01:26:50 +02:00
camDownButtonDown = true ;
2010-05-29 09:58:58 +02:00
}
//change camera mode
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("FreeCameraMode")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " FreeCameraMode " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . switchState ( ) ;
string stateString = gameCamera . getState ( ) = = GameCamera : : sGame ? lang . get ( " GameCamera " ) : lang . get ( " FreeCamera " ) ;
console . addLine ( lang . get ( " CameraModeSet " ) + " " + stateString ) ;
}
//reset camera mode to normal
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ResetCameraMode")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ResetCameraMode " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . resetPosition ( ) ;
}
//pause
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("PauseGame")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " PauseGame " ) , key , false ) = = true ) {
2011-01-30 00:50:21 +01:00
//printf("Toggle pause paused = %d\n",paused);
setPaused ( ! paused ) ;
2010-03-13 22:10:45 +01:00
}
2011-07-07 00:02:38 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ExtraTeamColorMarker " ) , key , false ) = = true ) {
//printf("Toggle ExtraTeamColorMarker\n");
toggleTeamColorMarker ( ) ;
}
2010-05-29 09:58:58 +02:00
//switch display color
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ChangeFontColor")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ChangeFontColor " ) , key , false ) = = true ) {
2010-05-29 09:58:58 +02:00
gui . switchToNextDisplayColor ( ) ;
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:58:58 +02:00
//increment speed
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("GameSpeedIncrease")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " GameSpeedIncrease " ) , key , false ) = = true ) {
2011-01-30 00:50:21 +01:00
bool speedChangesAllowed = ! NetworkManager : : getInstance ( ) . isNetworkGame ( ) ;
2010-05-29 09:58:58 +02:00
if ( speedChangesAllowed ) {
incSpeed ( ) ;
}
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:58:58 +02:00
//decrement speed
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("GameSpeedDecrease")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " GameSpeedDecrease " ) , key , false ) = = true ) {
2011-01-30 00:50:21 +01:00
bool speedChangesAllowed = ! NetworkManager : : getInstance ( ) . isNetworkGame ( ) ;
2010-05-29 09:58:58 +02:00
if ( speedChangesAllowed ) {
decSpeed ( ) ;
}
}
//exit
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ExitKey")) {
2011-07-04 20:05:02 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ExitKey " ) , key , false ) = = true ) {
2011-09-21 08:51:28 +02:00
//showMessageBox(lang.get("ExitGame?"), "", true);
popupMenu . setEnabled ( ! popupMenu . getEnabled ( ) ) ;
popupMenu . setVisible ( popupMenu . getEnabled ( ) ) ;
2010-05-29 09:58:58 +02:00
}
//group
2010-06-12 20:27:39 +02:00
//else if(key>='0' && key<'0'+Selection::maxGroups){
else {
2011-07-04 20:05:02 +02:00
//printf("GAME KEYDOWN #3\n");
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , key ) ;
2010-03-13 22:10:45 +01:00
2010-06-12 20:27:39 +02:00
for ( int idx = 1 ; idx < = Selection : : maxGroups ; idx + + ) {
string keyName = " GroupUnitsKey " + intToStr ( idx ) ;
2011-06-26 03:55:08 +02:00
//char groupHotKey = configKeys.getCharKey(keyName.c_str());
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] keyName [%s] group index = %d, key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),idx,groupHotKey,groupHotKey);
SDLKey groupHotKey = configKeys . getSDLKey ( keyName . c_str ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] keyName [%s] group index = %d, key = [%c] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , keyName . c_str ( ) , idx , groupHotKey , groupHotKey ) ;
2010-06-13 19:55:39 +02:00
2011-07-04 20:05:02 +02:00
//printf("input.keysym.mod = %d groupHotKey = %d key = %d isgroup = %d\n",key.keysym.mod,groupHotKey,key.keysym.sym,isKeyPressed(groupHotKey,key));
2011-06-26 03:55:08 +02:00
//if(key == groupHotKey) {
if ( isKeyPressed ( groupHotKey , key ) = = true ) {
2011-07-04 20:05:02 +02:00
//printf("GROUP KEY!\n");
2010-06-12 20:27:39 +02:00
//gui.groupKey(key-'0');
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-12 20:27:39 +02:00
gui . groupKey ( idx - 1 ) ;
break ;
}
}
2010-05-29 09:58:58 +02:00
}
2010-04-06 16:09:42 +02:00
2010-05-29 09:58:58 +02:00
//hotkeys
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] gameCamera.getState() = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , gameCamera . getState ( ) ) ;
2010-04-06 16:09:42 +02:00
2010-05-29 09:58:58 +02:00
if ( gameCamera . getState ( ) = = GameCamera : : sGame ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , key ) ;
2010-03-13 22:10:45 +01:00
2010-05-29 09:58:58 +02:00
gui . hotKey ( key ) ;
2010-03-13 22:10:45 +01:00
}
2010-06-12 20:27:39 +02:00
else {
2010-05-29 09:58:58 +02:00
//rotate camera leftt
2011-06-26 03:55:08 +02:00
//if(key == configKeys.getCharKey("CameraRotateLeft")) {
if ( isKeyPressed ( configKeys . getSDLKey ( " CameraRotateLeft " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setRotate ( - 1 ) ;
}
//rotate camera right
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraRotateRight")){
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraRotateRight " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setRotate ( 1 ) ;
}
//camera up
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraRotateUp")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraRotateUp " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveY ( 1 ) ;
}
//camera down
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraRotateDown")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraRotateDown " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveY ( - 1 ) ;
}
2010-03-13 22:10:45 +01:00
}
}
2010-09-11 18:14:03 +02:00
//throw runtime_error("Test Error!");
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:58:58 +02:00
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-06-26 03:55:08 +02:00
void Game : : keyUp ( SDL_KeyboardEvent key ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2010-05-29 09:58:58 +02:00
try {
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > keyUp ( key ) ;
return ;
}
2011-01-20 09:19:14 +01:00
2010-09-11 18:14:03 +02:00
if ( chatManager . getEditEnabled ( ) ) {
2010-05-29 09:58:58 +02:00
//send key to the chat manager
chatManager . keyUp ( key ) ;
}
2010-06-15 07:36:07 +02:00
else {
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2011-06-26 03:55:08 +02:00
//if(key == configKeys.getCharKey("ShowFullConsole")) {
if ( isKeyPressed ( configKeys . getSDLKey ( " ShowFullConsole " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
showFullConsole = false ;
2010-06-15 07:36:07 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraRotateLeft") ||
// key == configKeys.getCharKey("CameraRotateRight")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraRotateLeft " ) , key ) = = true | |
isKeyPressed ( configKeys . getSDLKey ( " CameraRotateRight " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setRotate ( 0 ) ;
2010-06-15 07:36:07 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraRotateDown") ||
// key == configKeys.getCharKey("CameraRotateUp")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraRotateDown " ) , key ) = = true | |
isKeyPressed ( configKeys . getSDLKey ( " CameraRotateUp " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveY ( 0 ) ;
2010-06-15 07:36:07 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeUp")){
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeUp " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveZ ( 0 ) ;
2011-04-12 01:26:50 +02:00
camUpButtonDown = false ;
calcCameraMoveZ ( ) ;
2010-06-15 07:36:07 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeDown")){
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeDown " ) , key ) = = true ) {
2011-04-10 23:38:29 +02:00
gameCamera . setMoveZ ( 0 ) ;
2011-04-12 01:26:50 +02:00
camDownButtonDown = false ;
calcCameraMoveZ ( ) ;
2011-04-10 23:38:29 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeLeft")){
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeLeft " ) , key ) = = true ) {
2011-04-10 23:38:29 +02:00
gameCamera . setMoveX ( 0 ) ;
2011-04-12 01:26:50 +02:00
camLeftButtonDown = false ;
calcCameraMoveX ( ) ;
2011-04-10 23:38:29 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("CameraModeRight")){
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraModeRight " ) , key ) = = true ) {
2010-05-29 09:58:58 +02:00
gameCamera . setMoveX ( 0 ) ;
2011-04-12 01:26:50 +02:00
camRightButtonDown = false ;
calcCameraMoveX ( ) ;
2010-05-29 09:58:58 +02:00
}
2010-03-13 22:10:45 +01:00
}
}
2010-05-29 09:58:58 +02:00
catch ( const exception & ex ) {
2011-04-28 00:35:45 +02:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-05-29 09:58:58 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-07-03 13:07:37 +02:00
if ( networkManager . getGameNetworkInterface ( ) ! = NULL ) {
2011-04-28 00:35:45 +02:00
GameNetworkInterface * networkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
networkInterface - > sendTextMessage ( szBuf , - 1 , true , " " ) ;
sleep ( 10 ) ;
2010-07-03 13:07:37 +02:00
networkManager . getGameNetworkInterface ( ) - > quitGame ( true ) ;
}
2010-05-29 09:58:58 +02:00
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-04-12 01:26:50 +02:00
void Game : : calcCameraMoveX ( ) {
//move camera left
if ( camLeftButtonDown = = true ) {
gameCamera . setMoveX ( - 1 ) ;
}
//move camera right
else if ( camRightButtonDown = = true ) {
gameCamera . setMoveX ( 1 ) ;
}
}
void Game : : calcCameraMoveZ ( ) {
//move camera up
if ( camUpButtonDown = = true ) {
gameCamera . setMoveZ ( 1 ) ;
}
//move camera down
else if ( camDownButtonDown = = true ) {
gameCamera . setMoveZ ( - 1 ) ;
}
}
2011-06-26 03:55:08 +02:00
void Game : : keyPress ( SDL_KeyboardEvent c ) {
2011-09-26 06:26:44 +02:00
if ( this - > masterserverMode = = true ) {
return ;
}
2011-01-20 09:19:14 +01:00
if ( gameStarted = = false ) {
return ;
}
2011-10-03 02:36:28 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > keyPress ( c ) ;
return ;
}
2011-01-20 09:19:14 +01:00
2010-03-13 22:10:45 +01:00
chatManager . keyPress ( c ) ;
}
2010-08-07 06:49:06 +02:00
Stats Game : : quitGame ( ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-24 03:23:18 +02:00
2011-01-02 01:39:13 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled = = true ) {
world . DumpWorldToLog ( ) ;
}
2010-08-06 05:55:17 +02:00
//Stats stats = *(world.getStats());
2010-08-07 06:49:06 +02:00
Stats endStats ;
2010-06-24 03:23:18 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-24 03:23:18 +02:00
2010-08-07 06:49:06 +02:00
endStats = * ( world . getStats ( ) ) ;
2011-09-24 22:22:47 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = true ) {
2011-09-24 22:22:47 +02:00
endStats . setIsMasterserverMode ( true ) ;
}
2010-08-06 05:55:17 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-02 06:18:03 +02:00
NetworkManager : : getInstance ( ) . end ( ) ;
//sleep(0);
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-02 06:18:03 +02:00
2010-08-07 06:49:06 +02:00
//ProgramState *newState = new BattleEnd(program, endStats);
2010-08-06 05:55:17 +02:00
2010-08-07 06:49:06 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//program->setState(newState);
return endStats ;
}
void Game : : exitGameState ( Program * program , Stats & endStats ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-06 05:55:17 +02:00
2010-08-07 06:49:06 +02:00
ProgramState * newState = new BattleEnd ( program , & endStats ) ;
2010-08-06 05:55:17 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-06 05:55:17 +02:00
program - > setState ( newState ) ;
2010-08-07 06:49:06 +02:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== PRIVATE ====================
// ==================== render ====================
void Game : : render3d ( ) {
2010-05-06 23:29:46 +02:00
Chrono chrono ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) chrono . start ( ) ;
2010-05-06 23:29:46 +02:00
2010-03-13 22:10:45 +01:00
Renderer & renderer = Renderer : : getInstance ( ) ;
//init
renderer . reset3d ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [reset3d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-05-06 23:29:46 +02:00
2011-07-24 01:22:30 +02:00
// renderer.computeVisibleQuad();
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [computeVisibleQuad]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
2010-05-06 23:29:46 +02:00
2010-03-13 22:10:45 +01:00
renderer . loadGameCameraMatrix ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [loadGameCameraMatrix] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-05-06 23:29:46 +02:00
2011-07-24 01:22:30 +02:00
renderer . computeVisibleQuad ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [computeVisibleQuad] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
renderer . setupLighting ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [setupLighting] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//shadow map
2010-08-24 04:49:55 +02:00
renderer . renderShadowsToTexture ( avgRenderFps ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderShadowsToTexture] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//clear buffers
renderer . clearBuffers ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d renderFps = %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//surface
2010-10-04 20:31:17 +02:00
renderer . renderSurface ( avgRenderFps ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderSurface] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//selection circles
renderer . renderSelectionEffects ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderSelectionEffects] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2011-07-07 00:02:38 +02:00
// renderTeamColorCircle
if ( ( renderExtraTeamColor & renderTeamColorCircleBit ) > 0 ) {
renderer . renderTeamColorCircle ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
}
2010-03-13 22:10:45 +01:00
//units
2010-10-04 20:31:17 +02:00
renderer . renderUnits ( avgRenderFps ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2011-07-07 00:02:38 +02:00
// renderTeamColorPlane
if ( ( renderExtraTeamColor & renderTeamColorPlaneBit ) > 0 ) {
renderer . renderTeamColorPlane ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
}
2010-03-13 22:10:45 +01:00
//objects
2010-10-04 20:31:17 +02:00
renderer . renderObjects ( avgRenderFps ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//water
renderer . renderWater ( ) ;
renderer . renderWaterEffects ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderWater] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//particles
renderer . renderParticleManager ( rsGame ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderParticleManager] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//mouse 3d
renderer . renderMouse3d ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderMouse3d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2010-09-03 03:50:16 +02:00
2010-10-04 18:43:00 +02:00
renderer . setLastRenderFps ( lastRenderFps ) ;
2010-03-13 22:10:45 +01:00
}
void Game : : render2d ( ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
2011-09-01 01:10:43 +02:00
//Config &config= Config::getInstance();
2010-03-13 22:10:45 +01:00
CoreData & coreData = CoreData : : getInstance ( ) ;
//init
renderer . reset2d ( ) ;
2011-06-09 02:59:03 +02:00
//HUD
2011-06-14 01:28:24 +02:00
if ( visibleHUD = = true & & photoModeEnabled = = false ) {
2011-06-10 00:54:45 +02:00
renderer . renderHud ( ) ;
}
2010-03-13 22:10:45 +01:00
//display
renderer . renderDisplay ( ) ;
//minimap
2010-09-11 18:14:03 +02:00
if ( photoModeEnabled = = false ) {
2010-03-13 22:10:45 +01:00
renderer . renderMinimap ( ) ;
}
//selection
renderer . renderSelectionQuad ( ) ;
2011-09-21 08:51:28 +02:00
if ( switchTeamConfirmMessageBox . getEnabled ( ) = = true ) {
renderer . renderMessageBox ( & switchTeamConfirmMessageBox ) ;
}
2010-03-13 22:10:45 +01:00
//exit message box
2010-09-11 18:14:03 +02:00
if ( errorMessageBox . getEnabled ( ) ) {
2010-07-01 08:11:14 +02:00
renderer . renderMessageBox ( & errorMessageBox ) ;
}
2010-09-11 18:14:03 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
renderer . renderMessageBox ( & mainMessageBox ) ;
}
2010-07-01 08:11:14 +02:00
2010-03-13 22:10:45 +01:00
//script message box
2010-07-01 08:11:14 +02:00
if ( mainMessageBox . getEnabled ( ) = = false & &
errorMessageBox . getEnabled ( ) = = false & &
2010-08-29 00:10:34 +02:00
scriptManager . getMessageBoxEnabled ( ) ) {
2010-03-13 22:10:45 +01:00
renderer . renderMessageBox ( scriptManager . getMessageBox ( ) ) ;
}
//script display text
if ( ! scriptManager . getDisplayText ( ) . empty ( ) & & ! scriptManager . getMessageBoxEnabled ( ) ) {
2010-08-12 00:31:26 +02:00
Vec4f fontColor = getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
2011-06-10 05:09:19 +02:00
if ( Renderer : : renderText3DEnabled = = true ) {
renderer . renderText3D (
scriptManager . getDisplayText ( ) , coreData . getMenuFontNormal3D ( ) ,
Vec3f ( fontColor . x , fontColor . y , fontColor . z ) , 200 , 680 , false ) ;
}
else {
renderer . renderText (
scriptManager . getDisplayText ( ) , coreData . getMenuFontNormal ( ) ,
Vec3f ( fontColor . x , fontColor . y , fontColor . z ) , 200 , 680 , false ) ;
}
2010-03-13 22:10:45 +01:00
}
2011-09-21 08:51:28 +02:00
renderer . renderPopupMenu ( & popupMenu ) ;
renderer . renderPopupMenu ( & popupMenuSwitchTeams ) ;
2010-07-08 10:29:51 +02:00
if ( program ! = NULL ) program - > renderProgramMsgBox ( ) ;
2010-03-13 22:10:45 +01:00
renderer . renderChatManager ( & chatManager ) ;
//debug info
2010-07-06 17:11:10 +02:00
bool perfLogging = false ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true | |
SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true ) {
perfLogging = true ;
}
2010-09-07 23:01:22 +02:00
string str = " " ;
2010-09-03 09:35:16 +02:00
std : : map < int , string > factionDebugInfo ;
2011-04-05 08:32:23 +02:00
world . getStats ( ) - > setWorldTimeElapsed ( world . getTimeFlow ( ) - > getTime ( ) ) ;
if ( difftime ( time ( NULL ) , lastMaxUnitCalcTime ) > = 1 ) {
lastMaxUnitCalcTime = time ( NULL ) ;
int totalUnitcount = 0 ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
totalUnitcount + = faction - > getUnitCount ( ) ;
}
if ( world . getStats ( ) - > getMaxConcurrentUnitCount ( ) < totalUnitcount ) {
world . getStats ( ) - > setMaxConcurrentUnitCount ( totalUnitcount ) ;
}
world . getStats ( ) - > setTotalEndGameConcurrentUnitCount ( totalUnitcount ) ;
2011-04-10 01:25:18 +02:00
world . getStats ( ) - > setFramesPlayed ( world . getFrameCount ( ) ) ;
2011-04-05 08:32:23 +02:00
}
2010-12-09 21:41:11 +01:00
if ( renderer . getShowDebugUI ( ) = = true | |
2010-07-06 17:11:10 +02:00
( perfLogging = = true & & difftime ( time ( NULL ) , lastRenderLog2d ) > = 1 ) ) {
2010-08-24 03:21:34 +02:00
str + = " MouseXY: " + intToStr ( mouseX ) + " , " + intToStr ( mouseY ) + " \n " ;
str + = " PosObjWord: " + intToStr ( gui . getPosObjWorld ( ) . x ) + " , " + intToStr ( gui . getPosObjWorld ( ) . y ) + " \n " ;
str + = " Render FPS: " + intToStr ( lastRenderFps ) + " [ " + intToStr ( avgRenderFps ) + " ] \n " ;
str + = " Update FPS: " + intToStr ( lastUpdateFps ) + " [ " + intToStr ( avgUpdateFps ) + " ] \n " ;
str + = " GameCamera pos: " + floatToStr ( gameCamera . getPos ( ) . x ) + " , " + floatToStr ( gameCamera . getPos ( ) . y ) + " , " + floatToStr ( gameCamera . getPos ( ) . z ) + " \n " ;
2011-04-13 20:45:27 +02:00
//str+= "Cached surfacedata: " + intToStr(renderer.getCachedSurfaceDataSize())+"\n";
2010-12-25 10:15:49 +01:00
str + = " Time: " + floatToStr ( world . getTimeFlow ( ) - > getTime ( ) , 2 ) + " \n " ;
if ( SystemFlags : : getThreadedLoggerRunning ( ) = = true ) {
2011-03-23 03:45:42 +01:00
str + = " Log buffer count: " + intToStr ( SystemFlags : : getLogEntryBufferCount ( ) ) + " \n " ;
2010-12-25 10:15:49 +01:00
}
2011-03-21 00:41:46 +01:00
2011-04-13 20:45:27 +02:00
//str+= "AttackWarningCount: " + intToStr(world.getUnitUpdater()->getAttackWarningCount()) + "\n";
2011-03-23 03:45:42 +01:00
2011-03-21 00:41:46 +01:00
str + = " Map: " + gameSettings . getMap ( ) + " \n " ;
str + = " Tileset: " + gameSettings . getTileset ( ) + " \n " ;
str + = " Techtree: " + gameSettings . getTech ( ) + " \n " ;
2010-08-24 03:21:34 +02:00
str + = " Triangle count: " + intToStr ( renderer . getTriangleCount ( ) ) + " \n " ;
str + = " Vertex count: " + intToStr ( renderer . getPointCount ( ) ) + " \n " ;
str + = " Frame count: " + intToStr ( world . getFrameCount ( ) ) + " \n " ;
2010-03-13 22:10:45 +01:00
//visible quad
Quad2i visibleQuad = renderer . getVisibleQuad ( ) ;
2011-08-30 20:28:30 +02:00
Quad2i visibleQuadCamera = renderer . getVisibleQuadFromCamera ( ) ;
2010-03-13 22:10:45 +01:00
2011-08-30 20:28:30 +02:00
str + = " Visible quad: " ;
2010-03-13 22:10:45 +01:00
for ( int i = 0 ; i < 4 ; + + i ) {
str + = " ( " + intToStr ( visibleQuad . p [ i ] . x ) + " , " + intToStr ( visibleQuad . p [ i ] . y ) + " ) " ;
}
str + = " \n " ;
2011-08-30 20:28:30 +02:00
str + = " Visible quad camera: " ;
for ( int i = 0 ; i < 4 ; + + i ) {
str + = " ( " + intToStr ( visibleQuadCamera . p [ i ] . x ) + " , " + intToStr ( visibleQuadCamera . p [ i ] . y ) + " ) " ;
}
str + = " \n " ;
str + = " Visible quad area: " + floatToStr ( visibleQuad . area ( ) ) + " \n " ;
str + = " Visible quad camera area: " + floatToStr ( visibleQuadCamera . area ( ) ) + " \n " ;
// Rect2i boundingRect= visibleQuad.computeBoundingRect();
// Rect2i scaledRect= boundingRect/Map::cellScale;
// scaledRect.clamp(0, 0, world.getMap()->getSurfaceW()-1, world.getMap()->getSurfaceH()-1);
// renderer.renderText3D("#1", coreData.getMenuFontNormal3D(), Vec3f(1.0f), scaledRect.p[0].x, scaledRect.p[0].y, false);
// renderer.renderText3D("#2", coreData.getMenuFontNormal3D(), Vec3f(1.0f), scaledRect.p[1].x, scaledRect.p[1].y, false);
2010-03-13 22:10:45 +01:00
2011-03-25 11:11:16 +01:00
int totalUnitcount = 0 ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
totalUnitcount + = faction - > getUnitCount ( ) ;
}
2010-09-10 11:09:12 +02:00
VisibleQuadContainerCache & qCache = renderer . getQuadCache ( ) ;
int visibleUnitCount = qCache . visibleQuadUnitList . size ( ) ;
2011-03-25 11:11:16 +01:00
str + = " Visible unit count: " + intToStr ( visibleUnitCount ) + " total: " + intToStr ( totalUnitcount ) + " \n " ;
2010-06-15 18:27:52 +02:00
2010-09-10 11:09:12 +02:00
int visibleObjectCount = qCache . visibleObjectList . size ( ) ;
2010-06-15 18:27:52 +02:00
str + = " Visible object count: " + intToStr ( visibleObjectCount ) + " \n " ;
2010-03-13 22:10:45 +01:00
// resources
2010-09-03 09:35:16 +02:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
2011-03-21 00:41:46 +01:00
string factionInfo = this - > gameSettings . getNetworkPlayerName ( i ) ;
switch ( this - > gameSettings . getFactionControl ( i ) ) {
case ctCpuEasy :
factionInfo + = " CPU Easy " ;
break ;
case ctCpu :
factionInfo + = " CPU Normal " ;
break ;
case ctCpuUltra :
factionInfo + = " CPU Ultra " ;
break ;
case ctCpuMega :
factionInfo + = " CPU Mega " ;
break ;
}
factionInfo + = " [ " + formatString ( this - > gameSettings . getFactionTypeName ( i ) ) +
2010-09-04 02:32:56 +02:00
" team: " + intToStr ( this - > gameSettings . getTeam ( i ) ) + " ] res: " ;
2010-09-03 09:35:16 +02:00
for ( int j = 0 ; j < world . getTechTree ( ) - > getResourceTypeCount ( ) ; + + j ) {
factionInfo + = intToStr ( world . getFaction ( i ) - > getResource ( j ) - > getAmount ( ) ) ;
factionInfo + = " " ;
}
factionDebugInfo [ i ] = factionInfo ;
}
2010-04-15 03:19:00 +02:00
}
2010-03-13 22:10:45 +01:00
2010-07-06 17:11:10 +02:00
if ( renderer . getShowDebugUI ( ) = = true ) {
2010-08-10 23:34:27 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
2011-09-01 01:10:43 +02:00
//int mx= metrics.getMinimapX();
//int my= metrics.getMinimapY();
//int mw= metrics.getMinimapW();
2010-08-10 23:34:27 +02:00
int mh = metrics . getMinimapH ( ) ;
2010-08-10 23:41:07 +02:00
const Vec4f fontColor = getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
2010-08-10 23:34:27 +02:00
2011-06-10 05:09:19 +02:00
if ( Renderer : : renderText3DEnabled = = true ) {
renderer . renderTextShadow3D ( str , coreData . getMenuFontNormal3D ( ) ,
fontColor , 10 , metrics . getVirtualH ( ) - mh - 60 , false ) ;
}
else {
renderer . renderTextShadow ( str , coreData . getMenuFontNormal ( ) ,
fontColor , 10 , metrics . getVirtualH ( ) - mh - 60 , false ) ;
}
2010-05-29 07:41:40 +02:00
2010-09-03 09:35:16 +02:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
string factionInfo = factionDebugInfo [ i ] ;
2010-11-09 10:06:52 +01:00
Vec3f playerColor = world . getFaction ( i ) - > getTexture ( ) - > getPixmapConst ( ) - > getPixel3f ( 0 , 0 ) ;
2010-09-03 09:35:16 +02:00
2011-06-10 05:09:19 +02:00
if ( Renderer : : renderText3DEnabled = = true ) {
renderer . renderText3D ( factionInfo , coreData . getMenuFontBig3D ( ) ,
Vec4f ( playerColor . x , playerColor . y , playerColor . z , 1.0 ) ,
10 , metrics . getVirtualH ( ) - mh - 90 - 280 - ( i * 16 ) , false ) ;
}
else {
renderer . renderText ( factionInfo , coreData . getMenuFontBig ( ) ,
Vec4f ( playerColor . x , playerColor . y , playerColor . z , 1.0 ) ,
10 , metrics . getVirtualH ( ) - mh - 90 - 280 - ( i * 16 ) , false ) ;
}
2010-09-03 09:35:16 +02:00
}
2011-02-06 08:01:54 +01:00
if ( ( renderer . getShowDebugUILevel ( ) & debugui_unit_titles ) = = debugui_unit_titles ) {
if ( renderer . getAllowRenderUnitTitles ( ) = = false ) {
renderer . setAllowRenderUnitTitles ( true ) ;
}
2011-07-01 09:46:18 +02:00
if ( Renderer : : renderText3DEnabled = = true ) {
renderer . renderUnitTitles3D ( coreData . getMenuFontNormal3D ( ) , Vec3f ( 1.0f ) ) ;
}
else {
renderer . renderUnitTitles ( coreData . getMenuFontNormal ( ) , Vec3f ( 1.0f ) ) ;
}
2010-05-29 09:07:46 +02:00
}
2010-03-13 22:10:45 +01:00
}
//network status
2010-07-06 17:11:10 +02:00
if ( renderNetworkStatus = = true ) {
2010-07-03 13:07:37 +02:00
if ( NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ! = NULL ) {
2010-08-10 23:34:27 +02:00
const Metrics & metrics = Metrics : : getInstance ( ) ;
int mx = metrics . getMinimapX ( ) ;
2011-09-01 01:10:43 +02:00
//int my= metrics.getMinimapY();
2010-08-10 23:34:27 +02:00
int mw = metrics . getMinimapW ( ) ;
2011-09-01 01:10:43 +02:00
//int mh= metrics.getMinimapH();
2010-08-10 23:41:07 +02:00
const Vec4f fontColor = getGui ( ) - > getDisplay ( ) - > getColor ( ) ;
2010-08-10 23:34:27 +02:00
2011-06-10 05:09:19 +02:00
if ( Renderer : : renderText3DEnabled = = true ) {
renderer . renderTextShadow3D (
NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) - > getNetworkStatus ( ) ,
coreData . getMenuFontNormal3D ( ) ,
fontColor , mx + mw + 5 , metrics . getVirtualH ( ) - 30 - 20 , false ) ;
}
else {
renderer . renderTextShadow (
NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) - > getNetworkStatus ( ) ,
coreData . getMenuFontNormal ( ) ,
fontColor , mx + mw + 5 , metrics . getVirtualH ( ) - 30 - 20 , false ) ;
}
2010-07-03 13:07:37 +02:00
}
2010-03-13 22:10:45 +01:00
}
//resource info
2010-09-11 18:14:03 +02:00
if ( photoModeEnabled = = false ) {
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = false ) {
renderer . renderResourceStatus ( ) ;
}
2010-04-14 22:49:14 +02:00
renderer . renderConsole ( & console , showFullConsole ) ;
2010-03-13 22:10:45 +01:00
}
//2d mouse
renderer . renderMouse2d ( mouseX , mouseY , mouse2d , gui . isSelectingPos ( ) ? 1.f : 0.f ) ;
2010-04-15 03:19:00 +02:00
2010-07-06 17:11:10 +02:00
if ( perfLogging = = true & & difftime ( time ( NULL ) , lastRenderLog2d ) > = 1 ) {
2010-04-15 03:19:00 +02:00
lastRenderLog2d = time ( NULL ) ;
2010-12-09 21:41:11 +01:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] Statistics: %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , str . c_str ( ) ) ;
2010-04-15 03:19:00 +02:00
}
2010-03-13 22:10:45 +01:00
}
// ==================== misc ====================
2010-12-25 10:15:49 +01:00
void Game : : checkWinner ( ) {
if ( gameOver = = false ) {
if ( gameSettings . getDefaultVictoryConditions ( ) ) {
2010-03-13 22:10:45 +01:00
checkWinnerStandard ( ) ;
}
2010-12-25 10:15:49 +01:00
else {
2010-03-13 22:10:45 +01:00
checkWinnerScripted ( ) ;
}
}
}
2010-12-25 10:15:49 +01:00
void Game : : checkWinnerStandard ( ) {
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = true | | world . getThisFaction ( ) - > getType ( ) - > getPersonalityType ( ) = = fpt_Observer ) {
2010-09-03 09:12:40 +02:00
// lookup int is team #, value is players alive on team
std : : map < int , int > teamsAlive ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
if ( i ! = world . getThisFactionIndex ( ) ) {
if ( hasBuilding ( world . getFaction ( i ) ) ) {
teamsAlive [ world . getFaction ( i ) - > getTeam ( ) ] = teamsAlive [ world . getFaction ( i ) - > getTeam ( ) ] + 1 ;
2010-03-13 22:10:45 +01:00
}
}
}
2010-09-03 09:12:40 +02:00
// did some team win
if ( teamsAlive . size ( ) < = 1 ) {
2010-05-15 20:59:17 +02:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
2010-09-03 09:12:40 +02:00
if ( i ! = world . getThisFactionIndex ( ) & & teamsAlive . find ( world . getFaction ( i ) - > getTeam ( ) ) ! = teamsAlive . end ( ) ) {
2010-03-13 22:10:45 +01:00
world . getStats ( ) - > setVictorious ( i ) ;
}
}
gameOver = true ;
2010-09-30 00:18:08 +02:00
if ( this - > gameSettings . isNetworkGame ( ) = = false | |
this - > gameSettings . getEnableObserverModeAtEndGame ( ) = = true ) {
2010-05-31 12:20:18 +02:00
// Let the happy winner view everything left in the world
2010-07-10 08:14:31 +02:00
// This caused too much LAG for network games
if ( this - > gameSettings . isNetworkGame ( ) = = false ) {
Renderer : : getInstance ( ) . setPhotoMode ( true ) ;
2010-10-30 05:03:44 +02:00
gameCamera . setMaxHeight ( PHOTO_MODE_MAXHEIGHT ) ;
2010-07-10 08:14:31 +02:00
}
// END
2010-05-31 12:20:18 +02:00
}
2010-05-15 20:59:17 +02:00
2010-09-03 09:12:40 +02:00
scriptManager . onGameOver ( true ) ;
2011-09-16 02:34:14 +02:00
if ( world . getFactionCount ( ) = = 1 & & world . getFaction ( 0 ) - > getType ( ) - > getPersonalityType ( ) = = fpt_Observer ) {
//printf("!!!!!!!!!!!!!!!!!!!!");
//gameCamera.setMoveY(100.0);
gameCamera . zoom ( - 300 ) ;
//gameCamera.update();
}
else {
showWinMessageBox ( ) ;
}
2010-03-13 22:10:45 +01:00
}
}
2010-09-03 09:12:40 +02:00
else {
//lose
bool lose = false ;
if ( hasBuilding ( world . getThisFaction ( ) ) = = false ) {
lose = true ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
if ( world . getFaction ( i ) - > getType ( ) - > getPersonalityType ( ) ! = fpt_Observer ) {
if ( world . getFaction ( i ) - > isAlly ( world . getThisFaction ( ) ) = = false ) {
world . getStats ( ) - > setVictorious ( i ) ;
}
}
}
gameOver = true ;
2010-09-30 00:18:08 +02:00
if ( this - > gameSettings . isNetworkGame ( ) = = false | |
this - > gameSettings . getEnableObserverModeAtEndGame ( ) = = true ) {
2010-09-03 09:12:40 +02:00
// Let the poor user watch everything unfold
// This caused too much LAG for network games
if ( this - > gameSettings . isNetworkGame ( ) = = false ) {
Renderer : : getInstance ( ) . setPhotoMode ( true ) ;
2010-10-30 05:03:44 +02:00
gameCamera . setMaxHeight ( PHOTO_MODE_MAXHEIGHT ) ;
2010-09-03 09:12:40 +02:00
}
// END
// but don't let him cheat via teamchat
chatManager . setDisableTeamMode ( true ) ;
}
scriptManager . onGameOver ( ! lose ) ;
showLoseMessageBox ( ) ;
}
//win
if ( lose = = false ) {
bool win = true ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
if ( i ! = world . getThisFactionIndex ( ) ) {
if ( world . getFaction ( i ) - > getType ( ) - > getPersonalityType ( ) ! = fpt_Observer ) {
if ( hasBuilding ( world . getFaction ( i ) ) & & world . getFaction ( i ) - > isAlly ( world . getThisFaction ( ) ) = = false ) {
win = false ;
}
}
}
}
//if win
if ( win ) {
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
if ( world . getFaction ( i ) - > getType ( ) - > getPersonalityType ( ) ! = fpt_Observer ) {
if ( world . getFaction ( i ) - > isAlly ( world . getThisFaction ( ) ) ) {
world . getStats ( ) - > setVictorious ( i ) ;
}
}
}
gameOver = true ;
2010-09-30 00:18:08 +02:00
if ( this - > gameSettings . isNetworkGame ( ) = = false | |
this - > gameSettings . getEnableObserverModeAtEndGame ( ) = = true ) {
2010-09-03 09:12:40 +02:00
// Let the happy winner view everything left in the world
2010-09-30 02:49:57 +02:00
//world.setFogOfWar(false);
2010-09-03 09:12:40 +02:00
// This caused too much LAG for network games
if ( this - > gameSettings . isNetworkGame ( ) = = false ) {
Renderer : : getInstance ( ) . setPhotoMode ( true ) ;
2010-10-30 05:03:44 +02:00
gameCamera . setMaxHeight ( PHOTO_MODE_MAXHEIGHT ) ;
2010-09-03 09:12:40 +02:00
}
// END
}
scriptManager . onGameOver ( win ) ;
showWinMessageBox ( ) ;
}
}
}
2010-03-13 22:10:45 +01:00
}
2010-09-11 18:14:03 +02:00
void Game : : checkWinnerScripted ( ) {
if ( scriptManager . getGameOver ( ) ) {
2010-03-13 22:10:45 +01:00
gameOver = true ;
2010-09-11 18:14:03 +02:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
if ( scriptManager . getPlayerModifiers ( i ) - > getWinner ( ) ) {
2010-03-13 22:10:45 +01:00
world . getStats ( ) - > setVictorious ( i ) ;
}
}
2010-08-29 00:10:34 +02:00
2010-10-04 23:31:53 +02:00
if ( this - > gameSettings . isNetworkGame ( ) = = false | |
this - > gameSettings . getEnableObserverModeAtEndGame ( ) = = true ) {
// Let the happy winner view everything left in the world
//world.setFogOfWar(false);
// This caused too much LAG for network games
if ( this - > gameSettings . isNetworkGame ( ) = = false ) {
Renderer : : getInstance ( ) . setPhotoMode ( true ) ;
2010-10-30 05:03:44 +02:00
gameCamera . setMaxHeight ( PHOTO_MODE_MAXHEIGHT ) ;
2010-10-04 23:31:53 +02:00
}
// END
}
2010-08-29 00:10:34 +02:00
scriptManager . onGameOver ( scriptManager . getPlayerModifiers ( world . getThisFactionIndex ( ) ) - > getWinner ( ) ) ;
2010-03-13 22:10:45 +01:00
if ( scriptManager . getPlayerModifiers ( world . getThisFactionIndex ( ) ) - > getWinner ( ) ) {
showWinMessageBox ( ) ;
}
else {
showLoseMessageBox ( ) ;
}
}
}
2010-12-25 10:15:49 +01:00
bool Game : : hasBuilding ( const Faction * faction ) {
for ( int i = 0 ; i < faction - > getUnitCount ( ) ; + + i ) {
if ( faction - > getUnit ( i ) - > getType ( ) - > hasSkillClass ( scBeBuilt ) ) {
2010-03-13 22:10:45 +01:00
return true ;
}
}
return false ;
}
2010-12-25 10:15:49 +01:00
void Game : : incSpeed ( ) {
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
switch ( speed ) {
case sSlow :
speed = sNormal ;
console . addLine ( lang . get ( " GameSpeedSet " ) + " " + lang . get ( " Normal " ) ) ;
break ;
case sNormal :
speed = sFast ;
console . addLine ( lang . get ( " GameSpeedSet " ) + " " + lang . get ( " Fast " ) ) ;
break ;
default :
break ;
}
}
2010-12-25 10:15:49 +01:00
void Game : : decSpeed ( ) {
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
switch ( speed ) {
case sNormal :
speed = sSlow ;
console . addLine ( lang . get ( " GameSpeedSet " ) + " " + lang . get ( " Slow " ) ) ;
break ;
case sFast :
speed = sNormal ;
console . addLine ( lang . get ( " GameSpeedSet " ) + " " + lang . get ( " Normal " ) ) ;
break ;
default :
break ;
}
}
2011-10-03 22:48:09 +02:00
void Game : : setPaused ( bool value , bool forceAllowPauseStateChange ) {
2011-01-30 00:50:21 +01:00
bool speedChangesAllowed = ! NetworkManager : : getInstance ( ) . isNetworkGame ( ) ;
2011-10-03 22:48:09 +02:00
//printf("Toggle pause value = %d, speedChangesAllowed = %d, forceAllowPauseStateChange = %d\n",value,speedChangesAllowed,forceAllowPauseStateChange);
if ( forceAllowPauseStateChange = = true | | speedChangesAllowed = = true ) {
//printf("setPaused paused = %d, value = %d\n",paused,value);
2011-01-30 00:50:21 +01:00
Lang & lang = Lang : : getInstance ( ) ;
if ( value = = false ) {
console . addLine ( lang . get ( " GameResumed " ) ) ;
paused = false ;
}
else {
console . addLine ( lang . get ( " GamePaused " ) ) ;
paused = true ;
}
2011-10-03 22:48:09 +02:00
//printf("setPaused new paused = %d\n",paused);
2011-01-30 00:50:21 +01:00
}
}
2010-12-25 10:15:49 +01:00
int Game : : getUpdateLoops ( ) {
if ( paused ) {
2010-03-13 22:10:45 +01:00
return 0 ;
}
2010-12-25 10:15:49 +01:00
else if ( speed = = sFast ) {
2010-03-13 22:10:45 +01:00
return Config : : getInstance ( ) . getInt ( " FastSpeedLoops " ) ;
}
2010-12-25 10:15:49 +01:00
else if ( speed = = sSlow ) {
2010-03-13 22:10:45 +01:00
return updateFps % 2 = = 0 ? 1 : 0 ;
}
return 1 ;
}
2010-12-25 10:15:49 +01:00
void Game : : showLoseMessageBox ( ) {
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2010-05-15 20:59:17 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
if ( networkManager . isNetworkGame ( ) = = true & & networkManager . getNetworkRole ( ) = = nrServer ) {
showMessageBox ( lang . get ( " YouLose " ) + " , " + lang . get ( " ExitGameServer? " ) , lang . get ( " BattleOver " ) , false ) ;
}
else {
showMessageBox ( lang . get ( " YouLose " ) + " , " + lang . get ( " ExitGame? " ) , lang . get ( " BattleOver " ) , false ) ;
}
2010-03-13 22:10:45 +01:00
}
2010-07-01 08:11:14 +02:00
void Game : : showWinMessageBox ( ) {
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2010-09-03 09:12:40 +02:00
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = true | | world . getThisFaction ( ) - > getType ( ) - > getPersonalityType ( ) = = fpt_Observer ) {
2010-09-03 09:12:40 +02:00
showMessageBox ( lang . get ( " GameOver " ) + " , " + lang . get ( " ExitGame? " ) , lang . get ( " BattleOver " ) , false ) ;
}
else {
showMessageBox ( lang . get ( " YouWin " ) + " , " + lang . get ( " ExitGame? " ) , lang . get ( " BattleOver " ) , false ) ;
}
2010-03-13 22:10:45 +01:00
}
2010-07-01 08:11:14 +02:00
void Game : : showMessageBox ( const string & text , const string & header , bool toggle ) {
if ( toggle = = false ) {
2010-03-13 22:10:45 +01:00
mainMessageBox . setEnabled ( false ) ;
}
2010-07-01 08:11:14 +02:00
if ( mainMessageBox . getEnabled ( ) = = false ) {
2010-03-13 22:10:45 +01:00
mainMessageBox . setText ( text ) ;
mainMessageBox . setHeader ( header ) ;
mainMessageBox . setEnabled ( true ) ;
}
2010-07-01 08:11:14 +02:00
else {
2010-03-13 22:10:45 +01:00
mainMessageBox . setEnabled ( false ) ;
}
}
2010-07-01 08:11:14 +02:00
void Game : : showErrorMessageBox ( const string & text , const string & header , bool toggle ) {
if ( toggle = = false ) {
errorMessageBox . setEnabled ( false ) ;
}
if ( errorMessageBox . getEnabled ( ) = = false ) {
errorMessageBox . setText ( text ) ;
errorMessageBox . setHeader ( header ) ;
errorMessageBox . setEnabled ( true ) ;
}
else {
errorMessageBox . setEnabled ( false ) ;
}
}
2010-08-28 22:52:25 +02:00
void Game : : startPerformanceTimer ( ) {
captureAvgTestStatus = true ;
updateFpsAvgTest = - 1 ;
renderFpsAvgTest = - 1 ;
}
void Game : : endPerformanceTimer ( ) {
captureAvgTestStatus = false ;
}
Vec2i Game : : getPerformanceTimerResults ( ) {
Vec2i results ( this - > updateFpsAvgTest , this - > renderFpsAvgTest ) ;
return results ;
}
2011-03-28 23:04:47 +02:00
void Game : : consoleAddLine ( string line ) {
console . addLine ( line ) ;
}
2011-07-07 00:02:38 +02:00
void Game : : toggleTeamColorMarker ( ) {
renderExtraTeamColor + + ;
renderExtraTeamColor = renderExtraTeamColor % 4 ;
}
2011-03-28 23:04:47 +02:00
2010-03-13 22:10:45 +01:00
} } //end namespace