2010-03-13 22:10:45 +01:00
// This file is part of Glest (www.glest.org)
//
2011-12-14 08:40:48 +01:00
// Copyright (C) 2001-2008 Martiñ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"
2011-10-03 02:36:28 +02:00
# include "menu_state_keysetup.h"
2012-05-22 08:17:56 +02:00
# include "video_player.h"
2013-05-01 22:56:19 +02:00
# include "compression_utils.h"
2012-05-22 08:17:56 +02:00
2010-03-13 22:10:45 +01:00
# include "leak_dumper.h"
using namespace Shared : : Graphics ;
using namespace Shared : : Util ;
using namespace Shared : : Platform ;
2013-05-01 22:56:19 +02:00
using namespace Shared : : CompressionUtil ;
2010-03-13 22:10:45 +01:00
namespace Glest { namespace Game {
2012-06-09 17:21:18 +02:00
string GameSettings : : playerDisconnectedText = " " ;
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 ;
2012-09-21 07:45:09 +02:00
const int CANCEL_DISCONNECT_PLAYER = - 1 ;
2012-04-04 02:30:16 +02:00
const float Game : : highlightTime = 0.5f ;
2011-10-22 00:42:59 +02:00
int fadeMusicMilliseconds = 3500 ;
2011-10-21 21:52:55 +02:00
2011-11-25 10:12:53 +01:00
// Check every x seconds if we should switch disconnected players to AI
const int NETWORK_PLAYER_CONNECTION_CHECK_SECONDS = 5 ;
2012-01-06 07:55:27 +01:00
int GAME_STATS_DUMP_INTERVAL = 60 * 10 ;
2011-03-22 03:02:54 +01:00
Game : : Game ( ) : ProgramState ( NULL ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-06 22:44:55 +02:00
2011-03-22 03:02:54 +01:00
originalDisplayMsgCallback = NULL ;
aiInterfaces . clear ( ) ;
2012-05-22 08:17:56 +02:00
videoPlayer = NULL ;
playingStaticVideo = false ;
2011-09-01 01:10:43 +02:00
mouse2d = 0 ;
mouseX = 0 ;
mouseY = 0 ;
updateFps = 0 ;
lastUpdateFps = 0 ;
avgUpdateFps = 0 ;
2013-03-25 23:25:57 +01:00
framesToCatchUpAsClient = 0 ;
2013-04-07 17:27:55 +02:00
framesToSlowDownAsClient = 0 ;
2011-09-01 01:10:43 +02:00
totalRenderFps = 0 ;
renderFps = 0 ;
lastRenderFps = 0 ;
avgRenderFps = 0 ;
currentAvgRenderFpsTotal = 0 ;
paused = false ;
2013-03-06 15:29:49 +01:00
pausedForJoinGame = false ;
2013-02-27 07:46:42 +01:00
pauseRequestSent = false ;
resumeRequestSent = false ;
2013-02-19 05:53:24 +01:00
pauseStateChanged = false ;
2011-09-01 01:10:43 +02:00
gameOver = false ;
renderNetworkStatus = false ;
showFullConsole = false ;
2012-07-14 01:19:53 +02:00
setMarker = false ;
2012-07-15 11:50:44 +02:00
cameraDragAllowed = false ;
2011-09-01 01:10:43 +02:00
mouseMoved = false ;
scrollSpeed = 0 ;
camLeftButtonDown = false ;
camRightButtonDown = false ;
camUpButtonDown = false ;
camDownButtonDown = false ;
2013-02-26 21:48:20 +01:00
this - > speed = 1 ;
2011-09-01 01:10:43 +02:00
weatherParticleSystem = NULL ;
isFirstRender = false ;
quitTriggeredIndicator = false ;
2012-10-02 08:20:39 +02:00
quitPendingIndicator = false ;
2011-09-01 01:10:43 +02:00
original_updateFps = 0 ;
original_cameraFps = 0 ;
captureAvgTestStatus = false ;
updateFpsAvgTest = 0 ;
renderFpsAvgTest = 0 ;
renderExtraTeamColor = 0 ;
photoModeEnabled = false ;
visibleHUD = false ;
2012-10-12 00:10:31 +02:00
timeDisplay = false ;
2011-09-01 01:10:43 +02:00
withRainEffect = false ;
program = NULL ;
gameStarted = false ;
2013-03-01 07:52:33 +01:00
this - > initialResumeSpeedLoops = false ;
2011-09-21 08:51:28 +02:00
2012-09-22 22:13:57 +02:00
highlightCellTexture = NULL ;
lastMasterServerGameStatsDump = 0 ;
lastMaxUnitCalcTime = 0 ;
lastRenderLog2d = 0 ;
playerIndexDisconnect = 0 ;
tickCount = 0 ;
2012-09-25 09:05:52 +02:00
currentCameraFollowUnit = NULL ;
2012-09-22 22:13:57 +02:00
2011-09-24 23:07:15 +02:00
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
popupMenuSwitchTeams . setEnabled ( false ) ;
popupMenuSwitchTeams . setVisible ( false ) ;
2012-09-21 07:45:09 +02:00
popupMenuDisconnectPlayer . setEnabled ( false ) ;
popupMenuDisconnectPlayer . setVisible ( false ) ;
2011-09-21 08:51:28 +02:00
switchTeamConfirmMessageBox . setEnabled ( false ) ;
2012-09-21 07:45:09 +02:00
disconnectPlayerConfirmMessageBox . setEnabled ( false ) ;
disconnectPlayerIndexMap . clear ( ) ;
2011-09-21 08:51:28 +02:00
exitGamePopupMenuIndex = - 1 ;
joinTeamPopupMenuIndex = - 1 ;
2011-10-03 22:48:09 +02:00
pauseGamePopupMenuIndex = - 1 ;
2012-04-14 01:13:02 +02:00
saveGamePopupMenuIndex = - 1 ;
loadGamePopupMenuIndex = - 1 ;
2011-10-03 02:36:28 +02:00
keyboardSetupPopupMenuIndex = - 1 ;
2012-09-21 07:45:09 +02:00
disconnectPlayerPopupMenuIndex = - 1 ;
2012-06-12 22:37:00 +02:00
isMarkCellEnabled = false ;
2012-09-20 06:10:34 +02:00
isMarkCellTextEnabled = false ;
2012-06-12 22:37:00 +02:00
markCellTexture = NULL ;
2012-06-13 18:19:44 +02:00
isUnMarkCellEnabled = false ;
unmarkCellTexture = NULL ;
2012-06-12 22:37:00 +02:00
2011-09-24 23:07:15 +02:00
masterserverMode = false ;
2011-10-03 02:36:28 +02:00
currentUIState = NULL ;
2011-10-21 22:57:42 +02:00
currentAmbientSound = NULL ;
2012-01-09 22:08:19 +01:00
//printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound);
2011-10-22 00:42:59 +02:00
2012-03-13 00:08:22 +01:00
loadGameNode = NULL ;
2012-03-20 05:53:26 +01:00
lastworldFrameCountForReplay = - 1 ;
2011-11-25 10:12:53 +01:00
lastNetworkPlayerConnectionCheck = time ( NULL ) ;
2013-02-15 19:25:10 +01:00
inJoinGameLoading = false ;
2012-01-06 07:55:27 +01:00
2013-04-07 17:27:55 +02:00
for ( int i = 0 ; i < GameConstants : : networkSmoothInterval ; i + + ) {
2013-04-10 01:15:48 +02:00
receivedTooEarlyInFrames [ i ] = - 1 ;
framesNeededToWaitForServerMessage [ i ] = - 1 ;
2013-04-07 17:27:55 +02:00
}
2012-03-20 05:53:26 +01:00
2012-01-06 07:55:27 +01:00
fadeMusicMilliseconds = Config : : getInstance ( ) . getInt ( " GameStartStopFadeSoundMilliseconds " , intToStr ( fadeMusicMilliseconds ) . c_str ( ) ) ;
GAME_STATS_DUMP_INTERVAL = Config : : getInstance ( ) . getInt ( " GameStatsDumpIntervalSeconds " , intToStr ( GAME_STATS_DUMP_INTERVAL ) . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
}
2011-10-06 22:44:55 +02:00
void Game : : resetMembers ( ) {
2010-09-09 03:44:25 +02:00
Unit : : setGame ( this ) ;
2011-01-20 09:19:14 +01:00
gameStarted = false ;
2013-03-01 07:52:33 +01:00
this - > initialResumeSpeedLoops = 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 ;
2012-01-06 07:55:27 +01:00
lastMasterServerGameStatsDump = 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 ;
2012-10-02 08:20:39 +02:00
quitPendingIndicator = 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 ) ;
2012-09-21 07:45:09 +02:00
popupMenuDisconnectPlayer . setEnabled ( false ) ;
popupMenuDisconnectPlayer . setVisible ( false ) ;
2011-09-21 08:51:28 +02:00
switchTeamConfirmMessageBox . setEnabled ( false ) ;
2012-09-21 07:45:09 +02:00
disconnectPlayerConfirmMessageBox . setEnabled ( false ) ;
disconnectPlayerIndexMap . clear ( ) ;
2011-09-21 08:51:28 +02:00
exitGamePopupMenuIndex = - 1 ;
joinTeamPopupMenuIndex = - 1 ;
2011-10-03 22:48:09 +02:00
pauseGamePopupMenuIndex = - 1 ;
2012-04-14 01:13:02 +02:00
saveGamePopupMenuIndex = - 1 ;
loadGamePopupMenuIndex = - 1 ;
2011-10-03 02:36:28 +02:00
keyboardSetupPopupMenuIndex = - 1 ;
2012-09-21 07:45:09 +02:00
disconnectPlayerPopupMenuIndex = - 1 ;
2012-06-12 22:37:00 +02:00
isMarkCellEnabled = false ;
2012-09-20 06:10:34 +02:00
isMarkCellTextEnabled = false ;
2012-06-12 22:37:00 +02:00
markCellTexture = NULL ;
2012-06-13 18:19:44 +02:00
isUnMarkCellEnabled = false ;
unmarkCellTexture = NULL ;
2012-06-12 22:37:00 +02:00
2011-10-03 02:36:28 +02:00
currentUIState = NULL ;
2011-09-21 08:51:28 +02:00
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 " ) ;
2012-10-12 00:10:31 +02:00
timeDisplay = Config : : getInstance ( ) . getBool ( " TimeDisplay " , " 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 ;
2013-03-25 23:25:57 +01:00
framesToCatchUpAsClient = 0 ;
2013-04-07 17:27:55 +02:00
framesToSlowDownAsClient = 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 ;
2013-03-06 15:29:49 +01:00
pausedForJoinGame = false ;
2013-02-27 07:46:42 +01:00
resumeRequestSent = false ;
pauseRequestSent = false ;
2013-02-19 05:53:24 +01:00
pauseStateChanged = false ;
2010-03-13 22:10:45 +01:00
gameOver = false ;
renderNetworkStatus = false ;
2013-02-26 21:48:20 +01:00
this - > speed = 1 ;
2010-04-14 22:49:14 +02:00
showFullConsole = false ;
2012-07-14 01:19:53 +02:00
setMarker = false ;
2011-10-21 22:57:42 +02:00
camLeftButtonDown = false ;
camRightButtonDown = false ;
camUpButtonDown = false ;
camDownButtonDown = false ;
2012-09-25 09:05:52 +02:00
currentCameraFollowUnit = NULL ;
2011-10-21 22:57:42 +02:00
currentAmbientSound = NULL ;
2012-01-09 22:08:19 +01:00
//printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound);
2010-06-01 18:54:44 +02:00
2012-03-13 00:08:22 +01:00
loadGameNode = NULL ;
2012-03-20 05:53:26 +01:00
lastworldFrameCountForReplay = - 1 ;
2012-03-13 00:08:22 +01:00
2011-11-25 10:12:53 +01:00
lastNetworkPlayerConnectionCheck = time ( NULL ) ;
2011-10-22 00:42:59 +02:00
2013-02-15 19:25:10 +01:00
inJoinGameLoading = false ;
2013-04-07 17:27:55 +02:00
for ( int i = 0 ; i < GameConstants : : networkSmoothInterval ; i + + ) {
2013-04-10 01:15:48 +02:00
receivedTooEarlyInFrames [ i ] = - 1 ;
framesNeededToWaitForServerMessage [ i ] = - 1 ;
2013-04-07 17:27:55 +02:00
}
2012-01-06 07:55:27 +01:00
fadeMusicMilliseconds = Config : : getInstance ( ) . getInt ( " GameStartStopFadeSoundMilliseconds " , intToStr ( fadeMusicMilliseconds ) . c_str ( ) ) ;
GAME_STATS_DUMP_INTERVAL = Config : : getInstance ( ) . getInt ( " GameStatsDumpIntervalSeconds " , intToStr ( GAME_STATS_DUMP_INTERVAL ) . c_str ( ) ) ;
2011-01-11 23:09:46 +01:00
Logger & logger = Logger : : getInstance ( ) ;
logger . showProgress ( ) ;
2011-10-06 22:44:55 +02:00
}
Game : : Game ( Program * program , const GameSettings * gameSettings , bool masterserverMode ) :
ProgramState ( program ) , lastMousePos ( 0 ) , isFirstRender ( true )
{
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-06 22:44:55 +02:00
this - > masterserverMode = masterserverMode ;
2012-05-22 08:17:56 +02:00
videoPlayer = NULL ;
playingStaticVideo = false ;
2011-10-06 22:44:55 +02:00
if ( this - > masterserverMode = = true ) {
printf ( " Starting a new game... \n " ) ;
}
this - > program = program ;
resetMembers ( ) ;
this - > gameSettings = * gameSettings ;
2011-01-11 23:09:46 +01:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
2011-10-21 21:52:55 +02:00
void Game : : endGame ( ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
2011-10-23 02:55:34 +02:00
quitGame ( ) ;
2011-10-21 21:52:55 +02:00
Object : : setStateCallback ( NULL ) ;
thisGamePtr = NULL ;
if ( originalDisplayMsgCallback ! = NULL ) {
NetworkInterface : : setDisplayMessageFunction ( originalDisplayMsgCallback ) ;
}
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
Logger & logger = Logger : : getInstance ( ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
2012-06-19 02:32:39 +02:00
logger . clearHints ( ) ;
2011-10-21 21:52:55 +02:00
logger . loadLoadingScreen ( " " ) ;
logger . setState ( Lang : : getInstance ( ) . get ( " Deleting " ) ) ;
//logger.add("Game", true);
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoading " , " " , true ) , false ) ;
2011-10-21 21:52:55 +02:00
logger . hideProgress ( ) ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
// Cannot Fade because sound files will be deleted below
SoundRenderer : : getInstance ( ) . stopAllSounds ( fadeMusicMilliseconds ) ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
// deleteValues(aiInterfaces.begin(), aiInterfaces.end());
// aiInterfaces.clear();
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
2011-10-22 21:45:05 +02:00
gui . end ( ) ; //selection must be cleared before deleting units
2011-10-21 21:52:55 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
// world.end(); //must die before selection because of referencers
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] aiInterfaces.size() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , aiInterfaces . size ( ) ) ;
2011-10-21 21:52:55 +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.
2011-10-22 21:45:05 +02:00
renderer . endGame ( false ) ;
2011-10-21 21:52:55 +02:00
GameConstants : : updateFps = original_updateFps ;
GameConstants : : cameraFps = original_cameraFps ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
Unit : : setGame ( NULL ) ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ==== END GAME ==== getCurrentPixelByteCount() = %llu \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ( long long unsigned int ) renderer . getCurrentPixelByteCount ( ) ) ;
2011-10-21 21:52:55 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " ==== END GAME ==== \n " ) ;
//this->program->reInitGl();
//renderer.reinitAll();
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-21 21:52:55 +02:00
}
2010-09-12 07:05:08 +02:00
Game : : ~ Game ( ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-06-01 18:54:44 +02:00
2011-10-23 02:55:34 +02:00
quitGame ( ) ;
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 ) ;
}
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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);
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoading " , " " , true ) , false ) ;
2011-01-11 23:09:46 +01:00
logger . hideProgress ( ) ;
2010-03-13 22:10:45 +01:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-05-07 08:46:55 +02:00
2011-10-21 21:52:55 +02:00
// Cannot Fade because sound files will be deleted below
2010-03-13 22:10:45 +01:00
SoundRenderer : : getInstance ( ) . stopAllSounds ( ) ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-02 04:50:20 +02:00
2013-01-10 22:16:28 +01:00
masterController . clearSlaves ( true ) ;
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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2013-01-23 22:03:00 +01:00
BaseColorPickEntity : : resetUniqueColors ( ) ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] aiInterfaces.size() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , aiInterfaces . size ( ) ) ;
2010-08-10 06:56:35 +02:00
2012-05-22 08:17:56 +02:00
delete videoPlayer ;
videoPlayer = NULL ;
playingStaticVideo = false ;
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.
2011-10-22 21:45:05 +02:00
renderer . endGame ( true ) ;
2010-08-10 06:56:35 +02:00
2010-08-25 20:26:17 +02:00
GameConstants : : updateFps = original_updateFps ;
GameConstants : : cameraFps = original_cameraFps ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-09-09 03:44:25 +02:00
Unit : : setGame ( NULL ) ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ==== END GAME ==== getCurrentPixelByteCount() = %llu \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ( long long unsigned int ) renderer . getCurrentPixelByteCount ( ) ) ;
2011-03-28 05:54:23 +02:00
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();
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ;
}
2012-09-25 09:05:52 +02:00
result = Renderer : : findTexture ( logoFilename ) ;
2011-01-26 10:09:59 +01:00
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 ;
2013-02-12 00:52:44 +01:00
string logoFullPathFilter = scenarioDir + factionLogoFilter ;
findAll ( logoFullPathFilter , loadScreenList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( loadScreenList . empty ( ) = = false ) {
2013-02-12 00:52:44 +01:00
int bestLogoIndex = 0 ;
if ( loadScreenList . size ( ) > 1 & & EndsWith ( factionLogoFilter , " .xml " ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Looking for best logo from a list of: " MG_SIZE_T_SPECIFIER " using filter: [%s] \n " , loadScreenList . size ( ) , logoFullPathFilter . c_str ( ) ) ;
int bestMinWidthDiff = INT_MAX ;
int bestMinHeightDiff = INT_MAX ;
// Now find the best texture for our screen
// Texture2D *result = preloadTexture(logoFilename);
for ( unsigned int logoIndex = 0 ; logoIndex < loadScreenList . size ( ) ; + + logoIndex ) {
string senarioLogo = scenarioDir + loadScreenList [ bestLogoIndex ] ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , senarioLogo . c_str ( ) ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Looking for best logo: %u [%s] \n " , logoIndex , senarioLogo . c_str ( ) ) ;
if ( fileExists ( senarioLogo ) = = true ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , senarioLogo . c_str ( ) ) ;
Texture2D * checkLogo = Renderer : : preloadTexture ( senarioLogo ) ;
if ( checkLogo ! = NULL ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
int minWidthDifference = abs ( metrics . getScreenW ( ) - checkLogo - > getPixmapConst ( ) - > getW ( ) ) ;
int minHeightDifference = abs ( metrics . getScreenH ( ) - checkLogo - > getPixmapConst ( ) - > getH ( ) ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Logo info: %d x %d (%d,%d) \n " , checkLogo - > getPixmapConst ( ) - > getW ( ) , checkLogo - > getPixmapConst ( ) - > getH ( ) , minWidthDifference , minHeightDifference ) ;
if ( minWidthDifference < bestMinWidthDiff ) {
bestMinWidthDiff = minWidthDifference ;
bestLogoIndex = logoIndex ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #1 New best logo is [%s] \n " , senarioLogo . c_str ( ) ) ;
}
else if ( minWidthDifference = = bestMinWidthDiff & &
minHeightDifference < bestMinHeightDiff ) {
bestMinHeightDiff = minHeightDifference ;
bestLogoIndex = logoIndex ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #2 New best logo is [%s] \n " , senarioLogo . c_str ( ) ) ;
}
}
}
}
}
string senarioLogo = scenarioDir + loadScreenList [ bestLogoIndex ] ;
2010-08-31 08:38:27 +02:00
if ( fileExists ( senarioLogo ) = = true ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] found scenario loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , senarioLogo . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
result = senarioLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
}
loadingImageUsed = true ;
}
}
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 = " " ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Searching for faction loading screen \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 " ;
2012-01-09 22:08:19 +01:00
//printf("In [%s::%s Line: %d] looking for loading screen '%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,factionLogo.c_str());
2011-03-22 03:02:54 +01:00
if ( fileExists ( factionLogo ) = = true ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] possible loading screen dir '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ;
2013-02-12 00:43:30 +01:00
string logoFullPathFilter = path + factionLogoFilter ;
findAll ( logoFullPathFilter , loadScreenList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( loadScreenList . empty ( ) = = false ) {
2013-02-12 00:43:30 +01:00
int bestLogoIndex = 0 ;
if ( loadScreenList . size ( ) > 1 & & EndsWith ( factionLogoFilter , " .xml " ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n Looking for best logo from a list of: " MG_SIZE_T_SPECIFIER " using filter: [%s] \n " , loadScreenList . size ( ) , logoFullPathFilter . c_str ( ) ) ;
int bestMinWidthDiff = INT_MAX ;
int bestMinHeightDiff = INT_MAX ;
// Now find the best texture for our screen
// Texture2D *result = preloadTexture(logoFilename);
for ( unsigned int logoIndex = 0 ; logoIndex < loadScreenList . size ( ) ; + + logoIndex ) {
string factionLogo = path + loadScreenList [ logoIndex ] ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Looking for best logo: %u [%s] \n " , logoIndex , factionLogo . c_str ( ) ) ;
if ( fileExists ( factionLogo ) = = true ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
Texture2D * checkLogo = Renderer : : preloadTexture ( factionLogo ) ;
if ( checkLogo ! = NULL ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
int minWidthDifference = abs ( metrics . getScreenW ( ) - checkLogo - > getPixmapConst ( ) - > getW ( ) ) ;
int minHeightDifference = abs ( metrics . getScreenH ( ) - checkLogo - > getPixmapConst ( ) - > getH ( ) ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Logo info: %d x %d (%d,%d) \n " , checkLogo - > getPixmapConst ( ) - > getW ( ) , checkLogo - > getPixmapConst ( ) - > getH ( ) , minWidthDifference , minHeightDifference ) ;
if ( minWidthDifference < bestMinWidthDiff ) {
bestMinWidthDiff = minWidthDifference ;
bestLogoIndex = logoIndex ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #1 New best logo is [%s] \n " , factionLogo . c_str ( ) ) ;
}
else if ( minWidthDifference = = bestMinWidthDiff & &
minHeightDifference < bestMinHeightDiff ) {
bestMinHeightDiff = minHeightDifference ;
bestLogoIndex = logoIndex ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #2 New best logo is [%s] \n " , factionLogo . c_str ( ) ) ;
}
}
}
}
}
string factionLogo = path + loadScreenList [ bestLogoIndex ] ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
if ( fileExists ( factionLogo ) = = true ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2010-08-31 08:38:27 +02:00
result = factionLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
}
loadingImageUsed = true ;
break ;
}
}
2012-08-10 22:06:41 +02:00
// Check if this is a linked faction
else {
//!!!
string factionXMLFile = path + factionName + " .xml " ;
//printf("A factionXMLFile [%s]\n",factionXMLFile.c_str());
if ( fileExists ( factionXMLFile ) = = true ) {
XmlTree xmlTreeFaction ( XML_RAPIDXML_ENGINE ) ;
std : : map < string , string > mapExtraTagReplacementValues ;
xmlTreeFaction . load ( factionXMLFile , Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) , true , true ) ;
const XmlNode * rootNode = xmlTreeFaction . getRootNode ( ) ;
//printf("B factionXMLFile [%s] root name [%s] root first child name [%s]\n",factionXMLFile.c_str(),rootNode->getName().c_str(),rootNode->getChild(0)->getName().c_str());
//printf("B factionXMLFile [%s] root name [%s]\n",factionXMLFile.c_str(),rootNode->getName().c_str());
if ( rootNode - > hasChild ( " link " ) = = true ) {
rootNode = rootNode - > getChild ( " link " ) ;
}
if ( rootNode - > getName ( ) = = " link " & & rootNode - > hasChild ( " techtree " ) = = true ) {
const XmlNode * linkNode = rootNode ;
//printf("C factionXMLFile [%s]\n",factionXMLFile.c_str());
//if(linkNode->hasChild("techtree") == true) {
const XmlNode * techtreeNode = linkNode - > getChild ( " techtree " ) ;
string linkedTechTreeName = techtreeNode - > getAttribute ( " name " ) - > getValue ( ) ;
//printf("D factionXMLFile [%s] linkedTechTreeName [%s]\n",factionXMLFile.c_str(),linkedTechTreeName.c_str());
if ( linkedTechTreeName ! = " " ) {
2012-10-16 21:07:50 +02:00
string linkedTechTreePath = TechTree : : findPath ( linkedTechTreeName , pathList ) ;
string techTreePath = linkedTechTreePath ;
endPathWithSlash ( techTreePath ) ;
string linkedCurrentPath = techTreePath + " factions/ " + factionName ;
endPathWithSlash ( linkedCurrentPath ) ;
2012-10-18 10:16:47 +02:00
//string linkedTmppath= linkedCurrentPath + factionName +".xml";
2012-10-16 21:07:50 +02:00
path = linkedCurrentPath ;
2012-08-10 22:06:41 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] possible loading screen dir '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , path . c_str ( ) ) ;
2012-10-16 21:07:50 +02:00
//printf("D1 idx = %d\ncurrentPath [%s]\npath [%s]\npathList[idx] [%s]\n",idx,currentPath.c_str(),path.c_str(),pathList[idx].c_str());
2012-08-10 22:06:41 +02:00
if ( isdir ( path . c_str ( ) ) = = true ) {
endPathWithSlash ( path ) ;
//printf("E path [%s]\n",path.c_str());
loadScreenList . clear ( ) ;
findAll ( path + factionLogoFilter , loadScreenList , false , false ) ;
if ( loadScreenList . empty ( ) = = false ) {
string factionLogo = path + loadScreenList [ 0 ] ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
//printf("F factionLogo [%s]\n",factionLogo.c_str());
if ( fileExists ( factionLogo ) = = true ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
result = factionLogo ;
if ( logger ! = NULL ) {
logger - > loadLoadingScreen ( result ) ;
}
loadingImageUsed = true ;
break ;
}
}
}
}
//}
}
}
}
2010-08-31 08:38:27 +02:00
}
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 = " " ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Searching for tech loading screen \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] possible loading screen dir '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ] ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionLogo . c_str ( ) ) ;
2011-03-22 03:02:54 +01:00
if ( fileExists ( factionLogo ) = = true ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found loading screen '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ( ) ;
2012-01-04 05:10:11 +01:00
string scenarioDir = extractDirectoryPathFromFile ( settings - > getScenarioDir ( ) ) ;
//printf("In loadHudTexture, scenarioDir [%s]\n",scenarioDir.c_str());
2011-06-09 02:59:03 +02:00
for ( int i = 0 ; i < settings - > getFactionCount ( ) ; + + i ) {
2012-05-06 23:19:31 +02:00
if ( ( settings - > getFactionControl ( i ) = = ctHuman ) | | ( settings - > getFactionControl ( i ) = = ctNetwork
& & settings - > getThisFactionIndex ( ) = = i ) ) {
2011-06-09 02:59:03 +02:00
factionName = settings - > getFactionTypeName ( i ) ;
break ;
}
}
2012-01-04 05:10:11 +01:00
if ( factionName ! = " " ) {
2012-03-03 08:48:05 +01:00
bool hudFound = false ;
2011-06-09 02:59:03 +02:00
Config & config = Config : : getInstance ( ) ;
vector < string > pathList = config . getPathListForType ( ptTechs , scenarioDir ) ;
2012-03-03 08:48:05 +01:00
for ( int idx = 0 ; hudFound = = false & & idx < pathList . size ( ) ; idx + + ) {
2011-06-09 02:59:03 +02:00
string currentPath = pathList [ idx ] ;
endPathWithSlash ( currentPath ) ;
vector < string > hudList ;
string path = currentPath + techName + " / " + " factions " + " / " + factionName ;
endPathWithSlash ( path ) ;
2013-02-12 00:43:30 +01:00
findAll ( path + GameConstants : : HUD_SCREEN_FILE_FILTER , hudList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( hudList . empty ( ) = = false ) {
2012-03-03 08:48:05 +01:00
for ( unsigned int hudIdx = 0 ; hudFound = = false & & hudIdx < hudList . size ( ) ; + + hudIdx ) {
string hudImageFileName = path + hudList [ hudIdx ] ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] looking for a HUD [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , hudImageFileName . c_str ( ) ) ;
2011-06-09 02:59:03 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled )
2012-03-03 08:48:05 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] looking for a HUD [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , hudImageFileName . c_str ( ) ) ;
2011-06-09 02:59:03 +02:00
2012-03-03 08:48:05 +01:00
if ( fileExists ( hudImageFileName ) = = true ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] found HUD image [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , hudImageFileName . c_str ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled )
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] found HUD image [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , hudImageFileName . c_str ( ) ) ;
2012-09-25 09:05:52 +02:00
Texture2D * texture = Renderer : : findTexture ( hudImageFileName ) ;
2012-03-03 08:48:05 +01:00
gui . setHudTexture ( texture ) ;
hudFound = true ;
//printf("Hud texture found! \n");
break ;
}
2011-06-09 02:59:03 +02:00
}
}
}
}
}
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 ) {
2012-10-06 09:06:40 +02:00
//string currentTechName_factionPreview = techName;
2011-03-22 03:02:54 +01:00
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 currentFactionName_factionPreview = factions [ factionIdx ] ;
2012-10-06 09:06:40 +02:00
string factionLogo = Game : : extractFactionLogoFile (
2011-03-22 03:02:54 +01:00
loadingImageUsed ,
currentFactionName_factionPreview ,
" " ,
techName ,
2011-03-31 00:14:51 +02:00
NULL ,
2013-02-12 00:43:30 +01:00
GameConstants : : PREVIEW_SCREEN_FILE_FILTER ) ;
2011-03-22 03:02:54 +01:00
if ( factionLogo = = " " ) {
factionLogo = Game : : extractFactionLogoFile (
loadingImageUsed ,
currentFactionName_factionPreview ,
" " ,
techName ,
2011-03-31 00:14:51 +02:00
NULL ,
2013-02-12 00:43:30 +01:00
GameConstants : : LOADING_SCREEN_FILE_FILTER ) ;
2011-03-22 03:02:54 +01:00
}
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 ) ;
}
2011-10-06 20:04:59 +02:00
void Game : : load ( int loadTypes ) {
2013-02-24 01:28:45 +01:00
bool showPerfStats = Config : : getInstance ( ) . getBool ( " ShowPerfStats " , " false " ) ;
Chrono chronoPerf ;
if ( showPerfStats ) chronoPerf . start ( ) ;
char perfBuf [ 8096 ] = " " ;
std : : vector < string > perfList ;
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] loadTypes = %d, gameSettings = [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ( ) ;
2011-10-21 21:52:55 +02:00
soundRenderer . stopAllSounds ( fadeMusicMilliseconds ) ;
2011-01-20 20:56:11 +01:00
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 ( ) ;
2012-06-18 00:52:30 +02:00
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
// loadHints
2013-02-24 01:28:45 +01:00
if ( data_path ! = " " ) {
endPathWithSlash ( data_path ) ;
}
2012-10-22 07:08:52 +02:00
2013-02-24 01:28:45 +01:00
string user_data_path = config . getString ( " UserData_Root " , " " ) ;
if ( user_data_path ! = " " ) {
endPathWithSlash ( user_data_path ) ;
}
2012-06-19 02:32:39 +02:00
2013-02-24 01:28:45 +01:00
string englishFile = getGameCustomCoreDataPath ( data_path , " data/lang/hint/hint_ " + Lang : : getInstance ( ) . getDefaultLanguage ( ) + " .lng " ) ;
string languageFile = getGameCustomCoreDataPath ( data_path , " data/lang/hint/hint_ " + Lang : : getInstance ( ) . getLanguage ( ) + " .lng " ) ;
string languageFileUserData = user_data_path + " data/lang/hint/hint_ " + Lang : : getInstance ( ) . getLanguage ( ) + " .lng " ;
2012-06-19 02:32:39 +02:00
2013-02-24 01:28:45 +01:00
if ( fileExists ( languageFileUserData ) = = true ) {
languageFile = languageFileUserData ;
}
if ( fileExists ( languageFile ) = = false ) {
// if there is no language specific file use english instead
languageFile = englishFile ;
}
if ( fileExists ( englishFile ) = = false ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] file [%s] not found \n " , __FILE__ , __FUNCTION__ , __LINE__ , englishFile . c_str ( ) ) ;
}
else {
logger . loadGameHints ( englishFile , languageFile , true ) ;
}
2010-08-31 08:38:27 +02:00
2010-09-12 07:05:08 +02:00
if ( ( loadTypes & lgt_FactionPreview ) = = lgt_FactionPreview ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
Game : : findFactionLogoFile ( & gameSettings , & logger ) ;
2010-03-13 22:10:45 +01:00
2012-09-22 22:13:57 +02:00
Shared : : Platform : : 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
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-06-18 00:52:30 +02:00
2011-06-09 02:59:03 +02:00
loadHudTexture ( & gameSettings ) ;
2012-06-12 22:37:00 +02:00
const string markCellTextureFilename = data_path + " data/core/misc_textures/mark_cell.png " ;
2012-09-25 09:05:52 +02:00
markCellTexture = Renderer : : findTexture ( markCellTextureFilename ) ;
2012-06-13 18:19:44 +02:00
const string unmarkCellTextureFilename = data_path + " data/core/misc_textures/unmark_cell.png " ;
2012-09-25 09:05:52 +02:00
unmarkCellTexture = Renderer : : findTexture ( unmarkCellTextureFilename ) ;
2012-07-13 23:50:34 +02:00
const string highlightCellTextureFilename = data_path + " data/core/misc_textures/pointer.png " ;
2012-09-25 09:05:52 +02:00
highlightCellTexture = Renderer : : findTexture ( highlightCellTextureFilename ) ;
2012-06-12 22:37:00 +02:00
2010-03-21 06:33:13 +01:00
string scenarioDir = " " ;
2010-09-12 07:05:08 +02:00
if ( gameSettings . getScenarioDir ( ) ! = " " ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error("Test!");
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-06-12 20:27:39 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2010-06-25 07:05:52 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-05-03 08:25:54 +02:00
2010-09-12 07:05:08 +02:00
set < string > factions ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ) ;
}
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-09-12 07:05:08 +02:00
if ( ( loadTypes & lgt_TechTree ) = = lgt_TechTree ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
}
2012-04-14 23:21:09 +02:00
throw megaglest_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
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-06-12 20:27:39 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2010-06-25 07:05:52 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-06-12 20:27:39 +02:00
// give CPU time to update other things to avoid apperance of hanging
sleep ( 0 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2010-06-25 07:05:52 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-09-12 07:05:08 +02:00
if ( scenarioName . empty ( ) = = false ) {
2013-05-21 22:28:42 +02:00
bool isTutorial = Scenario : : isGameTutorial ( gameSettings . getScenarioDir ( ) ) ;
//printf("Loading scenario gameSettings.getScenarioDir() [%s] scenarioName [%s] isTutorial: %d\n",gameSettings.getScenarioDir().c_str(),scenarioName.c_str(),isTutorial);
Lang : : getInstance ( ) . loadScenarioStrings ( gameSettings . getScenarioDir ( ) , scenarioName , isTutorial ) ;
2012-03-26 08:48:58 +02:00
//printf("In [%s::%s Line: %d] rootNode [%p][%s]\n",__FILE__,__FUNCTION__,__LINE__,loadGameNode,(loadGameNode != NULL ? loadGameNode->getName().c_str() : "none"));
world . loadScenario ( gameSettings . getScenarioDir ( ) , & checksum , false , loadGameNode ) ;
2010-09-12 07:05:08 +02:00
}
}
2010-04-24 14:22:35 +02:00
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
//good_fpu_control_registers(NULL,extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2013-02-24 01:28:45 +01:00
if ( showPerfStats & & chronoPerf . getMillis ( ) > = 50 ) {
for ( unsigned int x = 0 ; x < perfList . size ( ) ; + + x ) {
printf ( " %s " , perfList [ x ] . c_str ( ) ) ;
}
}
2010-03-13 22:10:45 +01:00
}
2010-09-12 07:05:08 +02:00
void Game : : init ( ) {
init ( false ) ;
}
2011-10-06 20:04:59 +02:00
void Game : : init ( bool initForPreviewOnly ) {
2013-02-24 01:28:45 +01:00
bool showPerfStats = Config : : getInstance ( ) . getBool ( " ShowPerfStats " , " false " ) ;
Chrono chronoPerf ;
if ( showPerfStats ) chronoPerf . start ( ) ;
char perfBuf [ 8096 ] = " " ;
std : : vector < string > perfList ;
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] initForPreviewOnly = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ( ) ;
2012-06-12 01:50:30 +02:00
GameSettings : : playerDisconnectedText = " * " + lang . get ( " AI " ) + " * " ;
2012-06-09 17:21:18 +02:00
2010-09-12 07:05:08 +02:00
if ( map = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " map == NULL " ) ;
2010-09-12 07:05:08 +02:00
}
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
}
2010-06-12 20:27:39 +02:00
2012-07-18 01:04:30 +02:00
try {
world . init ( this , gameSettings . getDefaultUnits ( ) ) ;
}
2012-07-21 01:51:10 +02:00
catch ( const megaglest_runtime_error & ex ) {
string sErrBuf = " " ;
if ( ex . wantStackTrace ( ) = = true ) {
char szErrBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szErrBuf , 8096 , " In [%s::%s %d] " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-07-21 01:51:10 +02:00
sErrBuf = string ( szErrBuf ) + string ( " \n error [ " ) + string ( ex . what ( ) ) + string ( " ] \n " ) ;
}
else {
sErrBuf = ex . what ( ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugError , sErrBuf . c_str ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , sErrBuf . c_str ( ) ) ;
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
}
2012-07-18 01:04:30 +02:00
catch ( const exception & ex ) {
2012-07-21 01:07:44 +02:00
char szErrBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szErrBuf , 8096 , " In [%s::%s %d] " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-07-21 01:07:44 +02:00
string sErrBuf = string ( szErrBuf ) + string ( " \n error [ " ) + string ( ex . what ( ) ) + string ( " ] \n " ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , sErrBuf . c_str ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , sErrBuf . c_str ( ) ) ;
2012-07-18 01:04:30 +02:00
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
}
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-13 00:08:22 +01:00
if ( loadGameNode ! = NULL ) {
//world.getMapPtr()->loadGame(loadGameNode,&world);
}
2010-06-12 20:27:39 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : 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 ) ;
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-13 00:40:54 +01:00
if ( this - > loadGameNode = = NULL ) {
gameCamera . init ( map - > getW ( ) , map - > getH ( ) ) ;
2010-06-12 20:27:39 +02:00
2012-03-13 00:40:54 +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 ) {
gameCamera . setCalculatedDefault ( map - > getMaxMapHeight ( ) + 13.0f ) ;
}
2011-02-10 01:14:21 +01:00
2012-03-13 00:40:54 +01:00
if ( world . getThisFaction ( ) ! = NULL ) {
const Vec2i & v = map - > getStartLocation ( world . getThisFaction ( ) - > getStartLocationIndex ( ) ) ;
gameCamera . setPos ( Vec2f ( v . x , v . y ) ) ;
}
2010-09-12 07:05:08 +02:00
}
2012-03-15 08:09:36 +01:00
else {
gui . loadGame ( loadGameNode , & world ) ;
2013-02-15 19:25:10 +01:00
if ( inJoinGameLoading = = true ) {
gameCamera . init ( map - > getW ( ) , map - > getH ( ) ) ;
// camera default height calculation
if ( map - > getCameraHeight ( ) > 0 & & gameCamera . getCalculatedDefault ( ) < map - > getCameraHeight ( ) ) {
gameCamera . setCalculatedDefault ( map - > getCameraHeight ( ) ) ;
}
else if ( gameCamera . getCalculatedDefault ( ) < map - > getMaxMapHeight ( ) + 13.0f ) {
gameCamera . setCalculatedDefault ( map - > getMaxMapHeight ( ) + 13.0f ) ;
}
if ( world . getThisFaction ( ) ! = NULL ) {
const Vec2i & v = map - > getStartLocation ( world . getThisFaction ( ) - > getStartLocationIndex ( ) ) ;
gameCamera . setPos ( Vec2f ( v . x , v . y ) ) ;
}
}
2012-03-15 08:09:36 +01:00
}
2010-06-12 20:27:39 +02:00
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2010-04-24 14:22:35 +02:00
2012-03-26 08:48:58 +02:00
scriptManager . init ( & world , & gameCamera , loadGameNode ) ;
2010-03-13 22:10:45 +01:00
2012-01-09 22:08:19 +01:00
//good_fpu_control_registers(NULL,extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-09-12 07:05:08 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] creating AI's \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2013-01-10 22:16:28 +01:00
masterController . clearSlaves ( true ) ;
2011-01-11 23:09:46 +01:00
deleteValues ( aiInterfaces . begin ( ) , aiInterfaces . end ( ) ) ;
2013-01-10 22:16:28 +01:00
std : : vector < SlaveThreadControllerInterface * > slaveThreadList ;
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 ) ;
2013-02-15 19:25:10 +01:00
//printf("Controltype = %d for index = %d\n",faction->getControlType(),i);
2010-09-14 21:10:37 +02:00
if ( faction - > getCpuControl ( enableServerControlledAI , isNetworkGame , role ) = = true ) {
2013-02-15 19:25:10 +01:00
//printf("** Loading AI player for Controltype = %d for index = %d\n",faction->getControlType(),i);
2010-09-12 07:05:08 +02:00
aiInterfaces [ i ] = new AiInterface ( * this , i , faction - > getTeam ( ) ) ;
2012-03-13 16:21:25 +01:00
if ( loadGameNode ! = NULL ) {
aiInterfaces [ i ] - > loadGame ( loadGameNode , faction ) ;
}
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , Lang : : getInstance ( ) . get ( " LogScreenGameLoadingCreatingAIFaction " , " " , true ) . c_str ( ) , i ) ;
2011-11-02 18:17:28 +01:00
logger . add ( szBuf , true ) ;
2013-01-10 22:16:28 +01:00
slaveThreadList . push_back ( aiInterfaces [ i ] - > getWorkerThread ( ) ) ;
2010-09-12 07:05:08 +02:00
}
else {
aiInterfaces [ i ] = NULL ;
}
2010-03-13 22:10:45 +01:00
}
2013-01-10 22:16:28 +01:00
if ( Config : : getInstance ( ) . getBool ( " EnableNewThreadManager " , " false " ) = = true ) {
masterController . setSlaves ( slaveThreadList ) ;
}
2010-03-13 22:10:45 +01:00
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2012-03-30 07:53:33 +02:00
if ( world . getFactionCount ( ) = = 1 & & world . getFaction ( 0 ) - > getPersonalityType ( ) = = fpt_Observer ) {
2011-09-16 02:34:14 +02:00
withRainEffect = false ;
}
2011-11-28 07:38:07 +01:00
if ( withRainEffect ) {
2011-06-21 01:48:22 +02:00
//weather particle systems
2011-11-02 18:17:28 +01:00
if ( world . getTileset ( ) - > getWeather ( ) = = wRainy ) {
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingCreatingRainParticles " , " " , true ) , true ) ;
2011-06-21 01:48:22 +02:00
weatherParticleSystem = new RainParticleSystem ( ) ;
weatherParticleSystem - > setSpeed ( 12.f / GameConstants : : updateFps ) ;
weatherParticleSystem - > setPos ( gameCamera . getPos ( ) ) ;
renderer . manageParticleSystem ( weatherParticleSystem , rsGame ) ;
}
2011-11-02 18:17:28 +01:00
else if ( world . getTileset ( ) - > getWeather ( ) = = wSnowy ) {
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingCreatingSnowParticles " , " " , true ) , true ) ;
2011-06-21 01:48:22 +02:00
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
}
2011-11-28 07:38:07 +01:00
else if ( world . getTileset ( ) - > getWeather ( ) = = wRainy ) {
world . getTileset ( ) - > setWeather ( wSunny ) ;
}
2012-03-14 08:23:41 +01:00
renderer . manageDeferredParticleSystems ( ) ;
2010-09-12 07:05:08 +02:00
}
2010-03-13 22:10:45 +01:00
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-03-13 22:10:45 +01:00
//init renderer state
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Initializing renderer \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ ) ;
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingInitRenderer " , " " , true ) , true ) ;
2012-03-14 08:23:41 +01:00
//printf("Before renderer.initGame\n");
2011-12-02 17:07:59 +01:00
renderer . initGame ( this , this - > getGameCameraPtr ( ) ) ;
2012-03-14 08:23:41 +01:00
//printf("After renderer.initGame\n");
2010-03-13 22:10:45 +01:00
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
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 ( ) ;
}
}
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-09-12 07:05:08 +02:00
if ( initForPreviewOnly = = false ) {
2012-01-09 22:08:19 +01:00
//good_fpu_control_registers(NULL,extractFileFromDirectoryPath(__FILE__).c_str(),__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 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2010-09-12 07:05:08 +02:00
SDL_PumpEvents ( ) ;
2010-06-12 20:27:39 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Waiting for network \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ ) ;
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingWaitForNetworkPlayers " , " " , true ) , true ) ;
2010-09-12 07:05:08 +02:00
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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Starting music stream \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingStartingMusic " , " " , true ) , 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 ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " world.getThisFaction() = = NULL " ) ;
2011-09-24 23:07:15 +02:00
}
if ( world . getThisFaction ( ) - > getType ( ) = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " world.getThisFaction() - > getType ( ) = = NULL " ) ;
2011-09-24 23:07:15 +02:00
}
//if(world.getThisFaction()->getType()->getMusic() == NULL) {
2012-04-14 23:21:09 +02:00
// throw megaglest_runtime_error("world.getThisFaction()->getType()->getMusic() == NULL");
2011-09-24 23:07:15 +02:00
//}
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 ( ) ;
2011-10-21 21:52:55 +02:00
soundRenderer . stopAllSounds ( fadeMusicMilliseconds ) ;
2011-01-18 05:56:42 +01:00
soundRenderer = SoundRenderer : : getInstance ( ) ;
Tileset * tileset = world . getTileset ( ) ;
AmbientSounds * ambientSounds = tileset - > getAmbientSounds ( ) ;
//rain
if ( tileset - > getWeather ( ) = = wRainy & & ambientSounds - > isEnabledRain ( ) ) {
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingStartingAmbient " , " " , true ) , true ) ;
2011-10-21 22:57:42 +02:00
currentAmbientSound = ambientSounds - > getRain ( ) ;
2012-01-09 22:08:19 +01:00
//printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound);
2011-10-21 22:57:42 +02:00
soundRenderer . playAmbient ( currentAmbientSound ) ;
2011-01-18 05:56:42 +01:00
}
//snow
if ( tileset - > getWeather ( ) = = wSnowy & & ambientSounds - > isEnabledSnow ( ) ) {
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingStartingAmbient " , " " , true ) , true ) ;
2011-10-21 22:57:42 +02:00
currentAmbientSound = ambientSounds - > getSnow ( ) ;
2012-01-09 22:08:19 +01:00
//printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound);
2011-10-21 22:57:42 +02:00
soundRenderer . playAmbient ( currentAmbientSound ) ;
2011-01-18 05:56:42 +01:00
}
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
2011-11-04 02:12:05 +01:00
logger . add ( Lang : : getInstance ( ) . get ( " LogScreenGameLoadingLaunchGame " , " " , true ) ) ;
2010-09-12 07:05:08 +02:00
}
2010-03-13 22:10:45 +01:00
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-10-26 06:35:14 +02:00
//throw "test";
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 " ) ;
2012-03-03 05:33:39 +01:00
setupPopupMenus ( false ) ;
2011-09-21 08:51:28 +02:00
2012-03-30 07:53:33 +02:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
//printf("Check for team switch to observer i = %d, team = %d [%d]\n",i,faction->getTeam(),(GameConstants::maxPlayers -1 + fpt_Observer));
if ( faction ! = NULL & & faction - > getTeam ( ) = = GameConstants : : maxPlayers - 1 + fpt_Observer ) {
faction - > setPersonalityType ( fpt_Observer ) ;
world . getStats ( ) - > setPersonalityType ( i , faction - > getPersonalityType ( ) ) ;
}
}
2013-02-24 01:28:45 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2013-03-01 07:52:33 +01:00
if ( role = = nrClient ) {
ClientInterface * clientInterface = dynamic_cast < ClientInterface * > ( networkManager . getClientInterface ( ) ) ;
if ( clientInterface ! = NULL & & clientInterface - > getResumeInGameJoin ( ) = = true ) {
2013-03-06 15:29:49 +01:00
//printf("Client sending resume message to server...\n");
2013-03-01 07:52:33 +01:00
clientInterface - > sendResumeGameMessage ( ) ;
//this->initialResumeSpeedLoops = true;
}
}
2012-03-03 05:33:39 +01:00
gameStarted = true ;
2011-09-21 08:51:28 +02:00
2012-03-03 05:33:39 +01:00
if ( this - > masterserverMode = = true ) {
printf ( " New game has started... \n " ) ;
2011-09-21 08:51:28 +02:00
}
2011-10-03 22:48:09 +02:00
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ==== START GAME ==== getCurrentPixelByteCount() = %llu \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ( long long unsigned int ) renderer . getCurrentPixelByteCount ( ) ) ;
2013-05-27 10:26:01 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " ============================================= \n " ) ;
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " ==== START GAME ==== \n " ) ;
2013-05-27 10:26:01 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " ============================================= \n " ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " Starting framecount: %d \n " , world . getFrameCount ( ) ) ;
2013-02-24 01:28:45 +01:00
if ( showPerfStats & & chronoPerf . getMillis ( ) > = 50 ) {
for ( unsigned int x = 0 ; x < perfList . size ( ) ; + + x ) {
printf ( " %s " , perfList [ x ] . c_str ( ) ) ;
}
}
2012-03-03 05:33:39 +01:00
}
// ==================== update ====================
void Game : : setupPopupMenus ( bool checkClientAdminOverrideOnly ) {
Lang & lang = Lang : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
ClientInterface * clientInterface = NULL ;
2013-05-26 08:45:56 +02:00
ServerInterface * serverInterface = NULL ;
2012-03-03 05:33:39 +01:00
2011-10-03 22:48:09 +02:00
bool allowAdminMenuItems = false ;
2013-05-26 08:45:56 +02:00
bool forceJoinInProgressUpdate = false ;
2011-10-03 22:48:09 +02:00
if ( role = = nrServer ) {
allowAdminMenuItems = true ;
2013-05-26 08:45:56 +02:00
if ( disconnectPlayerPopupMenuIndex = = - 1 ) {
serverInterface = dynamic_cast < ServerInterface * > ( networkManager . getServerInterface ( ) ) ;
if ( serverInterface ! = NULL & & checkClientAdminOverrideOnly = = true ) {
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = serverInterface - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
if ( slot ! = NULL & & slot - > getConnectHasHandshaked ( ) = = true & &
slot - > getCurrentFrameCount ( ) < = 0 ) {
//printf("Connected slot can be disconnected: %d\n",slot->getPlayerIndex());
forceJoinInProgressUpdate = true ;
break ;
}
}
}
}
2011-10-03 22:48:09 +02:00
}
else if ( role = = nrClient ) {
2012-03-03 05:33:39 +01:00
clientInterface = dynamic_cast < ClientInterface * > ( networkManager . getClientInterface ( ) ) ;
2011-10-03 22:48:09 +02:00
if ( clientInterface ! = NULL & &
2012-03-03 05:33:39 +01:00
( gameSettings . getMasterserver_admin ( ) = = clientInterface - > getSessionKey ( ) | |
clientInterface - > isMasterServerAdminOverride ( ) = = true ) ) {
2011-10-03 22:48:09 +02:00
allowAdminMenuItems = true ;
}
}
2012-03-03 05:33:39 +01:00
if ( checkClientAdminOverrideOnly = = false | |
2013-05-26 08:45:56 +02:00
forceJoinInProgressUpdate = = true | |
2012-03-03 05:33:39 +01:00
( clientInterface ! = NULL & &
( gameSettings . getMasterserver_admin ( ) ! = clientInterface - > getSessionKey ( ) & &
clientInterface - > isMasterServerAdminOverride ( ) = = true ) ) ) {
2013-02-17 08:15:01 +01:00
exitGamePopupMenuIndex = - 1 ;
joinTeamPopupMenuIndex = - 1 ;
pauseGamePopupMenuIndex = - 1 ;
saveGamePopupMenuIndex = - 1 ;
loadGamePopupMenuIndex = - 1 ;
keyboardSetupPopupMenuIndex = - 1 ;
disconnectPlayerPopupMenuIndex = - 1 ;
2013-05-26 08:45:56 +02:00
if ( checkClientAdminOverrideOnly = = true & & clientInterface ! = NULL ) {
2012-03-03 05:33:39 +01:00
gameSettings . setMasterserver_admin ( clientInterface - > getSessionKey ( ) ) ;
2012-06-22 16:30:48 +02:00
gameSettings . setMasterserver_admin_faction_index ( clientInterface - > getPlayerIndex ( ) ) ;
2012-03-03 05:33:39 +01: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 & &
2012-03-30 07:53:33 +02:00
world . getThisFaction ( ) ! = NULL & & world . getThisFaction ( ) - > getPersonalityType ( ) ! = fpt_Observer ) {
2012-03-03 05:33:39 +01:00
menuItems . push_back ( lang . get ( " JoinOtherTeam " ) ) ;
joinTeamPopupMenuIndex = menuItems . size ( ) - 1 ;
}
2011-09-21 08:51:28 +02:00
2012-09-24 19:13:27 +02:00
//menuItems.push_back(lang.get("MarkCell"));
//markCellPopupMenuIndex = menuItems.size()-1;
//menuItems.push_back(lang.get("UnMarkCell"));
//unmarkCellPopupMenuIndex = menuItems.size()-1;
2012-06-12 22:37:00 +02:00
2012-04-14 01:13:02 +02:00
if ( allowAdminMenuItems = = true ) {
2012-03-03 05:33:39 +01:00
menuItems . push_back ( lang . get ( " PauseResumeGame " ) ) ;
2012-04-14 01:13:02 +02:00
pauseGamePopupMenuIndex = menuItems . size ( ) - 1 ;
if ( gameSettings . isNetworkGame ( ) = = false ) {
menuItems . push_back ( lang . get ( " SaveGame " ) ) ;
saveGamePopupMenuIndex = menuItems . size ( ) - 1 ;
2011-09-27 12:16:09 +02:00
2012-04-14 01:13:02 +02:00
// menuItems.push_back(lang.get("LoadGame"));
// loadGamePopupMenuIndex= menuItems.size() - 1;
}
2012-09-21 07:45:09 +02:00
2013-02-17 08:15:01 +01:00
//printf("Checking disconnect menu: %d\n",gameSettings.isNetworkGame());
//for(int idx = 0; idx < GameConstants::maxPlayers; ++idx) {
// printf("Faction Index: %d, control: %d\n",idx,gameSettings.getFactionControl(idx));
//}
2012-09-21 07:45:09 +02:00
if ( gameSettings . isNetworkGame ( ) = = true ) {
menuItems . push_back ( lang . get ( " DisconnectNetorkPlayer " ) ) ;
disconnectPlayerPopupMenuIndex = menuItems . size ( ) - 1 ;
}
2012-04-14 01:13:02 +02:00
}
2012-03-03 05:33:39 +01:00
menuItems . push_back ( lang . get ( " Keyboardsetup " ) ) ;
keyboardSetupPopupMenuIndex = menuItems . size ( ) - 1 ;
2012-09-21 07:45:09 +02:00
2012-03-03 05:33:39 +01:00
menuItems . push_back ( lang . get ( " Cancel " ) ) ;
2012-06-12 22:37:00 +02:00
2012-03-03 05:33:39 +01:00
popupMenu . setW ( 100 ) ;
popupMenu . setH ( 100 ) ;
popupMenu . init ( lang . get ( " GameMenuTitle " ) , menuItems ) ;
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
popupMenuSwitchTeams . setEnabled ( false ) ;
popupMenuSwitchTeams . setVisible ( false ) ;
2012-09-21 07:45:09 +02:00
popupMenuDisconnectPlayer . setEnabled ( false ) ;
popupMenuDisconnectPlayer . setVisible ( false ) ;
2011-09-27 12:16:09 +02:00
}
2010-03-13 22:10:45 +01:00
}
//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 ( ) ;
}
2013-01-03 18:30:59 +01:00
bool showPerfStats = Config : : getInstance ( ) . getBool ( " ShowPerfStats " , " false " ) ;
Chrono chronoPerf ;
char perfBuf [ 8096 ] = " " ;
std : : vector < string > perfList ;
if ( showPerfStats ) chronoPerf . start ( ) ;
if ( showPerfStats ) {
sprintf ( perfBuf , " =============== FRAME: %d In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , world . getFrameCount ( ) , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
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
2012-10-02 08:20:39 +02:00
bool pendingQuitError = ( quitPendingIndicator = = true | |
( NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ! = NULL & &
NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) - > getQuit ( ) ) ) ;
//if(pendingQuitError) printf("#1 pendingQuitError = %d, quitPendingIndicator = %d, errorMessageBox.getEnabled() = %d\n",pendingQuitError,quitPendingIndicator,errorMessageBox.getEnabled());
if ( pendingQuitError = = true & &
( this - > masterserverMode = = true | |
( mainMessageBox . getEnabled ( ) = = false & & errorMessageBox . getEnabled ( ) = = false ) ) ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-10-02 08:20:39 +02:00
//printf("#2 pendingQuitError = %d, quitPendingIndicator = %d, errorMessageBox.getEnabled() = %d\n",pendingQuitError,quitPendingIndicator,errorMessageBox.getEnabled());
2011-01-02 01:39:13 +01:00
quitTriggeredIndicator = true ;
return ;
}
2011-09-24 23:07:15 +02:00
if ( this - > masterserverMode = = false ) {
2012-04-02 03:45:13 +02:00
if ( world . getFactionCount ( ) > 0 & & world . getThisFaction ( ) - > getFirstSwitchTeamVote ( ) ! = NULL ) {
2011-09-24 23:07:15 +02:00
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
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2011-09-24 23:07:15 +02:00
if ( lang . hasString ( " AllowPlayerJoinTeam " ) = = true ) {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , lang . get ( " AllowPlayerJoinTeam " ) . c_str ( ) , settings - > getNetworkPlayerName ( vote - > factionIndex ) . c_str ( ) , vote - > oldTeam , vote - > newTeam ) ;
2011-09-24 23:07:15 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " 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-24 23:07:15 +02:00
}
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
2013-03-01 07:52:33 +01:00
// Temp speed boost when player first joins an in progress game
//if(this->initialResumeSpeedLoops == true && updateLoops == 1) {
if ( this - > initialResumeSpeedLoops = = true ) {
2013-05-27 10:26:01 +02:00
printf ( " Resume In Progress Game: %d \n " , __LINE__ ) ;
2013-03-01 07:52:33 +01:00
this - > initialResumeSpeedLoops = false ;
2013-03-02 00:31:53 +01:00
//updateLoops = 80;
2013-03-01 07:52:33 +01:00
}
2013-03-02 01:53:55 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
bool enableServerControlledAI = this - > gameSettings . getEnableServerControlledAI ( ) ;
bool isNetworkGame = this - > gameSettings . isNetworkGame ( ) ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
2013-05-26 00:30:31 +02:00
if ( role = = nrClient & & updateLoops = = 1 & & world . getFrameCount ( ) > = ( gameSettings . getNetworkFramePeriod ( ) * 2 ) ) {
ClientInterface * clientInterface = dynamic_cast < ClientInterface * > ( networkManager . getClientInterface ( ) ) ;
if ( clientInterface ! = NULL ) {
uint64 lastNetworkFrameFromServer = clientInterface - > getCachedLastPendingFrameCount ( ) ;
//// if(lastNetworkFrameFromServer > 0 && lastNetworkFrameFromServer > (world.getFrameCount() + gameSettings.getNetworkFramePeriod())+1) {
//// //if(lastNetworkFrameFromServer > 0 && lastNetworkFrameFromServer > world.getFrameCount()) {
//// int frameDifference = ((lastNetworkFrameFromServer - world.getFrameCount()) / gameSettings.getNetworkFramePeriod()) * gameSettings.getNetworkFramePeriod();
////
//// //int frameDifference = lastNetworkFrameFromServer - world.getFrameCount();
// if(framesToCatchUpAsClient==0){
// if(lastNetworkFrameFromServer > 0 && lastNetworkFrameFromServer > (world.getFrameCount() + gameSettings.getNetworkFramePeriod()/4)) {
// //if(lastNetworkFrameFromServer > 0 && lastNetworkFrameFromServer > world.getFrameCount()) {
// int frameDifference = lastNetworkFrameFromServer - world.getFrameCount();
// printf("Client will speed up: %d frames lastNetworkFrameFromServer: %lld world.getFrameCount() = %d updateLoops = %d\n",frameDifference,(long long int)lastNetworkFrameFromServer,world.getFrameCount(),updateLoops);
// framesToCatchUpAsClient=frameDifference;
// // done below now: updateLoops += frameDifference;
2013-05-23 00:15:52 +02:00
// }
// }
2013-05-26 00:30:31 +02:00
//// //If client is ahead maybe this fixes it ( by titi ):
// if(updateLoops!=0 && lastNetworkFrameFromServer > 0 && world.getFrameCount() > lastNetworkFrameFromServer && (world.getFrameCount()%GameConstants::updateFps)>38 ){
// printf("Client will slow down because no message has arrived yet. currentFrame=%d \n",world.getFrameCount());
// updateLoops = 0;
2013-05-23 00:15:52 +02:00
// }
2013-05-26 00:30:31 +02:00
/////////////////////////////////
// TTTT new attempt to make things smoother:
///////////////
////////////////////////////////////////////
//get stats of received/waiting for packages
////////////////////////////////////////////
// calculate current receive Index slot:
int index = ( ( world . getFrameCount ( )
- ( world . getFrameCount ( )
% gameSettings . getNetworkFramePeriod ( ) ) )
/ gameSettings . getNetworkFramePeriod ( ) )
% GameConstants : : networkSmoothInterval ;
// clean the next frame slot
receivedTooEarlyInFrames [ ( index + 1 ) % GameConstants : : networkSmoothInterval ] = - 1 ;
framesNeededToWaitForServerMessage [ ( index + 1 ) % GameConstants : : networkSmoothInterval ] = - 1 ;
if ( receivedTooEarlyInFrames [ index ] = = - 1 ) {
// we need to check if we already received something for next frame
if ( lastNetworkFrameFromServer > 0 & & lastNetworkFrameFromServer > world . getFrameCount ( ) ) {
receivedTooEarlyInFrames [ index ] = lastNetworkFrameFromServer - world . getFrameCount ( ) ;
}
}
if ( framesNeededToWaitForServerMessage [ index ] = = - 1 ) {
// calc time waiting for message in milliseconds to frames
int64 timeClientWaitedForLastMessage = clientInterface - > getTimeClientWaitedForLastMessage ( ) ;
if ( timeClientWaitedForLastMessage > 0 ) {
printf ( " world.getFrameCount():%d index %d Client waited:%d ms \n " , world . getFrameCount ( ) , index , ( int ) timeClientWaitedForLastMessage ) ;
framesNeededToWaitForServerMessage [ index ] = timeClientWaitedForLastMessage * GameConstants : : updateFps / 1000 ;
printf ( " ClienttimeClientWaitedForLastMessage:%d ms which is %d frames \n " , ( int ) timeClientWaitedForLastMessage , framesNeededToWaitForServerMessage [ index ] ) ;
}
else {
framesNeededToWaitForServerMessage [ index ] = 0 ;
}
}
////////////////////////////////////////////
//use the recorded stats of received/waiting for packages
////////////////////////////////////////////
//lets see if the client is in front and had to wait for messages ...
//lets see if all last recorded frames where received too early
int minimum = 0 ;
int allowedMaxFallback = 5 ;
int countOfMessagesReceivedTooEarly = 0 ;
int countOfMessagesReceivedTooLate = 0 ;
int sumOfTooLateFrames = 0 ;
bool cleanupStats = false ;
for ( int i = 0 ; i < GameConstants : : networkSmoothInterval ; i + + ) {
if ( receivedTooEarlyInFrames [ i ] > allowedMaxFallback ) {
countOfMessagesReceivedTooEarly + + ;
if ( minimum = = 0 | | minimum > receivedTooEarlyInFrames [ i ] ) {
minimum = receivedTooEarlyInFrames [ i ] ;
}
}
if ( framesNeededToWaitForServerMessage [ i ] > 0 ) {
countOfMessagesReceivedTooLate + + ;
sumOfTooLateFrames + = framesNeededToWaitForServerMessage [ i ] ;
}
}
if ( countOfMessagesReceivedTooEarly = = GameConstants : : networkSmoothInterval - 1 ) // -1 because slot for next frame is already initialized
{ // all packages where too early
// we catch up the minimum-catchupInterval of what we recorded
framesToCatchUpAsClient = minimum - allowedMaxFallback ;
framesToSlowDownAsClient = 0 ;
cleanupStats = true ;
printf ( " Worldframe %d : Client will speed up: %d frames \n " , world . getFrameCount ( ) , framesToCatchUpAsClient ) ;
}
else if ( countOfMessagesReceivedTooLate > 3 ) {
framesToSlowDownAsClient = sumOfTooLateFrames / countOfMessagesReceivedTooLate ;
framesToCatchUpAsClient = 0 ;
cleanupStats = true ;
printf ( " Worldframe %d : Client will slow down: %d frames \n " , world . getFrameCount ( ) , framesToSlowDownAsClient ) ;
}
if ( cleanupStats = = true ) {
// Once we decided to use the stats to do some correction, we reset/cleanup our recorded stats
for ( int i = 0 ; i < GameConstants : : networkSmoothInterval ; i + + ) {
receivedTooEarlyInFrames [ i ] = - 1 ;
framesNeededToWaitForServerMessage [ i ] = - 1 ;
}
}
}
}
// we catch up a bit smoother with updateLoops = 2
if ( framesToCatchUpAsClient > 0 )
{
updateLoops = 2 ;
framesToCatchUpAsClient = framesToCatchUpAsClient - 1 ;
}
if ( framesToSlowDownAsClient > 0 )
{ // slowdown still the hard way.
updateLoops = 0 ;
framesToSlowDownAsClient = framesToSlowDownAsClient - 1 ;
}
2013-03-02 01:53:55 +01:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-06-15 18:27:52 +02:00
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
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 ) ;
2012-03-03 05:33:39 +01:00
setupPopupMenus ( true ) ;
2010-10-19 01:09:43 +02:00
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
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
2012-03-20 06:58:24 +01:00
Chrono chronoReplay ;
int64 lastReplaySecond = - 1 ;
int replayCommandsPlayed = 0 ;
int replayTotal = commander . getReplayCommandListForFrameCount ( ) ;
if ( replayTotal > 0 ) {
chronoReplay . start ( ) ;
}
2013-02-17 08:15:01 +01:00
2012-03-20 05:53:26 +01:00
do {
2012-03-20 08:14:50 +01:00
if ( replayTotal > 0 ) {
replayCommandsPlayed = ( replayTotal - commander . getReplayCommandListForFrameCount ( ) ) ;
}
2012-03-20 05:53:26 +01:00
for ( int i = 0 ; i < updateLoops ; + + i ) {
2013-01-03 18:30:59 +01:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-20 05:53:26 +01:00
//AiInterface
if ( commander . hasReplayCommandListForFrame ( ) = = false ) {
2013-01-01 19:55:26 +01:00
/*
2012-03-20 05:53:26 +01:00
for ( int j = 0 ; j < world . getFactionCount ( ) ; + + j ) {
Faction * faction = world . getFaction ( j ) ;
2012-10-10 02:27:34 +02:00
//printf("Faction Index = %d enableServerControlledAI = %d, isNetworkGame = %d, role = %d isCPU player = %d scriptManager.getPlayerModifiers(j)->getAiEnabled() = %d\n",j,enableServerControlledAI,isNetworkGame,role,faction->getCpuControl(enableServerControlledAI,isNetworkGame,role),scriptManager.getPlayerModifiers(j)->getAiEnabled());
2012-03-20 05:53:26 +01:00
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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , j , world . getFactionCount ( ) , chrono . getMillis ( ) ) ;
2012-10-10 02:27:34 +02:00
//printf("Faction Index = %d telling AI to do something pendingQuitError = %d\n",j,pendingQuitError);
2012-10-02 08:20:39 +02:00
if ( pendingQuitError = = false ) aiInterfaces [ j ] - > update ( ) ;
2012-03-20 05:53:26 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , j , world . getFactionCount ( ) , chrono . getMillis ( ) ) ;
}
}
2013-01-01 19:55:26 +01:00
*/
2013-01-10 22:16:28 +01:00
const bool newThreadManager = Config : : getInstance ( ) . getBool ( " EnableNewThreadManager " , " false " ) ;
if ( newThreadManager = = true ) {
int currentFrameCount = world . getFrameCount ( ) ;
masterController . signalSlaves ( & currentFrameCount ) ;
2013-05-26 08:03:32 +02:00
//bool slavesCompleted = masterController.waitTillSlavesTrigger(20000);
masterController . waitTillSlavesTrigger ( 20000 ) ;
2013-01-10 22:16:28 +01:00
}
else {
// Signal the faction threads to do any pre-processing
bool hasAIPlayer = false ;
for ( int j = 0 ; j < world . getFactionCount ( ) ; + + j ) {
Faction * faction = world . getFaction ( j ) ;
2013-01-01 19:55:26 +01:00
2013-01-10 22:16:28 +01:00
//printf("Faction Index = %d enableServerControlledAI = %d, isNetworkGame = %d, role = %d isCPU player = %d scriptManager.getPlayerModifiers(j)->getAiEnabled() = %d\n",j,enableServerControlledAI,isNetworkGame,role,faction->getCpuControl(enableServerControlledAI,isNetworkGame,role),scriptManager.getPlayerModifiers(j)->getAiEnabled());
2013-01-01 19:55:26 +01:00
2013-01-10 22:16:28 +01:00
if ( faction - > getCpuControl ( enableServerControlledAI , isNetworkGame , role ) = = true & &
scriptManager . getPlayerModifiers ( j ) - > getAiEnabled ( ) = = true ) {
2013-01-01 19:55:26 +01:00
2013-01-10 22:16:28 +01: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 [before AI updates] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , j , world . getFactionCount ( ) , chrono . getMillis ( ) ) ;
aiInterfaces [ j ] - > signalWorkerThread ( world . getFrameCount ( ) ) ;
hasAIPlayer = true ;
}
2013-01-01 19:55:26 +01:00
}
2013-01-10 22:16:28 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2013-01-01 19:55:26 +01:00
2013-01-10 22:16:28 +01:00
if ( hasAIPlayer = = true ) {
//sleep(0);
2013-01-01 19:55:26 +01:00
2013-01-10 22:16:28 +01:00
bool workThreadsFinished = false ;
Chrono chronoAI ;
chronoAI . start ( ) ;
2013-01-01 19:55:26 +01:00
2013-01-10 22:16:28 +01:00
const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000 ;
for ( ; chronoAI . getMillis ( ) < MAX_FACTION_THREAD_WAIT_MILLISECONDS ; ) {
workThreadsFinished = true ;
for ( int j = 0 ; j < world . getFactionCount ( ) ; + + j ) {
Faction * faction = world . getFaction ( j ) ;
if ( faction = = NULL ) {
throw megaglest_runtime_error ( " faction == NULL " ) ;
}
if ( faction - > getCpuControl ( enableServerControlledAI , isNetworkGame , role ) = = true & &
scriptManager . getPlayerModifiers ( j ) - > getAiEnabled ( ) = = true ) {
if ( aiInterfaces [ j ] - > isWorkerThreadSignalCompleted ( world . getFrameCount ( ) ) = = false ) {
workThreadsFinished = false ;
break ;
}
2013-01-03 18:30:59 +01:00
}
}
2013-01-10 22:16:28 +01:00
if ( workThreadsFinished = = false ) {
//sleep(0);
}
else {
break ;
}
2013-01-03 18:30:59 +01:00
}
}
}
2013-01-01 19:55:26 +01:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2013-01-01 19:55:26 +01:00
2011-10-03 22:48:09 +02:00
}
2012-03-20 06:58:24 +01:00
else {
2012-03-20 08:14:50 +01:00
// Simply show a progress message while replaying commands
2012-03-20 06:58:24 +01:00
if ( lastReplaySecond < chronoReplay . getSeconds ( ) ) {
lastReplaySecond = chronoReplay . getSeconds ( ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . clearBuffers ( ) ;
renderer . clearZBuffer ( ) ;
renderer . reset2d ( ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Please wait, loading game with replay [%d / %d]... " , replayCommandsPlayed , replayTotal ) ;
2012-03-20 06:58:24 +01:00
string text = szBuf ;
if ( Renderer : : renderText3DEnabled ) {
Font3D * font = CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
int w = metrics . getVirtualW ( ) ;
int renderX = ( w / 2 ) - ( font - > getMetrics ( ) - > getTextWidth ( text ) / 2 ) ;
int h = metrics . getVirtualH ( ) ;
int renderY = ( h / 2 ) + ( font - > getMetrics ( ) - > getHeight ( text ) / 2 ) ;
renderer . renderText3D (
text , font ,
Vec3f ( 1.f , 1.f , 0.f ) ,
renderX , renderY , false ) ;
}
else {
Font2D * font = CoreData : : getInstance ( ) . getMenuFontBig ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
int w = metrics . getVirtualW ( ) ;
int renderX = ( w / 2 ) ;
int h = metrics . getVirtualH ( ) ;
int renderY = ( h / 2 ) ;
renderer . renderText (
text , font ,
Vec3f ( 1.f , 1.f , 0.f ) ,
renderX , renderY , true ) ;
}
renderer . swapBuffers ( ) ;
}
}
2010-09-14 21:10:37 +02:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-20 05:53:26 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2012-03-20 05:53:26 +01:00
//World
2012-10-02 08:20:39 +02:00
if ( pendingQuitError = = false ) world . update ( ) ;
2012-03-20 05:53:26 +01:00
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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-09-26 02:15:37 +02:00
if ( currentCameraFollowUnit ! = NULL ) {
Vec3f c = currentCameraFollowUnit - > getCurrVector ( ) ;
2012-09-27 00:52:21 +02:00
int rotation = currentCameraFollowUnit - > getRotation ( ) ;
float angle = rotation + 180 ;
# ifdef USE_STREFLOP
c . z = c . z + 4 * streflop : : cosf ( static_cast < streflop : : Simple > ( degToRad ( angle ) ) ) ;
c . x = c . x + 4 * streflop : : sinf ( static_cast < streflop : : Simple > ( degToRad ( angle ) ) ) ;
# else
c . z = c . z + 4 * cosf ( degToRad ( angle ) ) ;
c . x = c . x + 4 * sinf ( degToRad ( angle ) ) ;
# endif
2012-09-26 21:25:35 +02:00
c . y = c . y + currentCameraFollowUnit - > getType ( ) - > getHeight ( ) / 2.f + 2.0f ;
2012-09-27 00:52:21 +02:00
2012-09-26 02:15:37 +02:00
getGameCameraPtr ( ) - > setPos ( c ) ;
2012-09-27 00:52:21 +02:00
rotation = ( 540 - rotation ) % 360 ;
getGameCameraPtr ( ) - > rotateToVH ( 18.0f , rotation ) ;
2012-09-26 02:15:37 +02:00
if ( currentCameraFollowUnit - > isAlive ( ) = = false ) {
2012-09-26 21:25:35 +02:00
currentCameraFollowUnit = NULL ;
2012-09-27 23:10:28 +02:00
getGameCameraPtr ( ) - > setState ( GameCamera : : sGame ) ;
2012-09-26 02:15:37 +02:00
}
}
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-20 05:53:26 +01:00
// Commander
//commander.updateNetwork();
2012-10-02 08:20:39 +02:00
if ( pendingQuitError = = false ) commander . signalNetworkUpdate ( this ) ;
2011-01-11 09:45:58 +01:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-20 05:53:26 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2012-03-20 05:53:26 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-20 05:53:26 +01:00
//Particle systems
if ( weatherParticleSystem ! = NULL ) {
weatherParticleSystem - > setPos ( gameCamera . getPos ( ) ) ;
}
2010-05-29 09:58:58 +02:00
2012-03-20 05:53:26 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-08-21 20:50:56 +02:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-20 05:53:26 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , i ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-05-29 09:58:58 +02:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-03-20 05:53:26 +01:00
//good_fpu_control_registers(NULL,extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
}
2011-10-03 22:48:09 +02:00
}
2012-03-20 05:53:26 +01:00
while ( commander . hasReplayCommandListForFrame ( ) = = true ) ;
2011-10-03 22:48:09 +02:00
}
//else if(role == nrClient) {
else {
2012-10-02 08:20:39 +02:00
if ( pendingQuitError = = false ) commander . signalNetworkUpdate ( this ) ;
2012-05-22 08:17:56 +02:00
if ( playingStaticVideo = = true ) {
if ( videoPlayer - > isPlaying ( ) = = false ) {
playingStaticVideo = false ;
tryPauseToggle ( false ) ;
}
}
2010-03-13 22:10:45 +01:00
}
2010-05-03 08:25:54 +02:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2010-05-29 09:58:58 +02:00
//call the chat manager
chatManager . updateNetwork ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-04-24 14:22:35 +02:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2012-06-12 22:37:00 +02:00
updateNetworkMarkedCells ( ) ;
2012-06-13 18:19:44 +02:00
updateNetworkUnMarkedCells ( ) ;
2012-07-13 23:50:34 +02:00
updateNetworkHighligtedCells ( ) ;
2012-06-12 22:37:00 +02:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
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 ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2013-02-17 08:15:01 +01:00
// START - Handle joining in progress games
if ( role = = nrServer ) {
ServerInterface * server = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2013-02-27 00:31:59 +01:00
if ( server - > getPauseForInGameConnection ( ) = = true ) {
2013-02-27 07:46:42 +01:00
bool clientNeedsGameSetup = false ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
if ( slot ! = NULL & & slot - > getPauseForInGameConnection ( ) = = true ) {
clientNeedsGameSetup = true ;
break ;
}
}
2013-03-06 15:29:49 +01:00
if ( pausedForJoinGame = = false | | clientNeedsGameSetup = = true ) {
2013-02-27 00:31:59 +01:00
//printf("================= Switching player pausing game\n");
2013-02-17 08:15:01 +01:00
2013-02-27 00:31:59 +01:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
2013-02-17 08:15:01 +01:00
2013-02-27 00:31:59 +01:00
//printf("Switching player check %d from: %d connected: %d, startindex = %d, connected #2: %d\n",i,faction->getControlType(),server->isClientConnected(faction->getStartLocationIndex()),faction->getStartLocationIndex(),server->isClientConnected(i));
//printf("Slot: %d faction name: %s\n",i,faction->getType()->getName().c_str());
2013-02-17 08:15:01 +01:00
2013-02-27 00:31:59 +01:00
if ( faction - > getControlType ( ) ! = ctNetwork & &
faction - > getControlType ( ) ! = ctHuman & &
server - > isClientConnected ( faction - > getStartLocationIndex ( ) ) = = true ) {
2013-02-17 08:15:01 +01:00
2013-02-27 00:31:59 +01:00
//printf("Switching player %d from: %d to %d\n",i,faction->getControlType(),ctNetwork);
//printf("Slot: %d faction name: %s GS faction: %s\n",i,faction->getType()->getName().c_str(),server->gameSettings.getFactionTypeName(i).c_str());
2013-02-17 08:15:01 +01:00
2013-02-27 00:31:59 +01:00
server - > gameSettings . setFactionControl ( i , ctNetwork ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
server - > gameSettings . setNetworkPlayerName ( i , slot - > getName ( ) ) ;
2013-06-01 04:31:12 +02:00
server - > gameSettings . setNetworkPlayerUUID ( i , slot - > getUUID ( ) ) ;
2013-05-28 09:10:13 +02:00
server - > gameSettings . setNetworkPlayerStatuses ( i , npst_None ) ;
2013-02-17 08:15:01 +01:00
2013-02-27 00:31:59 +01:00
this - > gameSettings . setFactionControl ( i , ctNetwork ) ;
this - > gameSettings . setNetworkPlayerName ( i , server - > gameSettings . getNetworkPlayerName ( i ) ) ;
2013-06-01 04:31:12 +02:00
this - > gameSettings . setNetworkPlayerUUID ( i , server - > gameSettings . getNetworkPlayerUUID ( i ) ) ;
2013-05-28 09:10:13 +02:00
this - > gameSettings . setNetworkPlayerStatuses ( i , npst_None ) ;
2013-02-27 00:31:59 +01:00
}
2013-02-17 08:15:01 +01:00
}
2013-02-27 00:31:59 +01:00
//printf("#1 Data synch: lmap %u ltile: %d ltech: %u\n",gameSettings.getMapCRC(),gameSettings.getTilesetCRC(),gameSettings.getTechCRC());
//printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC());
server - > broadcastGameSetup ( & server - > gameSettings , true ) ;
2013-02-17 08:15:01 +01:00
}
2013-02-19 23:00:15 +01:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
if ( slot ! = NULL & & slot - > getPauseForInGameConnection ( ) = = true ) {
slot - > setPauseForInGameConnection ( false ) ;
}
}
2013-02-17 08:15:01 +01:00
}
else if ( server - > getStartInGameConnectionLaunch ( ) = = true ) {
//printf("^^^ getStartInGameConnectionLaunch triggered!\n");
2013-02-19 23:00:15 +01:00
//server->setStartInGameConnectionLaunch(false);
2013-02-17 08:15:01 +01:00
2013-02-26 21:48:20 +01:00
this - > speed = 1 ;
2013-05-17 07:01:23 +02:00
//Lang &lang= Lang::getInstance();
2013-02-17 08:15:01 +01:00
bool pauseAndSaveGameForNewClient = false ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
2013-02-27 00:31:59 +01:00
2013-02-19 23:00:15 +01:00
if ( slot ! = NULL & & slot - > getStartInGameConnectionLaunch ( ) = = true ) {
2013-02-27 07:46:42 +01:00
//slot->setStartInGameConnectionLaunch(false);
2013-02-27 00:31:59 +01:00
pauseAndSaveGameForNewClient = true ;
2013-02-19 23:00:15 +01:00
}
2013-02-17 08:15:01 +01:00
if ( slot ! = NULL & & slot - > getJoinGameInProgress ( ) = = true ) {
//printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex());
this - > gameSettings . setFactionControl ( i , ctNetwork ) ;
this - > gameSettings . setNetworkPlayerName ( i , server - > gameSettings . getNetworkPlayerName ( i ) ) ;
2013-06-01 04:31:12 +02:00
this - > gameSettings . setNetworkPlayerUUID ( i , server - > gameSettings . getNetworkPlayerUUID ( i ) ) ;
2013-02-17 08:15:01 +01:00
2013-05-28 09:10:13 +02:00
if ( this - > gameSettings . getNetworkPlayerStatuses ( i ) = = npst_Disconnected ) {
this - > gameSettings . setNetworkPlayerStatuses ( i , npst_None ) ;
}
2013-02-17 08:15:01 +01:00
//printf("START Purging AI player for index: %d\n",i);
masterController . clearSlaves ( true ) ;
delete aiInterfaces [ i ] ;
aiInterfaces [ i ] = NULL ;
//printf("END Purging AI player for index: %d\n",i);
Faction * faction = world . getFaction ( i ) ;
faction - > setControlType ( ctNetwork ) ;
2013-02-27 00:31:59 +01:00
//pauseAndSaveGameForNewClient = true;
2013-02-17 08:15:01 +01:00
}
else if ( ( slot = = NULL | | slot - > isConnected ( ) = = false ) & &
this - > gameSettings . getFactionControl ( i ) = = ctNetwork & &
aiInterfaces [ i ] = = NULL ) {
faction - > setFactionDisconnectHandled ( false ) ;
//this->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1));
//server->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1));
}
}
2013-03-06 15:29:49 +01:00
if ( pauseAndSaveGameForNewClient = = true & & pausedForJoinGame = = false & &
2013-02-27 07:46:42 +01:00
pauseRequestSent = = false ) {
2013-03-06 15:29:49 +01:00
//printf("Pausing game for join in progress game...\n");
commander . tryPauseGame ( true , true ) ;
2013-02-27 07:46:42 +01:00
pauseRequestSent = true ;
2013-03-06 15:29:49 +01:00
return ;
2013-02-17 08:15:01 +01:00
}
}
2013-02-19 05:53:24 +01:00
//else if(server->getPauseForInGameConnection() == true && paused == true &&
2013-03-06 15:29:49 +01:00
if ( pausedForJoinGame = = true ) {
2013-02-27 00:31:59 +01:00
if ( pauseStateChanged = = true ) {
pauseStateChanged = false ;
}
2013-02-19 05:53:24 +01:00
2013-02-27 00:31:59 +01:00
if ( server - > getUnPauseForInGameConnection ( ) = = true ) {
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
2013-02-19 23:00:15 +01:00
2013-02-27 00:31:59 +01:00
this - > speed = 1 ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
if ( slot ! = NULL & & slot - > getUnPauseForInGameConnection ( ) = = true ) {
slot - > setUnPauseForInGameConnection ( false ) ;
}
2013-02-19 23:00:15 +01:00
}
2013-03-06 15:29:49 +01:00
//printf("Resuming game for join in progress game resumeRequestSent: %d...\n",resumeRequestSent);
2013-05-27 10:26:01 +02:00
//commander.tryResumeGame(true,false);
commander . tryResumeGame ( true , true ) ;
2013-02-27 07:46:42 +01:00
resumeRequestSent = true ;
2013-03-01 07:52:33 +01:00
// server->setAllowInGameConnections(false);
// for(int i = 0; i < world.getFactionCount(); ++i) {
// Faction *faction = world.getFaction(i);
// ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
// if(slot != NULL && slot->isConnected() == false) {
// server->setAllowInGameConnections(false);
// server->removeSlot(faction->getStartLocationIndex());
// }
// }
//server->shutdownFTPServer();
2013-02-27 00:31:59 +01:00
//return;
2013-02-19 23:00:15 +01:00
}
2013-02-27 07:46:42 +01:00
else if ( server - > getStartInGameConnectionLaunch ( ) = = true ) {
2013-02-27 00:31:59 +01:00
bool saveNetworkGame = false ;
2013-02-19 23:00:15 +01:00
2013-02-27 00:31:59 +01:00
ServerInterface * server = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2013-02-19 05:53:24 +01:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
2013-02-27 00:31:59 +01:00
if ( slot ! = NULL & & slot - > getJoinGameInProgress ( ) = = true & &
2013-02-27 07:46:42 +01:00
slot - > getStartInGameConnectionLaunch ( ) = = true & &
slot - > getSentSavedGameInfo ( ) = = false ) {
slot - > setStartInGameConnectionLaunch ( false ) ;
2013-02-27 00:31:59 +01:00
saveNetworkGame = true ;
break ;
2013-02-19 05:53:24 +01:00
}
}
2013-02-17 08:15:01 +01:00
2013-02-27 00:31:59 +01:00
if ( saveNetworkGame = = true ) {
//printf("Saved network game to disk\n");
string file = this - > saveGame ( GameConstants : : saveNetworkGameFileServer , " temp/ " ) ;
2013-05-01 22:56:19 +02:00
string saveGameFilePath = " temp/ " ;
string saveGameFileCompressed = saveGameFilePath + string ( GameConstants : : saveNetworkGameFileServerCompressed ) ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
saveGameFilePath = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + saveGameFilePath ;
saveGameFileCompressed = saveGameFilePath + string ( GameConstants : : saveNetworkGameFileServerCompressed ) ;
}
else {
string userData = Config : : getInstance ( ) . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
saveGameFilePath = userData + saveGameFilePath ;
saveGameFileCompressed = saveGameFilePath + string ( GameConstants : : saveNetworkGameFileServerCompressed ) ;
}
bool compressed_result = compressFileToZIPFile (
file , saveGameFileCompressed ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Saved game [%s] compressed to [%s] returned: %d \n " , file . c_str ( ) , saveGameFileCompressed . c_str ( ) , compressed_result ) ;
2013-02-27 00:31:59 +01:00
char szBuf [ 8096 ] = " " ;
Lang & lang = Lang : : getInstance ( ) ;
snprintf ( szBuf , 8096 , lang . get ( " GameSaved " , " " , true ) . c_str ( ) , file . c_str ( ) ) ;
console . addLine ( szBuf ) ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
ConnectionSlot * slot = server - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
if ( slot ! = NULL & & slot - > getJoinGameInProgress ( ) = = true & &
slot - > getSentSavedGameInfo ( ) = = false ) {
NetworkMessageReady networkMessageReady ( 0 ) ;
slot - > sendMessage ( & networkMessageReady ) ;
slot - > setSentSavedGameInfo ( true ) ;
}
}
2013-02-19 23:00:15 +01:00
}
}
2013-02-17 08:15:01 +01:00
}
2013-02-27 07:46:42 +01:00
//else {
// handle setting changes from clients
Map * map = world . getMap ( ) ;
//printf("switchSetupRequests != NULL\n");
2013-02-17 08:15:01 +01:00
2013-02-27 07:46:42 +01:00
bool switchRequested = switchSetupForSlots ( server , 0 , map - > getMaxPlayers ( ) , false ) ;
switchRequested = switchRequested | | switchSetupForSlots ( server , map - > getMaxPlayers ( ) , GameConstants : : maxPlayers , true ) ;
2013-02-17 08:15:01 +01:00
2013-02-27 07:46:42 +01:00
if ( switchRequested = = true ) {
//printf("Send new game setup from switch: %d\n",switchRequested);
2013-02-17 08:15:01 +01:00
2013-02-27 07:46:42 +01:00
//for(int i= 0; i < gameSettings.getFactionCount(); ++i) {
//printf("#1 Faction Index: %d control: %d startlocation: %d\n",i,gameSettings.getFactionControl(i),gameSettings.getStartLocationIndex(i));
2013-02-17 08:15:01 +01:00
2013-02-27 07:46:42 +01:00
//printf("#2 Faction Index: %d control: %d startlocation: %d\n",i,server->gameSettings.getFactionControl(i),server->gameSettings.getStartLocationIndex(i));
//}
2013-02-17 08:15:01 +01:00
2013-02-27 07:46:42 +01:00
server - > broadcastGameSetup ( & server - > gameSettings , true ) ;
2013-02-17 08:15:01 +01:00
}
2013-02-27 07:46:42 +01:00
//}
// Make the server wait a bit for clients to start.
2013-03-06 15:29:49 +01:00
if ( pausedForJoinGame = = false & & resumeRequestSent = = true ) {
2013-02-27 07:46:42 +01:00
resumeRequestSent = false ;
2013-03-01 07:52:33 +01:00
//sleep(500);
2013-02-17 08:15:01 +01:00
}
}
// END - Handle joining in progress games
2010-05-29 09:58:58 +02:00
//update auto test
if ( Config : : getInstance ( ) . getBool ( " AutoTest " ) ) {
AutoTest : : getInstance ( ) . updateGame ( this ) ;
2012-03-17 09:20:17 +01:00
return ;
2010-05-29 09:58:58 +02:00
}
2011-10-06 20:04:59 +02:00
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
2011-10-06 20:04:59 +02:00
if ( world . getQueuedScenario ( ) ! = " " ) {
string name = world . getQueuedScenario ( ) ;
2011-10-06 22:44:55 +02:00
bool keepFactions = world . getQueuedScenarioKeepFactions ( ) ;
world . setQueuedScenario ( " " , false ) ;
2011-10-06 20:04:59 +02:00
2012-10-06 09:06:40 +02:00
//vector<string> results;
2011-10-06 20:04:59 +02:00
const vector < string > & dirList = Config : : getInstance ( ) . getPathListForType ( ptScenarios ) ;
string scenarioFile = Scenario : : getScenarioPath ( dirList , name ) ;
2011-10-21 22:57:42 +02:00
try {
gameStarted = false ;
2012-11-10 07:37:23 +01:00
//printf("\nname [%s] scenarioFile [%s] results.size() = " MG_SIZE_T_SPECIFIER "\n",name.c_str(),scenarioFile.c_str(),results.size());
2012-01-09 22:08:19 +01:00
//printf("[%s:%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2013-05-21 22:28:42 +02:00
bool isTutorial = Scenario : : isGameTutorial ( scenarioFile ) ;
2011-10-06 20:04:59 +02:00
ScenarioInfo scenarioInfo ;
2013-05-21 22:28:42 +02:00
Scenario : : loadScenarioInfo ( scenarioFile , & scenarioInfo , isTutorial ) ;
2011-10-06 20:04:59 +02:00
2012-01-09 22:08:19 +01:00
//printf("[%s:%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2011-10-06 20:04:59 +02:00
GameSettings gameSettings ;
Scenario : : loadGameSettings ( dirList , & scenarioInfo , & gameSettings , scenarioFile ) ;
//Program *program = world->getGame()->getProgram();
//program->setState(new Game(program, &gameSettings, false));
//world->end();
2011-10-06 22:44:55 +02:00
2011-10-06 20:04:59 +02:00
//world->getMapPtr()->end();
//world.end();
2011-10-06 22:44:55 +02:00
if ( keepFactions = = false ) {
world . end ( ) ;
2013-01-23 22:03:00 +01:00
2011-10-06 22:44:55 +02:00
world . cleanup ( ) ;
world . clearTileset ( ) ;
SoundRenderer : : getInstance ( ) . stopAllSounds ( ) ;
2013-01-10 22:16:28 +01:00
masterController . clearSlaves ( true ) ;
2011-10-06 22:44:55 +02:00
deleteValues ( aiInterfaces . begin ( ) , aiInterfaces . end ( ) ) ;
aiInterfaces . clear ( ) ;
gui . end ( ) ; //selection must be cleared before deleting units
world . end ( ) ; //must die before selection because of referencers
2013-01-23 22:03:00 +01:00
BaseColorPickEntity : : resetUniqueColors ( ) ;
2011-10-06 22:44:55 +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.
Renderer & renderer = Renderer : : getInstance ( ) ;
2011-10-22 21:45:05 +02:00
renderer . endGame ( true ) ;
2011-10-06 22:44:55 +02:00
GameConstants : : updateFps = original_updateFps ;
GameConstants : : cameraFps = original_cameraFps ;
this - > setGameSettings ( & gameSettings ) ;
this - > resetMembers ( ) ;
this - > load ( ) ;
this - > init ( ) ;
2011-10-06 20:04:59 +02:00
}
2011-10-06 22:44:55 +02:00
else {
2011-10-21 22:57:42 +02:00
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
2012-01-09 22:08:19 +01:00
//printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound);
2011-10-21 22:57:42 +02:00
if ( currentAmbientSound ) {
soundRenderer . stopAmbient ( currentAmbientSound ) ;
}
//soundRenderer.stopAllSounds();
soundRenderer . stopAllSounds ( fadeMusicMilliseconds ) ;
2011-10-06 22:44:55 +02:00
world . endScenario ( ) ;
2013-01-23 22:03:00 +01:00
BaseColorPickEntity : : resetUniqueColors ( ) ;
2011-10-06 22:44:55 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . endScenario ( ) ;
world . clearTileset ( ) ;
this - > setGameSettings ( & gameSettings ) ;
this - > load ( lgt_FactionPreview | lgt_TileSet | lgt_Map | lgt_Scenario ) ;
2011-10-06 20:04:59 +02:00
2012-07-18 01:04:30 +02:00
try {
world . init ( this , gameSettings . getDefaultUnits ( ) , false ) ;
}
catch ( const exception & ex ) {
2012-07-21 01:07:44 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] \n Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-07-18 01:04:30 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
}
2011-10-07 00:19:58 +02:00
world . initUnitsForScenario ( ) ;
2011-10-06 22:44:55 +02:00
Map * map = world . getMap ( ) ;
gameCamera . init ( map - > getW ( ) , map - > getH ( ) ) ;
2011-10-06 20:04:59 +02:00
2011-10-06 22:44:55 +02: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 ) {
gameCamera . setCalculatedDefault ( map - > getMaxMapHeight ( ) + 13.0f ) ;
}
2011-10-06 20:04:59 +02:00
2012-03-26 08:48:58 +02:00
scriptManager . init ( & world , & gameCamera , loadGameNode ) ;
2011-12-02 17:07:59 +01:00
renderer . initGame ( this , this - > getGameCameraPtr ( ) ) ;
2011-10-06 20:04:59 +02:00
2011-10-06 22:44:55 +02:00
//sounds
2011-10-21 22:57:42 +02:00
//soundRenderer.stopAllSounds(fadeMusicMilliseconds);
//soundRenderer.stopAllSounds();
//soundRenderer= SoundRenderer::getInstance();
2011-10-06 20:04:59 +02:00
2011-10-06 22:44:55 +02:00
Tileset * tileset = world . getTileset ( ) ;
AmbientSounds * ambientSounds = tileset - > getAmbientSounds ( ) ;
2011-10-06 20:04:59 +02:00
2011-10-06 22:44:55 +02:00
//rain
if ( tileset - > getWeather ( ) = = wRainy & & ambientSounds - > isEnabledRain ( ) ) {
//logger.add("Starting ambient stream", true);
2011-10-21 22:57:42 +02:00
currentAmbientSound = ambientSounds - > getRain ( ) ;
2012-01-09 22:08:19 +01:00
//printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound);
2011-10-21 22:57:42 +02:00
soundRenderer . playAmbient ( currentAmbientSound ) ;
2011-10-06 22:44:55 +02:00
}
//snow
if ( tileset - > getWeather ( ) = = wSnowy & & ambientSounds - > isEnabledSnow ( ) ) {
//logger.add("Starting ambient stream", true);
2011-10-21 22:57:42 +02:00
currentAmbientSound = ambientSounds - > getSnow ( ) ;
2012-01-09 22:08:19 +01:00
//printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound);
2011-10-21 22:57:42 +02:00
soundRenderer . playAmbient ( currentAmbientSound ) ;
2011-10-06 22:44:55 +02:00
}
if ( this - > masterserverMode = = false ) {
StrSound * gameMusic = world . getThisFaction ( ) - > getType ( ) - > getMusic ( ) ;
soundRenderer . playMusic ( gameMusic ) ;
}
2011-10-21 22:57:42 +02:00
gameStarted = true ;
2011-10-06 20:04:59 +02:00
}
2011-10-06 22:44:55 +02:00
//this->init();
2011-10-06 20:04:59 +02:00
2012-01-09 22:08:19 +01:00
//printf("[%s:%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2011-10-06 20:04:59 +02:00
//Checksum checksum;
//world->loadScenario(scenarioFile, &checksum, true);
2011-10-21 22:57:42 +02:00
}
2013-02-01 09:12:20 +01:00
# if defined(WIN32)
catch ( const exception ) {
# else
2011-10-21 22:57:42 +02:00
catch ( const exception & ex ) {
2013-02-01 09:12:20 +01:00
# endif
2011-10-21 22:57:42 +02:00
gameStarted = true ;
2012-10-26 06:35:14 +02:00
totalRenderFps + + ;
2011-10-21 22:57:42 +02:00
2011-12-02 17:07:59 +01:00
throw ;
2011-10-21 22:57:42 +02:00
}
2011-10-06 20:04:59 +02:00
}
2013-01-03 18:30:59 +01:00
if ( showPerfStats ) {
sprintf ( perfBuf , " In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chronoPerf . getMillis ( ) ) ;
perfList . push_back ( perfBuf ) ;
}
if ( showPerfStats & & chronoPerf . getMillis ( ) > = 50 ) {
for ( unsigned int x = 0 ; x < perfList . size ( ) ; + + x ) {
printf ( " %s " , perfList [ x ] . c_str ( ) ) ;
}
}
2010-05-29 09:58:58 +02:00
}
catch ( const exception & ex ) {
2012-10-02 08:20:39 +02:00
quitPendingIndicator = true ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
2010-10-06 22:22:06 +02:00
2012-10-02 08:20:39 +02:00
//printf("#100 quitPendingIndicator = %d, errorMessageBox.getEnabled() = %d\n",quitPendingIndicator,errorMessageBox.getEnabled());
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
}
}
2013-02-16 11:07:36 +01:00
bool Game : : switchSetupForSlots ( ServerInterface * & serverInterface ,
int startIndex , int endIndex , bool onlyNetworkUnassigned ) {
bool switchRequested = false ;
if ( serverInterface = = NULL ) {
return switchRequested ;
}
MutexSafeWrapper safeMutex ( serverInterface - > getSwitchSetupRequestsMutex ( ) , CODE_AT_LINE ) ;
SwitchSetupRequest * * switchSetupRequests = serverInterface - > getSwitchSetupRequests ( ) ;
if ( switchSetupRequests = = NULL ) {
return switchRequested ;
}
Map * map = world . getMap ( ) ;
for ( int i = startIndex ; i < endIndex ; + + i ) {
if ( switchSetupRequests [ i ] ! = NULL ) {
//printf("Faction Index: %d Switch slot = %d to = %d current control = %d\n",i,switchSetupRequests[i]->getCurrentSlotIndex(),switchSetupRequests[i]->getToSlotIndex(),gameSettings.getFactionControl(i));
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] switchSetupRequests[i]->getSwitchFlags() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , switchSetupRequests [ i ] - > getSwitchFlags ( ) ) ;
if ( onlyNetworkUnassigned = = true & & gameSettings . getFactionControl ( i ) ! = ctNetworkUnassigned ) {
if ( i < map - > getMaxPlayers ( ) | | ( i > = map - > getMaxPlayers ( ) & & gameSettings . getFactionControl ( i ) ! = ctNetwork ) ) {
continue ;
}
}
if ( gameSettings . getFactionControl ( i ) = = ctNetwork | |
gameSettings . getFactionControl ( i ) = = ctNetworkUnassigned | |
//(gameSettings.getFactionControl(i) != ctClosed && gameSettings.getFactionControl(i) != ctHuman)) {
( gameSettings . getFactionControl ( i ) ! = ctHuman ) ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] switchSetupRequests[i]->getToFactionIndex() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , switchSetupRequests [ i ] - > getToSlotIndex ( ) ) ;
if ( switchSetupRequests [ i ] - > getToSlotIndex ( ) ! = - 1 ) {
int newSlotIdx = switchSetupRequests [ i ] - > getToSlotIndex ( ) ;
//printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentSlotIndex(),switchSetupRequests[i]->getToSlotIndex());
int switchSlotIdx = switchSetupRequests [ i ] - > getCurrentSlotIndex ( ) ;
if ( serverInterface - > switchSlot ( switchSlotIdx , newSlotIdx ) ) {
//printf("switchSlot returned true\n");
switchRequested = true ;
int oldFactionIndex = gameSettings . getFactionIndexForStartLocation ( switchSlotIdx ) ;
int newFactionIndex = gameSettings . getFactionIndexForStartLocation ( newSlotIdx ) ;
//printf("Switching faction for index %d [%d] to %d\n",newSlotIdx,switchSlotIdx,gameSettings.getFactionControl(newFactionIndex));
gameSettings . setNetworkPlayerName ( oldFactionIndex , " " ) ;
serverInterface - > gameSettings . setNetworkPlayerName ( oldFactionIndex , " " ) ;
2013-06-01 04:31:12 +02:00
gameSettings . setNetworkPlayerUUID ( oldFactionIndex , " " ) ;
serverInterface - > gameSettings . setNetworkPlayerUUID ( oldFactionIndex , " " ) ;
2013-02-16 11:07:36 +01:00
gameSettings . setFactionControl ( newFactionIndex , ctNetwork ) ;
serverInterface - > gameSettings . setFactionControl ( newFactionIndex , ctNetwork ) ;
//printf("#1a Faction Index: %d control: %d startlocation: %d\n",newFactionIndex,gameSettings.getFactionControl(newFactionIndex),gameSettings.getStartLocationIndex(newFactionIndex));
//printf("#2a Faction Index: %d control: %d startlocation: %d\n",newFactionIndex,serverInterface->gameSettings.getFactionControl(newFactionIndex),serverInterface->gameSettings.getStartLocationIndex(newFactionIndex));
try {
//if(switchSetupRequests[i]->getSelectedFactionName() != "") {
// listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
//}
//if(switchSetupRequests[i]->getToTeam() != -1) {
// listBoxTeams[newFactionIdx].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
//}
if ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ! = " " ) {
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[newFactionIdx].getText() [%s] switchSetupRequests[i]->getNetworkPlayerName() [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,labelPlayerNames[newFactionIdx].getText().c_str(),switchSetupRequests[i]->getNetworkPlayerName().c_str());
gameSettings . setNetworkPlayerName ( newFactionIndex , switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
serverInterface - > gameSettings . setNetworkPlayerName ( newFactionIndex , switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
}
// if(gameSettings.getFactionControl(switchFactionIdx) == ctNetworkUnassigned) {
// serverInterface->removeSlot(switchFactionIdx);
// //listBoxControls[switchFactionIdx].setSelectedItemIndex(ctClosed);
// gameSettings.getFactionControl(switchFactionIdx)
//
// labelPlayers[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players);
// labelPlayerNames[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players);
// listBoxControls[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players);
// listBoxFactions[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players);
// listBoxTeams[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players);
// labelNetStatus[switchSlotIdx].setVisible(switchSlotIdx+1 <= mapInfo.players);
// }
}
catch ( const runtime_error & e ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] caught exception error = [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
}
}
2013-03-06 15:29:49 +01:00
//printf("AFTER switchSlot returned\n");
2013-02-16 11:07:36 +01:00
}
else {
try {
//if(switchSetupRequests[i]->getSelectedFactionName() != "") {
// listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
//}
//if(switchSetupRequests[i]->getToTeam() != -1) {
// listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
//}
if ( ( switchSetupRequests [ i ] - > getSwitchFlags ( ) & ssrft_NetworkPlayerName ) = = ssrft_NetworkPlayerName ) {
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, switchSetupRequests[i]->getSwitchFlags() = %d, switchSetupRequests[i]->getNetworkPlayerName() [%s], labelPlayerNames[i].getText() [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,switchSetupRequests[i]->getSwitchFlags(),switchSetupRequests[i]->getNetworkPlayerName().c_str(),labelPlayerNames[i].getText().c_str());
if ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
//labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName());
gameSettings . setNetworkPlayerName ( i , switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
serverInterface - > gameSettings . setNetworkPlayerName ( i , switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
switchRequested = true ;
}
else {
//labelPlayerNames[i].setText("");
gameSettings . setNetworkPlayerName ( i , " " ) ;
serverInterface - > gameSettings . setNetworkPlayerName ( i , " " ) ;
switchRequested = true ;
}
//SetActivePlayerNameEditor();
//switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName);
}
}
catch ( const runtime_error & e ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] caught exception error = [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
}
}
}
delete switchSetupRequests [ i ] ;
switchSetupRequests [ i ] = NULL ;
}
}
return switchRequested ;
}
2012-06-12 22:37:00 +02:00
void Game : : updateNetworkMarkedCells ( ) {
try {
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
if ( gameNetworkInterface ! = NULL & &
2012-09-25 09:05:52 +02:00
gameNetworkInterface - > getMarkedCellList ( false ) . empty ( ) = = false ) {
2012-06-12 22:37:00 +02:00
std : : vector < MarkedCell > chatList = gameNetworkInterface - > getMarkedCellList ( true ) ;
for ( int idx = 0 ; idx < chatList . size ( ) ; idx + + ) {
MarkedCell mc = chatList [ idx ] ;
2012-09-25 09:05:52 +02:00
if ( mc . getFactionIndex ( ) > = 0 ) {
mc . setFaction ( ( const Faction * ) world . getFaction ( mc . getFactionIndex ( ) ) ) ;
}
2012-06-12 22:37:00 +02:00
Map * map = world . getMap ( ) ;
Vec2i surfaceCellPos = map - > toSurfCoords ( mc . getTargetPos ( ) ) ;
mapMarkedCellList [ surfaceCellPos ] = mc ;
}
}
}
catch ( const std : : exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-06-12 22:37:00 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
}
2012-06-13 18:19:44 +02:00
void Game : : updateNetworkUnMarkedCells ( ) {
try {
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
if ( gameNetworkInterface ! = NULL & &
gameNetworkInterface - > getUnMarkedCellList ( false ) . empty ( ) = = false ) {
2012-09-22 22:37:42 +02:00
//Lang &lang= Lang::getInstance();
2012-06-13 18:19:44 +02:00
std : : vector < UnMarkedCell > chatList = gameNetworkInterface - > getUnMarkedCellList ( true ) ;
for ( int idx = 0 ; idx < chatList . size ( ) ; idx + + ) {
UnMarkedCell mc = chatList [ idx ] ;
mc . setFaction ( ( const Faction * ) world . getFaction ( mc . getFactionIndex ( ) ) ) ;
Map * map = world . getMap ( ) ;
Vec2i surfaceCellPos = map - > toSurfCoords ( mc . getTargetPos ( ) ) ;
mapMarkedCellList . erase ( surfaceCellPos ) ;
}
}
}
catch ( const std : : exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-06-13 18:19:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
}
2013-02-16 11:07:36 +01:00
2012-07-13 23:50:34 +02:00
void Game : : updateNetworkHighligtedCells ( ) {
try {
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
//update the current entries
for ( int idx = highlightedCells . size ( ) - 1 ; idx > = 0 ; idx - - ) {
MarkedCell * mc = & highlightedCells [ idx ] ;
mc - > decrementAliveCount ( ) ;
2012-10-13 07:06:53 +02:00
if ( mc - > getAliveCount ( ) < 0 ) {
2012-07-13 23:50:34 +02:00
highlightedCells . erase ( highlightedCells . begin ( ) + idx ) ;
}
}
if ( gameNetworkInterface ! = NULL & &
gameNetworkInterface - > getHighlightedCellList ( false ) . empty ( ) = = false ) {
2012-09-22 22:37:42 +02:00
//Lang &lang= Lang::getInstance();
2012-07-13 23:50:34 +02:00
std : : vector < MarkedCell > highlighList = gameNetworkInterface - > getHighlightedCellList ( true ) ;
for ( int idx = 0 ; idx < highlighList . size ( ) ; idx + + ) {
MarkedCell mc = highlighList [ idx ] ; // I want a copy here
2012-10-15 22:39:54 +02:00
if ( mc . getFactionIndex ( ) > = 0 ) {
mc . setFaction ( ( const Faction * ) world . getFaction ( mc . getFactionIndex ( ) ) ) ; // set faction pointer
}
2012-07-13 23:50:34 +02:00
addOrReplaceInHighlightedCells ( mc ) ;
}
}
}
catch ( const std : : exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-07-13 23:50:34 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
}
void Game : : addOrReplaceInHighlightedCells ( MarkedCell mc ) {
2012-10-13 07:06:53 +02:00
if ( mc . getFactionIndex ( ) > = 0 ) {
for ( int i = highlightedCells . size ( ) - 1 ; i > = 0 ; i - - ) {
MarkedCell * currentMc = & highlightedCells [ i ] ;
if ( currentMc - > getFactionIndex ( ) = = mc . getFactionIndex ( ) ) {
highlightedCells . erase ( highlightedCells . begin ( ) + i ) ;
}
2012-07-13 23:50:34 +02:00
}
}
2012-10-13 07:06:53 +02:00
if ( mc . getAliveCount ( ) < = 0 ) {
mc . setAliveCount ( 200 ) ;
}
2012-07-13 23:50:34 +02:00
highlightedCells . push_back ( mc ) ;
2012-07-15 23:01:56 +02:00
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
2012-10-15 22:39:54 +02:00
const Faction * faction = mc . getFaction ( ) ;
if ( getWorld ( ) - > getThisFaction ( ) = = NULL ) {
throw megaglest_runtime_error ( " getWorld() - > getThisFaction ( ) = = NULL " ) ;
}
//printf("faction [%p][%s]\n",faction,(faction != NULL ? faction->getType()->getName().c_str() : ""));
if ( ( faction = = NULL ) | |
( faction - > getTeam ( ) = = getWorld ( ) - > getThisFaction ( ) - > getTeam ( ) ) ) {
2012-07-17 23:29:39 +02:00
soundRenderer . playFx ( coreData . getMarkerSound ( ) ) ;
}
2012-07-13 23:50:34 +02:00
}
2010-10-19 01:09:43 +02:00
void Game : : ReplaceDisconnectedNetworkPlayersWithAI ( bool isNetworkGame , NetworkRole role ) {
2011-11-25 10:12:53 +01:00
if ( role = = nrServer & & isNetworkGame = = true & &
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , lastNetworkPlayerConnectionCheck ) > = NETWORK_PLAYER_CONNECTION_CHECK_SECONDS ) {
2011-11-25 10:12:53 +01:00
lastNetworkPlayerConnectionCheck = time ( NULL ) ;
2010-10-19 01:09:43 +02:00
Logger & logger = Logger : : getInstance ( ) ;
ServerInterface * server = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2013-01-10 22:16:28 +01:00
bool newAIPlayerCreated = false ;
2010-10-19 01:09:43 +02:00
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 ) ) {
2011-11-25 10:12:53 +01:00
//ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
//if(aiInterfaces[i] == NULL && (slot == NULL || slot->isConnected() == false)) {
if ( aiInterfaces [ i ] = = NULL & &
server - > isClientConnected ( faction - > getStartLocationIndex ( ) ) = = false ) {
2011-02-15 04:32:14 +01:00
faction - > setFactionDisconnectHandled ( true ) ;
2010-10-19 01:09:43 +02:00
2012-06-09 17:21:18 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-03-30 07:53:33 +02:00
if ( faction - > getPersonalityType ( ) ! = fpt_Observer ) {
2012-10-10 01:18:07 +02:00
//faction->setControlType(ctCpuUltra);
2011-02-15 04:32:14 +01:00
aiInterfaces [ i ] = new AiInterface ( * this , i , faction - > getTeam ( ) , faction - > getStartLocationIndex ( ) ) ;
2011-11-02 18:17:28 +01:00
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , Lang : : getInstance ( ) . get ( " LogScreenGameLoadingCreatingAIFaction " , " " , true ) . c_str ( ) , i ) ;
2011-11-02 18:17:28 +01:00
logger . add ( szBuf , true ) ;
2011-02-15 04:32:14 +01:00
2011-04-05 16:59:48 +02:00
string msg = " Player #%d [%s] has disconnected, switching player to AI mode! " ;
if ( lang . hasString ( " GameSwitchPlayerToAI " ) ) {
msg = lang . get ( " GameSwitchPlayerToAI " ) ;
}
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , msg . c_str ( ) , i + 1 , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) ) ;
2012-06-09 17:21:18 +02:00
commander . tryNetworkPlayerDisconnected ( i ) ;
2013-01-10 22:16:28 +01:00
newAIPlayerCreated = true ;
2011-02-15 04:32:14 +01:00
}
else {
2011-04-05 16:59:48 +02:00
string msg = " Player #%d [%s] has disconnected, but player was only an observer! " ;
if ( lang . hasString ( " GameSwitchPlayerObserverToAI " ) ) {
msg = lang . get ( " GameSwitchPlayerObserverToAI " ) ;
}
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , 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
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
}
}
}
2013-01-10 22:16:28 +01:00
if ( newAIPlayerCreated = = true & & Config : : getInstance ( ) . getBool ( " EnableNewThreadManager " , " false " ) = = true ) {
bool enableServerControlledAI = this - > gameSettings . getEnableServerControlledAI ( ) ;
masterController . clearSlaves ( true ) ;
std : : vector < SlaveThreadControllerInterface * > slaveThreadList ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
if ( faction - > getCpuControl ( enableServerControlledAI , isNetworkGame , role ) = = true ) {
slaveThreadList . push_back ( aiInterfaces [ i ] - > getWorkerThread ( ) ) ;
}
}
masterController . setSlaves ( slaveThreadList ) ;
}
2010-10-19 01:09:43 +02:00
}
}
2010-03-13 22:10:45 +01:00
void Game : : updateCamera ( ) {
2011-10-05 05:42:29 +02:00
if ( currentUIState ! = NULL ) {
currentUIState - > updateCamera ( ) ;
return ;
}
2010-03-13 22:10:45 +01:00
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
2012-03-13 00:40:54 +01:00
if ( this - > loadGameNode = = NULL ) {
2012-09-27 23:10:28 +02:00
gameCamera . setState ( GameCamera : : sGame ) ;
2012-03-13 00:40:54 +01:00
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
2011-12-02 18:27:13 +01:00
updateWorldStats ( ) ;
2011-12-02 17:07:59 +01: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 ) ;
2011-12-02 17:07:59 +01:00
if ( server - > isClientConnected ( faction - > getStartLocationIndex ( ) ) = = true ) {
2011-09-24 09:46:56 +02:00
connectedClients + + ;
}
}
if ( connectedClients = = 0 ) {
quitTriggeredIndicator = true ;
}
2012-01-06 07:55:27 +01:00
else {
string str = " " ;
std : : map < int , string > factionDebugInfo ;
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , lastMasterServerGameStatsDump ) > = GAME_STATS_DUMP_INTERVAL ) {
2012-01-06 07:55:27 +01:00
lastMasterServerGameStatsDump = time ( NULL ) ;
str = getDebugStats ( factionDebugInfo ) ;
printf ( " == Current in-game stats (interval %d) == \n %s \n " , GAME_STATS_DUMP_INTERVAL , str . c_str ( ) ) ;
}
}
2011-09-24 09:46:56 +02:00
}
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 ;
}
2011-10-05 05:42:29 +02:00
else {
Renderer & renderer = Renderer : : getInstance ( ) ;
2012-05-24 08:16:54 +02:00
if ( renderer . getCustom3dMenu ( ) ! = NULL ) {
renderer . setCustom3dMenu ( NULL ) ;
2011-10-05 05:42:29 +02:00
}
}
2011-10-03 02:36:28 +02:00
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
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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 ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== tick ====================
2012-04-12 17:38:53 +02:00
void Game : : removeUnitFromSelection ( const Unit * unit ) {
2012-04-12 22:43:19 +02:00
try {
Selection * selection = gui . getSelectionPtr ( ) ;
for ( int i = 0 ; i < selection - > getCount ( ) ; + + i ) {
const Unit * currentUnit = selection - > getUnit ( i ) ;
if ( currentUnit = = unit ) {
selection - > unSelect ( i ) ;
break ;
}
}
}
catch ( const exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-04-12 22:43:19 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
2012-10-17 22:15:50 +02:00
}
//abort();
}
}
bool Game : : addUnitToSelection ( Unit * unit ) {
bool result = false ;
try {
Selection * selection = gui . getSelectionPtr ( ) ;
if ( selection ! = NULL ) {
result = selection - > select ( unit ) ;
}
}
catch ( const exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-10-17 22:15:50 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
//abort();
}
return result ;
}
void Game : : addUnitToGroupSelection ( Unit * unit , int groupIndex ) {
try {
Selection * selection = gui . getSelectionPtr ( ) ;
if ( selection ! = NULL ) {
selection - > addUnitToGroup ( groupIndex , unit ) ;
}
}
catch ( const exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-10-17 22:15:50 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
//abort();
}
}
void Game : : removeUnitFromGroupSelection ( int unitId , int groupIndex ) {
try {
Selection * selection = gui . getSelectionPtr ( ) ;
if ( selection ! = NULL ) {
selection - > removeUnitFromGroup ( groupIndex , unitId ) ;
}
}
catch ( const exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-10-17 22:15:50 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
}
//abort();
}
}
void Game : : recallGroupSelection ( int groupIndex ) {
try {
Selection * selection = gui . getSelectionPtr ( ) ;
if ( selection ! = NULL ) {
selection - > recallGroup ( groupIndex ) ;
}
}
catch ( const exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-10-17 22:15:50 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , szBuf ) ;
if ( errorMessageBox . getEnabled ( ) = = false ) {
ErrorDisplayMessage ( ex . what ( ) , true ) ;
2012-04-12 17:38:53 +02:00
}
2012-04-12 22:43:19 +02:00
//abort();
2012-04-12 17:38:53 +02:00
}
}
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 ;
}
2012-05-22 08:17:56 +02:00
void Game : : setupRenderForVideo ( ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
2012-05-23 21:59:52 +02:00
//renderer.clearBuffers();
2012-05-22 08:17:56 +02:00
//3d
2012-05-23 21:59:52 +02:00
//renderer.reset3dMenu();
//renderer.clearZBuffer();
2012-05-22 08:17:56 +02:00
//2d
2012-05-23 21:59:52 +02:00
//renderer.reset2d();
renderer . setupRenderForVideo ( ) ;
2012-05-22 08:17:56 +02:00
}
void Game : : tryPauseToggle ( bool pauseValue ) {
bool allowAdminMenuItems = false ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
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 ;
}
}
bool isNetworkGame = this - > gameSettings . isNetworkGame ( ) ;
//printf("Try Pause allowAdminMenuItems = %d, pauseValue = %d\n",allowAdminMenuItems,pauseValue);
if ( allowAdminMenuItems ) {
if ( pauseValue = = true ) {
2013-03-06 15:29:49 +01:00
commander . tryPauseGame ( false , false ) ;
2012-05-22 08:17:56 +02:00
}
else {
if ( isNetworkGame = = false ) {
2013-03-06 15:29:49 +01:00
setPaused ( pauseValue , true , false , false ) ;
2012-05-22 08:17:56 +02:00
}
else {
2013-03-06 15:29:49 +01:00
commander . tryResumeGame ( false , false ) ;
2012-05-22 08:17:56 +02:00
}
}
}
}
2012-09-24 19:13:27 +02:00
void Game : : startMarkCell ( ) {
int totalMarkedCellsForPlayer = 0 ;
for ( std : : map < Vec2i , MarkedCell > : : iterator iterMap = mapMarkedCellList . begin ( ) ;
iterMap ! = mapMarkedCellList . end ( ) ; + + iterMap ) {
MarkedCell & bm = iterMap - > second ;
if ( bm . getPlayerIndex ( ) = = world . getThisFaction ( ) - > getStartLocationIndex ( ) ) {
totalMarkedCellsForPlayer + + ;
}
}
const int MAX_MARKER_COUNT = 5 ;
if ( totalMarkedCellsForPlayer < MAX_MARKER_COUNT ) {
isMarkCellEnabled = true ;
}
else {
Lang & lang = Lang : : getInstance ( ) ;
console . addLine ( lang . get ( " MaxMarkerCount " ) + " " + intToStr ( MAX_MARKER_COUNT ) ) ;
}
}
2012-09-25 09:05:52 +02:00
void Game : : processInputText ( string text , bool cancelled ) {
isMarkCellTextEnabled = false ;
if ( cancelled = = false ) {
//printf("Note [%s]\n",text.c_str());
cellMarkedData . setNote ( text ) ;
addCellMarker ( cellMarkedPos , cellMarkedData ) ;
// if(text.find("\\n") != text.npos) {
// replaceAll(text, "\\n", "\n");
// }
// if(text.find("\\t") != text.npos) {
// replaceAll(text, "\\t", "\t");
// }
//
// cellMarkedData.setNote(text);
// mapMarkedCellList[cellMarkedPos] = cellMarkedData;
//
// GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
//
// int factionIndex = -1;
// int playerIndex = -1;
// if(cellMarkedData.getFaction() != NULL) {
// factionIndex = cellMarkedData.getFaction()->getIndex();
// playerIndex = cellMarkedData.getFaction()->getStartLocationIndex();
// }
// gameNetworkInterface->sendMarkCellMessage(
// cellMarkedData.getTargetPos(),
// factionIndex,
// cellMarkedData.getNote(),
// playerIndex);
//
// Renderer &renderer= Renderer::getInstance();
// renderer.forceQuadCacheUpdate();
}
}
void Game : : addCellMarker ( Vec2i cellPos , MarkedCell cellData ) {
//printf("Note [%s]\n",text.c_str());
string text = cellData . getNote ( ) ;
if ( text . find ( " \\ n " ) ! = text . npos ) {
replaceAll ( text , " \\ n " , " \n " ) ;
}
if ( text . find ( " \\ t " ) ! = text . npos ) {
replaceAll ( text , " \\ t " , " \t " ) ;
}
cellData . setNote ( text ) ;
mapMarkedCellList [ cellPos ] = cellData ;
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
int factionIndex = - 1 ;
int playerIndex = - 1 ;
if ( cellData . getFaction ( ) ! = NULL ) {
factionIndex = cellData . getFaction ( ) - > getIndex ( ) ;
playerIndex = cellData . getFaction ( ) - > getStartLocationIndex ( ) ;
}
//printf("Adding Cell marker pos [%s] factionIndex [%d] note [%s] playerIndex = %d\n",cellData.getTargetPos().getString().c_str(),factionIndex,cellData.getNote().c_str(),playerIndex);
gameNetworkInterface - > sendMarkCellMessage (
cellData . getTargetPos ( ) ,
factionIndex ,
cellData . getNote ( ) ,
playerIndex ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . forceQuadCacheUpdate ( ) ;
}
void Game : : removeCellMarker ( Vec2i surfaceCellPos , const Faction * faction ) {
//Vec2i surfaceCellPos = map->toSurfCoords(Vec2i(xCell,yCell));
Map * map = world . getMap ( ) ;
SurfaceCell * sc = map - > getSurfaceCell ( surfaceCellPos ) ;
Vec3f vertex = sc - > getVertex ( ) ;
Vec2i targetPos ( vertex . x , vertex . z ) ;
//printf("Remove Cell marker lookup pos [%s] factionIndex [%d]\n",surfaceCellPos.getString().c_str(),(faction != NULL ? faction->getIndex() : -1));
if ( mapMarkedCellList . find ( surfaceCellPos ) ! = mapMarkedCellList . end ( ) ) {
MarkedCell mc = mapMarkedCellList [ surfaceCellPos ] ;
if ( mc . getFaction ( ) = = faction ) {
mapMarkedCellList . erase ( surfaceCellPos ) ;
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
int factionIndex = ( faction ! = NULL ? faction - > getIndex ( ) : - 1 ) ;
//printf("Remvoing Cell marker pos [%s] factionIndex [%d] note [%s]\n",mc.getTargetPos().getString().c_str(),factionIndex,mc.getNote().c_str());
gameNetworkInterface - > sendUnMarkCellMessage ( mc . getTargetPos ( ) , factionIndex ) ;
}
}
2012-11-10 07:37:23 +01:00
//printf("#1 ADDED in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size());
2012-09-25 09:05:52 +02:00
//isUnMarkCellEnabled = false;
Renderer & renderer = Renderer : : getInstance ( ) ;
//renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos);
renderer . forceQuadCacheUpdate ( ) ;
}
2012-10-13 07:06:53 +02:00
void Game : : showMarker ( Vec2i cellPos , MarkedCell cellData ) {
//setMarker = true;
//if(setMarker) {
//Vec2i targetPos = cellData.targetPos;
//Vec2i screenPos(x,y-60);
//Renderer &renderer= Renderer::getInstance();
//renderer.computePosition(screenPos, targetPos);
//Vec2i surfaceCellPos = map->toSurfCoords(targetPos);
//MarkedCell mc(targetPos,world.getThisFaction(),"none",world.getThisFaction()->getStartLocationIndex());
addOrReplaceInHighlightedCells ( cellData ) ;
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
gameNetworkInterface - > sendHighlightCellMessage ( cellData . getTargetPos ( ) , cellData . getFactionIndex ( ) ) ;
//}
}
2012-09-25 09:05:52 +02:00
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 ;
}
2012-07-15 11:50:44 +02:00
cameraDragAllowed = false ;
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 {
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
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 ;
2012-06-12 22:37:00 +02:00
bool originalIsMarkCellEnabled = isMarkCellEnabled ;
2012-06-13 18:19:44 +02:00
bool originalIsUnMarkCellEnabled = isUnMarkCellEnabled ;
2010-05-29 09:58:58 +02:00
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);
2013-02-17 08:15:01 +01:00
//printf("popupMenu.mouseClick == true result.first = %d disconnectPlayerPopupMenuIndex = %d\n",result.first,disconnectPlayerPopupMenuIndex);
2011-09-21 08:51:28 +02:00
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 ) ;
2011-10-05 18:02:26 +02:00
2012-03-30 07:53:33 +02:00
if ( faction - > getPersonalityType ( ) ! = fpt_Observer & &
2011-10-05 18:02:26 +02:00
uniqueTeamNumbersUsed . find ( faction - > getTeam ( ) ) = = uniqueTeamNumbersUsed . end ( ) ) {
2011-09-21 08:51:28 +02:00
uniqueTeamNumbersUsed [ faction - > getTeam ( ) ] = true ;
}
2012-03-30 07:53:33 +02:00
if ( faction - > getPersonalityType ( ) ! = fpt_Observer & &
2011-10-05 18:02:26 +02:00
world . getThisFaction ( ) - > getIndex ( ) ! = faction - > getIndex ( ) & &
world . getThisFaction ( ) - > getTeam ( ) ! = faction - > getTeam ( ) ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2011-09-21 10:00:00 +02:00
if ( lang . hasString ( " JoinPlayerTeam " ) = = true ) {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , lang . get ( " JoinPlayerTeam " ) . c_str ( ) , faction - > getIndex ( ) , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) , faction - > getTeam ( ) ) ;
2011-09-21 10:00:00 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Join player #%d - %s on Team: %d " , faction - > getIndex ( ) , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) , faction - > getTeam ( ) ) ;
2011-09-21 10:00:00 +02:00
}
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 ) ;
}
2012-09-21 07:45:09 +02:00
else if ( result . first = = disconnectPlayerPopupMenuIndex ) {
Lang & lang = Lang : : getInstance ( ) ;
2013-05-26 08:45:56 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
ServerInterface * serverInterface = NULL ;
if ( role = = nrServer ) {
serverInterface = dynamic_cast < ServerInterface * > ( networkManager . getServerInterface ( ) ) ;
}
2012-09-21 07:45:09 +02:00
disconnectPlayerIndexMap . clear ( ) ;
std : : vector < string > menuItems ;
for ( unsigned int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
2012-09-21 17:03:13 +02:00
//printf("faction->getPersonalityType() = %d index [%d,%d] control [%d] networkstatus [%d]\n",faction->getPersonalityType(),world.getThisFaction()->getIndex(),faction->getIndex(),faction->getControlType(),this->gameSettings.getNetworkPlayerStatuses(i));
2012-09-21 07:45:09 +02:00
2013-05-26 08:45:56 +02:00
bool isSlotJoinInProgressClient = false ;
if ( serverInterface ! = NULL ) {
ConnectionSlot * slot = serverInterface - > getSlot ( faction - > getStartLocationIndex ( ) ) ;
if ( slot ! = NULL & & slot - > getConnectHasHandshaked ( ) = = true & &
slot - > getCurrentFrameCount ( ) < = 0 ) {
isSlotJoinInProgressClient = true ;
}
}
2013-05-28 09:10:13 +02:00
//printf("isSlotJoinInProgressClient: %d [%d] [%d][%d] [%d] [%d] [%d]\n",
// isSlotJoinInProgressClient,faction->getPersonalityType(),faction->getIndex(),world.getThisFaction()->getIndex(),faction->getControlType(),this->gameSettings.getNetworkPlayerStatuses(i),i);
2013-05-26 08:45:56 +02:00
if ( isSlotJoinInProgressClient = = true | |
( faction - > getPersonalityType ( ) ! = fpt_Observer & &
2012-09-21 07:45:09 +02:00
world . getThisFaction ( ) - > getIndex ( ) ! = faction - > getIndex ( ) & &
2012-09-21 17:03:13 +02:00
faction - > getControlType ( ) = = ctNetwork & &
2013-05-26 08:45:56 +02:00
this - > gameSettings . getNetworkPlayerStatuses ( i ) ! = npst_Disconnected ) ) {
2012-09-21 07:45:09 +02:00
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-09-21 07:45:09 +02:00
if ( lang . hasString ( " DisconnectNetorkPlayerIndex " ) = = true ) {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , lang . get ( " DisconnectNetorkPlayerIndex " ) . c_str ( ) , faction - > getIndex ( ) + 1 , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) ) ;
2012-09-21 07:45:09 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Disconnect player #%d - %s: " , faction - > getIndex ( ) + 1 , this - > gameSettings . getNetworkPlayerName ( i ) . c_str ( ) ) ;
2012-09-21 07:45:09 +02:00
}
menuItems . push_back ( szBuf ) ;
2012-09-22 04:17:49 +02:00
//disconnectPlayerIndexMap[menuItems.size()-1] = faction->getStartLocationIndex();
disconnectPlayerIndexMap [ menuItems . size ( ) - 1 ] = faction - > getIndex ( ) ;
2012-09-21 07:45:09 +02:00
}
}
menuItems . push_back ( lang . get ( " Cancel " ) ) ;
disconnectPlayerIndexMap [ menuItems . size ( ) - 1 ] = CANCEL_DISCONNECT_PLAYER ;
popupMenuDisconnectPlayer . setW ( 100 ) ;
popupMenuDisconnectPlayer . setH ( 100 ) ;
popupMenuDisconnectPlayer . init ( lang . get ( " DisconnectNetorkPlayer " ) , menuItems ) ;
popupMenuDisconnectPlayer . setEnabled ( true ) ;
popupMenuDisconnectPlayer . 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 ;
2011-10-05 05:42:29 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
2012-05-24 08:16:54 +02:00
renderer . setCustom3dMenu ( newMenu ) ;
2011-10-05 05:42:29 +02:00
//currentUIState->load();
currentUIState - > init ( ) ;
2013-04-30 08:17:30 +02:00
// open keyboard shortcuts setup screen
newMenu - > setState ( new MenuStateKeysetup ( program , newMenu , & currentUIState ) ) ;
2011-10-03 02:36:28 +02:00
}
2011-10-03 22:48:09 +02:00
else if ( result . first = = pauseGamePopupMenuIndex ) {
//this->setPaused(!paused);
//printf("popup paused = %d\n",paused);
2011-10-25 20:39:11 +02:00
bool allowAdminMenuItems = false ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
if ( role = = nrServer ) {
allowAdminMenuItems = true ;
2011-10-03 22:48:09 +02:00
}
2011-10-25 20:39:11 +02:00
else if ( role = = nrClient ) {
ClientInterface * clientInterface = dynamic_cast < ClientInterface * > ( networkManager . getClientInterface ( ) ) ;
if ( clientInterface ! = NULL & &
gameSettings . getMasterserver_admin ( ) = = clientInterface - > getSessionKey ( ) ) {
allowAdminMenuItems = true ;
}
}
if ( allowAdminMenuItems ) {
2012-04-01 20:23:26 +02:00
if ( getPaused ( ) = = false ) {
2013-03-06 15:29:49 +01:00
commander . tryPauseGame ( false , false ) ;
2011-10-25 20:39:11 +02:00
}
else {
2013-03-06 15:29:49 +01:00
commander . tryResumeGame ( false , false ) ;
2011-10-25 20:39:11 +02:00
}
2011-10-03 22:48:09 +02:00
}
}
2012-04-14 01:13:02 +02:00
else if ( result . first = = saveGamePopupMenuIndex ) {
saveGame ( ) ;
}
2012-09-24 19:13:27 +02:00
//else if(result.first == markCellPopupMenuIndex) {
// startMarkCell();
//}
//else if(result.first == unmarkCellPopupMenuIndex) {
// isUnMarkCellEnabled = true;
//}
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 ) ;
2012-10-06 09:06:40 +02:00
//bool isNetworkGame = this->gameSettings.isNetworkGame();
2011-09-21 08:51:28 +02:00
int teamIndex = switchTeamIndexMap [ result . first ] ;
switch ( teamIndex ) {
case CREATE_NEW_TEAM :
{
int newTeam = getFirstUnusedTeamNumber ( ) ;
2012-10-06 09:06:40 +02:00
//if(isNetworkGame == true) {
2011-09-21 08:51:28 +02:00
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeam ( faction , newTeam ) ;
2012-10-06 09:06:40 +02:00
//}
//else {
// const Faction *faction = world.getThisFaction();
// commander.trySwitchTeam(faction,newTeam);
//}
2011-09-21 08:51:28 +02:00
}
break ;
case CANCEL_SWITCH_TEAM :
break ;
default :
2012-10-06 09:06:40 +02:00
//if(isNetworkGame == true) {
2011-09-21 08:51:28 +02:00
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeam ( faction , teamIndex ) ;
2012-10-06 09:06:40 +02:00
//}
//else {
// const Faction *faction = world.getThisFaction();
// commander.trySwitchTeam(faction,teamIndex);
//}
2011-09-21 08:51:28 +02:00
break ;
}
}
2012-09-21 07:45:09 +02:00
else if ( popupMenuDisconnectPlayer . mouseClick ( x , y ) ) {
//popupMenuSwitchTeams
std : : pair < int , string > result = popupMenuDisconnectPlayer . mouseClickedMenuItem ( x , y ) ;
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
popupMenuDisconnectPlayer . setEnabled ( false ) ;
popupMenuDisconnectPlayer . setVisible ( false ) ;
//bool isNetworkGame = this->gameSettings.isNetworkGame();
2012-09-22 04:17:49 +02:00
//int playerIndex = disconnectPlayerIndexMap[result.first];
int factionIndex = disconnectPlayerIndexMap [ result . first ] ;
switch ( factionIndex ) {
2012-09-21 07:45:09 +02:00
case CANCEL_DISCONNECT_PLAYER :
break ;
default :
// if(isNetworkGame == true) {
// const Faction *faction = world.getThisFaction();
// commander.trySwitchTeam(faction,teamIndex);
// }
// else {
// const Faction *faction = world.getThisFaction();
// commander.trySwitchTeam(faction,teamIndex);
// }
GameSettings * settings = world . getGameSettingsPtr ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-09-21 07:45:09 +02:00
if ( lang . hasString ( " DisconnectNetorkPlayerIndexConfirm " ) = = true ) {
2013-05-29 08:13:21 +02:00
snprintf ( szBuf , 8096 , lang . get ( " DisconnectNetorkPlayerIndexConfirm " ) . c_str ( ) , factionIndex + 1 , settings - > getNetworkPlayerName ( factionIndex ) . c_str ( ) ) ;
2012-09-21 07:45:09 +02:00
}
else {
2013-05-29 08:13:21 +02:00
snprintf ( szBuf , 8096 , " Confirm disconnection for player #%d - %s? " , factionIndex + 1 , settings - > getNetworkPlayerName ( factionIndex ) . c_str ( ) ) ;
2012-09-21 07:45:09 +02:00
}
disconnectPlayerConfirmMessageBox . setText ( szBuf ) ;
disconnectPlayerConfirmMessageBox . init ( lang . get ( " Yes " ) , lang . get ( " No " ) ) ;
disconnectPlayerConfirmMessageBox . setEnabled ( true ) ;
2012-09-22 04:17:49 +02:00
playerIndexDisconnect = world . getFaction ( factionIndex ) - > getStartLocationIndex ( ) ;
2012-09-21 07:45:09 +02:00
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
if ( gameNetworkInterface ! = NULL ) {
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = settings - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2012-09-21 07:45:09 +02:00
if ( lang . hasString ( " DisconnectNetorkPlayerIndexConfirmed " , languageList [ i ] ) = = true ) {
2013-05-29 08:13:21 +02:00
snprintf ( szMsg , 8096 , lang . get ( " DisconnectNetorkPlayerIndexConfirmed " , languageList [ i ] ) . c_str ( ) , factionIndex + 1 , settings - > getNetworkPlayerName ( factionIndex ) . c_str ( ) ) ;
2012-09-21 07:45:09 +02:00
}
else {
2013-05-29 08:13:21 +02:00
snprintf ( szMsg , 8096 , " Notice - Admin is warning to disconnect player #%d - %s! " , factionIndex + 1 , settings - > getNetworkPlayerName ( factionIndex ) . c_str ( ) ) ;
2012-09-21 07:45:09 +02:00
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
gameNetworkInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
sleep ( 10 ) ;
}
break ;
}
}
2011-09-21 08:51:28 +02:00
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 ;
2012-02-19 18:37:53 +01:00
vote - > allowSwitchTeam = ( button = = 0 ) ;
2011-09-21 08:51:28 +02:00
const Faction * faction = world . getThisFaction ( ) ;
commander . trySwitchTeamVote ( faction , vote ) ;
}
}
2012-09-21 07:45:09 +02:00
else if ( disconnectPlayerConfirmMessageBox . getEnabled ( ) = = true ) {
int button = - 1 ;
if ( disconnectPlayerConfirmMessageBox . mouseClick ( x , y , button ) ) {
disconnectPlayerConfirmMessageBox . setEnabled ( false ) ;
if ( button = = 0 ) {
const Faction * faction = world . getThisFaction ( ) ;
commander . tryDisconnectNetworkPlayer ( faction , playerIndexDisconnect ) ;
}
}
}
2011-09-21 08:51:28 +02:00
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 ( ) ) {
2012-02-19 18:37:53 +01:00
int button = 0 ;
2010-05-29 09:58:58 +02:00
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
{
2012-07-14 01:19:53 +02:00
if ( ! setMarker ) {
2012-07-15 11:50:44 +02:00
cameraDragAllowed = true ;
2012-07-14 01:19:53 +02:00
gameCamera . setPos ( Vec2f ( static_cast < float > ( xCell ) , static_cast < float > ( yCell ) ) ) ;
}
2010-05-29 09:58:58 +02:00
}
2012-06-12 22:37:00 +02:00
2012-07-14 01:19:53 +02:00
if ( setMarker ) {
2012-07-13 23:50:34 +02:00
Vec2i surfaceCellPos = map - > toSurfCoords ( Vec2i ( xCell , yCell ) ) ;
SurfaceCell * sc = map - > getSurfaceCell ( surfaceCellPos ) ;
Vec3f vertex = sc - > getVertex ( ) ;
Vec2i targetPos ( vertex . x , vertex . z ) ;
2012-09-21 00:18:10 +02:00
MarkedCell mc ( targetPos , world . getThisFaction ( ) , " none " , world . getThisFaction ( ) - > getStartLocationIndex ( ) ) ;
2012-07-13 23:50:34 +02:00
addOrReplaceInHighlightedCells ( mc ) ;
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
gameNetworkInterface - > sendHighlightCellMessage ( mc . getTargetPos ( ) , mc . getFaction ( ) - > getIndex ( ) ) ;
}
2012-06-12 22:37:00 +02:00
if ( originalIsMarkCellEnabled = = true & & isMarkCellEnabled = = true ) {
Vec2i surfaceCellPos = map - > toSurfCoords ( Vec2i ( xCell , yCell ) ) ;
SurfaceCell * sc = map - > getSurfaceCell ( surfaceCellPos ) ;
Vec3f vertex = sc - > getVertex ( ) ;
Vec2i targetPos ( vertex . x , vertex . z ) ;
2012-09-21 00:18:10 +02:00
MarkedCell mc ( targetPos , world . getThisFaction ( ) , " placeholder for note " , world . getThisFaction ( ) - > getStartLocationIndex ( ) ) ;
2012-06-12 22:37:00 +02:00
2012-09-20 06:10:34 +02:00
//GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
//gameNetworkInterface->sendMarkCellMessage(mc.getTargetPos(),mc.getFaction()->getIndex(),mc.getNote());
2012-06-12 22:37:00 +02:00
2012-11-10 07:37:23 +01:00
//printf("#1 ADDED in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size());
2012-06-12 22:37:00 +02:00
isMarkCellEnabled = false ;
2012-09-20 06:10:34 +02:00
cellMarkedData = mc ;
cellMarkedPos = surfaceCellPos ;
isMarkCellTextEnabled = true ;
chatManager . switchOnEdit ( this , 500 ) ;
2012-06-12 22:37:00 +02:00
2012-06-13 18:19:44 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
//renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos);
renderer . forceQuadCacheUpdate ( ) ;
}
if ( originalIsUnMarkCellEnabled = = true & & isUnMarkCellEnabled = = true ) {
Vec2i surfaceCellPos = map - > toSurfCoords ( Vec2i ( xCell , yCell ) ) ;
SurfaceCell * sc = map - > getSurfaceCell ( surfaceCellPos ) ;
Vec3f vertex = sc - > getVertex ( ) ;
Vec2i targetPos ( vertex . x , vertex . z ) ;
2012-09-25 09:05:52 +02:00
// if(mapMarkedCellList.find(surfaceCellPos) != mapMarkedCellList.end()) {
// MarkedCell mc = mapMarkedCellList[surfaceCellPos];
// if(mc.getFaction() == world.getThisFaction()) {
// mapMarkedCellList.erase(surfaceCellPos);
// GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
// gameNetworkInterface->sendUnMarkCellMessage(mc.getTargetPos(),mc.getFaction()->getIndex());
// }
// }
2012-06-13 18:19:44 +02:00
isUnMarkCellEnabled = false ;
2012-09-25 09:05:52 +02:00
removeCellMarker ( surfaceCellPos , world . getThisFaction ( ) ) ;
2012-11-10 07:37:23 +01:00
//printf("#1 ADDED in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size());
2012-09-25 09:05:52 +02:00
2012-06-12 22:37:00 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
//renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos);
renderer . forceQuadCacheUpdate ( ) ;
}
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 ) ;
2012-06-12 22:37:00 +02:00
2012-07-14 01:19:53 +02:00
if ( setMarker ) {
2012-07-13 23:50:34 +02:00
Vec2i targetPos ;
Vec2i screenPos ( x , y - 60 ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . computePosition ( screenPos , targetPos ) ;
Vec2i surfaceCellPos = map - > toSurfCoords ( targetPos ) ;
2012-09-21 00:18:10 +02:00
MarkedCell mc ( targetPos , world . getThisFaction ( ) , " none " , world . getThisFaction ( ) - > getStartLocationIndex ( ) ) ;
2012-07-13 23:50:34 +02:00
addOrReplaceInHighlightedCells ( mc ) ;
GameNetworkInterface * gameNetworkInterface = NetworkManager : : getInstance ( ) . getGameNetworkInterface ( ) ;
gameNetworkInterface - > sendHighlightCellMessage ( mc . getTargetPos ( ) , mc . getFaction ( ) - > getIndex ( ) ) ;
}
2012-06-12 22:37:00 +02:00
if ( originalIsMarkCellEnabled = = true & & isMarkCellEnabled = = true ) {
Vec2i targetPos ;
2012-06-22 07:40:23 +02:00
Vec2i screenPos ( x , y - 60 ) ;
2012-06-12 22:37:00 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . computePosition ( screenPos , targetPos ) ;
Vec2i surfaceCellPos = map - > toSurfCoords ( targetPos ) ;
2012-09-21 00:18:10 +02:00
MarkedCell mc ( targetPos , world . getThisFaction ( ) , " placeholder for note " , world . getThisFaction ( ) - > getStartLocationIndex ( ) ) ;
2012-06-12 22:37:00 +02:00
2012-11-10 07:37:23 +01:00
//printf("#2 ADDED in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size());
2012-06-12 22:37:00 +02:00
isMarkCellEnabled = false ;
2012-09-20 06:10:34 +02:00
cellMarkedData = mc ;
cellMarkedPos = surfaceCellPos ;
isMarkCellTextEnabled = true ;
chatManager . switchOnEdit ( this , 500 ) ;
2012-06-12 22:37:00 +02:00
//renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos);
renderer . forceQuadCacheUpdate ( ) ;
}
2012-06-13 18:19:44 +02:00
if ( originalIsUnMarkCellEnabled = = true & & isUnMarkCellEnabled = = true ) {
Vec2i targetPos ;
2012-06-22 07:40:23 +02:00
Vec2i screenPos ( x , y - 35 ) ;
2012-06-13 18:19:44 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . computePosition ( screenPos , targetPos ) ;
Vec2i surfaceCellPos = map - > toSurfCoords ( targetPos ) ;
2012-09-25 09:05:52 +02:00
// if(mapMarkedCellList.find(surfaceCellPos) != mapMarkedCellList.end()) {
// MarkedCell mc = mapMarkedCellList[surfaceCellPos];
// if(mc.getFaction() == world.getThisFaction()) {
// mapMarkedCellList.erase(surfaceCellPos);
// GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
// gameNetworkInterface->sendUnMarkCellMessage(mc.getTargetPos(),mc.getFaction()->getIndex());
// }
// }
2012-06-13 18:19:44 +02:00
isUnMarkCellEnabled = false ;
2012-09-25 09:05:52 +02:00
removeCellMarker ( surfaceCellPos , world . getThisFaction ( ) ) ;
2012-11-10 07:37:23 +01:00
//printf("#1 ADDED in marked list pos [%s] markedCells.size() = " MG_SIZE_T_SPECIFIER "\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size());
2012-06-13 18:19:44 +02:00
//Renderer &renderer= Renderer::getInstance();
//renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos);
renderer . forceQuadCacheUpdate ( ) ;
}
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 ) ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ( ) ) {
2012-02-19 18:37:53 +01:00
int button = 0 ;
2010-05-29 09:58:58 +02:00
if ( mainMessageBox . mouseClick ( x , y , button ) ) {
2012-02-19 18:37:53 +01:00
if ( button = = 0 ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
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 {
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
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 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] x = %d y = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) , x , y ) ;
2011-04-28 00:35:45 +02:00
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
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
2011-01-20 09:19:14 +01:00
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 ) {
2012-09-27 23:10:28 +02:00
gameCamera . setState ( GameCamera : : sGame ) ;
2011-01-20 09:19:14 +01:00
}
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 {
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
2011-01-20 09:19:14 +01:00
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 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
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 {
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
2011-01-20 09:19:14 +01:00
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 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
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 {
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
2011-01-20 09:19:14 +01:00
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 ) ;
2012-09-21 07:45:09 +02:00
popupMenuDisconnectPlayer . mouseMove ( x , y ) ;
2011-09-21 08:51:28 +02:00
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;
2010-03-23 03:35:55 +01:00
2012-01-09 22:08:19 +01:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-09-26 02:15:37 +02:00
if ( currentCameraFollowUnit = = NULL ) {
2012-10-06 09:06:40 +02:00
float ymult = 0.2f ;
float xmult = 0.2f ;
2013-02-10 00:20:40 +01:00
Vec2i oldPos = Shared : : Platform : : Window : : getOldMousePos ( ) ;
int oldx = ( oldPos . x * metrics . getVirtualW ( ) / metrics . getScreenW ( ) ) ;
int oldy = ( ( metrics . getScreenH ( ) - oldPos . y ) * metrics . getVirtualH ( ) / metrics . getScreenH ( ) ) ;
lastMousePos . x = oldx ;
lastMousePos . y = oldy ;
gameCamera . transitionVH ( - ( y - oldy ) * ymult , ( oldx - x ) * xmult ) ;
2012-09-26 02:15:37 +02:00
}
2010-05-29 09:58:58 +02:00
mouseX = lastMousePos . x ;
mouseY = lastMousePos . y ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : revertMousePos ( ) ;
2010-03-30 02:25:35 +02:00
2012-01-09 22:08:19 +01:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__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
}
2012-09-26 02:15:37 +02:00
else if ( currentCameraFollowUnit = = NULL ) {
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
{
2012-07-13 04:03:15 +02:00
if ( ms - > get ( mbLeft ) & & metrics . isInMinimap ( x , y ) ) {
int xm = x - metrics . getMinimapX ( ) ;
int ym = y - metrics . getMinimapY ( ) ;
2010-05-29 09:58:58 +02:00
2012-07-13 04:03:15 +02:00
Map * map = world . getMap ( ) ;
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 ( ) ) ) ;
if ( map - > isInside ( xCell , yCell ) & & map - > isInsideSurface ( map - > toSurfCoords ( Vec2i ( xCell , yCell ) ) ) ) {
if ( gui . isSelectingPos ( ) ) {
gui . mouseDownLeftGraphics ( xCell , yCell , true ) ;
}
else
{
2012-07-15 11:50:44 +02:00
if ( cameraDragAllowed = = true ) {
2012-07-14 01:19:53 +02:00
gameCamera . setPos ( Vec2f ( static_cast < float > ( xCell ) , static_cast < float > ( yCell ) ) ) ;
}
2012-07-13 04:03:15 +02:00
}
2011-08-31 02:24:14 +02:00
}
2012-07-13 04:03:15 +02:00
}
else {
bool mouseMoveScrollsWorld = Config : : getInstance ( ) . getBool ( " MouseMoveScrollsWorld " , " true " ) ;
2012-09-01 21:18:31 +02:00
if ( mouseMoveScrollsWorld = = true ) {
2012-07-13 04:03:15 +02:00
if ( y < 10 ) {
gameCamera . setMoveZ ( - scrollSpeed ) ;
}
else if ( y > metrics . getVirtualH ( ) - 10 ) {
gameCamera . setMoveZ ( scrollSpeed ) ;
}
else {
gameCamera . setMoveZ ( 0 ) ;
}
if ( x < 10 ) {
gameCamera . setMoveX ( - scrollSpeed ) ;
}
else if ( x > metrics . getVirtualW ( ) - 10 ) {
gameCamera . setMoveX ( scrollSpeed ) ;
}
else {
gameCamera . setMoveX ( 0 ) ;
}
2011-08-31 02:24:14 +02:00
}
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 ) ;
}
2012-09-21 07:45:09 +02:00
if ( disconnectPlayerConfirmMessageBox . getEnabled ( ) = = true ) {
disconnectPlayerConfirmMessageBox . 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 ;
2011-10-07 05:48:07 +02:00
2012-09-20 06:10:34 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . computePosition ( Vec2i ( mouseX , mouseY ) , mouseCellPos ) ;
2010-05-29 09:58:58 +02:00
}
catch ( const exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
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 {
2012-01-09 22:08:19 +01:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__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 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
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
}
2012-09-24 19:13:27 +02:00
void Game : : startCameraFollowUnit ( ) {
Selection * selection = gui . getSelectionPtr ( ) ;
if ( selection - > getCount ( ) = = 1 ) {
Unit * currentUnit = selection - > getUnitPtr ( 0 ) ;
if ( currentUnit ! = NULL ) {
currentCameraFollowUnit = currentUnit ;
2012-09-27 23:10:28 +02:00
getGameCameraPtr ( ) - > setState ( GameCamera : : sUnit ) ;
2012-09-26 02:15:37 +02:00
getGameCameraPtr ( ) - > setPos ( currentCameraFollowUnit - > getCurrVector ( ) ) ;
int rotation = currentCameraFollowUnit - > getRotation ( ) ;
getGameCameraPtr ( ) - > stop ( ) ;
2012-09-26 21:25:35 +02:00
getGameCameraPtr ( ) - > rotateToVH ( 0.0f , ( 540 - rotation ) % 360 ) ;
getGameCameraPtr ( ) - > setHAng ( ( 540 - rotation ) % 360 ) ;
2012-09-26 02:15:37 +02:00
getGameCameraPtr ( ) - > setVAng ( 0.0f ) ;
2012-09-24 19:13:27 +02:00
}
}
else {
if ( currentCameraFollowUnit ! = NULL ) {
currentCameraFollowUnit = NULL ;
}
}
}
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 {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = [%c] [%d] gameStarted [%d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , key . keysym . sym , key . keysym . sym , gameStarted ) ;
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
2011-01-20 09:19:14 +01:00
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 ( ) ;
2012-09-01 21:18:31 +02:00
bool formerChatState = chatManager . getEditEnabled ( ) ;
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
2012-09-01 21:18:31 +02:00
if ( formerChatState = = false & & chatManager . getEditEnabled ( ) ) {
camUpButtonDown = false ;
camDownButtonDown = false ;
camLeftButtonDown = false ;
camRightButtonDown = false ;
gameCamera . stopMove ( ) ;
}
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");
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = [%d - %c] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ) ;
2012-01-09 22:08:19 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] key = [%d - %c] pausegame [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,key,key,configKeys.getCharKey("PauseGame"));
2010-06-12 20:27:39 +02:00
2012-07-20 16:38:28 +02:00
//printf("SDL [%d] key [%d][%d]\n",configKeys.getSDLKey("SetMarker"),key.keysym.unicode,key.keysym.sym);
bool setMarkerKeyAllowsModifier = false ;
2012-09-24 19:13:27 +02:00
if ( configKeys . getSDLKey ( " SetMarker " ) = = SDLK_RALT | |
configKeys . getSDLKey ( " SetMarker " ) = = SDLK_LALT ) {
2012-07-20 16:38:28 +02:00
setMarkerKeyAllowsModifier = true ;
}
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 ;
}
2012-07-20 16:38:28 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " SetMarker " ) , key , setMarkerKeyAllowsModifier ) = = true ) {
2012-07-14 01:19:53 +02:00
setMarker = 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 ) {
2012-09-27 00:52:21 +02:00
if ( gameCamera . getState ( ) = = GameCamera : : sFree )
{
2012-09-27 23:10:28 +02:00
gameCamera . setState ( GameCamera : : sGame ) ;
2012-10-03 22:13:11 +02:00
string stateString = gameCamera . getState ( ) = = GameCamera : : sGame ? lang . get ( " GameCamera " ) : lang . get ( " FreeCamera " ) ;
console . addLine ( lang . get ( " CameraModeSet " ) + " " + stateString ) ;
2012-09-27 00:52:21 +02:00
}
else if ( gameCamera . getState ( ) = = GameCamera : : sGame )
{
2012-09-27 23:10:28 +02:00
gameCamera . setState ( GameCamera : : sFree ) ;
2012-10-03 22:13:11 +02:00
string stateString = gameCamera . getState ( ) = = GameCamera : : sGame ? lang . get ( " GameCamera " ) : lang . get ( " FreeCamera " ) ;
console . addLine ( lang . get ( " CameraModeSet " ) + " " + stateString ) ;
2012-09-27 00:52:21 +02:00
}
//else ignore!
2010-05-29 09:58:58 +02:00
}
//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 ) {
2012-09-24 19:13:27 +02:00
if ( currentCameraFollowUnit ! = NULL ) {
currentCameraFollowUnit = NULL ;
}
2012-09-27 23:10:28 +02:00
gameCamera . setState ( GameCamera : : sGame ) ;
2010-05-29 09:58:58 +02:00
}
//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);
2011-10-26 06:13:14 +02:00
//setPaused(!paused);
bool allowAdminMenuItems = false ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
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 ) {
2012-04-01 20:23:26 +02:00
if ( getPaused ( ) = = false ) {
2013-03-06 15:29:49 +01:00
commander . tryPauseGame ( false , false ) ;
2011-10-26 06:13:14 +02:00
}
else {
2013-03-06 15:29:49 +01:00
commander . tryResumeGame ( false , false ) ;
2011-10-26 06:13:14 +02:00
}
}
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 ) {
2013-02-26 21:48:20 +01:00
bool speedChangesAllowed = ! NetworkManager : : getInstance ( ) . isNetworkGameWithConnectedClients ( ) ;
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 ) {
2013-02-26 21:48:20 +01:00
bool speedChangesAllowed = ! NetworkManager : : getInstance ( ) . isNetworkGameWithConnectedClients ( ) ;
2010-05-29 09:58:58 +02:00
if ( speedChangesAllowed ) {
decSpeed ( ) ;
}
}
2012-09-24 19:13:27 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " BookmarkAdd " ) , key , false ) = = true ) {
startMarkCell ( ) ;
}
else if ( isKeyPressed ( configKeys . getSDLKey ( " BookmarkRemove " ) , key , false ) = = true ) {
isUnMarkCellEnabled = true ;
}
else if ( isKeyPressed ( configKeys . getSDLKey ( " CameraFollowSelectedUnit " ) , key , false ) = = true ) {
startCameraFollowUnit ( ) ;
}
2010-05-29 09:58:58 +02:00
//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");
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , key ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " ====== Check ingame custom grouping hotkeys ====== \n " ) ;
//printf("====== Check ingame custom grouping hotkeys ======\n");
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());
2012-01-09 22:08:19 +01: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",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,keyName.c_str(),idx,groupHotKey,groupHotKey);
2011-06-26 03:55:08 +02:00
SDLKey groupHotKey = configKeys . getSDLKey ( keyName . c_str ( ) ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , keyName . c_str ( ) , idx , groupHotKey , groupHotKey ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " input.keysym.mod = %d groupHotKey = %d key = %d (%d) [%s] isgroup = %d \n " , key . keysym . mod , groupHotKey , key . keysym . sym , key . keysym . unicode , keyName . c_str ( ) , isKeyPressed ( groupHotKey , key ) ) ;
//printf("input.keysym.mod = %d groupHotKey = %d key = %d (%d) [%s] isgroup = %d\n",key.keysym.mod,groupHotKey,key.keysym.sym,key.keysym.unicode,keyName.c_str(),isKeyPressed(groupHotKey,key));
2010-06-13 19:55:39 +02:00
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');
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] gameCamera.getState() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , gameCamera . getState ( ) ) ;
2010-04-06 16:09:42 +02:00
2012-09-27 01:21:49 +02:00
if ( gameCamera . getState ( ) ! = GameCamera : : sFree ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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
}
2012-03-15 16:57:21 +01:00
if ( isKeyPressed ( configKeys . getSDLKey ( " SaveGame " ) , key ) = = true ) {
2012-04-14 01:13:02 +02:00
saveGame ( ) ;
2012-03-15 16:57:21 +01:00
}
2010-03-13 22:10:45 +01:00
}
2010-09-11 18:14:03 +02:00
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error("Test Error!");
2010-03-13 22:10:45 +01:00
}
2010-05-29 09:58:58 +02:00
catch ( const exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
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 {
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
2011-01-20 09:19:14 +01:00
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
}
2012-07-14 01:19:53 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " SetMarker " ) , key ) = = true ) {
setMarker = false ;
}
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 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-04-28 00:35:45 +02:00
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 ;
}
2012-10-26 06:35:14 +02:00
if ( gameStarted = = false | | totalRenderFps < = 0 ) {
2011-01-20 09:19:14 +01:00
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 ( ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-06-24 03:23:18 +02:00
2012-03-15 16:57:21 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled = = true ) {
2011-01-02 01:39:13 +01:00
world . DumpWorldToLog ( ) ;
2012-03-15 16:57:21 +01:00
}
//printf("Check savegame\n");
//printf("Saving...\n");
2012-03-17 09:20:17 +01:00
if ( Config : : getInstance ( ) . getBool ( " AutoTest " ) ) {
this - > saveGame ( GameConstants : : saveGameFileAutoTestDefault ) ;
}
2011-01-02 01:39:13 +01:00
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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-06-24 03:23:18 +02:00
2010-08-07 06:49:06 +02:00
endStats = * ( world . getStats ( ) ) ;
2011-12-02 17:07:59 +01: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
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-02 06:18:03 +02:00
2012-01-09 22:08:19 +01:00
//printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-08-02 06:18:03 +02:00
NetworkManager : : getInstance ( ) . end ( ) ;
//sleep(0);
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-02 06:18:03 +02:00
2010-08-07 06:49:06 +02:00
return endStats ;
}
void Game : : exitGameState ( Program * program , Stats & endStats ) {
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-06 05:55:17 +02:00
2011-10-21 21:52:55 +02:00
Game * game = dynamic_cast < Game * > ( program - > getState ( ) ) ;
if ( game ) {
2012-11-20 03:26:51 +01:00
game - > setEndGameTeamWinnersAndLosers ( ) ;
2011-10-21 21:52:55 +02:00
game - > endGame ( ) ;
}
2013-05-17 07:01:23 +02:00
if ( ( game ! = NULL & & game - > isMasterserverMode ( ) = = true ) | |
2012-03-17 09:20:17 +01:00
Config : : getInstance ( ) . getBool ( " AutoTest " ) = = true ) {
2011-12-02 18:27:13 +01:00
printf ( " Game ending with stats: \n " ) ;
printf ( " ----------------------- \n " ) ;
string gameStats = endStats . getStats ( ) ;
printf ( " %s " , gameStats . c_str ( ) ) ;
printf ( " ----------------------- \n " ) ;
}
2011-10-21 21:52:55 +02:00
ProgramState * newState = new BattleEnd ( program , & endStats , game ) ;
2010-08-06 05:55:17 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-06 05:55:17 +02:00
2011-10-21 21:52:55 +02:00
program - > setState ( newState , false ) ;
2010-08-07 06:49:06 +02:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-03-13 22:10:45 +01:00
}
// ==================== PRIVATE ====================
2012-10-13 09:33:33 +02:00
void Game : : highlightUnit ( int unitId , float radius , float thickness , Vec4f color ) {
HighlightSpecialUnitInfo info ;
info . radius = radius ;
info . thickness = thickness ;
info . color = color ;
unitHighlightList [ unitId ] = info ;
}
void Game : : unhighlightUnit ( int unitId ) {
if ( unitHighlightList . find ( unitId ) ! = unitHighlightList . end ( ) ) {
unitHighlightList . erase ( unitId ) ;
}
}
2010-03-13 22:10:45 +01:00
// ==================== 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 ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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();
2012-01-09 22:08:19 +01:00
// 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",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
2011-07-24 01:22:30 +02:00
// 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 ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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 ( ) ;
2012-01-09 22:08:19 +01:00
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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-07-24 01:22:30 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
renderer . setupLighting ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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 ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//clear buffers
renderer . clearBuffers ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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 ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//selection circles
renderer . renderSelectionEffects ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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 ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-07-07 00:02:38 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
}
2012-09-11 23:16:24 +02:00
2012-10-13 09:33:33 +02:00
renderer . renderSpecialHighlightUnits ( unitHighlightList ) ;
2012-09-11 23:16:24 +02:00
// renderTeamColorCircle
renderer . renderMorphEffects ( ) ;
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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
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 ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-07-07 00:02:38 +02:00
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 ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//water
renderer . renderWater ( ) ;
renderer . renderWaterEffects ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
//particles
renderer . renderParticleManager ( rsGame ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 22:10:45 +01:00
2012-07-13 23:50:34 +02:00
2010-03-13 22:10:45 +01:00
//mouse 3d
renderer . renderMouse3d ( ) ;
2012-01-09 22:08:19 +01: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 " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
2010-09-03 03:50:16 +02:00
2012-06-22 06:58:44 +02:00
renderer . renderUnitsToBuild ( avgRenderFps ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnitsToBuild] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , renderFps , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-10-04 18:43:00 +02:00
renderer . setLastRenderFps ( lastRenderFps ) ;
2010-03-13 22:10:45 +01:00
}
2011-12-02 18:27:13 +01:00
void Game : : updateWorldStats ( ) {
world . getStats ( ) - > setWorldTimeElapsed ( world . getTimeFlow ( ) - > getTime ( ) ) ;
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , lastMaxUnitCalcTime ) > = 1 ) {
2011-12-02 18:27:13 +01:00
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 ) ;
world . getStats ( ) - > setFramesPlayed ( world . getFrameCount ( ) ) ;
}
}
2012-01-06 07:55:27 +01:00
string Game : : getDebugStats ( std : : map < int , string > & factionDebugInfo ) {
string str = " " ;
if ( this - > masterserverMode = = false ) {
str + = " MouseXY: " + intToStr ( mouseX ) + " , " + intToStr ( mouseY ) + " \n " ;
if ( world . getMap ( ) - > isInsideSurface ( world . getMap ( ) - > toSurfCoords ( mouseCellPos ) ) = = true ) {
str + = " MouseXY cell coords: " + intToStr ( mouseCellPos . x ) + " , " + intToStr ( mouseCellPos . y ) + " \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 " ;
if ( this - > masterserverMode = = false ) {
str + = " GameCamera pos: " + floatToStr ( gameCamera . getPos ( ) . x ) + " , " + floatToStr ( gameCamera . getPos ( ) . y ) + " , " + floatToStr ( gameCamera . getPos ( ) . z ) + " \n " ;
//str+= "Cached surfacedata: " + intToStr(renderer.getCachedSurfaceDataSize())+"\n";
}
//intToStr(stats.getFramesToCalculatePlaytime()/GameConstants::updateFps/60
str + = " Time: " + floatToStr ( world . getTimeFlow ( ) - > getTime ( ) , 2 ) + " [ " + floatToStr ( ( float ) world . getStats ( ) - > getFramesToCalculatePlaytime ( ) / ( float ) GameConstants : : updateFps / 60.0 , 2 ) + " ] \n " ;
if ( SystemFlags : : getThreadedLoggerRunning ( ) = = true ) {
str + = " Log buffer count: " + intToStr ( SystemFlags : : getLogEntryBufferCount ( ) ) + " \n " ;
}
str + = " UnitRangeCellsLookupItemCache: " + world . getUnitUpdater ( ) - > getUnitRangeCellsLookupItemCacheStats ( ) + " \n " ;
str + = " ExploredCellsLookupItemCache: " + world . getExploredCellsLookupItemCacheStats ( ) + " \n " ;
str + = " FowAlphaCellsLookupItemCache: " + world . getFowAlphaCellsLookupItemCacheStats ( ) + " \n " ;
2013-01-27 23:10:24 +01:00
str + = " Selection type: " + toLower ( Config : : getInstance ( ) . getString ( " SelectionType " , Config : : selectBufPicking ) ) + " \n " ;
2013-01-24 01:14:29 +01:00
2012-01-06 07:55:27 +01:00
//str+= "AllFactionsCacheStats: " + world.getAllFactionsCacheStats()+"\n";
//str+= "AttackWarningCount: " + intToStr(world.getUnitUpdater()->getAttackWarningCount()) + "\n";
str + = " Map: " + gameSettings . getMap ( ) + " \n " ;
str + = " Tileset: " + gameSettings . getTileset ( ) + " \n " ;
str + = " Techtree: " + gameSettings . getTech ( ) + " \n " ;
if ( this - > masterserverMode = = false ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
str + = " Triangle count: " + intToStr ( renderer . getTriangleCount ( ) ) + " \n " ;
str + = " Vertex count: " + intToStr ( renderer . getPointCount ( ) ) + " \n " ;
}
str + = " Frame count: " + intToStr ( world . getFrameCount ( ) ) + " \n " ;
//visible quad
if ( this - > masterserverMode = = false ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
Quad2i visibleQuad = renderer . getVisibleQuad ( ) ;
Quad2i visibleQuadCamera = renderer . getVisibleQuadFromCamera ( ) ;
str + = " Visible quad: " ;
for ( int i = 0 ; i < 4 ; + + i ) {
str + = " ( " + intToStr ( visibleQuad . p [ i ] . x ) + " , " + intToStr ( visibleQuad . p [ i ] . y ) + " ) " ;
}
// str+= "\n";
// 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);
}
int totalUnitcount = 0 ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
totalUnitcount + = faction - > getUnitCount ( ) ;
}
if ( this - > masterserverMode = = false ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
VisibleQuadContainerCache & qCache = renderer . getQuadCache ( ) ;
int visibleUnitCount = qCache . visibleQuadUnitList . size ( ) ;
str + = " Visible unit count: " + intToStr ( visibleUnitCount ) + " total: " + intToStr ( totalUnitcount ) + " \n " ;
int visibleObjectCount = qCache . visibleObjectList . size ( ) ;
str + = " Visible object count: " + intToStr ( visibleObjectCount ) + " \n " ;
}
else {
str + = " Total unit count: " + intToStr ( totalUnitcount ) + " \n " ;
}
// resources
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
string factionInfo = this - > gameSettings . getNetworkPlayerName ( i ) ;
2013-06-01 04:31:12 +02:00
factionInfo + = " [ " + this - > gameSettings . getNetworkPlayerUUID ( i ) + " ] " ;
2012-01-06 07:55:27 +01:00
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 ) ) +
" team: " + intToStr ( this - > gameSettings . getTeam ( i ) ) + " ] " ;
bool showResourceDebugInfo = false ;
if ( showResourceDebugInfo = = true ) {
factionInfo + = " res: " ;
for ( int j = 0 ; j < world . getTechTree ( ) - > getResourceTypeCount ( ) ; + + j ) {
factionInfo + = intToStr ( world . getFaction ( i ) - > getResource ( j ) - > getAmount ( ) ) ;
factionInfo + = " " ;
}
}
factionDebugInfo [ i ] = factionInfo ;
}
return str ;
}
2011-12-02 18:27:13 +01:00
void Game : : render2d ( ) {
2010-03-13 22:10:45 +01:00
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 ( ) ;
}
2012-06-12 22:37:00 +02:00
renderer . renderVisibleMarkedCells ( ) ;
2012-09-20 06:10:34 +02:00
renderer . renderVisibleMarkedCells ( true , lastMousePos . x , lastMousePos . y ) ;
2012-06-12 22:37:00 +02:00
2010-03-13 22:10:45 +01:00
//selection
renderer . renderSelectionQuad ( ) ;
2012-07-13 23:50:34 +02:00
//highlighted Cells
renderer . renderHighlightedCellsOnMinimap ( ) ;
2011-09-21 08:51:28 +02:00
if ( switchTeamConfirmMessageBox . getEnabled ( ) = = true ) {
renderer . renderMessageBox ( & switchTeamConfirmMessageBox ) ;
}
2012-09-21 07:45:09 +02:00
if ( disconnectPlayerConfirmMessageBox . getEnabled ( ) = = true ) {
renderer . renderMessageBox ( & disconnectPlayerConfirmMessageBox ) ;
}
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 ( ) ,
2013-05-25 22:46:36 +02:00
Vec3f ( fontColor . x , fontColor . y , fontColor . z ) , 200 , 660 , false ) ;
2011-06-10 05:09:19 +02:00
}
else {
renderer . renderText (
scriptManager . getDisplayText ( ) , coreData . getMenuFontNormal ( ) ,
2013-05-25 22:46:36 +02:00
Vec3f ( fontColor . x , fontColor . y , fontColor . z ) , 200 , 660 , false ) ;
2011-06-10 05:09:19 +02:00
}
2010-03-13 22:10:45 +01:00
}
2012-05-22 08:17:56 +02:00
renderVideoPlayer ( ) ;
2011-09-21 08:51:28 +02:00
renderer . renderPopupMenu ( & popupMenu ) ;
renderer . renderPopupMenu ( & popupMenuSwitchTeams ) ;
2012-09-21 07:45:09 +02:00
renderer . renderPopupMenu ( & popupMenuDisconnectPlayer ) ;
2011-09-21 08:51:28 +02:00
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 ;
2010-12-09 21:41:11 +01:00
if ( renderer . getShowDebugUI ( ) = = true | |
2012-09-22 22:13:57 +02:00
( perfLogging = = true & & difftime ( ( long int ) time ( NULL ) , lastRenderLog2d ) > = 1 ) ) {
2012-01-06 07:55:27 +01:00
str = getDebugStats ( factionDebugInfo ) ;
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();
2011-12-02 17:07:59 +01:00
//int my= metrics.getMinimapY();
2011-09-01 01:10:43 +02:00
//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
2011-11-28 06:54:31 +01:00
vector < string > lineTokens ;
Tokenize ( str , lineTokens , " \n " ) ;
int fontHeightNormal = ( Renderer : : renderText3DEnabled = = true ? coreData . getMenuFontNormal3D ( ) - > getMetrics ( ) - > getHeight ( " W " ) : coreData . getMenuFontNormal ( ) - > getMetrics ( ) - > getHeight ( " W " ) ) ;
int fontHeightBig = ( Renderer : : renderText3DEnabled = = true ? coreData . getMenuFontBig3D ( ) - > getMetrics ( ) - > getHeight ( " W " ) : coreData . getMenuFontBig ( ) - > getMetrics ( ) - > getHeight ( " W " ) ) ;
int playerPosY = lineTokens . size ( ) * fontHeightNormal ;
//printf("lineTokens.size() = %d\n",lineTokens.size());
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 ) ,
2011-11-28 06:54:31 +01:00
10 ,
//metrics.getVirtualH() - mh - 90 - 280 - (i * 16),
2011-11-28 08:05:00 +01:00
metrics . getVirtualH ( ) - mh - 60 - playerPosY - fontHeightBig - ( fontHeightBig * i ) ,
2011-11-28 06:54:31 +01:00
false ) ;
2011-06-10 05:09:19 +02:00
}
else {
renderer . renderText ( factionInfo , coreData . getMenuFontBig ( ) ,
Vec4f ( playerColor . x , playerColor . y , playerColor . z , 1.0 ) ,
2011-11-28 06:54:31 +01:00
10 ,
//metrics.getVirtualH() - mh - 90 - 280 - (i * 16),
2011-11-28 08:05:00 +01:00
metrics . getVirtualH ( ) - mh - 60 - playerPosY - fontHeightBig - ( fontHeightBig * i ) ,
2011-11-28 06:54:31 +01:00
false ) ;
2011-06-10 05:09:19 +02:00
}
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
}
2012-08-15 16:37:27 +02:00
// clock
2012-10-12 00:10:31 +02:00
if ( photoModeEnabled = = false & & timeDisplay = = true ) {
2012-08-15 16:37:27 +02:00
renderer . renderClock ( ) ;
}
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
2012-09-22 22:13:57 +02:00
if ( perfLogging = = true & & difftime ( ( long int ) time ( NULL ) , lastRenderLog2d ) > = 1 ) {
2010-04-15 03:19:00 +02:00
lastRenderLog2d = time ( NULL ) ;
2010-12-09 21:41:11 +01:00
2012-01-09 22:08:19 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] Statistics: %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __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 ( ) ;
}
}
}
2012-11-20 03:26:51 +01:00
void Game : : setEndGameTeamWinnersAndLosers ( ) {
2013-01-25 03:55:28 +01:00
//bool lose= false;
2012-11-20 03:26:51 +01:00
bool checkTeamIndex = ! ( this - > masterserverMode = = false & & world . getThisFaction ( ) - > getPersonalityType ( ) ! = fpt_Observer ) ;
// lookup int is team #, value is players alive on team
std : : map < int , int > teamsAlive ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
if ( checkTeamIndex = = false | | i ! = world . getThisFactionIndex ( ) ) {
if ( factionLostGame ( world . getFaction ( i ) ) = = false ) {
teamsAlive [ world . getFaction ( i ) - > getTeam ( ) ] = teamsAlive [ world . getFaction ( i ) - > getTeam ( ) ] + 1 ;
}
}
}
// did some team win
if ( teamsAlive . size ( ) < = 1 ) {
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
if ( checkTeamIndex = = false | | i ! = world . getThisFactionIndex ( ) ) {
if ( teamsAlive . find ( world . getFaction ( i ) - > getTeam ( ) ) ! = teamsAlive . end ( ) ) {
world . getStats ( ) - > setVictorious ( i ) ;
}
else if ( i = = world . getThisFactionIndex ( ) ) {
2013-01-25 03:55:28 +01:00
//lose= true;
2012-11-20 03:26:51 +01:00
}
}
}
bool firstGameOverTrigger = false ;
if ( gameOver = = false ) {
firstGameOverTrigger = true ;
gameOver = true ;
}
if ( this - > gameSettings . isNetworkGame ( ) = = false | |
this - > gameSettings . getEnableObserverModeAtEndGame ( ) = = true ) {
// Let the happy winner view everything left in the world
// This caused too much LAG for network games
if ( this - > gameSettings . isNetworkGame ( ) = = false ) {
Renderer : : getInstance ( ) . setPhotoMode ( true ) ;
gameCamera . setMaxHeight ( PHOTO_MODE_MAXHEIGHT ) ;
}
// END
}
if ( firstGameOverTrigger = = true ) {
scriptManager . onGameOver ( true ) ;
}
if ( world . getFactionCount ( ) = = 1 & & world . getFaction ( 0 ) - > getPersonalityType ( ) = = fpt_Observer ) {
//printf("!!!!!!!!!!!!!!!!!!!!");
//gameCamera.setMoveY(100.0);
gameCamera . zoom ( - 300 ) ;
//gameCamera.update();
}
// else {
// if(lose == true) {
// showLoseMessageBox();
// }
// else {
// showWinMessageBox();
// }
// }
}
}
2010-12-25 10:15:49 +01:00
void Game : : checkWinnerStandard ( ) {
2012-04-02 17:02:44 +02:00
if ( world . getFactionCount ( ) < = 0 ) {
return ;
}
2012-03-30 07:53:33 +02:00
if ( this - > masterserverMode = = true | | world . getThisFaction ( ) - > 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 ( ) ) {
2012-05-03 22:25:35 +02:00
//if(hasBuilding(world.getFaction(i))) {
if ( factionLostGame ( world . getFaction ( i ) ) = = false ) {
2010-09-03 09:12:40 +02:00
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
2012-03-30 07:53:33 +02:00
if ( world . getFactionCount ( ) = = 1 & & world . getFaction ( 0 ) - > getPersonalityType ( ) = = fpt_Observer ) {
2011-09-16 02:34:14 +02:00
//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 ;
2012-05-03 22:25:35 +02:00
//if(hasBuilding(world.getThisFaction()) == false) {
if ( factionLostGame ( world . getThisFaction ( ) ) = = true ) {
2010-09-03 09:12:40 +02:00
lose = true ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
2012-03-30 07:53:33 +02:00
if ( world . getFaction ( i ) - > getPersonalityType ( ) ! = fpt_Observer ) {
2010-09-03 09:12:40 +02:00
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 ( ) ) {
2012-03-30 07:53:33 +02:00
if ( world . getFaction ( i ) - > getPersonalityType ( ) ! = fpt_Observer ) {
2012-05-03 22:25:35 +02:00
//if(hasBuilding(world.getFaction(i)) &&
if ( factionLostGame ( world . getFaction ( i ) ) = = false & &
world . getFaction ( i ) - > isAlly ( world . getThisFaction ( ) ) = = false ) {
2010-09-03 09:12:40 +02:00
win = false ;
}
}
}
}
//if win
if ( win ) {
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
2012-03-30 07:53:33 +02:00
if ( world . getFaction ( i ) - > getPersonalityType ( ) ! = fpt_Observer ) {
2010-09-03 09:12:40 +02:00
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 ( ) {
2012-03-30 16:48:54 +02:00
if ( scriptManager . getIsGameOver ( ) ) {
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 ( ) ;
}
}
}
2012-07-19 01:52:44 +02:00
bool Game : : factionLostGame ( int factionIndex ) {
return factionLostGame ( world . getFaction ( factionIndex ) ) ;
}
2012-05-03 22:25:35 +02:00
bool Game : : factionLostGame ( const Faction * faction ) {
for ( int i = 0 ; i < faction - > getUnitCount ( ) ; + + i ) {
const UnitType * ut = faction - > getUnit ( i ) - > getType ( ) ;
if ( ut - > getCountInVictoryConditions ( ) = = ucvcNotSet ) {
if ( faction - > getUnit ( i ) - > getType ( ) - > hasSkillClass ( scBeBuilt ) ) {
return false ;
}
}
else if ( ut - > getCountInVictoryConditions ( ) = = ucvcTrue ) {
return false ;
}
}
return true ;
}
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 ( ) ;
2013-01-31 13:36:51 +01:00
2013-02-26 21:48:20 +01:00
if ( this - > speed < Config : : getInstance ( ) . getInt ( " FastSpeedLoops " ) ) {
if ( this - > speed = = 0 ) {
this - > speed = 1 ;
}
else {
this - > speed + + ;
2013-01-31 13:36:51 +01:00
}
2013-02-26 21:48:20 +01:00
console . addLine ( lang . get ( " GameSpeedSet " ) + " " + ( ( this - > speed = = 0 ) ? lang . get ( " Slow " ) : ( this - > speed = = 1 ) ? lang . get ( " Normal " ) : " x " + intToStr ( this - > speed ) ) ) ;
2010-03-13 22:10:45 +01:00
}
}
2010-12-25 10:15:49 +01:00
void Game : : decSpeed ( ) {
2010-03-13 22:10:45 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2013-02-26 21:48:20 +01:00
if ( this - > speed > 0 ) {
this - > speed - - ;
console . addLine ( lang . get ( " GameSpeedSet " ) + " " + ( ( this - > speed = = 0 ) ? lang . get ( " Slow " ) : ( this - > speed = = 1 ) ? lang . get ( " Normal " ) : " x " + intToStr ( this - > speed ) ) ) ;
2010-03-13 22:10:45 +01:00
}
}
2013-03-06 15:29:49 +01:00
void Game : : setPaused ( bool value , bool forceAllowPauseStateChange , bool clearCaches , bool joinNetworkGame ) {
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);
2013-05-27 10:26:01 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " game.cpp line: %d setPaused value: %d clearCaches: %d forceAllowPauseStateChange: %d speedChangesAllowed: %d pausedForJoinGame: %d joinNetworkGame: %d \n " , __LINE__ , value , clearCaches , forceAllowPauseStateChange , speedChangesAllowed , pausedForJoinGame , joinNetworkGame ) ;
//printf("Line: %d setPaused value: %d clearCaches: %d forceAllowPauseStateChange: %d speedChangesAllowed: %d pausedForJoinGame: %d joinNetworkGame: %d\n",__LINE__,value,clearCaches,forceAllowPauseStateChange,speedChangesAllowed,pausedForJoinGame,joinNetworkGame);
2011-10-03 22:48:09 +02:00
if ( forceAllowPauseStateChange = = true | | speedChangesAllowed = = true ) {
//printf("setPaused paused = %d, value = %d\n",paused,value);
2011-01-30 00:50:21 +01:00
2013-05-30 08:28:09 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2013-03-06 15:29:49 +01:00
// Cannot change pause state while client is joining in progress game
2013-05-30 08:28:09 +02:00
if ( pausedForJoinGame = = true & & joinNetworkGame = = false & &
networkManager . getNetworkRole ( ) = = nrServer ) {
2013-03-06 15:29:49 +01:00
ServerInterface * server = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = this - > gameSettings . getUniqueNetworkPlayerLanguages ( ) ;
bool haveClientConnectedButNoReady = false ;
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 & & slot - > isReady ( ) = = false ) {
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
char szMsg [ 8096 ] = " " ;
if ( lang . hasString ( " JoinPlayerToCurrentGameLaunch " , languageList [ i ] ) = = true ) {
snprintf ( szMsg , 8096 , lang . get ( " JoinPlayerToCurrentGameLaunch " , languageList [ i ] ) . c_str ( ) , slot - > getName ( ) . c_str ( ) ) ;
}
else {
snprintf ( szMsg , 8096 , " Player: %s is about to join the game, please wait... " , slot - > getName ( ) . c_str ( ) ) ;
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
server - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
haveClientConnectedButNoReady = true ;
}
}
}
if ( haveClientConnectedButNoReady = = true ) {
return ;
}
}
2013-05-27 10:26:01 +02:00
//printf("Line: %d setPaused value: %d clearCaches: %d\n",__LINE__,value,clearCaches);
2011-01-30 00:50:21 +01:00
Lang & lang = Lang : : getInstance ( ) ;
if ( value = = false ) {
console . addLine ( lang . get ( " GameResumed " ) ) ;
paused = false ;
2013-03-06 15:29:49 +01:00
pausedForJoinGame = false ;
2013-02-19 05:53:24 +01:00
pauseStateChanged = true ;
2013-02-17 08:15:01 +01:00
if ( clearCaches = = true ) {
2013-05-27 10:26:01 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " game.cpp line: %d Clear Caches for resume in progress game \n " , __LINE__ ) ;
//printf("Line: %d Clear Caches for resume in progress game\n",__LINE__);
2013-02-17 08:15:01 +01:00
world . clearCaches ( ) ;
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
faction - > clearCaches ( ) ;
}
2013-03-06 16:02:17 +01:00
world . refreshAllUnitExplorations ( ) ;
2013-02-17 08:15:01 +01:00
}
setupPopupMenus ( false ) ;
2013-03-01 07:52:33 +01:00
//!!!
2013-05-30 08:28:09 +02:00
//NetworkManager &networkManager= NetworkManager::getInstance();
2013-03-01 07:52:33 +01:00
if ( networkManager . getNetworkRole ( ) = = nrClient ) {
//ClientInterface *clientInterface = dynamic_cast<ClientInterface *>(networkManager.getClientInterface());
//if(clientInterface != NULL && clientInterface->getResumeInGameJoin() == true) {
initialResumeSpeedLoops = true ;
//}
}
2011-01-30 00:50:21 +01:00
}
else {
console . addLine ( lang . get ( " GamePaused " ) ) ;
paused = true ;
2013-03-06 15:29:49 +01:00
pausedForJoinGame = joinNetworkGame ;
2013-02-19 05:53:24 +01:00
pauseStateChanged = true ;
//!!!
2013-02-15 19:25:10 +01:00
2013-02-19 05:53:24 +01:00
if ( clearCaches = = true ) {
2013-05-27 10:26:01 +02:00
//printf("Line: %d Clear Caches for resume in progress game\n",__LINE__);
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugWorldSynch , " game.cpp line: %d Clear Caches for resume in progress game \n " , __LINE__ ) ;
2013-02-19 05:53:24 +01:00
world . clearCaches ( ) ;
2013-02-15 19:25:10 +01:00
for ( int i = 0 ; i < world . getFactionCount ( ) ; + + i ) {
Faction * faction = world . getFaction ( i ) ;
2013-02-19 05:53:24 +01:00
faction - > clearCaches ( ) ;
2013-02-15 19:25:10 +01:00
}
2013-03-06 16:02:17 +01:00
world . refreshAllUnitExplorations ( ) ;
2013-02-15 19:25:10 +01:00
}
2013-02-28 02:31:02 +01:00
pauseRequestSent = false ;
2011-01-30 00:50:21 +01:00
}
2011-10-03 22:48:09 +02:00
//printf("setPaused new paused = %d\n",paused);
2011-01-30 00:50:21 +01:00
}
}
2012-04-01 20:23:26 +02:00
bool Game : : getPaused ( )
{
bool speedChangesAllowed = ! NetworkManager : : getInstance ( ) . isNetworkGame ( ) ;
if ( speedChangesAllowed ) {
if ( popupMenu . getVisible ( ) = = true | | popupMenuSwitchTeams . getVisible ( ) = = true ) {
return true ;
}
2012-04-03 02:32:52 +02:00
// if(mainMessageBox.getEnabled() == true || errorMessageBox.getEnabled() == true){
// return true;
// }
2012-04-01 20:23:26 +02:00
if ( currentUIState ! = NULL ) {
return true ;
}
}
return paused ;
}
2010-12-25 10:15:49 +01:00
int Game : : getUpdateLoops ( ) {
2012-03-20 05:53:26 +01:00
if ( commander . hasReplayCommandListForFrame ( ) = = true ) {
return 1 ;
}
2012-04-01 20:23:26 +02:00
if ( getPaused ( ) ) {
2010-03-13 22:10:45 +01:00
return 0 ;
}
2013-02-26 21:48:20 +01:00
else if ( this - > speed = = 0 ) {
2010-03-13 22:10:45 +01:00
return updateFps % 2 = = 0 ? 1 : 0 ;
}
2013-01-31 13:36:51 +01:00
else
2013-02-26 21:48:20 +01:00
return this - > speed ;
2010-03-13 22:10:45 +01:00
}
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 ) {
2011-11-25 18:01:35 +01:00
showMessageBox ( lang . get ( " YouLose " ) + " " + lang . get ( " ExitGameServer? " ) , lang . get ( " BattleOver " ) , false ) ;
2010-05-15 20:59:17 +02:00
}
else {
2011-11-25 18:01:35 +01:00
showMessageBox ( lang . get ( " YouLose " ) + " " + lang . get ( " ExitGame? " ) , lang . get ( " BattleOver " ) , false ) ;
2010-05-15 20:59:17 +02:00
}
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
2012-03-30 07:53:33 +02:00
if ( this - > masterserverMode = = true | | world . getThisFaction ( ) - > getPersonalityType ( ) = = fpt_Observer ) {
2011-11-25 18:01:35 +01:00
showMessageBox ( lang . get ( " GameOver " ) + " " + lang . get ( " ExitGame? " ) , lang . get ( " BattleOver " ) , false ) ;
2010-09-03 09:12:40 +02:00
}
else {
2011-11-25 18:01:35 +01:00
showMessageBox ( lang . get ( " YouWin " ) + " " + lang . get ( " ExitGame? " ) , lang . get ( " BattleOver " ) , false ) ;
2010-09-03 09:12:40 +02:00
}
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
2012-03-20 05:53:26 +01:00
void Game : : addNetworkCommandToReplayList ( NetworkCommand * networkCommand , int worldFrameCount ) {
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " SaveCommandsForReplay " , " false " ) = = true ) {
2012-03-20 06:23:32 +01:00
replayCommandList . push_back ( make_pair ( worldFrameCount , * networkCommand ) ) ;
2012-03-20 05:53:26 +01:00
}
}
2012-05-22 08:17:56 +02:00
void Game : : renderVideoPlayer ( ) {
if ( videoPlayer ! = NULL ) {
if ( videoPlayer - > isPlaying ( ) = = true ) {
videoPlayer - > playFrame ( false ) ;
}
else {
delete videoPlayer ;
videoPlayer = NULL ;
}
}
}
void Game : : playStaticVideo ( const string & playVideo ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & &
Shared : : Graphics : : VideoPlayer : : hasBackEndVideoPlayer ( ) = = true ) {
//togglePauseGame(true,true);
tryPauseToggle ( true ) ;
setupRenderForVideo ( ) ;
// Context *c= GraphicsInterface::getInstance().getCurrentContext();
// SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
//
// string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
// //printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
// Shared::Graphics::VideoPlayer player(playVideo.c_str(),
// screen,
// 0,0,
// screen->w,
// screen->h,
// screen->format->BitsPerPixel,
// vlcPluginsPath,
// SystemFlags::VERBOSE_MODE_ENABLED);
// player.PlayVideo();
//}
//tryPauseToggle(false);
playStreamingVideo ( playVideo ) ;
playingStaticVideo = true ;
}
}
void Game : : playStreamingVideo ( const string & playVideo ) {
if ( videoPlayer = = NULL ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & &
Shared : : Graphics : : VideoPlayer : : hasBackEndVideoPlayer ( ) = = true ) {
Context * c = GraphicsInterface : : getInstance ( ) . getCurrentContext ( ) ;
SDL_Surface * screen = static_cast < ContextGl * > ( c ) - > getPlatformContextGlPtr ( ) - > getScreen ( ) ;
string vlcPluginsPath = Config : : getInstance ( ) . getString ( " VideoPlayerPluginsPath " , " " ) ;
2012-05-23 21:59:52 +02:00
videoPlayer = new Shared : : Graphics : : VideoPlayer (
& Renderer : : getInstance ( ) ,
2012-05-25 18:33:34 +02:00
playVideo ,
" " ,
2012-05-22 08:17:56 +02:00
screen ,
0 , 0 ,
screen - > w ,
screen - > h ,
screen - > format - > BitsPerPixel ,
2012-09-27 03:17:57 +02:00
false ,
2012-05-22 08:17:56 +02:00
vlcPluginsPath ,
SystemFlags : : VERBOSE_MODE_ENABLED ) ;
}
}
else {
if ( videoPlayer - > isPlaying ( ) = = false ) {
delete videoPlayer ;
videoPlayer = NULL ;
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & &
Shared : : Graphics : : VideoPlayer : : hasBackEndVideoPlayer ( ) = = true ) {
Context * c = GraphicsInterface : : getInstance ( ) . getCurrentContext ( ) ;
SDL_Surface * screen = static_cast < ContextGl * > ( c ) - > getPlatformContextGlPtr ( ) - > getScreen ( ) ;
string vlcPluginsPath = Config : : getInstance ( ) . getString ( " VideoPlayerPluginsPath " , " " ) ;
2012-05-23 21:59:52 +02:00
videoPlayer = new Shared : : Graphics : : VideoPlayer (
& Renderer : : getInstance ( ) ,
2012-05-25 18:33:34 +02:00
playVideo ,
" " ,
2012-05-23 21:59:52 +02:00
screen ,
0 , 0 ,
screen - > w ,
screen - > h ,
screen - > format - > BitsPerPixel ,
2012-09-27 03:17:57 +02:00
false ,
2012-05-23 21:59:52 +02:00
vlcPluginsPath ,
SystemFlags : : VERBOSE_MODE_ENABLED ) ;
2012-05-22 08:17:56 +02:00
}
}
}
if ( videoPlayer ! = NULL ) {
videoPlayer - > initPlayer ( ) ;
}
}
void Game : : stopStreamingVideo ( const string & playVideo ) {
if ( videoPlayer ! = NULL ) {
videoPlayer - > StopVideo ( ) ;
}
}
void Game : : stopAllVideo ( ) {
if ( videoPlayer ! = NULL ) {
videoPlayer - > StopVideo ( ) ;
}
}
2012-04-14 01:13:02 +02:00
void Game : : saveGame ( ) {
string file = this - > saveGame ( GameConstants : : saveGameFilePattern ) ;
char szBuf [ 8096 ] = " " ;
Lang & lang = Lang : : getInstance ( ) ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , lang . get ( " GameSaved " , " " , true ) . c_str ( ) , file . c_str ( ) ) ;
2012-04-14 01:13:02 +02:00
console . addLine ( szBuf ) ;
Config & config = Config : : getInstance ( ) ;
config . setString ( " LastSavedGame " , file ) ;
config . save ( ) ;
}
2013-02-15 19:25:10 +01:00
string Game : : saveGame ( string name , string path ) {
2012-03-17 12:26:39 +01:00
Config & config = Config : : getInstance ( ) ;
2012-03-15 16:57:21 +01:00
// auto name file if using saved file pattern string
if ( name = = GameConstants : : saveGameFilePattern ) {
time_t curTime = time ( NULL ) ;
struct tm * loctime = localtime ( & curTime ) ;
char szBuf2 [ 100 ] = " " ;
strftime ( szBuf2 , 100 , " %Y%m%d_%H%M%S " , loctime ) ;
2012-03-17 09:20:17 +01:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , name . c_str ( ) , szBuf2 ) ;
2012-03-17 09:20:17 +01:00
name = szBuf ;
}
else if ( name = = GameConstants : : saveGameFileAutoTestDefault ) {
time_t curTime = time ( NULL ) ;
struct tm * loctime = localtime ( & curTime ) ;
char szBuf2 [ 100 ] = " " ;
strftime ( szBuf2 , 100 , " %Y%m%d_%H%M%S " , loctime ) ;
2012-03-15 16:57:21 +01:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , name . c_str ( ) , szBuf2 ) ;
2012-03-15 16:57:21 +01:00
name = szBuf ;
}
2012-03-20 06:23:32 +01:00
// Save the file now
2013-02-15 19:25:10 +01:00
string saveGameFile = path + name ;
2012-03-20 06:23:32 +01:00
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
saveGameFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + saveGameFile ;
}
else {
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
saveGameFile = userData + saveGameFile ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Saving game to [%s] \n " , saveGameFile . c_str ( ) ) ;
// This condition will re-play all the commands from a replay file
// INSTEAD of saving from a saved game.
if ( config . getBool ( " SaveCommandsForReplay " , " false " ) = = true ) {
std : : map < string , string > mapTagReplacements ;
XmlTree xmlTreeSaveGame ( XML_RAPIDXML_ENGINE ) ;
xmlTreeSaveGame . init ( " megaglest-saved-game " ) ;
XmlNode * rootNodeReplay = xmlTreeSaveGame . getRootNode ( ) ;
//std::map<string,string> mapTagReplacements;
time_t now = time ( NULL ) ;
struct tm * loctime = localtime ( & now ) ;
char szBuf [ 4096 ] = " " ;
strftime ( szBuf , 4095 , " %Y-%m-%d %H:%M:%S " , loctime ) ;
rootNodeReplay - > addAttribute ( " version " , glestVersionString , mapTagReplacements ) ;
rootNodeReplay - > addAttribute ( " timestamp " , szBuf , mapTagReplacements ) ;
XmlNode * gameNodeReplay = rootNodeReplay - > addChild ( " Game " ) ;
gameSettings . saveGame ( gameNodeReplay ) ;
gameNodeReplay - > addAttribute ( " LastWorldFrameCount " , intToStr ( world . getFrameCount ( ) ) , mapTagReplacements ) ;
for ( unsigned int i = 0 ; i < replayCommandList . size ( ) ; + + i ) {
std : : pair < int , NetworkCommand > & cmd = replayCommandList [ i ] ;
XmlNode * networkCommandNode = cmd . second . saveGame ( gameNodeReplay ) ;
networkCommandNode - > addAttribute ( " worldFrameCount " , intToStr ( cmd . first ) , mapTagReplacements ) ;
}
string replayFile = saveGameFile + " .replay " ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Saving game replay commands to [%s] \n " , replayFile . c_str ( ) ) ;
xmlTreeSaveGame . save ( replayFile ) ;
}
2012-03-15 06:59:23 +01:00
//XmlTree xmlTree(XML_XERCES_ENGINE);
XmlTree xmlTree ;
2012-03-10 04:27:25 +01:00
xmlTree . init ( " megaglest-saved-game " ) ;
XmlNode * rootNode = xmlTree . getRootNode ( ) ;
std : : map < string , string > mapTagReplacements ;
time_t now = time ( NULL ) ;
struct tm * loctime = localtime ( & now ) ;
char szBuf [ 4096 ] = " " ;
strftime ( szBuf , 4095 , " %Y-%m-%d %H:%M:%S " , loctime ) ;
rootNode - > addAttribute ( " version " , glestVersionString , mapTagReplacements ) ;
rootNode - > addAttribute ( " timestamp " , szBuf , mapTagReplacements ) ;
XmlNode * gameNode = rootNode - > addChild ( " Game " ) ;
//World world;
world . saveGame ( gameNode ) ;
//AiInterfaces aiInterfaces;
for ( unsigned int i = 0 ; i < aiInterfaces . size ( ) ; + + i ) {
AiInterface * aiIntf = aiInterfaces [ i ] ;
if ( aiIntf ! = NULL ) {
aiIntf - > saveGame ( gameNode ) ;
}
}
//Gui gui;
gui . saveGame ( gameNode ) ;
//GameCamera gameCamera;
gameCamera . saveGame ( gameNode ) ;
//Commander commander;
//Console console;
//ChatManager chatManager;
//ScriptManager scriptManager;
2012-03-26 08:48:58 +02:00
scriptManager . saveGame ( gameNode ) ;
2012-03-10 04:27:25 +01:00
//misc
//Checksum checksum;
gameNode - > addAttribute ( " checksum " , intToStr ( checksum . getSum ( ) ) , mapTagReplacements ) ;
//string loadingText;
// int mouse2d;
gameNode - > addAttribute ( " mouse2d " , intToStr ( mouse2d ) , mapTagReplacements ) ;
// int mouseX;
gameNode - > addAttribute ( " mouseX " , intToStr ( mouseX ) , mapTagReplacements ) ;
// int mouseY; //coords win32Api
gameNode - > addAttribute ( " mouseY " , intToStr ( mouseY ) , mapTagReplacements ) ;
// Vec2i mouseCellPos;
gameNode - > addAttribute ( " mouseCellPos " , mouseCellPos . getString ( ) , mapTagReplacements ) ;
// int updateFps, lastUpdateFps, avgUpdateFps;
// int totalRenderFps, renderFps, lastRenderFps, avgRenderFps,currentAvgRenderFpsTotal;
//Uint64 tickCount;
gameNode - > addAttribute ( " tickCount " , intToStr ( tickCount ) , mapTagReplacements ) ;
//bool paused;
gameNode - > addAttribute ( " paused " , intToStr ( paused ) , mapTagReplacements ) ;
//bool gameOver;
gameNode - > addAttribute ( " gameOver " , intToStr ( gameOver ) , mapTagReplacements ) ;
//bool renderNetworkStatus;
//bool showFullConsole;
//bool mouseMoved;
//float scrollSpeed;
2013-02-19 07:41:56 +01:00
gameNode - > addAttribute ( " scrollSpeed " , floatToStr ( scrollSpeed , 16 ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
//bool camLeftButtonDown;
//bool camRightButtonDown;
//bool camUpButtonDown;
//bool camDownButtonDown;
//Speed speed;
gameNode - > addAttribute ( " speed " , intToStr ( speed ) , mapTagReplacements ) ;
//GraphicMessageBox mainMessageBox;
//GraphicMessageBox errorMessageBox;
//misc ptr
//ParticleSystem *weatherParticleSystem;
if ( weatherParticleSystem ! = NULL ) {
weatherParticleSystem - > saveGame ( gameNode ) ;
}
//GameSettings gameSettings;
2012-03-13 00:08:22 +01:00
gameSettings . saveGame ( gameNode ) ;
2012-03-10 04:27:25 +01:00
//Vec2i lastMousePos;
gameNode - > addAttribute ( " lastMousePos " , lastMousePos . getString ( ) , mapTagReplacements ) ;
//time_t lastRenderLog2d;
gameNode - > addAttribute ( " lastRenderLog2d " , intToStr ( lastRenderLog2d ) , mapTagReplacements ) ;
//DisplayMessageFunction originalDisplayMsgCallback;
//bool isFirstRender;
gameNode - > addAttribute ( " isFirstRender " , intToStr ( isFirstRender ) , mapTagReplacements ) ;
//bool quitTriggeredIndicator;
//int original_updateFps;
gameNode - > addAttribute ( " original_updateFps " , intToStr ( original_updateFps ) , mapTagReplacements ) ;
//int original_cameraFps;
gameNode - > addAttribute ( " original_cameraFps " , intToStr ( original_cameraFps ) , mapTagReplacements ) ;
//bool captureAvgTestStatus;
gameNode - > addAttribute ( " captureAvgTestStatus " , intToStr ( captureAvgTestStatus ) , mapTagReplacements ) ;
//int updateFpsAvgTest;
gameNode - > addAttribute ( " updateFpsAvgTest " , intToStr ( updateFpsAvgTest ) , mapTagReplacements ) ;
//int renderFpsAvgTest;
gameNode - > addAttribute ( " renderFpsAvgTest " , intToStr ( renderFpsAvgTest ) , mapTagReplacements ) ;
//int renderExtraTeamColor;
gameNode - > addAttribute ( " renderExtraTeamColor " , intToStr ( renderExtraTeamColor ) , mapTagReplacements ) ;
//static const int renderTeamColorCircleBit=1;
//static const int renderTeamColorPlaneBit=2;
//bool photoModeEnabled;
gameNode - > addAttribute ( " photoModeEnabled " , intToStr ( photoModeEnabled ) , mapTagReplacements ) ;
//bool visibleHUD;
gameNode - > addAttribute ( " visibleHUD " , intToStr ( visibleHUD ) , mapTagReplacements ) ;
2012-10-12 00:10:31 +02:00
//bool timeDisplay
gameNode - > addAttribute ( " timeDisplay " , intToStr ( timeDisplay ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
//bool withRainEffect;
gameNode - > addAttribute ( " withRainEffect " , intToStr ( withRainEffect ) , mapTagReplacements ) ;
//Program *program;
//bool gameStarted;
gameNode - > addAttribute ( " gameStarted " , intToStr ( gameStarted ) , mapTagReplacements ) ;
//time_t lastMaxUnitCalcTime;
gameNode - > addAttribute ( " lastMaxUnitCalcTime " , intToStr ( lastMaxUnitCalcTime ) , mapTagReplacements ) ;
//PopupMenu popupMenu;
//PopupMenu popupMenuSwitchTeams;
//std::map<int,int> switchTeamIndexMap;
//GraphicMessageBox switchTeamConfirmMessageBox;
//int exitGamePopupMenuIndex;
//int joinTeamPopupMenuIndex;
//int pauseGamePopupMenuIndex;
//int keyboardSetupPopupMenuIndex;
//GLuint statelist3dMenu;
//ProgramState *currentUIState;
//bool masterserverMode;
//StrSound *currentAmbientSound;
//time_t lastNetworkPlayerConnectionCheck;
gameNode - > addAttribute ( " lastNetworkPlayerConnectionCheck " , intToStr ( lastNetworkPlayerConnectionCheck ) , mapTagReplacements ) ;
//time_t lastMasterServerGameStatsDump;
gameNode - > addAttribute ( " lastMasterServerGameStatsDump " , intToStr ( lastMasterServerGameStatsDump ) , mapTagReplacements ) ;
2012-10-18 00:57:04 +02:00
XmlNode * unitHighlightListNode = gameNode - > addChild ( " unitHighlightList " ) ;
//for(unsigned int i = 0; i < unitHighlightList.size(); ++i) {
for ( std : : map < int , HighlightSpecialUnitInfo > : : iterator iterMap = unitHighlightList . begin ( ) ;
iterMap ! = unitHighlightList . end ( ) ; + + iterMap ) {
HighlightSpecialUnitInfo & info = iterMap - > second ;
XmlNode * infoNode = unitHighlightListNode - > addChild ( " info " ) ;
infoNode - > addAttribute ( " unitid " , intToStr ( iterMap - > first ) , mapTagReplacements ) ;
2013-02-19 07:41:56 +01:00
infoNode - > addAttribute ( " radius " , floatToStr ( info . radius , 16 ) , mapTagReplacements ) ;
infoNode - > addAttribute ( " thickness " , floatToStr ( info . thickness , 16 ) , mapTagReplacements ) ;
2012-10-18 00:57:04 +02:00
infoNode - > addAttribute ( " color " , info . color . getString ( ) , mapTagReplacements ) ;
}
gameNode - > addAttribute ( " timeDisplay " , intToStr ( timeDisplay ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
xmlTree . save ( saveGameFile ) ;
2012-03-15 16:57:21 +01:00
2012-03-17 05:19:17 +01:00
if ( masterserverMode = = false ) {
// take Screenshot
string jpgFileName = saveGameFile + " .jpg " ;
2012-03-17 12:26:39 +01:00
Renderer : : getInstance ( ) . saveScreen ( jpgFileName , config . getInt ( " SaveGameScreenshotWidth " , " 800 " ) , config . getInt ( " SaveGameScreenshotHeight " , " 600 " ) ) ;
2012-03-17 05:19:17 +01:00
}
2012-03-17 02:32:18 +01:00
2012-03-15 16:57:21 +01:00
return saveGameFile ;
2012-03-10 04:27:25 +01:00
}
2013-02-15 19:25:10 +01:00
void Game : : loadGame ( string name , Program * programPtr , bool isMasterserverMode , const GameSettings * joinGameSettings ) {
2012-03-20 06:23:32 +01:00
Config & config = Config : : getInstance ( ) ;
// This condition will re-play all the commands from a replay file
// INSTEAD of saving from a saved game.
2013-02-15 19:25:10 +01:00
if ( joinGameSettings = = NULL & & config . getBool ( " SaveCommandsForReplay " , " false " ) = = true ) {
2012-03-20 06:23:32 +01:00
XmlTree xmlTreeReplay ( XML_RAPIDXML_ENGINE ) ;
std : : map < string , string > mapExtraTagReplacementValues ;
xmlTreeReplay . load ( name + " .replay " , Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) , true ) ;
const XmlNode * rootNode = xmlTreeReplay . getRootNode ( ) ;
if ( rootNode - > hasChild ( " megaglest-saved-game " ) = = true ) {
rootNode = rootNode - > getChild ( " megaglest-saved-game " ) ;
}
//const XmlNode *versionNode= rootNode->getChild("megaglest-saved-game");
const XmlNode * versionNode = rootNode ;
Lang & lang = Lang : : getInstance ( ) ;
string gameVer = versionNode - > getAttribute ( " version " ) - > getValue ( ) ;
2012-12-29 22:31:54 +01:00
if ( gameVer ! = glestVersionString & & checkVersionComptability ( gameVer , glestVersionString ) = = false ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , lang . get ( " SavedGameBadVersion " ) . c_str ( ) , gameVer . c_str ( ) , glestVersionString . c_str ( ) ) ;
2013-05-25 10:02:07 +02:00
throw megaglest_runtime_error ( szBuf , true ) ;
2012-03-20 06:23:32 +01:00
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Found saved game version that matches your application version: [%s] --> [%s] \n " , gameVer . c_str ( ) , glestVersionString . c_str ( ) ) ;
XmlNode * gameNode = rootNode - > getChild ( " Game " ) ;
GameSettings newGameSettingsReplay ;
newGameSettingsReplay . loadGame ( gameNode ) ;
2012-03-29 02:43:03 +02:00
//printf("Loading scenario [%s]\n",newGameSettingsReplay.getScenarioDir().c_str());
if ( newGameSettingsReplay . getScenarioDir ( ) ! = " " & & fileExists ( newGameSettingsReplay . getScenarioDir ( ) ) = = false ) {
newGameSettingsReplay . setScenarioDir ( Scenario : : getScenarioPath ( Config : : getInstance ( ) . getPathListForType ( ptScenarios ) , newGameSettingsReplay . getScenario ( ) ) ) ;
//printf("Loading scenario #2 [%s]\n",newGameSettingsReplay.getScenarioDir().c_str());
}
2012-03-20 06:23:32 +01:00
//GameSettings newGameSettings;
//newGameSettings.loadGame(gameNode);
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Game settings loaded\n");
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
networkManager . end ( ) ;
networkManager . init ( nrServer , true ) ;
Game * newGame = new Game ( programPtr , & newGameSettingsReplay , isMasterserverMode ) ;
newGame - > lastworldFrameCountForReplay = gameNode - > getAttribute ( " LastWorldFrameCount " ) - > getIntValue ( ) ;
vector < XmlNode * > networkCommandNodeList = gameNode - > getChildList ( " NetworkCommand " ) ;
2012-11-10 07:37:23 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " networkCommandNodeList.size() = " MG_SIZE_T_SPECIFIER " \n " , networkCommandNodeList . size ( ) ) ;
2012-03-20 06:23:32 +01:00
for ( unsigned int i = 0 ; i < networkCommandNodeList . size ( ) ; + + i ) {
XmlNode * node = networkCommandNodeList [ i ] ;
int worldFrameCount = node - > getAttribute ( " worldFrameCount " ) - > getIntValue ( ) ;
NetworkCommand command ;
command . loadGame ( node ) ;
newGame - > commander . addToReplayCommandList ( command , worldFrameCount ) ;
}
programPtr - > setState ( newGame ) ;
return ;
}
2012-03-14 23:48:46 +01:00
XmlTree xmlTree ( XML_RAPIDXML_ENGINE ) ;
2012-03-13 00:08:22 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Before load of XML \n " ) ;
std : : map < string , string > mapExtraTagReplacementValues ;
xmlTree . load ( name , Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) , true ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " After load of XML \n " ) ;
const XmlNode * rootNode = xmlTree . getRootNode ( ) ;
2012-03-14 22:52:13 +01:00
if ( rootNode - > hasChild ( " megaglest-saved-game " ) = = true ) {
rootNode = rootNode - > getChild ( " megaglest-saved-game " ) ;
}
2012-03-13 00:08:22 +01:00
//const XmlNode *versionNode= rootNode->getChild("megaglest-saved-game");
const XmlNode * versionNode = rootNode ;
2012-03-17 04:32:20 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2012-03-13 00:08:22 +01:00
string gameVer = versionNode - > getAttribute ( " version " ) - > getValue ( ) ;
2012-12-29 22:31:54 +01:00
if ( gameVer ! = glestVersionString & & checkVersionComptability ( gameVer , glestVersionString ) = = false ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , lang . get ( " SavedGameBadVersion " ) . c_str ( ) , gameVer . c_str ( ) , glestVersionString . c_str ( ) ) ;
2013-05-25 10:02:07 +02:00
throw megaglest_runtime_error ( szBuf , true ) ;
2012-03-13 00:08:22 +01:00
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Found saved game version that matches your application version: [%s] --> [%s] \n " , gameVer . c_str ( ) , glestVersionString . c_str ( ) ) ;
XmlNode * gameNode = rootNode - > getChild ( " Game " ) ;
GameSettings newGameSettings ;
2013-02-15 19:25:10 +01:00
if ( joinGameSettings ! = NULL ) {
newGameSettings = * joinGameSettings ;
XmlNode * worldNode = gameNode - > getChild ( " World " ) ;
XmlNode * guiNode = gameNode - > getChild ( " Gui " ) ;
XmlNode * selectionNode = guiNode - > getChild ( " Selection " ) ;
2013-02-16 21:02:22 +01:00
XmlNode * statsNode = worldNode - > getChild ( " Stats " ) ;
2013-02-19 07:41:56 +01:00
XmlNode * minimapNode = worldNode - > getChild ( " Minimap " ) ;
// This is explored fog of war for the host player, clear it
minimapNode - > clearChild ( " fowPixmap1 " ) ;
2013-02-15 19:25:10 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
NetworkRole role = networkManager . getNetworkRole ( ) ;
ClientInterface * clientInterface = dynamic_cast < ClientInterface * > ( networkManager . getClientInterface ( ) ) ;
for ( int i = 0 ; i < newGameSettings . getFactionCount ( ) ; + + i ) {
//replace by network
if ( newGameSettings . getFactionControl ( i ) = = ctHuman ) {
newGameSettings . setFactionControl ( i , ctNetwork ) ;
}
//set the faction index
if ( newGameSettings . getStartLocationIndex ( i ) = = clientInterface - > getPlayerIndex ( ) ) {
newGameSettings . setThisFactionIndex ( i ) ;
newGameSettings . setFactionControl ( i , ctNetwork ) ;
worldNode - > getAttribute ( " thisFactionIndex " ) - > setValue ( intToStr ( i ) ) ;
2013-02-16 21:02:22 +01:00
//worldNode->getAttribute("thisTeamIndex")->setValue(intToStr(newGameSettings.getTeam(i)));
2013-02-15 19:25:10 +01:00
XmlNode * factionNode = worldNode - > getChild ( " Faction " , i ) ;
factionNode - > getAttribute ( " thisFaction " ) - > setValue ( intToStr ( i ) ) ;
factionNode - > getAttribute ( " control " ) - > setValue ( intToStr ( ctNetwork ) ) ;
selectionNode - > getAttribute ( " factionIndex " ) - > setValue ( intToStr ( i ) ) ;
2013-02-16 21:02:22 +01:00
//selectionNode->getAttribute("teamIndex")->setValue(intToStr(newGameSettings.getTeam(i)));
statsNode - > getAttribute ( " thisFactionIndex " ) - > setValue ( intToStr ( i ) ) ;
2013-02-15 19:25:10 +01:00
}
else {
2013-02-16 21:02:22 +01:00
XmlNode * factionNode = worldNode - > getChild ( " Faction " , i ) ;
factionNode - > getAttribute ( " thisFaction " ) - > setValue ( intToStr ( 0 ) ) ;
2013-02-15 19:25:10 +01:00
}
}
}
else {
newGameSettings . loadGame ( gameNode ) ;
//printf("Loading scenario [%s]\n",newGameSettings.getScenarioDir().c_str());
if ( newGameSettings . getScenarioDir ( ) ! = " " & & fileExists ( newGameSettings . getScenarioDir ( ) ) = = false ) {
newGameSettings . setScenarioDir ( Scenario : : getScenarioPath ( Config : : getInstance ( ) . getPathListForType ( ptScenarios ) , newGameSettings . getScenario ( ) ) ) ;
//printf("Loading scenario #2 [%s]\n",newGameSettings.getScenarioDir().c_str());
}
2012-03-29 02:43:03 +02:00
}
2012-03-13 00:08:22 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Game settings loaded \n " ) ;
2013-02-15 19:25:10 +01:00
if ( joinGameSettings = = NULL ) {
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
networkManager . end ( ) ;
networkManager . init ( nrServer , true ) ;
}
2012-03-13 00:08:22 +01:00
Game * newGame = new Game ( programPtr , & newGameSettings , isMasterserverMode ) ;
newGame - > loadGameNode = gameNode ;
2013-02-15 19:25:10 +01:00
newGame - > inJoinGameLoading = ( joinGameSettings ! = NULL ) ;
2012-03-13 01:00:10 +01:00
// newGame->mouse2d = gameNode->getAttribute("mouse2d")->getIntValue();
// int mouseX;
// newGame->mouseX = gameNode->getAttribute("mouseX")->getIntValue();
// int mouseY; //coords win32Api
// newGame->mouseY = gameNode->getAttribute("mouseY")->getIntValue();
// Vec2i mouseCellPos;
// newGame->mouseCellPos = Vec2i::strToVec2(gameNode->getAttribute("mouseCellPos")->getValue());
// int updateFps, lastUpdateFps, avgUpdateFps;
// int totalRenderFps, renderFps, lastRenderFps, avgRenderFps,currentAvgRenderFpsTotal;
//Uint64 tickCount;
newGame - > tickCount = gameNode - > getAttribute ( " tickCount " ) - > getIntValue ( ) ;
//bool paused;
2012-04-16 22:15:57 +02:00
newGame - > paused = gameNode - > getAttribute ( " paused " ) - > getIntValue ( ) ! = 0 ;
2012-03-13 01:00:10 +01:00
//bool gameOver;
2012-04-16 22:15:57 +02:00
newGame - > gameOver = gameNode - > getAttribute ( " gameOver " ) - > getIntValue ( ) ! = 0 ;
2012-03-13 01:00:10 +01:00
//bool renderNetworkStatus;
//bool showFullConsole;
//bool mouseMoved;
//float scrollSpeed;
// newGame->scrollSpeed = gameNode->getAttribute("scrollSpeed")->getFloatValue();
//bool camLeftButtonDown;
//bool camRightButtonDown;
//bool camUpButtonDown;
//bool camDownButtonDown;
//Speed speed;
//gameNode->addAttribute("speed",intToStr(speed), mapTagReplacements);
//GraphicMessageBox mainMessageBox;
//GraphicMessageBox errorMessageBox;
//misc ptr
//ParticleSystem *weatherParticleSystem;
// if(weatherParticleSystem != NULL) {
// weatherParticleSystem->saveGame(gameNode);
// }
//GameSettings gameSettings;
// gameSettings.saveGame(gameNode);
//Vec2i lastMousePos;
// gameNode->addAttribute("lastMousePos",lastMousePos.getString(), mapTagReplacements);
//time_t lastRenderLog2d;
// gameNode->addAttribute("lastRenderLog2d",intToStr(lastRenderLog2d), mapTagReplacements);
//DisplayMessageFunction originalDisplayMsgCallback;
//bool isFirstRender;
// gameNode->addAttribute("isFirstRender",intToStr(isFirstRender), mapTagReplacements);
//bool quitTriggeredIndicator;
//int original_updateFps;
// gameNode->addAttribute("original_updateFps",intToStr(original_updateFps), mapTagReplacements);
//int original_cameraFps;
// gameNode->addAttribute("original_cameraFps",intToStr(original_cameraFps), mapTagReplacements);
//bool captureAvgTestStatus;
// gameNode->addAttribute("captureAvgTestStatus",intToStr(captureAvgTestStatus), mapTagReplacements);
//int updateFpsAvgTest;
// gameNode->addAttribute("updateFpsAvgTest",intToStr(updateFpsAvgTest), mapTagReplacements);
//int renderFpsAvgTest;
// gameNode->addAttribute("renderFpsAvgTest",intToStr(renderFpsAvgTest), mapTagReplacements);
//int renderExtraTeamColor;
newGame - > renderExtraTeamColor = gameNode - > getAttribute ( " renderExtraTeamColor " ) - > getIntValue ( ) ;
//static const int renderTeamColorCircleBit=1;
//static const int renderTeamColorPlaneBit=2;
//bool photoModeEnabled;
//gameNode->addAttribute("photoModeEnabled",intToStr(photoModeEnabled), mapTagReplacements);
2012-04-16 22:15:57 +02:00
newGame - > photoModeEnabled = gameNode - > getAttribute ( " photoModeEnabled " ) - > getIntValue ( ) ! = 0 ;
2012-03-13 01:00:10 +01:00
//bool visibleHUD;
//gameNode->addAttribute("visibleHUD",intToStr(visibleHUD), mapTagReplacements);
2012-04-16 22:15:57 +02:00
newGame - > visibleHUD = gameNode - > getAttribute ( " visibleHUD " ) - > getIntValue ( ) ! = 0 ;
2012-10-12 00:10:31 +02:00
newGame - > timeDisplay = gameNode - > getAttribute ( " timeDisplay " ) - > getIntValue ( ) ! = 0 ;
2012-03-13 01:00:10 +01:00
//bool withRainEffect;
//gameNode->addAttribute("withRainEffect",intToStr(withRainEffect), mapTagReplacements);
2012-04-16 22:15:57 +02:00
newGame - > withRainEffect = gameNode - > getAttribute ( " withRainEffect " ) - > getIntValue ( ) ! = 0 ;
2012-03-13 01:00:10 +01:00
//Program *program;
2013-02-15 19:25:10 +01:00
if ( joinGameSettings = = NULL ) {
if ( gameNode - > hasChild ( " unitHighlightList " ) = = true ) {
XmlNode * unitHighlightListNode = gameNode - > getChild ( " unitHighlightList " ) ;
vector < XmlNode * > infoNodeList = unitHighlightListNode - > getChildList ( " info " ) ;
for ( unsigned int i = 0 ; i < infoNodeList . size ( ) ; + + i ) {
XmlNode * infoNode = infoNodeList [ i ] ;
2012-10-18 00:57:04 +02:00
2013-02-15 19:25:10 +01:00
int unitId = infoNode - > getAttribute ( " radius " ) - > getIntValue ( ) ;
HighlightSpecialUnitInfo info ;
info . radius = infoNode - > getAttribute ( " radius " ) - > getFloatValue ( ) ;
info . thickness = infoNode - > getAttribute ( " thickness " ) - > getFloatValue ( ) ;
info . color = Vec4f : : strToVec4 ( infoNode - > getAttribute ( " color " ) - > getValue ( ) ) ;
2012-10-18 00:57:04 +02:00
2013-02-15 19:25:10 +01:00
newGame - > unitHighlightList [ unitId ] = info ;
}
2012-10-18 00:57:04 +02:00
}
}
newGame - > timeDisplay = gameNode - > getAttribute ( " timeDisplay " ) - > getIntValue ( ) ! = 0 ;
2012-03-13 01:00:10 +01:00
//bool gameStarted;
//gameNode->addAttribute("gameStarted",intToStr(gameStarted), mapTagReplacements);
// newGame->gameStarted = gameNode->getAttribute("gameStarted")->getIntValue();
//time_t lastMaxUnitCalcTime;
//gameNode->addAttribute("lastMaxUnitCalcTime",intToStr(lastMaxUnitCalcTime), mapTagReplacements);
//PopupMenu popupMenu;
//PopupMenu popupMenuSwitchTeams;
//std::map<int,int> switchTeamIndexMap;
//GraphicMessageBox switchTeamConfirmMessageBox;
//int exitGamePopupMenuIndex;
//int joinTeamPopupMenuIndex;
//int pauseGamePopupMenuIndex;
//int keyboardSetupPopupMenuIndex;
//GLuint statelist3dMenu;
//ProgramState *currentUIState;
//bool masterserverMode;
//StrSound *currentAmbientSound;
//time_t lastNetworkPlayerConnectionCheck;
//gameNode->addAttribute("lastNetworkPlayerConnectionCheck",intToStr(lastNetworkPlayerConnectionCheck), mapTagReplacements);
//time_t lastMasterServerGameStatsDump;
//gameNode->addAttribute("lastMasterServerGameStatsDump",intToStr(lastMasterServerGameStatsDump), mapTagReplacements);
2013-02-15 19:25:10 +01:00
if ( joinGameSettings = = NULL ) {
newGame - > gameCamera . loadGame ( gameNode ) ;
}
2012-03-13 00:08:22 +01:00
const XmlNode * worldNode = gameNode - > getChild ( " World " ) ;
newGame - > world . loadGame ( worldNode ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Starting Game ... \n " ) ;
programPtr - > setState ( newGame ) ;
}
2010-03-13 22:10:45 +01:00
} } //end namespace