2010-03-13 23:00:01 +01:00
// This file is part of Glest (www.glest.org)
//
2011-12-28 05:46:36 +01:00
// Copyright (C) 2001-2005 Martiño Figueroa
2010-03-13 23:00:01 +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 "menu_state_custom_game.h"
# include "renderer.h"
# include "sound_renderer.h"
# include "core_data.h"
# include "config.h"
# include "menu_state_new_game.h"
2010-05-16 18:40:21 +02:00
# include "menu_state_masterserver.h"
2011-10-30 23:23:57 +01:00
# include "menu_state_join_game.h"
2010-03-13 23:00:01 +01:00
# include "metrics.h"
# include "network_manager.h"
# include "network_message.h"
# include "client_interface.h"
# include "conversion.h"
# include "socket.h"
# include "game.h"
2010-05-13 00:58:00 +02:00
# include "util.h"
2010-03-27 19:43:38 +01:00
# include <algorithm>
# include <time.h>
2010-05-13 00:58:00 +02:00
# include <curl/curl.h>
2010-10-22 09:28:55 +02:00
# include "cache_manager.h"
2011-02-16 00:53:48 +01:00
# include <iterator>
2011-02-08 04:50:59 +01:00
# include "map_preview.h"
2013-10-31 01:57:36 +01:00
# include "gen_uuid.h"
2011-02-16 00:53:48 +01:00
# include "leak_dumper.h"
2010-03-13 23:00:01 +01:00
namespace Glest { namespace Game {
2013-11-19 22:57:28 +01:00
using namespace : : Shared : : Util ;
2010-03-13 23:00:01 +01:00
2014-01-27 23:15:05 +01:00
const int MASTERSERVER_BROADCAST_MAX_WAIT_RESPONSE_SECONDS = 15 ;
2012-10-07 01:01:14 +02:00
const int MASTERSERVER_BROADCAST_PUBLISH_SECONDS = 6 ;
2014-01-27 23:15:05 +01:00
const int BROADCAST_MAP_DELAY_SECONDS = 5 ;
const int BROADCAST_SETTINGS_SECONDS = 4 ;
2012-09-20 23:57:00 +02:00
static const char * SAVED_GAME_FILENAME = " lastCustomGameSettings.mgg " ;
static const char * DEFAULT_GAME_FILENAME = " data/defaultGameSetup.mgg " ;
static const char * DEFAULT_NETWORKGAME_FILENAME = " data/defaultNetworkGameSetup.mgg " ;
2011-12-03 09:17:49 +01:00
2013-12-31 08:32:06 +01:00
const int mapPreviewTexture_X = 5 ;
const int mapPreviewTexture_Y = 185 ;
const int mapPreviewTexture_W = 150 ;
const int mapPreviewTexture_H = 150 ;
2010-03-27 08:09:34 +01:00
struct FormatString {
void operator ( ) ( string & s ) {
s = formatString ( s ) ;
}
} ;
2010-03-13 23:00:01 +01:00
// =====================================================
// class MenuStateCustomGame
// =====================================================
2013-11-07 19:39:08 +01:00
enum THREAD_NOTIFIER_TYPE {
tnt_MASTERSERVER = 1 ,
tnt_CLIENTS = 2
} ;
2010-03-13 23:00:01 +01:00
2011-09-24 09:46:56 +02:00
MenuStateCustomGame : : MenuStateCustomGame ( Program * program , MainMenu * mainMenu ,
2011-10-30 23:23:57 +01:00
bool openNetworkSlots , ParentMenuState parentMenuState , bool autostart ,
2011-12-26 07:29:14 +01:00
GameSettings * settings , bool masterserverMode ,
string autoloadScenarioName ) :
MenuState ( program , mainMenu , " new-game " ) {
try {
2012-07-06 00:03:15 +02:00
this - > headlessServerMode = masterserverMode ;
if ( this - > headlessServerMode = = true ) {
2011-09-27 12:16:09 +02:00
printf ( " Waiting for players to join and start a game... \n " ) ;
}
2013-10-31 01:57:36 +01:00
this - > gameUUID = getUUIDAsString ( ) ;
2014-01-03 19:19:10 +01:00
this - > zoomedMap = false ;
2013-12-31 08:32:06 +01:00
this - > render_mapPreviewTexture_X = mapPreviewTexture_X ;
this - > render_mapPreviewTexture_Y = mapPreviewTexture_Y ;
this - > render_mapPreviewTexture_W = mapPreviewTexture_W ;
this - > render_mapPreviewTexture_H = mapPreviewTexture_H ;
2011-09-24 09:46:56 +02:00
this - > lastMasterServerSettingsUpdateCount = 0 ;
this - > masterserverModeMinimalResources = true ;
2011-10-30 23:23:57 +01:00
this - > parentMenuState = parentMenuState ;
2012-05-26 01:00:36 +02:00
this - > factionVideo = NULL ;
2012-07-15 21:45:55 +02:00
factionVideoSwitchedOffVolume = false ;
2011-09-24 09:46:56 +02:00
//printf("this->masterserverMode = %d [%d]\n",this->masterserverMode,masterserverMode);
2011-03-28 23:04:47 +02:00
forceWaitForShutdown = true ;
2010-10-02 04:17:50 +02:00
this - > autostart = autostart ;
2011-09-16 02:34:14 +02:00
this - > autoStartSettings = settings ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] autostart = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , autostart ) ;
2010-06-01 01:39:07 +02:00
2010-09-09 23:07:39 +02:00
containerName = " CustomGame " ;
2010-08-21 09:41:26 +02:00
activeInputLabel = NULL ;
2010-06-11 06:55:49 +02:00
showGeneralError = false ;
generalErrorToShow = " --- " ;
2010-08-31 08:38:27 +02:00
currentFactionLogo = " " ;
factionTexture = NULL ;
2010-10-30 05:29:29 +02:00
currentTechName_factionPreview = " " ;
currentFactionName_factionPreview = " " ;
2010-11-01 17:44:05 +01:00
mapPreviewTexture = NULL ;
2010-12-21 06:07:10 +01:00
hasCheckedForUPNP = false ;
2011-01-31 00:01:55 +01:00
needToPublishDelayed = false ;
2011-01-29 21:13:29 +01:00
mapPublishingDelayTimer = time ( NULL ) ;
2010-06-11 06:55:49 +02:00
2011-03-19 06:11:36 +01:00
lastCheckedCRCTilesetName = " " ;
lastCheckedCRCTechtreeName = " " ;
lastCheckedCRCMapName = " " ;
2013-06-23 07:23:02 +02:00
last_Forced_CheckedCRCTilesetName = " " ;
last_Forced_CheckedCRCTechtreeName = " " ;
last_Forced_CheckedCRCMapName = " " ;
2013-11-16 19:36:54 +01:00
lastCheckedCRCTilesetValue = 0 ;
lastCheckedCRCTechtreeValue = 0 ;
lastCheckedCRCMapValue = 0 ;
2011-03-19 06:11:36 +01:00
2010-05-17 08:41:05 +02:00
publishToMasterserverThread = NULL ;
2013-11-07 19:39:08 +01:00
publishToClientsThread = NULL ;
2010-03-13 23:00:01 +01:00
Lang & lang = Lang : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
2010-03-27 08:09:34 +01:00
Config & config = Config : : getInstance ( ) ;
2010-08-23 06:33:21 +02:00
defaultPlayerName = config . getString ( " NetPlayerName " , Socket : : getHostName ( ) . c_str ( ) ) ;
2010-09-26 23:34:00 +02:00
enableFactionTexturePreview = config . getBool ( " FactionPreview " , " true " ) ;
enableMapPreview = config . getBool ( " MapPreview " , " true " ) ;
2010-12-07 07:12:51 +01:00
2010-06-09 00:50:37 +02:00
showFullConsole = false ;
2010-06-03 23:07:55 +02:00
2011-12-26 07:29:14 +01:00
enableScenarioTexturePreview = Config : : getInstance ( ) . getBool ( " EnableScenarioTexturePreview " , " true " ) ;
scenarioLogoTexture = NULL ;
previewLoadDelayTimer = time ( NULL ) ;
needToLoadTextures = true ;
this - > autoloadScenarioName = autoloadScenarioName ;
this - > dirList = Config : : getInstance ( ) . getPathListForType ( ptScenarios ) ;
2010-09-09 00:37:24 +02:00
mainMessageBox . registerGraphicComponent ( containerName , " mainMessageBox " ) ;
2014-12-09 02:36:30 +01:00
mainMessageBox . init ( lang . getString ( " Ok " ) , 500 , 300 ) ;
2010-06-11 06:55:49 +02:00
mainMessageBox . setEnabled ( false ) ;
mainMessageBoxState = 0 ;
2010-06-03 23:07:55 +02:00
//initialize network interface
2010-06-03 23:14:42 +02:00
NetworkManager : : getInstance ( ) . end ( ) ;
2010-06-11 06:55:49 +02:00
2012-01-06 07:55:27 +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-11 06:55:49 +02:00
serverInitError = false ;
try {
2011-03-11 13:14:24 +01:00
networkManager . init ( nrServer , openNetworkSlots ) ;
2010-06-11 06:55:49 +02:00
}
catch ( const std : : exception & ex ) {
serverInitError = true ;
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Network init error: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2010-06-11 06:55:49 +02:00
2012-03-31 10:28:42 +02:00
showGeneralError = true ;
generalErrorToShow = szBuf ;
2010-06-11 06:55:49 +02:00
}
2012-01-06 07:55:27 +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-03 23:07:55 +02:00
2010-03-13 23:00:01 +01:00
needToSetChangedGameSettings = false ;
2010-05-13 08:43:56 +02:00
needToRepublishToMasterserver = false ;
2010-05-13 13:19:10 +02:00
needToBroadcastServerSettings = false ;
2014-10-28 21:52:10 +01:00
lastGameSettingsreceivedCount = - 1 ;
2010-05-17 01:03:22 +02:00
showMasterserverError = false ;
2012-03-03 09:28:15 +01:00
tMasterserverErrorElapsed = 0 ;
2010-05-17 01:03:22 +02:00
masterServererErrorToShow = " --- " ;
2010-05-17 18:02:47 +02:00
lastSetChangedGameSettings = 0 ;
lastMasterserverPublishing = 0 ;
2010-07-09 19:12:57 +02:00
lastNetworkPing = 0 ;
2010-05-16 18:40:21 +02:00
soundConnectionCount = 0 ;
2010-03-13 23:00:01 +01:00
2013-06-13 03:37:15 +02:00
techTree . reset ( new TechTree ( config . getPathListForType ( ptTechs ) ) ) ;
2010-09-04 13:49:54 +02:00
int labelOffset = 23 ;
2013-10-25 21:35:10 +02:00
int setupPos = 605 ;
2010-06-04 02:33:34 +02:00
int mapHeadPos = 330 ;
2010-09-04 13:49:54 +02:00
int mapPos = mapHeadPos - labelOffset ;
2011-11-04 01:36:07 +01:00
int aHeadPos = 240 ;
2010-09-04 13:49:54 +02:00
int aPos = aHeadPos - labelOffset ;
2010-06-04 02:33:34 +02:00
int networkHeadPos = 700 ;
2010-09-04 13:49:54 +02:00
int networkPos = networkHeadPos - labelOffset ;
2010-08-28 01:08:35 +02:00
int xoffset = 10 ;
2010-12-07 07:12:51 +01:00
2013-10-25 21:35:10 +02:00
//create
2014-12-15 21:39:11 +01:00
int buttonx = 170 ;
2013-10-25 21:35:10 +02:00
int buttony = 180 ;
2014-12-15 21:39:11 +01:00
// player status
listBoxPlayerStatus . registerGraphicComponent ( containerName , " listBoxPlayerStatus " ) ;
listBoxPlayerStatus . init ( buttonx , buttony , 150 ) ;
vector < string > playerStatuses ;
playerStatuses . push_back ( lang . getString ( " PlayerStatusSetup " ) ) ;
playerStatuses . push_back ( lang . getString ( " PlayerStatusBeRightBack " ) ) ;
playerStatuses . push_back ( lang . getString ( " PlayerStatusReady " ) ) ;
listBoxPlayerStatus . setItems ( playerStatuses ) ;
listBoxPlayerStatus . setSelectedItemIndex ( 2 , true ) ;
listBoxPlayerStatus . setTextColor ( Vec3f ( 0.0f , 1.0f , 0.0f ) ) ;
listBoxPlayerStatus . setLighted ( false ) ;
listBoxPlayerStatus . setVisible ( true ) ;
buttonx + = 180 ;
2013-10-25 21:35:10 +02:00
buttonReturn . registerGraphicComponent ( containerName , " buttonReturn " ) ;
buttonReturn . init ( buttonx , buttony , 125 ) ;
2014-12-15 21:39:11 +01:00
buttonx + = 130 ;
2013-10-25 21:35:10 +02:00
buttonRestoreLastSettings . registerGraphicComponent ( containerName , " buttonRestoreLastSettings " ) ;
2014-12-15 21:39:11 +01:00
buttonRestoreLastSettings . init ( buttonx , buttony , 220 ) ;
buttonx + = 225 ;
2013-10-25 21:35:10 +02:00
buttonPlayNow . registerGraphicComponent ( containerName , " buttonPlayNow " ) ;
2014-12-15 21:39:11 +01:00
buttonPlayNow . init ( buttonx , buttony , 125 ) ;
buttonx + = 130 ;
2013-10-25 21:35:10 +02:00
2012-05-12 04:21:21 +02:00
labelLocalGameVersion . registerGraphicComponent ( containerName , " labelLocalGameVersion " ) ;
labelLocalGameVersion . init ( 10 , networkHeadPos + labelOffset ) ;
2010-09-09 00:37:24 +02:00
labelLocalIP . registerGraphicComponent ( containerName , " labelLocalIP " ) ;
2012-05-12 04:21:21 +02:00
labelLocalIP . init ( 360 , networkHeadPos + labelOffset ) ;
2010-07-10 08:14:31 +02:00
string ipText = " none " ;
std : : vector < std : : string > ipList = Socket : : getLocalIPAddressList ( ) ;
2011-09-01 01:10:43 +02:00
if ( ipList . empty ( ) = = false ) {
2010-07-10 08:14:31 +02:00
ipText = " " ;
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) ipList . size ( ) ; idx + + ) {
2010-07-10 08:14:31 +02:00
string ip = ipList [ idx ] ;
if ( ipText ! = " " ) {
ipText + = " , " ;
}
ipText + = ip ;
}
}
2012-10-06 14:56:53 +02:00
string serverPort = config . getString ( " PortServer " , intToStr ( GameConstants : : serverPort ) . c_str ( ) ) ;
2012-10-06 15:45:42 +02:00
string externalPort = config . getString ( " PortExternal " , serverPort . c_str ( ) ) ;
2013-10-29 07:13:38 +01:00
labelLocalIP . setText ( lang . getString ( " LanIP " ) + ipText + " ( " + serverPort + " / " + externalPort + " ) " ) ;
2010-12-21 06:07:10 +01:00
ServerSocket : : setExternalPort ( strToInt ( externalPort ) ) ;
2010-07-10 08:14:31 +02:00
2012-05-12 04:21:21 +02:00
if ( EndsWith ( glestVersionString , " -dev " ) = = false ) {
labelLocalGameVersion . setText ( glestVersionString ) ;
}
else {
2013-11-29 22:13:30 +01:00
labelLocalGameVersion . setText ( glestVersionString + " [ " + getCompileDateTime ( ) + " , " + getGITRevisionString ( ) + " ] " ) ;
2012-05-12 04:21:21 +02:00
}
2012-01-05 03:03:54 +01:00
xoffset = 70 ;
2011-12-28 05:46:36 +01:00
// MapFilter
labelMapFilter . registerGraphicComponent ( containerName , " labelMapFilter " ) ;
labelMapFilter . init ( xoffset + 310 , mapHeadPos ) ;
2013-10-29 07:13:38 +01:00
labelMapFilter . setText ( lang . getString ( " MapFilter " ) + " : " ) ;
2011-12-28 05:46:36 +01:00
listBoxMapFilter . registerGraphicComponent ( containerName , " listBoxMapFilter " ) ;
listBoxMapFilter . init ( xoffset + 310 , mapPos , 80 ) ;
listBoxMapFilter . pushBackItem ( " - " ) ;
for ( int i = 1 ; i < GameConstants : : maxPlayers + 1 ; + + i ) {
listBoxMapFilter . pushBackItem ( intToStr ( i ) ) ;
}
listBoxMapFilter . setSelectedItemIndex ( 0 ) ;
2010-08-28 01:08:35 +02:00
// Map
2010-09-09 00:37:24 +02:00
labelMap . registerGraphicComponent ( containerName , " labelMap " ) ;
2010-08-28 01:08:35 +02:00
labelMap . init ( xoffset + 100 , mapHeadPos ) ;
2013-10-29 07:13:38 +01:00
labelMap . setText ( lang . getString ( " Map " ) + " : " ) ;
2010-09-09 00:37:24 +02:00
2011-12-28 05:46:36 +01:00
//map listBox
2010-09-09 00:37:24 +02:00
listBoxMap . registerGraphicComponent ( containerName , " listBoxMap " ) ;
2010-08-28 01:08:35 +02:00
listBoxMap . init ( xoffset + 100 , mapPos , 200 ) ;
2011-12-28 05:46:36 +01:00
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
// will also ensure they are alphabetically listed (rather than how the OS provides them)
int initialMapSelection = setupMapList ( " " ) ;
2010-08-30 22:02:58 +02:00
listBoxMap . setItems ( formattedPlayerSortedMaps [ 0 ] ) ;
2011-04-05 01:11:59 +02:00
listBoxMap . setSelectedItemIndex ( initialMapSelection ) ;
2010-09-09 00:37:24 +02:00
labelMapInfo . registerGraphicComponent ( containerName , " labelMapInfo " ) ;
2011-11-02 20:02:25 +01:00
labelMapInfo . init ( xoffset + 100 , mapPos - labelOffset - 10 , 200 , 40 ) ;
2010-12-07 07:12:51 +01:00
2011-12-28 05:46:36 +01:00
labelTileset . registerGraphicComponent ( containerName , " labelTileset " ) ;
labelTileset . init ( xoffset + 460 , mapHeadPos ) ;
2013-10-29 07:13:38 +01:00
labelTileset . setText ( lang . getString ( " Tileset " ) ) ;
2010-12-07 07:12:51 +01:00
2010-08-28 01:08:35 +02:00
//tileset listBox
2010-09-09 00:37:24 +02:00
listBoxTileset . registerGraphicComponent ( containerName , " listBoxTileset " ) ;
2010-08-28 01:08:35 +02:00
listBoxTileset . init ( xoffset + 460 , mapPos , 150 ) ;
2013-06-13 23:20:55 +02:00
2011-12-28 05:46:36 +01:00
setupTilesetList ( " " ) ;
2012-09-27 08:42:57 +02:00
Chrono seed ( true ) ;
2012-10-30 18:12:04 +01:00
srand ( ( unsigned int ) seed . getCurTicks ( ) ) ;
2012-09-27 08:42:57 +02:00
2011-01-02 01:39:13 +01:00
listBoxTileset . setSelectedItemIndex ( rand ( ) % listBoxTileset . getItemCount ( ) ) ;
2010-09-09 00:37:24 +02:00
2010-08-28 01:08:35 +02:00
//tech Tree listBox
2013-06-13 03:37:15 +02:00
int initialTechSelection = setupTechList ( " " , true ) ;
2011-12-28 05:46:36 +01:00
2010-09-09 00:37:24 +02:00
listBoxTechTree . registerGraphicComponent ( containerName , " listBoxTechTree " ) ;
2010-08-28 01:08:35 +02:00
listBoxTechTree . init ( xoffset + 650 , mapPos , 150 ) ;
2013-11-01 06:25:55 +01:00
if ( listBoxTechTree . getItemCount ( ) > 0 ) {
listBoxTechTree . setSelectedItemIndex ( initialTechSelection ) ;
}
2010-09-09 00:37:24 +02:00
labelTechTree . registerGraphicComponent ( containerName , " labelTechTree " ) ;
2010-08-28 01:08:35 +02:00
labelTechTree . init ( xoffset + 650 , mapHeadPos ) ;
2013-10-29 07:13:38 +01:00
labelTechTree . setText ( lang . getString ( " TechTree " ) ) ;
2010-09-04 13:49:54 +02:00
2010-12-20 22:59:46 +01:00
// fog - o - war
// @350 ? 300 ?
labelFogOfWar . registerGraphicComponent ( containerName , " labelFogOfWar " ) ;
labelFogOfWar . init ( xoffset + 100 , aHeadPos , 130 ) ;
2013-10-29 07:13:38 +01:00
labelFogOfWar . setText ( lang . getString ( " FogOfWar " ) ) ;
2010-12-20 22:59:46 +01:00
listBoxFogOfWar . registerGraphicComponent ( containerName , " listBoxFogOfWar " ) ;
listBoxFogOfWar . init ( xoffset + 100 , aPos , 130 ) ;
2013-10-29 07:13:38 +01:00
listBoxFogOfWar . pushBackItem ( lang . getString ( " Enabled " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . getString ( " Explored " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . getString ( " Disabled " ) ) ;
2010-12-20 22:59:46 +01:00
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ;
2010-09-09 00:37:24 +02:00
// Allow Observers
labelAllowObservers . registerGraphicComponent ( containerName , " labelAllowObservers " ) ;
2010-12-20 22:59:46 +01:00
labelAllowObservers . init ( xoffset + 310 , aHeadPos , 80 ) ;
2013-10-29 07:13:38 +01:00
labelAllowObservers . setText ( lang . getString ( " AllowObservers " ) ) ;
2010-09-09 00:37:24 +02:00
2012-10-22 17:52:08 +02:00
checkBoxAllowObservers . registerGraphicComponent ( containerName , " checkBoxAllowObservers " ) ;
checkBoxAllowObservers . init ( xoffset + 310 , aPos ) ;
checkBoxAllowObservers . setValue ( false ) ;
2010-12-07 07:12:51 +01:00
2013-06-20 21:18:29 +02:00
vector < string > rMultiplier ;
2012-09-17 01:42:56 +02:00
for ( int i = 0 ; i < 45 ; + + i ) {
rMultiplier . push_back ( floatToStr ( 0.5f + 0.1f * i , 1 ) ) ;
}
labelFallbackCpuMultiplier . registerGraphicComponent ( containerName , " labelFallbackCpuMultiplier " ) ;
labelFallbackCpuMultiplier . init ( xoffset + 460 , aHeadPos , 80 ) ;
2013-10-29 07:13:38 +01:00
labelFallbackCpuMultiplier . setText ( lang . getString ( " FallbackCpuMultiplier " ) ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . registerGraphicComponent ( containerName , " listBoxFallbackCpuMultiplier " ) ;
listBoxFallbackCpuMultiplier . init ( xoffset + 460 , aPos , 80 ) ;
listBoxFallbackCpuMultiplier . setItems ( rMultiplier ) ;
2013-11-01 20:48:04 +01:00
listBoxFallbackCpuMultiplier . setSelectedItem ( " 1.0 " ) ;
2012-09-17 01:42:56 +02:00
2011-09-21 08:51:28 +02:00
// Allow Switch Team Mode
labelEnableSwitchTeamMode . registerGraphicComponent ( containerName , " labelEnableSwitchTeamMode " ) ;
2011-11-04 01:36:07 +01:00
labelEnableSwitchTeamMode . init ( xoffset + 310 , aHeadPos + 45 , 80 ) ;
2013-10-29 07:13:38 +01:00
labelEnableSwitchTeamMode . setText ( lang . getString ( " EnableSwitchTeamMode " ) ) ;
2011-09-21 08:51:28 +02:00
2012-10-22 17:52:08 +02:00
checkBoxEnableSwitchTeamMode . registerGraphicComponent ( containerName , " checkBoxEnableSwitchTeamMode " ) ;
checkBoxEnableSwitchTeamMode . init ( xoffset + 310 , aPos + 45 ) ;
checkBoxEnableSwitchTeamMode . setValue ( false ) ;
2011-09-21 08:51:28 +02:00
labelAISwitchTeamAcceptPercent . registerGraphicComponent ( containerName , " labelAISwitchTeamAcceptPercent " ) ;
2011-11-04 01:36:07 +01:00
labelAISwitchTeamAcceptPercent . init ( xoffset + 460 , aHeadPos + 45 , 80 ) ;
2013-10-29 07:13:38 +01:00
labelAISwitchTeamAcceptPercent . setText ( lang . getString ( " AISwitchTeamAcceptPercent " ) ) ;
2011-09-21 08:51:28 +02:00
listBoxAISwitchTeamAcceptPercent . registerGraphicComponent ( containerName , " listBoxAISwitchTeamAcceptPercent " ) ;
2011-11-04 01:36:07 +01:00
listBoxAISwitchTeamAcceptPercent . init ( xoffset + 460 , aPos + 45 , 80 ) ;
2011-09-21 08:51:28 +02:00
for ( int i = 0 ; i < = 100 ; i = i + 10 ) {
listBoxAISwitchTeamAcceptPercent . pushBackItem ( intToStr ( i ) ) ;
}
listBoxAISwitchTeamAcceptPercent . setSelectedItem ( intToStr ( 30 ) ) ;
2013-06-13 03:37:15 +02:00
labelAllowNativeLanguageTechtree . registerGraphicComponent ( containerName , " labelAllowNativeLanguageTechtree " ) ;
labelAllowNativeLanguageTechtree . init ( xoffset + 650 , mapHeadPos - 50 ) ;
2013-10-29 07:13:38 +01:00
labelAllowNativeLanguageTechtree . setText ( lang . getString ( " AllowNativeLanguageTechtree " ) ) ;
2010-09-09 00:37:24 +02:00
2013-06-13 03:37:15 +02:00
checkBoxAllowNativeLanguageTechtree . registerGraphicComponent ( containerName , " checkBoxAllowNativeLanguageTechtree " ) ;
checkBoxAllowNativeLanguageTechtree . init ( xoffset + 650 , mapHeadPos - 70 ) ;
checkBoxAllowNativeLanguageTechtree . setValue ( false ) ;
2010-07-21 20:21:40 +02:00
2013-10-26 00:09:19 +02:00
// Network Scenario
int scenarioX = 810 ;
int scenarioY = 140 ;
labelScenario . registerGraphicComponent ( containerName , " labelScenario " ) ;
labelScenario . init ( scenarioX , scenarioY ) ;
2013-10-29 07:13:38 +01:00
labelScenario . setText ( lang . getString ( " Scenario " ) ) ;
2013-10-26 00:09:19 +02:00
listBoxScenario . registerGraphicComponent ( containerName , " listBoxScenario " ) ;
listBoxScenario . init ( scenarioX , scenarioY - 30 , 190 ) ;
checkBoxScenario . registerGraphicComponent ( containerName , " checkBoxScenario " ) ;
checkBoxScenario . init ( scenarioX + 90 , scenarioY ) ;
checkBoxScenario . setValue ( false ) ;
2013-10-25 21:35:10 +02:00
//scenario listbox
vector < string > resultsScenarios ;
findDirs ( dirList , resultsScenarios ) ;
// Filter out only scenarios with no network slots
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) resultsScenarios . size ( ) ; + + i ) {
2013-10-25 21:35:10 +02:00
string scenario = resultsScenarios [ i ] ;
string file = Scenario : : getScenarioPath ( dirList , scenario ) ;
try {
if ( file ! = " " ) {
bool isTutorial = Scenario : : isGameTutorial ( file ) ;
Scenario : : loadScenarioInfo ( file , & scenarioInfo , isTutorial ) ;
bool isNetworkScenario = false ;
2013-11-19 07:56:09 +01:00
for ( unsigned int j = 0 ; isNetworkScenario = = false & & j < ( unsigned int ) GameConstants : : maxPlayers ; + + j ) {
2013-10-25 21:35:10 +02:00
if ( scenarioInfo . factionControls [ j ] = = ctNetwork ) {
isNetworkScenario = true ;
}
}
if ( isNetworkScenario = = true ) {
scenarioFiles . push_back ( scenario ) ;
}
}
}
catch ( const std : : exception & ex ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error loading scenario [%s]: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , scenario . c_str ( ) , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
showGeneralError = true ;
generalErrorToShow = szBuf ;
//throw megaglest_runtime_error(szBuf);
}
}
resultsScenarios . clear ( ) ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) scenarioFiles . size ( ) ; + + i ) {
2013-10-25 21:35:10 +02:00
resultsScenarios . push_back ( formatString ( scenarioFiles [ i ] ) ) ;
}
listBoxScenario . setItems ( resultsScenarios ) ;
if ( resultsScenarios . empty ( ) = = true ) {
checkBoxScenario . setEnabled ( false ) ;
}
2010-08-28 01:08:35 +02:00
// Advanced Options
2010-09-09 00:37:24 +02:00
labelAdvanced . registerGraphicComponent ( containerName , " labelAdvanced " ) ;
2010-09-04 13:49:54 +02:00
labelAdvanced . init ( 810 , 80 , 80 ) ;
2013-10-29 07:13:38 +01:00
labelAdvanced . setText ( lang . getString ( " AdvancedGameOptions " ) ) ;
2010-09-09 00:37:24 +02:00
2012-10-22 17:52:08 +02:00
checkBoxAdvanced . registerGraphicComponent ( containerName , " checkBoxAdvanced " ) ;
checkBoxAdvanced . init ( 810 , 80 - labelOffset ) ;
checkBoxAdvanced . setValue ( false ) ;
2010-03-13 23:00:01 +01:00
2010-08-28 01:08:35 +02:00
// network things
// PublishServer
2010-10-11 02:53:25 +02:00
xoffset = 90 ;
2010-09-09 00:37:24 +02:00
labelPublishServer . registerGraphicComponent ( containerName , " labelPublishServer " ) ;
2010-10-11 02:53:25 +02:00
labelPublishServer . init ( 50 , networkHeadPos , 100 ) ;
2013-10-29 07:13:38 +01:00
labelPublishServer . setText ( lang . getString ( " PublishServer " ) ) ;
2010-09-09 00:37:24 +02:00
2012-10-22 17:52:08 +02:00
checkBoxPublishServer . registerGraphicComponent ( containerName , " checkBoxPublishServer " ) ;
checkBoxPublishServer . init ( 50 , networkPos ) ;
2012-11-09 22:50:01 +01:00
checkBoxPublishServer . setValue ( false ) ;
if ( ( this - > headlessServerMode = = true | |
( openNetworkSlots = = true & & parentMenuState ! = pLanGame ) ) & &
GlobalStaticFlags : : isFlagSet ( gsft_lan_mode ) = = false ) {
2012-10-22 17:52:08 +02:00
checkBoxPublishServer . setValue ( true ) ;
2011-03-11 13:14:24 +01:00
}
2010-06-04 02:33:34 +02:00
2011-10-21 00:30:09 +02:00
labelGameName . registerGraphicComponent ( containerName , " labelGameName " ) ;
2013-10-25 21:35:10 +02:00
labelGameName . init ( 50 + checkBoxPublishServer . getW ( ) + 2 , networkPos , 200 ) ;
2011-10-21 00:30:09 +02:00
labelGameName . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelGameName . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = false ) {
2011-10-21 01:27:39 +02:00
labelGameName . setText ( defaultPlayerName + " 's game " ) ;
}
else {
2011-10-21 01:44:01 +02:00
labelGameName . setText ( " headless ( " + defaultPlayerName + " ) " ) ;
2011-10-21 01:27:39 +02:00
}
2013-10-25 21:35:10 +02:00
labelGameName . setEditable ( true ) ;
2012-07-26 08:27:00 +02:00
labelGameName . setMaxEditWidth ( 20 ) ;
2013-10-25 21:35:10 +02:00
labelGameName . setMaxEditRenderWidth ( 200 ) ;
bool allowInProgressJoin = Config : : getInstance ( ) . getBool ( " EnableJoinInProgressGame " , " false " ) ;
labelAllowInGameJoinPlayer . registerGraphicComponent ( containerName , " labelAllowInGameJoinPlayer " ) ;
labelAllowInGameJoinPlayer . init ( xoffset + 410 , 670 , 80 ) ;
2013-10-29 07:13:38 +01:00
labelAllowInGameJoinPlayer . setText ( lang . getString ( " AllowInGameJoinPlayer " ) ) ;
2013-10-25 21:35:10 +02:00
labelAllowInGameJoinPlayer . setVisible ( allowInProgressJoin ) ;
checkBoxAllowInGameJoinPlayer . registerGraphicComponent ( containerName , " checkBoxAllowInGameJoinPlayer " ) ;
checkBoxAllowInGameJoinPlayer . init ( xoffset + 600 , 670 ) ;
checkBoxAllowInGameJoinPlayer . setValue ( false ) ;
checkBoxAllowInGameJoinPlayer . setVisible ( allowInProgressJoin ) ;
2014-01-27 23:15:05 +01:00
labelAllowTeamUnitSharing . registerGraphicComponent ( containerName , " labelAllowTeamUnitSharing " ) ;
labelAllowTeamUnitSharing . init ( xoffset + 410 , 670 , 80 ) ;
labelAllowTeamUnitSharing . setText ( lang . getString ( " AllowTeamUnitSharing " ) ) ;
labelAllowTeamUnitSharing . setVisible ( true ) ;
checkBoxAllowTeamUnitSharing . registerGraphicComponent ( containerName , " checkBoxAllowTeamUnitSharing " ) ;
checkBoxAllowTeamUnitSharing . init ( xoffset + 600 , 670 ) ;
checkBoxAllowTeamUnitSharing . setValue ( false ) ;
checkBoxAllowTeamUnitSharing . setVisible ( true ) ;
labelAllowTeamResourceSharing . registerGraphicComponent ( containerName , " labelAllowTeamResourceSharing " ) ;
labelAllowTeamResourceSharing . init ( xoffset + 410 , 640 , 80 ) ;
labelAllowTeamResourceSharing . setText ( lang . getString ( " AllowTeamResourceSharing " ) ) ;
labelAllowTeamResourceSharing . setVisible ( true ) ;
checkBoxAllowTeamResourceSharing . registerGraphicComponent ( containerName , " checkBoxAllowTeamResourceSharing " ) ;
checkBoxAllowTeamResourceSharing . init ( xoffset + 600 , 640 ) ;
checkBoxAllowTeamResourceSharing . setValue ( false ) ;
checkBoxAllowTeamResourceSharing . setVisible ( true ) ;
2010-10-26 23:52:00 +02:00
// Network Pause for lagged clients
2010-09-09 00:37:24 +02:00
labelNetworkPauseGameForLaggedClients . registerGraphicComponent ( containerName , " labelNetworkPauseGameForLaggedClients " ) ;
2013-05-04 08:09:00 +02:00
labelNetworkPauseGameForLaggedClients . init ( labelAllowInGameJoinPlayer . getX ( ) , networkHeadPos , 80 ) ;
2013-10-29 07:13:38 +01:00
labelNetworkPauseGameForLaggedClients . setText ( lang . getString ( " NetworkPauseGameForLaggedClients " ) ) ;
2010-09-09 00:37:24 +02:00
2012-10-22 17:52:08 +02:00
checkBoxNetworkPauseGameForLaggedClients . registerGraphicComponent ( containerName , " checkBoxNetworkPauseGameForLaggedClients " ) ;
2013-05-04 08:09:00 +02:00
checkBoxNetworkPauseGameForLaggedClients . init ( checkBoxAllowInGameJoinPlayer . getX ( ) , networkHeadPos ) ;
2012-10-22 17:52:08 +02:00
checkBoxNetworkPauseGameForLaggedClients . setValue ( true ) ;
2010-07-16 18:53:19 +02:00
2010-03-13 23:00:01 +01:00
//list boxes
2013-10-27 17:13:27 +01:00
xoffset = 30 ;
2010-08-28 01:08:35 +02:00
int rowHeight = 27 ;
2010-03-13 23:00:01 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-03-11 12:11:46 +01:00
2010-09-09 00:37:24 +02:00
labelPlayers [ i ] . registerGraphicComponent ( containerName , " labelPlayers " + intToStr ( i ) ) ;
2013-10-24 02:02:08 +02:00
labelPlayers [ i ] . init ( xoffset , setupPos - 30 - i * rowHeight + 2 ) ;
labelPlayers [ i ] . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelPlayers [ i ] . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-09-09 00:37:24 +02:00
2013-10-24 02:02:08 +02:00
labelPlayerStatus [ i ] . registerGraphicComponent ( containerName , " labelPlayerStatus " + intToStr ( i ) ) ;
2013-11-08 03:50:59 +01:00
labelPlayerStatus [ i ] . init ( xoffset + 15 , setupPos - 30 - i * rowHeight + 2 , 60 ) ;
2010-09-09 00:37:24 +02:00
labelPlayerNames [ i ] . registerGraphicComponent ( containerName , " labelPlayerNames " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
labelPlayerNames [ i ] . init ( xoffset + 30 , setupPos - 30 - i * rowHeight ) ;
2010-12-07 07:12:51 +01:00
2010-09-09 00:37:24 +02:00
listBoxControls [ i ] . registerGraphicComponent ( containerName , " listBoxControls " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxControls [ i ] . init ( xoffset + 170 , setupPos - 30 - i * rowHeight ) ;
2010-12-07 07:12:51 +01:00
2011-04-13 06:04:08 +02:00
buttonBlockPlayers [ i ] . registerGraphicComponent ( containerName , " buttonBlockPlayers " + intToStr ( i ) ) ;
2012-10-06 00:43:00 +02:00
//buttonBlockPlayers[i].init(xoffset+355, setupPos-30-i*rowHeight, 70);
2013-10-27 17:13:27 +01:00
buttonBlockPlayers [ i ] . init ( xoffset + 210 , setupPos - 30 - i * rowHeight , 70 ) ;
2013-10-29 07:13:38 +01:00
buttonBlockPlayers [ i ] . setText ( lang . getString ( " BlockPlayer " ) ) ;
2011-12-05 06:26:48 +01:00
buttonBlockPlayers [ i ] . setFont ( CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ) ;
buttonBlockPlayers [ i ] . setFont3D ( CoreData : : getInstance ( ) . getDisplayFontSmall3D ( ) ) ;
2011-04-13 06:04:08 +02:00
2010-11-09 00:15:50 +01:00
listBoxRMultiplier [ i ] . registerGraphicComponent ( containerName , " listBoxRMultiplier " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxRMultiplier [ i ] . init ( xoffset + 310 , setupPos - 30 - i * rowHeight , 70 ) ;
2010-12-07 07:12:51 +01:00
2010-09-09 00:37:24 +02:00
listBoxFactions [ i ] . registerGraphicComponent ( containerName , " listBoxFactions " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxFactions [ i ] . init ( xoffset + 390 , setupPos - 30 - i * rowHeight , 250 ) ;
2013-10-24 02:02:08 +02:00
listBoxFactions [ i ] . setLeftControlled ( true ) ;
2010-09-09 00:37:24 +02:00
listBoxTeams [ i ] . registerGraphicComponent ( containerName , " listBoxTeams " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxTeams [ i ] . init ( xoffset + 650 , setupPos - 30 - i * rowHeight , 60 ) ;
2014-12-06 00:54:00 +01:00
listBoxTeams [ i ] . setLighted ( true ) ;
2010-09-09 00:37:24 +02:00
labelNetStatus [ i ] . registerGraphicComponent ( containerName , " labelNetStatus " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
labelNetStatus [ i ] . init ( xoffset + 715 , setupPos - 30 - i * rowHeight , 60 ) ;
2011-11-15 23:28:51 +01:00
labelNetStatus [ i ] . setFont ( CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ) ;
labelNetStatus [ i ] . setFont3D ( CoreData : : getInstance ( ) . getDisplayFontSmall3D ( ) ) ;
2010-03-13 23:00:01 +01:00
}
2013-10-24 02:02:08 +02:00
buttonClearBlockedPlayers . registerGraphicComponent ( containerName , " buttonClearBlockedPlayers " ) ;
2013-10-27 17:13:27 +01:00
buttonClearBlockedPlayers . init ( xoffset + 170 , setupPos - 30 - 8 * rowHeight , 140 ) ;
2013-10-24 02:02:08 +02:00
2010-11-09 00:15:50 +01:00
labelControl . registerGraphicComponent ( containerName , " labelControl " ) ;
2013-10-27 17:13:27 +01:00
labelControl . init ( xoffset + 170 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2013-10-29 07:13:38 +01:00
labelControl . setText ( lang . getString ( " Control " ) ) ;
2010-12-07 07:12:51 +01:00
2010-11-09 00:15:50 +01:00
labelRMultiplier . registerGraphicComponent ( containerName , " labelRMultiplier " ) ;
2013-10-27 17:13:27 +01:00
labelRMultiplier . init ( xoffset + 310 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2010-12-07 07:12:51 +01:00
2010-09-09 00:37:24 +02:00
labelFaction . registerGraphicComponent ( containerName , " labelFaction " ) ;
2013-10-27 17:13:27 +01:00
labelFaction . init ( xoffset + 390 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2013-10-29 07:13:38 +01:00
labelFaction . setText ( lang . getString ( " Faction " ) ) ;
2010-09-09 00:37:24 +02:00
labelTeam . registerGraphicComponent ( containerName , " labelTeam " ) ;
2013-10-27 17:13:27 +01:00
labelTeam . init ( xoffset + 650 , setupPos , 50 , GraphicListBox : : defH , true ) ;
2013-10-29 07:13:38 +01:00
labelTeam . setText ( lang . getString ( " Team " ) ) ;
2010-12-07 07:12:51 +01:00
2010-06-04 02:33:34 +02:00
labelControl . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelControl . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-11-09 00:15:50 +01:00
labelRMultiplier . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelRMultiplier . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-06-04 02:33:34 +02:00
labelFaction . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelFaction . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-06-04 02:33:34 +02:00
labelTeam . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelTeam . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-12-07 07:12:51 +01:00
2013-10-25 07:45:54 +02:00
//xoffset=100;
2013-10-24 02:02:08 +02:00
2010-03-13 23:00:01 +01:00
//texts
2013-10-29 07:13:38 +01:00
buttonClearBlockedPlayers . setText ( lang . getString ( " BlockPlayerClear " ) ) ;
buttonReturn . setText ( lang . getString ( " Return " ) ) ;
buttonPlayNow . setText ( lang . getString ( " PlayNow " ) ) ;
buttonRestoreLastSettings . setText ( lang . getString ( " ReloadLastGameSettings " ) ) ;
2010-03-13 23:00:01 +01:00
2013-06-20 21:18:29 +02:00
vector < string > controlItems ;
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " Closed " ) ) ;
controlItems . push_back ( lang . getString ( " CpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " Cpu " ) ) ;
controlItems . push_back ( lang . getString ( " CpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " CpuMega " ) ) ;
controlItems . push_back ( lang . getString ( " Network " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkUnassigned " ) ) ;
controlItems . push_back ( lang . getString ( " Human " ) ) ;
2010-12-07 07:12:51 +01:00
2010-09-14 21:10:37 +02:00
if ( config . getBool ( " EnableNetworkCpu " , " false " ) = = true ) {
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " NetworkCpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpu " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuMega " ) ) ;
2010-09-14 21:10:37 +02:00
}
2013-06-20 21:18:29 +02:00
vector < string > teamItems ;
2010-09-04 02:32:56 +02:00
for ( int i = 1 ; i < = GameConstants : : maxPlayers ; + + i ) {
teamItems . push_back ( intToStr ( i ) ) ;
}
for ( int i = GameConstants : : maxPlayers + 1 ; i < = GameConstants : : maxPlayers + GameConstants : : specialFactions ; + + i ) {
teamItems . push_back ( intToStr ( i ) ) ;
}
2010-03-13 23:00:01 +01:00
2011-12-28 05:46:36 +01:00
reloadFactions ( false , " " ) ;
2010-03-13 23:00:01 +01:00
2011-12-28 05:46:36 +01:00
if ( factionFiles . empty ( ) = = true ) {
2011-01-02 01:39:13 +01:00
showGeneralError = true ;
generalErrorToShow = " [#1] There are no factions for the tech tree [ " + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " ] " ;
2010-03-18 22:26:40 +01:00
}
2010-03-13 23:00:01 +01:00
2011-12-26 07:29:14 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setText ( " " ) ;
labelPlayerStatus [ i ] . setTexture ( CoreData : : getInstance ( ) . getStatusReadyTexture ( ) ) ;
labelPlayerStatus [ i ] . setH ( 16 ) ;
labelPlayerStatus [ i ] . setW ( 12 ) ;
2011-03-11 12:11:46 +01:00
2013-10-29 07:13:38 +01:00
//labelPlayers[i].setText(lang.getString("Player")+" "+intToStr(i));
2013-10-27 17:13:27 +01:00
labelPlayers [ i ] . setText ( intToStr ( i + 1 ) ) ;
2010-08-21 09:41:26 +02:00
labelPlayerNames [ i ] . setText ( " * " ) ;
2012-07-26 08:27:00 +02:00
labelPlayerNames [ i ] . setMaxEditWidth ( 16 ) ;
2012-07-26 17:26:59 +02:00
labelPlayerNames [ i ] . setMaxEditRenderWidth ( 135 ) ;
2010-08-21 09:41:26 +02:00
2010-03-13 23:00:01 +01:00
listBoxTeams [ i ] . setItems ( teamItems ) ;
listBoxTeams [ i ] . setSelectedItemIndex ( i ) ;
2010-10-22 19:20:55 +02:00
lastSelectedTeamIndex [ i ] = listBoxTeams [ i ] . getSelectedItemIndex ( ) ;
2010-03-13 23:00:01 +01:00
listBoxControls [ i ] . setItems ( controlItems ) ;
2010-11-09 00:15:50 +01:00
listBoxRMultiplier [ i ] . setItems ( rMultiplier ) ;
2013-11-01 20:48:04 +01:00
listBoxRMultiplier [ i ] . setSelectedItem ( " 1.0 " ) ;
2010-03-13 23:00:01 +01:00
labelNetStatus [ i ] . setText ( " " ) ;
}
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( getCurrentMapFile ( ) ) , & mapInfo , true ) ;
2010-03-13 23:00:01 +01:00
labelMapInfo . setText ( mapInfo . desc ) ;
2012-01-06 07:55:27 +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 01:39:07 +02:00
2010-03-13 23:00:01 +01:00
//init controllers
2010-06-11 06:55:49 +02:00
if ( serverInitError = = false ) {
2011-09-24 23:07:15 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2013-06-01 04:31:12 +02:00
if ( serverInterface = = NULL ) {
throw megaglest_runtime_error ( " serverInterface == NULL " ) ;
}
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = true ) {
2011-09-24 23:07:15 +02:00
listBoxControls [ 0 ] . setSelectedItemIndex ( ctNetwork ) ;
2012-10-06 00:43:00 +02:00
updateResourceMultiplier ( 0 ) ;
2011-09-24 23:07:15 +02:00
}
else {
2013-10-25 21:35:10 +02:00
setSlotHuman ( 0 ) ;
2012-10-06 00:43:00 +02:00
updateResourceMultiplier ( 0 ) ;
2011-09-24 23:07:15 +02:00
}
2010-08-21 09:41:26 +02:00
labelPlayerNames [ 0 ] . setText ( " " ) ;
labelPlayerNames [ 0 ] . setText ( getHumanPlayerName ( ) ) ;
2012-10-06 00:43:00 +02:00
if ( openNetworkSlots = = true ) {
for ( int i = 1 ; i < mapInfo . players ; + + i ) {
2010-06-11 06:55:49 +02:00
listBoxControls [ i ] . setSelectedItemIndex ( ctNetwork ) ;
}
2010-03-13 23:00:01 +01:00
}
2010-06-11 06:55:49 +02:00
else {
listBoxControls [ 1 ] . setSelectedItemIndex ( ctCpu ) ;
}
updateControlers ( ) ;
updateNetworkSlots ( ) ;
2010-06-01 01:39:07 +02:00
2012-01-06 07:55:27 +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-31 08:11:31 +02:00
2010-06-11 06:55:49 +02:00
// Ensure we have set the gamesettings at least once
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
2011-09-24 23:07:15 +02:00
2010-06-11 06:55:49 +02:00
serverInterface - > setGameSettings ( & gameSettings , false ) ;
}
2012-01-06 07:55:27 +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 01:39:07 +02:00
2010-11-11 02:24:48 +01:00
updateAllResourceMultiplier ( ) ;
2010-09-04 01:15:42 +02:00
// write hint to console:
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2010-12-07 07:12:51 +01:00
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " ToSwitchOffMusicPress " ) + " - \" " + configKeys . getString ( " ToggleMusic " ) + " \" " ) ;
2010-09-04 01:15:42 +02:00
2010-06-09 00:50:37 +02:00
chatManager . init ( & console , - 1 , true ) ;
2010-05-13 08:43:56 +02:00
2010-09-09 00:37:24 +02:00
GraphicComponent : : applyAllCustomProperties ( containerName ) ;
2013-01-23 15:51:28 +01:00
static string mutexOwnerId = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
2013-11-07 19:39:08 +01:00
publishToMasterserverThread = new SimpleTaskThread ( this , 0 , 300 , false , ( void * ) tnt_MASTERSERVER ) ;
2013-01-23 15:51:28 +01:00
publishToMasterserverThread - > setUniqueID ( mutexOwnerId ) ;
2013-11-07 19:39:08 +01:00
static string mutexOwnerId2 = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
publishToClientsThread = new SimpleTaskThread ( this , 0 , 200 , false , ( void * ) tnt_CLIENTS , false ) ;
publishToClientsThread - > setUniqueID ( mutexOwnerId2 ) ;
2010-05-13 08:43:56 +02:00
publishToMasterserverThread - > start ( ) ;
2013-11-07 19:39:08 +01:00
publishToClientsThread - > start ( ) ;
2010-06-01 01:39:07 +02:00
2014-02-08 01:37:55 +01:00
if ( openNetworkSlots = = true ) {
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
if ( fileExists ( data_path + DEFAULT_NETWORKGAME_FILENAME ) = = true )
loadGameSettings ( data_path + DEFAULT_NETWORKGAME_FILENAME ) ;
2012-09-20 23:57:00 +02:00
}
else {
2014-02-08 01:37:55 +01:00
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
if ( fileExists ( data_path + DEFAULT_GAME_FILENAME ) = = true )
loadGameSettings ( data_path + DEFAULT_GAME_FILENAME ) ;
2012-09-20 23:57:00 +02:00
}
2012-01-06 07:55:27 +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-12-26 07:29:14 +01:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-26 07:29:14 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-26 07:29:14 +01:00
}
2010-05-13 08:43:56 +02:00
}
2011-10-25 20:39:11 +02:00
void MenuStateCustomGame : : reloadUI ( ) {
Lang & lang = Lang : : getInstance ( ) ;
Config & config = Config : : getInstance ( ) ;
2011-11-04 00:38:43 +01:00
console . resetFonts ( ) ;
2014-12-09 02:36:30 +01:00
mainMessageBox . init ( lang . getString ( " Ok " ) , 500 , 300 ) ;
2011-10-25 20:39:11 +02:00
2012-05-12 04:21:21 +02:00
if ( EndsWith ( glestVersionString , " -dev " ) = = false ) {
labelLocalGameVersion . setText ( glestVersionString ) ;
}
else {
2013-11-29 22:13:30 +01:00
labelLocalGameVersion . setText ( glestVersionString + " [ " + getCompileDateTime ( ) + " , " + getGITRevisionString ( ) + " ] " ) ;
2012-05-12 04:21:21 +02:00
}
2013-06-20 21:18:29 +02:00
//vector<string> teamItems, controlItems, results , rMultiplier;
2011-10-25 20:39:11 +02:00
string ipText = " none " ;
std : : vector < std : : string > ipList = Socket : : getLocalIPAddressList ( ) ;
if ( ipList . empty ( ) = = false ) {
ipText = " " ;
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) ipList . size ( ) ; idx + + ) {
2011-10-25 20:39:11 +02:00
string ip = ipList [ idx ] ;
if ( ipText ! = " " ) {
ipText + = " , " ;
}
ipText + = ip ;
}
}
2012-10-06 14:56:53 +02:00
string serverPort = config . getString ( " PortServer " , intToStr ( GameConstants : : serverPort ) . c_str ( ) ) ;
2012-10-06 15:45:42 +02:00
string externalPort = config . getString ( " PortExternal " , serverPort . c_str ( ) ) ;
2013-10-29 07:13:38 +01:00
labelLocalIP . setText ( lang . getString ( " LanIP " ) + ipText + " ( " + serverPort + " / " + externalPort + " ) " ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelMap . setText ( lang . getString ( " Map " ) + " : " ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelMapFilter . setText ( lang . getString ( " MapFilter " ) + " : " ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelTileset . setText ( lang . getString ( " Tileset " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelTechTree . setText ( lang . getString ( " TechTree " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelAllowNativeLanguageTechtree . setText ( lang . getString ( " AllowNativeLanguageTechtree " ) ) ;
2013-06-13 03:37:15 +02:00
2013-10-29 07:13:38 +01:00
labelFogOfWar . setText ( lang . getString ( " FogOfWar " ) ) ;
2011-10-25 20:39:11 +02:00
std : : vector < std : : string > listBoxData ;
2013-10-29 07:13:38 +01:00
listBoxData . push_back ( lang . getString ( " Enabled " ) ) ;
listBoxData . push_back ( lang . getString ( " Explored " ) ) ;
listBoxData . push_back ( lang . getString ( " Disabled " ) ) ;
2011-10-25 20:39:11 +02:00
listBoxFogOfWar . setItems ( listBoxData ) ;
// Allow Observers
2013-10-29 07:13:38 +01:00
labelAllowObservers . setText ( lang . getString ( " AllowObservers " ) ) ;
2011-10-25 20:39:11 +02:00
// Allow Switch Team Mode
2013-10-29 07:13:38 +01:00
labelEnableSwitchTeamMode . setText ( lang . getString ( " EnableSwitchTeamMode " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelAllowInGameJoinPlayer . setText ( lang . getString ( " AllowInGameJoinPlayer " ) ) ;
2013-02-15 19:25:10 +01:00
2014-01-27 23:15:05 +01:00
labelAllowTeamUnitSharing . setText ( lang . getString ( " AllowTeamUnitSharing " ) ) ;
labelAllowTeamResourceSharing . setText ( lang . getString ( " AllowTeamResourceSharing " ) ) ;
2013-10-29 07:13:38 +01:00
labelAISwitchTeamAcceptPercent . setText ( lang . getString ( " AISwitchTeamAcceptPercent " ) ) ;
2011-10-25 20:39:11 +02:00
listBoxData . clear ( ) ;
// Advanced Options
2013-10-29 07:13:38 +01:00
labelAdvanced . setText ( lang . getString ( " AdvancedGameOptions " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelPublishServer . setText ( lang . getString ( " PublishServer " ) ) ;
2011-10-25 20:39:11 +02:00
labelGameName . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelGameName . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = false ) {
2011-10-25 20:39:11 +02:00
labelGameName . setText ( defaultPlayerName + " 's game " ) ;
}
else {
labelGameName . setText ( " headless ( " + defaultPlayerName + " ) " ) ;
}
2013-10-29 07:13:38 +01:00
labelNetworkPauseGameForLaggedClients . setText ( lang . getString ( " NetworkPauseGameForLaggedClients " ) ) ;
2011-10-25 20:39:11 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2013-10-29 07:13:38 +01:00
buttonBlockPlayers [ i ] . setText ( lang . getString ( " BlockPlayer " ) ) ;
2011-10-25 20:39:11 +02:00
}
2013-10-29 07:13:38 +01:00
labelControl . setText ( lang . getString ( " Control " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelFaction . setText ( lang . getString ( " Faction " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelTeam . setText ( lang . getString ( " Team " ) ) ;
2011-10-25 20:39:11 +02:00
labelControl . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelControl . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
labelRMultiplier . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelRMultiplier . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
labelFaction . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelFaction . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
labelTeam . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelTeam . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
//texts
2013-10-29 07:13:38 +01:00
buttonClearBlockedPlayers . setText ( lang . getString ( " BlockPlayerClear " ) ) ;
buttonReturn . setText ( lang . getString ( " Return " ) ) ;
buttonPlayNow . setText ( lang . getString ( " PlayNow " ) ) ;
buttonRestoreLastSettings . setText ( lang . getString ( " ReloadLastGameSettings " ) ) ;
2011-10-25 20:39:11 +02:00
2013-06-20 21:18:29 +02:00
vector < string > controlItems ;
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " Closed " ) ) ;
controlItems . push_back ( lang . getString ( " CpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " Cpu " ) ) ;
controlItems . push_back ( lang . getString ( " CpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " CpuMega " ) ) ;
controlItems . push_back ( lang . getString ( " Network " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkUnassigned " ) ) ;
controlItems . push_back ( lang . getString ( " Human " ) ) ;
2011-10-25 20:39:11 +02:00
if ( config . getBool ( " EnableNetworkCpu " , " false " ) = = true ) {
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " NetworkCpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpu " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuMega " ) ) ;
2011-10-25 20:39:11 +02:00
}
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2013-10-27 17:13:27 +01:00
labelPlayers [ i ] . setText ( intToStr ( i + 1 ) ) ;
2011-10-25 20:39:11 +02:00
listBoxControls [ i ] . setItems ( controlItems ) ;
}
2013-10-29 07:13:38 +01:00
labelFallbackCpuMultiplier . setText ( lang . getString ( " FallbackCpuMultiplier " ) ) ;
2011-10-25 20:39:11 +02:00
2012-01-06 07:55:27 +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-25 20:39:11 +02:00
vector < string > playerStatuses ;
2013-10-29 07:13:38 +01:00
playerStatuses . push_back ( lang . getString ( " PlayerStatusSetup " ) ) ;
playerStatuses . push_back ( lang . getString ( " PlayerStatusBeRightBack " ) ) ;
playerStatuses . push_back ( lang . getString ( " PlayerStatusReady " ) ) ;
2011-10-25 20:39:11 +02:00
listBoxPlayerStatus . setItems ( playerStatuses ) ;
2013-10-29 07:13:38 +01:00
labelScenario . setText ( lang . getString ( " Scenario " ) ) ;
2011-12-26 07:29:14 +01:00
2013-10-29 22:13:44 +01:00
reloadFactions ( true , ( checkBoxScenario . getValue ( ) = = true ? scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] : " " ) ) ;
2011-10-25 20:39:11 +02:00
// write hint to console:
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " ToSwitchOffMusicPress " ) + " - \" " + configKeys . getString ( " ToggleMusic " ) + " \" " ) ;
2011-10-25 20:39:11 +02:00
chatManager . init ( & console , - 1 , true ) ;
GraphicComponent : : reloadFontsForRegisterGraphicComponents ( containerName ) ;
}
2013-11-07 19:39:08 +01:00
void MenuStateCustomGame : : cleanupThread ( SimpleTaskThread * * thread ) {
//printf("LINE: %d *thread = %p\n",__LINE__,*thread);
if ( thread ! = NULL & & * thread ! = NULL ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1 cleanupThread callingThread [%p] \n " , * thread ) ;
2012-01-06 07:55:27 +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-01-02 10:33:37 +01:00
2013-11-07 19:39:08 +01:00
SimpleTaskThread * threadPtr = * thread ;
int value = threadPtr - > getUserdataAsInt ( ) ;
THREAD_NOTIFIER_TYPE threadType = ( THREAD_NOTIFIER_TYPE ) value ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1. cleanupThread callingThread [%p] value = %d \n " , * thread , value ) ;
2011-01-02 10:33:37 +01:00
needToBroadcastServerSettings = false ;
needToRepublishToMasterserver = false ;
lastNetworkPing = time ( NULL ) ;
2013-11-07 19:39:08 +01:00
threadPtr - > setThreadOwnerValid ( false ) ;
2011-01-02 10:33:37 +01:00
2012-01-06 07:55:27 +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-03-28 23:04:47 +02:00
2013-11-07 19:39:08 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1.. cleanupThread callingThread [%p] value = %d \n " , * thread , value ) ;
2011-03-28 23:04:47 +02:00
if ( forceWaitForShutdown = = true ) {
time_t elapsed = time ( NULL ) ;
2013-11-07 19:39:08 +01:00
threadPtr - > signalQuit ( ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1a cleanupThread callingThread [%p] \n " , * thread ) ;
for ( ; ( threadPtr - > canShutdown ( false ) = = false | |
threadPtr - > getRunningStatus ( ) = = true ) & &
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , elapsed ) < = 15 ; ) {
2011-03-28 23:04:47 +02:00
//sleep(150);
}
2013-11-07 19:39:08 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1b cleanupThread callingThread [%p] \n " , * thread ) ;
if ( threadPtr - > canShutdown ( true ) = = true & &
threadPtr - > getRunningStatus ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1c cleanupThread callingThread [%p] \n " , * thread ) ;
delete threadPtr ;
//printf("LINE: %d *thread = %p\n",__LINE__,*thread);
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-03-28 23:04:47 +02:00
}
2012-03-05 23:53:03 +01:00
else {
2013-11-07 19:39:08 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1d cleanupThread callingThread [%p] \n " , * thread ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-11-07 19:39:08 +01:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] Error cannot shutdown thread \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-03-05 23:53:03 +01:00
//SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " %s " , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2013-11-07 19:39:08 +01:00
if ( threadType = = tnt_MASTERSERVER ) {
threadPtr - > setOverrideShutdownTask ( shutdownTaskStatic ) ;
}
threadPtr - > setDeleteSelfOnExecutionDone ( true ) ;
threadPtr - > setDeleteAfterExecute ( true ) ;
//printf("LINE: %d *thread = %p\n",__LINE__,*thread);
2012-03-05 23:53:03 +01:00
}
2013-11-07 19:39:08 +01:00
threadPtr = NULL ;
2013-12-14 08:04:12 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\n#1e cleanupThread callingThread [%p]\n",*thread);
2011-03-28 23:04:47 +02:00
}
2011-09-28 17:32:57 +02:00
else {
2013-11-07 19:39:08 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1f cleanupThread callingThread [%p] \n " , * thread ) ;
threadPtr - > signalQuit ( ) ;
2011-10-01 01:55:07 +02:00
sleep ( 0 ) ;
2013-11-07 19:39:08 +01:00
if ( threadPtr - > canShutdown ( true ) = = true & &
threadPtr - > getRunningStatus ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1g cleanupThread callingThread [%p] \n " , * thread ) ;
delete threadPtr ;
//printf("LINE: %d *thread = %p\n",__LINE__,*thread);
2011-09-28 17:34:03 +02:00
}
2012-03-05 23:53:03 +01:00
else {
2013-11-07 19:39:08 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #1h cleanupThread callingThread [%p] \n " , * thread ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-11-07 19:39:08 +01:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] Error cannot shutdown thread \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-03-05 23:53:03 +01:00
//SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " %s " , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2013-11-07 19:39:08 +01:00
if ( threadType = = tnt_MASTERSERVER ) {
threadPtr - > setOverrideShutdownTask ( shutdownTaskStatic ) ;
}
threadPtr - > setDeleteSelfOnExecutionDone ( true ) ;
threadPtr - > setDeleteAfterExecute ( true ) ;
//printf("LINE: %d *thread = %p\n",__LINE__,*thread);
2012-03-05 23:53:03 +01:00
}
2011-01-02 07:46:48 +01:00
}
2011-01-02 10:33:37 +01:00
2013-11-07 19:39:08 +01:00
* thread = NULL ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n #2 cleanupThread callingThread [%p] \n " , * thread ) ;
2011-01-02 07:46:48 +01:00
}
2013-11-07 19:39:08 +01:00
//printf("LINE: %d *thread = %p\n",__LINE__,*thread);
}
void MenuStateCustomGame : : cleanup ( ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( publishToMasterserverThread ) {
//printf("LINE: %d\n",__LINE__);
cleanupThread ( & publishToMasterserverThread ) ;
}
if ( publishToClientsThread ) {
//printf("LINE: %d\n",__LINE__);
cleanupThread ( & publishToClientsThread ) ;
}
//printf("LINE: %d\n",__LINE__);
2010-06-01 01:39:07 +02:00
2012-01-06 07:55:27 +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-31 08:38:27 +02:00
2010-11-01 17:44:05 +01:00
cleanupMapPreviewTexture ( ) ;
2010-08-31 08:38:27 +02:00
2012-05-26 01:00:36 +02:00
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
}
2011-03-28 23:04:47 +02:00
if ( forceWaitForShutdown = = true ) {
NetworkManager : : getInstance ( ) . end ( ) ;
}
2012-01-06 07:55:27 +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 23:00:01 +01:00
}
2011-01-02 10:33:37 +01:00
MenuStateCustomGame : : ~ MenuStateCustomGame ( ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-02 10:33:37 +01:00
cleanup ( ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-02 10:33:37 +01:00
}
2011-01-02 07:46:48 +01:00
void MenuStateCustomGame : : returnToParentMenu ( ) {
2012-01-06 07:55:27 +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-11 06:55:49 +02:00
2010-05-16 18:40:21 +02:00
needToBroadcastServerSettings = false ;
needToRepublishToMasterserver = false ;
2011-01-02 10:33:37 +01:00
lastNetworkPing = time ( NULL ) ;
2011-10-30 23:23:57 +01:00
ParentMenuState parentMenuState = this - > parentMenuState ;
2010-12-07 07:12:51 +01:00
2012-01-06 07:55:27 +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-11 06:55:49 +02:00
2011-03-28 23:04:47 +02:00
forceWaitForShutdown = false ;
2011-10-30 23:23:57 +01:00
if ( parentMenuState = = pMasterServer ) {
2012-01-06 07:55:27 +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-01-02 10:33:37 +01:00
cleanup ( ) ;
2010-05-16 18:40:21 +02:00
mainMenu - > setState ( new MenuStateMasterserver ( program , mainMenu ) ) ;
}
2011-10-30 23:23:57 +01:00
else if ( parentMenuState = = pLanGame ) {
2012-01-06 07:55:27 +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-30 23:23:57 +01:00
cleanup ( ) ;
mainMenu - > setState ( new MenuStateJoinGame ( program , mainMenu ) ) ;
}
2010-06-05 02:58:32 +02:00
else {
2012-01-06 07:55:27 +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-01-02 10:33:37 +01:00
cleanup ( ) ;
2010-05-16 18:40:21 +02:00
mainMenu - > setState ( new MenuStateNewGame ( program , mainMenu ) ) ;
}
2010-06-11 06:55:49 +02:00
2012-01-06 07:55:27 +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-16 18:40:21 +02:00
}
2011-09-26 06:26:44 +02:00
void MenuStateCustomGame : : mouseClick ( int x , int y , MouseButton mouseButton ) {
if ( isMasterserverMode ( ) = = true ) {
return ;
}
2010-03-13 23:00:01 +01:00
2011-01-02 01:39:13 +01:00
try {
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
int oldListBoxMapfilterIndex = listBoxMapFilter . getSelectedItemIndex ( ) ;
if ( mainMessageBox . getEnabled ( ) ) {
2012-02-19 18:37:53 +01:00
int button = 0 ;
2013-05-26 04:44:36 +02:00
if ( mainMessageBox . mouseClick ( x , y , button ) ) {
2011-01-02 01:39:13 +01:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2013-05-26 04:44:36 +02:00
if ( button = = 0 ) {
2011-01-02 01:39:13 +01:00
mainMessageBox . setEnabled ( false ) ;
}
}
}
2011-10-23 12:49:36 +02:00
else {
2012-10-15 09:44:44 +02:00
string advanceToItemStartingWith = " " ;
2013-11-19 22:57:28 +01:00
if ( : : Shared : : Platform : : Window : : isKeyStateModPressed ( KMOD_SHIFT ) = = true ) {
const wchar_t lastKey = : : Shared : : Platform : : Window : : extractLastKeyPressed ( ) ;
2013-11-02 12:04:52 +01:00
// xxx:
2013-10-24 02:02:08 +02:00
// string hehe=lastKey;
// printf("lastKey = %d [%c] '%s'\n",lastKey,lastKey,hehe);
advanceToItemStartingWith = lastKey ;
2012-10-15 09:44:44 +02:00
}
2012-11-15 00:51:18 +01:00
2013-12-31 08:32:06 +01:00
if ( mapPreviewTexture ! = NULL ) {
// printf("X: %d Y: %d [%d, %d, %d, %d]\n",
// x, y,
// this->render_mapPreviewTexture_X, this->render_mapPreviewTexture_X + this->render_mapPreviewTexture_W,
// this->render_mapPreviewTexture_Y, this->render_mapPreviewTexture_Y + this->render_mapPreviewTexture_H);
if ( x > = this - > render_mapPreviewTexture_X & & x < = this - > render_mapPreviewTexture_X + this - > render_mapPreviewTexture_W & &
y > = this - > render_mapPreviewTexture_Y & & y < = this - > render_mapPreviewTexture_Y + this - > render_mapPreviewTexture_H ) {
if ( this - > render_mapPreviewTexture_X = = mapPreviewTexture_X & &
this - > render_mapPreviewTexture_Y = = mapPreviewTexture_Y & &
this - > render_mapPreviewTexture_W = = mapPreviewTexture_W & &
this - > render_mapPreviewTexture_H = = mapPreviewTexture_H ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
this - > render_mapPreviewTexture_X = 0 ;
this - > render_mapPreviewTexture_Y = 0 ;
this - > render_mapPreviewTexture_W = metrics . getVirtualW ( ) ;
this - > render_mapPreviewTexture_H = metrics . getVirtualH ( ) ;
2014-01-03 19:19:10 +01:00
this - > zoomedMap = true ;
2013-12-31 08:32:06 +01:00
cleanupMapPreviewTexture ( ) ;
}
else {
this - > render_mapPreviewTexture_X = mapPreviewTexture_X ;
this - > render_mapPreviewTexture_Y = mapPreviewTexture_Y ;
this - > render_mapPreviewTexture_W = mapPreviewTexture_W ;
this - > render_mapPreviewTexture_H = mapPreviewTexture_H ;
2014-01-03 19:19:10 +01:00
this - > zoomedMap = false ;
2013-12-31 08:32:06 +01:00
cleanupMapPreviewTexture ( ) ;
}
2014-01-03 19:19:10 +01:00
return ;
2013-12-31 08:32:06 +01:00
}
2014-01-03 19:19:10 +01:00
if ( this - > zoomedMap = = true ) {
return ;
}
2013-12-31 08:32:06 +01:00
}
2012-10-15 09:44:44 +02:00
if ( activeInputLabel ! = NULL & & ! ( activeInputLabel - > mouseClick ( x , y ) ) ) {
2011-10-23 12:49:36 +02:00
setActiveInputLabel ( NULL ) ;
}
if ( buttonReturn . mouseClick ( x , y ) | | serverInitError = = true ) {
2012-01-06 07:55:27 +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-01-02 01:39:13 +01:00
2011-10-23 12:49:36 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2011-01-02 01:39:13 +01:00
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-10-23 12:49:36 +02:00
needToBroadcastServerSettings = false ;
needToRepublishToMasterserver = false ;
lastNetworkPing = time ( NULL ) ;
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2011-01-02 01:39:13 +01:00
2012-01-06 07:55:27 +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-05 09:52:14 +02:00
2011-10-23 12:49:36 +02:00
returnToParentMenu ( ) ;
2011-11-03 21:36:56 +01:00
return ;
2011-10-23 12:49:36 +02:00
}
else if ( buttonPlayNow . mouseClick ( x , y ) & & buttonPlayNow . getEnabled ( ) ) {
2012-01-06 07:55:27 +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-11 06:55:49 +02:00
2011-10-23 12:49:36 +02:00
PlayNow ( true ) ;
return ;
}
else if ( buttonRestoreLastSettings . mouseClick ( x , y ) & & buttonRestoreLastSettings . getEnabled ( ) ) {
2013-05-26 04:44:36 +02:00
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
2011-10-23 12:49:36 +02:00
RestoreLastGameSettings ( ) ;
}
2012-10-15 09:44:44 +02:00
else if ( listBoxMap . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2011-10-23 12:49:36 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , getCurrentMapFile ( ) . c_str ( ) ) ;
2010-06-05 17:48:50 +02:00
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-03-13 23:00:01 +01:00
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( getCurrentMapFile ( ) , " " , false ) , & mapInfo , true ) ;
2011-10-23 12:49:36 +02:00
labelMapInfo . setText ( mapInfo . desc ) ;
updateControlers ( ) ;
updateNetworkSlots ( ) ;
2010-06-04 23:46:10 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2010-03-13 23:00:01 +01:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
//delay publishing for 5 seconds
needToPublishDelayed = true ;
mapPublishingDelayTimer = time ( NULL ) ;
}
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & listBoxFogOfWar . mouseClick ( x , y ) ) {
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2011-10-23 12:49:36 +02:00
cleanupMapPreviewTexture ( ) ;
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2010-05-13 08:43:56 +02:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & checkBoxAllowObservers . mouseClick ( x , y ) ) {
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2010-09-04 03:24:17 +02:00
2011-12-28 05:46:36 +01:00
reloadFactions ( true , ( checkBoxScenario . getValue ( ) = = true ? scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] : " " ) ) ;
2010-09-04 03:24:17 +02:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2013-02-15 19:25:10 +01:00
else if ( checkBoxAllowInGameJoinPlayer . mouseClick ( x , y ) ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-02-15 19:25:10 +01:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
needToRepublishToMasterserver = true ;
}
2014-01-27 23:15:05 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
2013-02-15 19:25:10 +01:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
serverInterface - > setAllowInGameConnections ( checkBoxAllowInGameJoinPlayer . getValue ( ) = = true ) ;
}
2014-01-27 23:15:05 +01:00
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & checkBoxAllowTeamUnitSharing . mouseClick ( x , y ) ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
if ( checkBoxPublishServer . getValue ( ) = = true ) {
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & checkBoxAllowTeamResourceSharing . mouseClick ( x , y ) ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
if ( checkBoxPublishServer . getValue ( ) = = true ) {
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2013-06-13 03:37:15 +02:00
else if ( checkBoxAllowNativeLanguageTechtree . mouseClick ( x , y ) ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-06-13 03:37:15 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & checkBoxEnableSwitchTeamMode . mouseClick ( x , y ) ) {
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-09-21 08:51:28 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2011-09-21 08:51:28 +02:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & listBoxAISwitchTeamAcceptPercent . getEnabled ( ) & & listBoxAISwitchTeamAcceptPercent . mouseClick ( x , y ) ) {
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-09-21 08:51:28 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2011-09-21 08:51:28 +02:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & listBoxFallbackCpuMultiplier . getEditable ( ) = = true & & listBoxFallbackCpuMultiplier . mouseClick ( x , y ) ) {
2012-09-17 01:42:56 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2012-09-17 01:42:56 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2012-09-17 01:42:56 +02:00
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxAdvanced . mouseClick ( x , y ) ) {
2011-10-23 12:49:36 +02:00
}
2012-10-15 09:44:44 +02:00
else if ( listBoxTileset . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-09-02 01:15:08 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true )
{
2011-01-31 00:01:55 +01:00
2011-10-23 12:49:36 +02:00
//delay publishing for 5 seconds
needToPublishDelayed = true ;
mapPublishingDelayTimer = time ( NULL ) ;
}
}
else if ( listBoxMapFilter . mouseClick ( x , y ) ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-10-23 12:49:36 +02:00
switchToNextMapGroup ( listBoxMapFilter . getSelectedItemIndex ( ) - oldListBoxMapfilterIndex ) ;
2011-03-29 11:45:15 +02:00
2011-10-23 12:49:36 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , getCurrentMapFile ( ) . c_str ( ) ) ;
2011-01-02 01:39:13 +01:00
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( getCurrentMapFile ( ) ) , & mapInfo , true ) ;
2011-10-23 12:49:36 +02:00
labelMapInfo . setText ( mapInfo . desc ) ;
updateControlers ( ) ;
updateNetworkSlots ( ) ;
2011-01-02 01:39:13 +01:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2010-03-13 23:00:01 +01:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-10-15 09:44:44 +02:00
else if ( listBoxTechTree . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2013-05-05 07:35:12 +02:00
reloadFactions ( listBoxTechTree . getItemCount ( ) < = 1 , ( checkBoxScenario . getValue ( ) = = true ? scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] : " " ) ) ;
2010-03-13 23:00:01 +01:00
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2010-05-13 08:43:56 +02:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxPublishServer . mouseClick ( x , y ) & & checkBoxPublishServer . getEditable ( ) ) {
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
2011-03-11 13:14:24 +01:00
2011-10-23 12:49:36 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2012-10-22 17:52:08 +02:00
serverInterface - > setPublishEnabled ( checkBoxPublishServer . getValue ( ) = = true ) ;
2011-10-23 12:49:36 +02:00
}
2012-10-22 17:52:08 +02:00
else if ( labelGameName . mouseClick ( x , y ) & & checkBoxPublishServer . getEditable ( ) ) {
2011-10-23 12:49:36 +02:00
setActiveInputLabel ( & labelGameName ) ;
}
2012-10-22 17:52:08 +02:00
else if ( checkBoxAdvanced . getValue ( ) = = 1 & & checkBoxNetworkPauseGameForLaggedClients . mouseClick ( x , y ) ) {
2011-10-23 12:49:36 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-08-05 01:39:12 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-12-07 07:12:51 +01:00
2011-10-23 12:49:36 +02:00
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
}
2011-12-26 07:29:14 +01:00
else if ( listBoxScenario . mouseClick ( x , y ) | | checkBoxScenario . mouseClick ( x , y ) ) {
processScenario ( ) ;
}
2011-10-23 12:49:36 +02:00
else {
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-12-07 07:12:51 +01:00
2012-10-22 17:52:08 +02:00
// set multiplier
if ( listBoxRMultiplier [ i ] . mouseClick ( x , y ) ) {
2013-06-20 21:18:29 +02:00
//printf("Line: %d multiplier index: %d i: %d itemcount: %d\n",__LINE__,listBoxRMultiplier[i].getSelectedItemIndex(),i,listBoxRMultiplier[i].getItemCount());
//for(int indexData = 0; indexData < listBoxRMultiplier[i].getItemCount(); ++indexData) {
//string item = listBoxRMultiplier[i].getItem(indexData);
//printf("Item index: %d value: %s\n",indexData,item.c_str());
//}
2012-10-22 17:52:08 +02:00
}
2010-08-23 06:33:21 +02:00
2011-10-23 12:49:36 +02:00
//ensure thet only 1 human player is present
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( i , true ) ;
2011-10-22 03:02:29 +02:00
2011-10-23 12:49:36 +02:00
bool checkControTypeClicked = false ;
int selectedControlItemIndex = listBoxControls [ i ] . getSelectedItemIndex ( ) ;
if ( selectedControlItemIndex ! = ctNetwork | |
( selectedControlItemIndex = = ctNetwork & & ( slot = = NULL | | slot - > isConnected ( ) = = false ) ) ) {
checkControTypeClicked = true ;
}
2011-10-22 03:02:29 +02:00
2011-10-23 12:49:36 +02:00
//printf("checkControTypeClicked = %d selectedControlItemIndex = %d i = %d\n",checkControTypeClicked,selectedControlItemIndex,i);
2010-03-13 23:00:01 +01:00
2013-11-02 23:30:16 +01:00
if ( selectedControlItemIndex ! = ctHuman & &
checkControTypeClicked = = true & &
listBoxControls [ i ] . mouseClick ( x , y ) ) {
2012-01-06 07:55:27 +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-23 06:33:21 +02:00
2013-11-05 20:40:27 +01:00
ControlType currentControlType = static_cast < ControlType > (
listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
2012-07-26 22:47:16 +02:00
int slotsToChangeStart = i ;
int slotsToChangeEnd = i ;
// If control is pressed while changing player types then change all other slots to same type
2013-11-19 22:57:28 +01:00
if ( : : Shared : : Platform : : Window : : isKeyStateModPressed ( KMOD_CTRL ) = = true & &
2013-11-05 20:40:27 +01:00
currentControlType ! = ctHuman ) {
2012-07-26 22:47:16 +02:00
slotsToChangeStart = 0 ;
slotsToChangeEnd = mapInfo . players - 1 ;
2011-10-23 12:49:36 +02:00
}
2011-10-22 03:02:29 +02:00
2012-07-26 22:47:16 +02:00
for ( int index = slotsToChangeStart ; index < = slotsToChangeEnd ; + + index ) {
2013-11-05 20:40:27 +01:00
if ( index ! = i & & static_cast < ControlType > (
listBoxControls [ index ] . getSelectedItemIndex ( ) ) ! = ctHuman ) {
2012-07-26 22:47:16 +02:00
listBoxControls [ index ] . setSelectedItemIndex ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
}
// Skip over networkunassigned
if ( listBoxControls [ index ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned & &
selectedControlItemIndex ! = ctNetworkUnassigned ) {
listBoxControls [ index ] . mouseClick ( x , y ) ;
}
//look for human players
int humanIndex1 = - 1 ;
int humanIndex2 = - 1 ;
for ( int j = 0 ; j < GameConstants : : maxPlayers ; + + j ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ j ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman ) {
if ( humanIndex1 = = - 1 ) {
humanIndex1 = j ;
}
else {
humanIndex2 = j ;
}
2011-10-23 12:49:36 +02:00
}
}
2010-08-23 06:33:21 +02:00
2012-07-26 22:47:16 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , humanIndex1 , humanIndex2 ) ;
2010-08-23 06:33:21 +02:00
2012-07-26 22:47:16 +02:00
//no human
if ( humanIndex1 = = - 1 & & humanIndex2 = = - 1 ) {
2013-10-25 21:35:10 +02:00
setSlotHuman ( index ) ;
2012-07-26 22:47:16 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d, labelPlayerNames[i].getText() [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , index , labelPlayerNames [ index ] . getText ( ) . c_str ( ) ) ;
2010-08-23 06:33:21 +02:00
2012-07-26 22:47:16 +02:00
//printf("humanIndex1 = %d humanIndex2 = %d i = %d listBoxControls[i].getSelectedItemIndex() = %d\n",humanIndex1,humanIndex2,i,listBoxControls[i].getSelectedItemIndex());
}
//2 humans
else if ( humanIndex1 ! = - 1 & & humanIndex2 ! = - 1 ) {
int closeSlotIndex = ( humanIndex1 = = index ? humanIndex2 : humanIndex1 ) ;
int humanSlotIndex = ( closeSlotIndex = = humanIndex1 ? humanIndex2 : humanIndex1 ) ;
2010-03-13 23:00:01 +01:00
2012-07-26 22:47:16 +02:00
string origPlayName = labelPlayerNames [ closeSlotIndex ] . getText ( ) ;
2010-10-30 06:24:26 +02:00
2012-07-26 22:47:16 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] closeSlotIndex = %d, origPlayName [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , closeSlotIndex , origPlayName . c_str ( ) ) ;
2011-10-23 12:49:36 +02:00
2012-07-26 22:47:16 +02:00
listBoxControls [ closeSlotIndex ] . setSelectedItemIndex ( ctClosed ) ;
2013-10-25 21:35:10 +02:00
setSlotHuman ( humanSlotIndex ) ;
2012-07-26 22:47:16 +02:00
labelPlayerNames [ humanSlotIndex ] . setText ( ( origPlayName ! = " " ? origPlayName : getHumanPlayerName ( ) ) ) ;
}
updateNetworkSlots ( ) ;
2011-10-23 12:49:36 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2012-07-26 22:47:16 +02:00
needToRepublishToMasterserver = true ;
}
2011-04-13 06:04:08 +02:00
2012-07-26 22:47:16 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
updateResourceMultiplier ( index ) ;
2011-10-23 12:49:36 +02:00
}
}
else if ( buttonClearBlockedPlayers . mouseClick ( x , y ) ) {
2013-05-26 04:44:36 +02:00
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
2011-10-23 12:49:36 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
if ( serverInterface ! = NULL ) {
2011-04-13 06:04:08 +02:00
ServerSocket * serverSocket = serverInterface - > getServerSocket ( ) ;
if ( serverSocket ! = NULL ) {
2011-10-23 12:49:36 +02:00
serverSocket - > clearBlockedIPAddress ( ) ;
}
}
}
else if ( buttonBlockPlayers [ i ] . mouseClick ( x , y ) ) {
2013-05-26 04:44:36 +02:00
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
2011-10-23 12:49:36 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
if ( serverInterface ! = NULL ) {
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > isConnected ( ) ) {
2011-10-23 12:49:36 +02:00
ServerSocket * serverSocket = serverInterface - > getServerSocket ( ) ;
if ( serverSocket ! = NULL ) {
2014-01-08 21:48:56 +01:00
serverSocket - > addIPAddressToBlockedList ( serverInterface - > getSlot ( i , true ) - > getIpAddress ( ) ) ;
2011-10-23 12:49:36 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = serverInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int j = 0 ; j < languageList . size ( ) ; + + j ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-10-23 12:49:36 +02:00
if ( lang . hasString ( " BlockPlayerServerMsg " , languageList [ j ] ) = = true ) {
2014-01-08 21:48:56 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " BlockPlayerServerMsg " , languageList [ j ] ) . c_str ( ) , serverInterface - > getSlot ( i , true ) - > getIpAddress ( ) . c_str ( ) ) ;
2011-10-23 12:49:36 +02:00
}
else {
2014-01-08 21:48:56 +01:00
snprintf ( szMsg , 8096 , " The server has temporarily blocked IP Address [%s] from this game. " , serverInterface - > getSlot ( i , true ) - > getIpAddress ( ) . c_str ( ) ) ;
2011-10-23 12:49:36 +02:00
}
2011-04-13 06:04:08 +02:00
2011-10-23 12:49:36 +02:00
serverInterface - > sendTextMessage ( szMsg , - 1 , true , languageList [ j ] ) ;
}
sleep ( 1 ) ;
2014-01-08 21:48:56 +01:00
serverInterface - > getSlot ( i , true ) - > close ( ) ;
2011-10-23 12:49:36 +02:00
}
2011-04-13 06:04:08 +02:00
}
}
2011-10-23 12:49:36 +02:00
}
2012-11-15 00:51:18 +01:00
else if ( listBoxFactions [ i ] . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2011-10-23 12:49:36 +02:00
// Disallow CPU players to be observers
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) & &
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuEasy | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpu | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuUltra | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuMega ) ) {
listBoxFactions [ i ] . setSelectedItemIndex ( 0 ) ;
}
//
2010-03-13 23:00:01 +01:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
2010-10-30 06:24:26 +02:00
2011-10-23 12:49:36 +02:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
else if ( listBoxTeams [ i ] . mouseClick ( x , y ) )
{
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
if ( listBoxTeams [ i ] . getSelectedItemIndex ( ) + 1 ! = ( GameConstants : : maxPlayers + fpt_Observer ) ) {
lastSelectedTeamIndex [ i ] = listBoxTeams [ i ] . getSelectedItemIndex ( ) ;
}
}
else {
lastSelectedTeamIndex [ i ] = - 1 ;
}
2010-05-13 08:43:56 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-10-23 12:49:36 +02:00
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ; ;
}
}
else if ( labelPlayerNames [ i ] . mouseClick ( x , y ) ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman ) {
setActiveInputLabel ( & labelPlayerNames [ i ] ) ;
break ;
}
}
}
2013-12-31 08:32:06 +01:00
}
2011-01-02 01:39:13 +01:00
}
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true & & listBoxPlayerStatus . mouseClick ( x , y ) ) {
2012-01-06 07:55:27 +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-03-29 11:45:15 +02:00
2011-03-11 12:11:46 +01:00
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
2011-06-21 01:48:22 +02:00
if ( getNetworkPlayerStatus ( ) = = npst_PickSettings )
{
listBoxPlayerStatus . setTextColor ( Vec3f ( 1.0f , 0.0f , 0.0f ) ) ;
listBoxPlayerStatus . setLighted ( true ) ;
}
else if ( getNetworkPlayerStatus ( ) = = npst_BeRightBack )
{
listBoxPlayerStatus . setTextColor ( Vec3f ( 1.0f , 1.0f , 0.0f ) ) ;
listBoxPlayerStatus . setLighted ( true ) ;
}
else if ( getNetworkPlayerStatus ( ) = = npst_Ready )
{
listBoxPlayerStatus . setTextColor ( Vec3f ( 0.0f , 1.0f , 0.0f ) ) ;
listBoxPlayerStatus . setLighted ( false ) ;
}
2011-03-29 11:45:15 +02:00
2012-01-06 07:55:27 +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-03-11 12:11:46 +01:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-03-11 12:11:46 +01:00
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2011-01-02 01:39:13 +01:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-03-31 10:28:42 +02:00
2011-01-02 01:39:13 +01:00
showGeneralError = true ;
generalErrorToShow = szBuf ;
2010-03-13 23:00:01 +01:00
}
2010-05-31 21:57:10 +02:00
2012-01-06 07:55:27 +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 23:00:01 +01:00
}
2010-11-11 02:24:48 +01:00
void MenuStateCustomGame : : updateAllResourceMultiplier ( ) {
for ( int j = 0 ; j < GameConstants : : maxPlayers ; + + j ) {
updateResourceMultiplier ( j ) ;
}
}
void MenuStateCustomGame : : updateResourceMultiplier ( const int index ) {
2013-06-20 21:18:29 +02:00
//printf("Line: %d multiplier index: %d index: %d\n",__LINE__,listBoxRMultiplier[index].getSelectedItemIndex(),index);
ControlType ct = static_cast < ControlType > ( listBoxControls [ index ] . getSelectedItemIndex ( ) ) ;
2013-11-01 20:48:04 +01:00
if ( ct = = ctCpuEasy | | ct = = ctNetworkCpuEasy )
2013-06-20 21:18:29 +02:00
{
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : easyMultiplier , 1 ) ) ;
2013-06-20 21:18:29 +02:00
listBoxRMultiplier [ index ] . setEnabled ( checkBoxScenario . getValue ( ) = = false ) ;
}
else if ( ct = = ctCpu | | ct = = ctNetworkCpu ) {
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : normalMultiplier , 1 ) ) ;
2013-06-20 21:18:29 +02:00
listBoxRMultiplier [ index ] . setEnabled ( checkBoxScenario . getValue ( ) = = false ) ;
}
else if ( ct = = ctCpuUltra | | ct = = ctNetworkCpuUltra )
{
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : ultraMultiplier , 1 ) ) ;
2013-06-20 21:18:29 +02:00
listBoxRMultiplier [ index ] . setEnabled ( checkBoxScenario . getValue ( ) = = false ) ;
}
else if ( ct = = ctCpuMega | | ct = = ctNetworkCpuMega )
{
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : megaMultiplier , 1 ) ) ;
2013-06-20 21:18:29 +02:00
listBoxRMultiplier [ index ] . setEnabled ( checkBoxScenario . getValue ( ) = = false ) ;
}
2013-11-01 20:48:04 +01:00
//if(ct == ctHuman || ct == ctNetwork || ct == ctClosed) {
else {
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : normalMultiplier , 1 ) ) ;
2013-11-01 20:48:04 +01:00
listBoxRMultiplier [ index ] . setEnabled ( false ) ;
//!!!listBoxRMultiplier[index].setEnabled(checkBoxScenario.getValue() == false);
}
2013-06-20 21:18:29 +02:00
listBoxRMultiplier [ index ] . setEditable ( listBoxRMultiplier [ index ] . getEnabled ( ) ) ;
listBoxRMultiplier [ index ] . setVisible ( ct ! = ctHuman & & ct ! = ctNetwork & & ct ! = ctClosed ) ;
//listBoxRMultiplier[index].setVisible(ct != ctClosed);
//printf("Line: %d multiplier index: %d index: %d\n",__LINE__,listBoxRMultiplier[index].getSelectedItemIndex(),index);
2010-11-11 02:24:48 +01:00
}
2012-09-20 23:57:00 +02:00
void MenuStateCustomGame : : loadGameSettings ( std : : string fileName ) {
2010-10-02 04:17:50 +02:00
// Ensure we have set the gamesettings at least once
2012-09-20 23:57:00 +02:00
GameSettings gameSettings = loadGameSettingsFromFile ( fileName ) ;
2010-10-02 04:17:50 +02:00
if ( gameSettings . getMap ( ) = = " " ) {
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
loadGameSettings ( & gameSettings ) ;
}
2010-12-07 07:12:51 +01:00
2010-10-02 04:17:50 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
serverInterface - > setGameSettings ( & gameSettings , false ) ;
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2010-10-30 06:24:26 +02:00
needToRepublishToMasterserver = true ;
}
2010-10-02 04:17:50 +02:00
2011-04-20 00:53:37 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
2010-10-02 04:17:50 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2012-09-20 23:57:00 +02:00
void MenuStateCustomGame : : RestoreLastGameSettings ( ) {
loadGameSettings ( SAVED_GAME_FILENAME ) ;
}
2013-06-23 07:23:02 +02:00
bool MenuStateCustomGame : : checkNetworkPlayerDataSynch ( bool checkMapCRC ,
bool checkTileSetCRC , bool checkTechTreeCRC ) {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
bool dataSynchCheckOk = true ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
2014-01-08 21:48:56 +01:00
MutexSafeWrapper safeMutex ( serverInterface - > getSlotMutex ( i ) , CODE_AT_LINE ) ;
ConnectionSlot * slot = serverInterface - > getSlot ( i , false ) ;
2013-06-23 07:23:02 +02:00
if ( slot ! = NULL & & slot - > isConnected ( ) & &
( slot - > getAllowDownloadDataSynch ( ) = = true | |
slot - > getAllowGameDataSynchCheck ( ) = = true ) ) {
if ( checkMapCRC = = true & &
slot - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
dataSynchCheckOk = false ;
break ;
}
if ( checkTileSetCRC = = true & &
slot - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
dataSynchCheckOk = false ;
break ;
}
if ( checkTechTreeCRC = = true & &
slot - > getNetworkGameDataSynchCheckOkTech ( ) = = false ) {
dataSynchCheckOk = false ;
break ;
}
}
}
}
return dataSynchCheckOk ;
}
2011-09-16 02:34:14 +02:00
void MenuStateCustomGame : : PlayNow ( bool saveGame ) {
2013-11-01 06:25:55 +01:00
if ( listBoxTechTree . getItemCount ( ) < = 0 ) {
mainMessageBoxState = 1 ;
char szMsg [ 8096 ] = " " ;
strcpy ( szMsg , " Cannot start game. \n There are no tech-trees! \n " ) ;
printf ( " %s " , szMsg ) ;
showMessageBox ( szMsg , " " , false ) ;
return ;
}
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-09-16 02:34:14 +02:00
if ( saveGame = = true ) {
2011-12-03 09:17:49 +01:00
saveGameSettingsToFile ( SAVED_GAME_FILENAME ) ;
2011-09-16 02:34:14 +02:00
}
2010-10-02 04:17:50 +02:00
2011-03-28 23:04:47 +02:00
forceWaitForShutdown = false ;
2010-10-02 04:17:50 +02:00
closeUnusedSlots ( ) ;
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
std : : vector < string > randomFactionSelectionList ;
int RandomCount = 0 ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
// Check for random faction selection and choose the faction now
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
2013-11-01 06:25:55 +01:00
if ( listBoxFactions [ i ] . getSelectedItem ( ) = = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) & &
listBoxFactions [ i ] . getItemCount ( ) > 1 ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i ) ;
2010-10-02 04:17:50 +02:00
// Max 1000 tries to get a random, unused faction
for ( int findRandomFaction = 1 ; findRandomFaction < 1000 ; + + findRandomFaction ) {
2012-09-27 08:42:57 +02:00
Chrono seed ( true ) ;
2012-10-30 18:12:04 +01:00
srand ( ( unsigned int ) seed . getCurTicks ( ) + findRandomFaction ) ;
2012-09-27 08:42:57 +02:00
2010-10-02 04:17:50 +02:00
int selectedFactionIndex = rand ( ) % listBoxFactions [ i ] . getItemCount ( ) ;
string selectedFactionName = listBoxFactions [ i ] . getItem ( selectedFactionIndex ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] selectedFactionName [%s] selectedFactionIndex = %d, findRandomFaction = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , selectedFactionName . c_str ( ) , selectedFactionIndex , findRandomFaction ) ;
2010-10-02 04:17:50 +02:00
if ( selectedFactionName ! = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) & &
selectedFactionName ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) & &
std : : find ( randomFactionSelectionList . begin ( ) , randomFactionSelectionList . end ( ) , selectedFactionName ) = = randomFactionSelectionList . end ( ) ) {
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
listBoxFactions [ i ] . setSelectedItem ( selectedFactionName ) ;
randomFactionSelectionList . push_back ( selectedFactionName ) ;
break ;
}
}
if ( listBoxFactions [ i ] . getSelectedItem ( ) = = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] RandomCount = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , RandomCount ) ;
2010-10-02 04:17:50 +02:00
2010-10-19 05:53:52 +02:00
// Find first real faction and use it
int factionIndexToUse = RandomCount ;
for ( int useIdx = 0 ; useIdx < listBoxFactions [ i ] . getItemCount ( ) ; useIdx + + ) {
string selectedFactionName = listBoxFactions [ i ] . getItem ( useIdx ) ;
if ( selectedFactionName ! = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) & &
selectedFactionName ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
factionIndexToUse = useIdx ;
break ;
}
}
listBoxFactions [ i ] . setSelectedItemIndex ( factionIndexToUse ) ;
randomFactionSelectionList . push_back ( listBoxFactions [ i ] . getItem ( factionIndexToUse ) ) ;
2010-10-02 04:17:50 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d, listBoxFactions[i].getSelectedItem() [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , listBoxFactions [ i ] . getSelectedItem ( ) . c_str ( ) ) ;
2010-10-02 04:17:50 +02:00
RandomCount + + ;
}
}
}
if ( RandomCount > 0 ) {
needToSetChangedGameSettings = true ;
}
safeMutex . ReleaseLock ( true ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( true ) ;
2010-10-02 04:17:50 +02:00
GameSettings gameSettings ;
2011-09-10 03:45:34 +02:00
loadGameSettings ( & gameSettings , true ) ;
2010-10-02 04:17:50 +02:00
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
// Send the game settings to each client if we have at least one networked client
safeMutex . Lock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . Lock ( ) ;
2010-10-02 04:17:50 +02:00
2013-06-23 07:23:02 +02:00
bool dataSynchCheckOk = checkNetworkPlayerDataSynch ( true , true , true ) ;
2010-10-02 04:17:50 +02:00
2011-10-15 03:03:24 +02:00
// Ensure we have no dangling network players
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
mainMessageBoxState = 1 ;
Lang & lang = Lang : : getInstance ( ) ;
2013-12-18 02:35:51 +01:00
string sMsg = " " ;
2011-10-15 03:03:24 +02:00
if ( lang . hasString ( " NetworkSlotUnassignedErrorUI " ) = = true ) {
2013-12-18 02:35:51 +01:00
sMsg = lang . getString ( " NetworkSlotUnassignedErrorUI " ) ;
2011-10-15 03:03:24 +02:00
}
else {
2013-12-18 02:35:51 +01:00
sMsg = " Cannot start game. \n Some player(s) are not in a network game slot! " ;
2011-10-15 03:03:24 +02:00
}
2013-12-18 02:35:51 +01:00
showMessageBox ( sMsg , " " , false ) ;
2011-10-15 03:03:24 +02:00
const vector < string > languageList = serverInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int j = 0 ; j < languageList . size ( ) ; + + j ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-10-15 03:03:24 +02:00
if ( lang . hasString ( " NetworkSlotUnassignedError " , languageList [ j ] ) = = true ) {
2013-12-15 07:37:15 +01:00
string msg_string = lang . getString ( " NetworkSlotUnassignedError " ) ;
2013-12-15 07:59:32 +01:00
# ifdef WIN32
strncpy ( szMsg , msg_string . c_str ( ) , min ( ( int ) msg_string . length ( ) , 8095 ) ) ;
# else
2013-12-15 07:37:15 +01:00
strncpy ( szMsg , msg_string . c_str ( ) , std : : min ( ( int ) msg_string . length ( ) , 8095 ) ) ;
2013-12-15 07:59:32 +01:00
# endif
2011-10-15 03:03:24 +02:00
}
else {
2011-10-17 22:56:11 +02:00
strcpy ( szMsg , " Cannot start game, some player(s) are not in a network game slot! " ) ;
2011-10-15 03:03:24 +02:00
}
serverInterface - > sendTextMessage ( szMsg , - 1 , true , languageList [ j ] ) ;
}
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2011-10-15 03:03:24 +02:00
return ;
}
}
2010-10-02 04:17:50 +02:00
if ( dataSynchCheckOk = = false ) {
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
mainMessageBoxState = 1 ;
2012-03-31 10:28:42 +02:00
showMessageBox ( " You cannot start the game because \n one or more clients do not have the same game data! " , " Data Mismatch Error " , false ) ;
2010-10-02 04:17:50 +02:00
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2010-10-02 04:17:50 +02:00
return ;
}
else {
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
if ( ( hasNetworkGameSettings ( ) = = true & &
needToSetChangedGameSettings = = true ) | | ( RandomCount > 0 ) ) {
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
serverInterface - > setGameSettings ( & gameSettings , true ) ;
2010-10-15 00:41:03 +02:00
serverInterface - > broadcastGameSetup ( & gameSettings ) ;
2010-10-02 04:17:50 +02:00
needToSetChangedGameSettings = false ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2012-01-06 07:55:27 +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-10-24 00:06:49 +02:00
2012-07-24 21:29:15 +02:00
// Last check, stop human player from being in same slot as network
if ( isMasterserverMode ( ) = = false ) {
bool hasHuman = false ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
// Check for random faction selection and choose the faction now
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
hasHuman = true ;
break ;
}
}
if ( hasHuman = = false ) {
mainMessageBoxState = 1 ;
Lang & lang = Lang : : getInstance ( ) ;
2013-12-18 08:57:45 +01:00
string sMsg = lang . getString ( " NetworkSlotNoHumanErrorUI " , " " , true ) ;
showMessageBox ( sMsg , " " , false ) ;
2012-07-24 21:29:15 +02:00
const vector < string > languageList = serverInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int j = 0 ; j < languageList . size ( ) ; + + j ) {
2013-12-18 08:57:45 +01:00
sMsg = lang . getString ( " NetworkSlotNoHumanError " , " " , true ) ;
2012-07-24 21:29:15 +02:00
2013-12-18 08:57:45 +01:00
serverInterface - > sendTextMessage ( sMsg , - 1 , true , languageList [ j ] ) ;
2012-07-24 21:29:15 +02:00
}
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2012-07-24 21:29:15 +02:00
return ;
}
}
2010-10-24 00:06:49 +02:00
// Tell the server Interface whether or not to publish game status updates to masterserver
2012-10-22 17:52:08 +02:00
serverInterface - > setNeedToRepublishToMasterserver ( checkBoxPublishServer . getValue ( ) = = true ) ;
2010-10-24 00:06:49 +02:00
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
bool bOkToStart = serverInterface - > launchGame ( & gameSettings ) ;
if ( bOkToStart = = true ) {
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getEditable ( ) & &
checkBoxPublishServer . getValue ( ) = = true ) {
2010-10-02 04:17:50 +02:00
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
needToRepublishToMasterserver = true ;
lastMasterserverPublishing = 0 ;
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
}
needToBroadcastServerSettings = false ;
needToRepublishToMasterserver = false ;
2011-01-02 10:33:37 +01:00
lastNetworkPing = time ( NULL ) ;
2010-10-02 04:17:50 +02:00
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2010-10-02 04:17:50 +02:00
2012-01-06 07:55:27 +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-10-02 04:17:50 +02:00
assert ( program ! = NULL ) ;
2012-01-06 07:55:27 +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-01-02 10:33:37 +01:00
cleanup ( ) ;
2012-07-06 00:03:15 +02:00
Game * newGame = new Game ( program , & gameSettings , this - > headlessServerMode ) ;
2011-03-28 23:04:47 +02:00
forceWaitForShutdown = false ;
2011-02-12 08:34:32 +01:00
program - > setState ( newGame ) ;
2010-10-02 04:17:50 +02:00
return ;
}
else {
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2010-10-02 04:17:50 +02:00
}
}
}
2011-09-26 06:26:44 +02:00
void MenuStateCustomGame : : mouseMove ( int x , int y , const MouseState * ms ) {
if ( isMasterserverMode ( ) = = true ) {
return ;
}
2010-05-17 01:03:22 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
mainMessageBox . mouseMove ( x , y ) ;
}
2010-03-13 23:00:01 +01:00
buttonReturn . mouseMove ( x , y ) ;
buttonPlayNow . mouseMove ( x , y ) ;
2010-06-01 02:32:24 +02:00
buttonRestoreLastSettings . mouseMove ( x , y ) ;
2011-04-13 06:04:08 +02:00
buttonClearBlockedPlayers . mouseMove ( x , y ) ;
2010-03-13 23:00:01 +01:00
2010-10-08 03:41:53 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-11-09 00:15:50 +01:00
listBoxRMultiplier [ i ] . mouseMove ( x , y ) ;
2010-03-13 23:00:01 +01:00
listBoxControls [ i ] . mouseMove ( x , y ) ;
2011-04-13 06:04:08 +02:00
buttonBlockPlayers [ i ] . mouseMove ( x , y ) ;
2010-03-13 23:00:01 +01:00
listBoxFactions [ i ] . mouseMove ( x , y ) ;
listBoxTeams [ i ] . mouseMove ( x , y ) ;
}
2011-10-21 00:30:09 +02:00
2010-03-13 23:00:01 +01:00
listBoxMap . mouseMove ( x , y ) ;
2014-01-27 23:15:05 +01:00
2012-10-22 17:52:08 +02:00
if ( checkBoxAdvanced . getValue ( ) = = 1 ) {
2010-09-04 03:50:36 +02:00
listBoxFogOfWar . mouseMove ( x , y ) ;
2012-10-22 17:52:08 +02:00
checkBoxAllowObservers . mouseMove ( x , y ) ;
2010-09-04 03:50:36 +02:00
2012-10-22 17:52:08 +02:00
checkBoxEnableSwitchTeamMode . mouseMove ( x , y ) ;
2011-09-21 08:51:28 +02:00
listBoxAISwitchTeamAcceptPercent . mouseMove ( x , y ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . mouseMove ( x , y ) ;
2011-09-21 08:51:28 +02:00
2010-09-04 03:50:36 +02:00
labelNetworkPauseGameForLaggedClients . mouseMove ( x , y ) ;
2012-10-22 17:52:08 +02:00
checkBoxNetworkPauseGameForLaggedClients . mouseMove ( x , y ) ;
2010-09-04 03:50:36 +02:00
2014-01-27 23:15:05 +01:00
labelAllowTeamUnitSharing . mouseMove ( x , y ) ;
checkBoxAllowTeamUnitSharing . mouseMove ( x , y ) ;
labelAllowTeamResourceSharing . mouseMove ( x , y ) ;
checkBoxAllowTeamResourceSharing . mouseMove ( x , y ) ;
2010-09-04 03:50:36 +02:00
}
2013-02-15 19:25:10 +01:00
checkBoxAllowInGameJoinPlayer . mouseMove ( x , y ) ;
2013-06-13 03:37:15 +02:00
checkBoxAllowNativeLanguageTechtree . mouseMove ( x , y ) ;
2010-03-13 23:00:01 +01:00
listBoxTileset . mouseMove ( x , y ) ;
2010-08-28 01:08:35 +02:00
listBoxMapFilter . mouseMove ( x , y ) ;
2010-03-13 23:00:01 +01:00
listBoxTechTree . mouseMove ( x , y ) ;
2012-10-22 17:52:08 +02:00
checkBoxPublishServer . mouseMove ( x , y ) ;
2010-07-21 20:21:40 +02:00
2012-10-22 17:52:08 +02:00
checkBoxAdvanced . mouseMove ( x , y ) ;
2011-12-26 07:29:14 +01:00
checkBoxScenario . mouseMove ( x , y ) ;
listBoxScenario . mouseMove ( x , y ) ;
2010-03-13 23:00:01 +01:00
}
2011-09-24 09:46:56 +02:00
bool MenuStateCustomGame : : isMasterserverMode ( ) const {
2012-07-06 00:03:15 +02:00
return ( this - > headlessServerMode = = true & & this - > masterserverModeMinimalResources = = true ) ;
2011-09-26 01:57:42 +02:00
//return false;
2011-09-24 09:46:56 +02:00
}
2012-06-09 04:59:46 +02:00
bool MenuStateCustomGame : : isVideoPlaying ( ) {
bool result = false ;
if ( factionVideo ! = NULL ) {
result = factionVideo - > isPlaying ( ) ;
}
return result ;
}
2010-08-31 08:38:27 +02:00
void MenuStateCustomGame : : render ( ) {
2010-04-11 03:25:06 +02:00
try {
Renderer & renderer = Renderer : : getInstance ( ) ;
2010-03-13 23:00:01 +01:00
2012-10-15 17:06:21 +02:00
if ( mainMessageBox . getEnabled ( ) = = false ) {
if ( factionTexture ! = NULL ) {
if ( factionVideo = = NULL | | factionVideo - > isPlaying ( ) = = false ) {
2013-01-27 23:10:59 +01:00
renderer . renderTextureQuad ( 800 , 600 , 200 , 150 , factionTexture , 1.0f ) ;
2012-10-15 17:06:21 +02:00
}
2012-09-27 01:16:29 +02:00
}
2010-11-01 17:44:05 +01:00
}
2012-05-26 01:00:36 +02:00
if ( factionVideo ! = NULL ) {
if ( factionVideo - > isPlaying ( ) = = true ) {
factionVideo - > playFrame ( false ) ;
}
2012-09-26 00:52:07 +02:00
else {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & &
2013-11-19 22:57:28 +01:00
: : Shared : : Graphics : : VideoPlayer : : hasBackEndVideoPlayer ( ) = = true ) {
2012-09-26 00:52:07 +02:00
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
if ( serverInterface ! = NULL ) {
initFactionPreview ( serverInterface - > getGameSettings ( ) ) ;
}
}
}
}
2012-05-26 01:00:36 +02:00
}
2011-12-26 07:29:14 +01:00
2011-04-24 07:39:13 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
2010-06-01 01:39:07 +02:00
renderer . renderMessageBox ( & mainMessageBox ) ;
2012-10-16 07:27:51 +02:00
renderer . renderButton ( & buttonReturn ) ;
2010-03-13 23:00:01 +01:00
}
2011-04-24 07:39:13 +02:00
else {
2012-10-15 17:06:21 +02:00
if ( mapPreviewTexture ! = NULL ) {
2013-12-31 08:32:06 +01:00
//renderer.renderTextureQuad(5,185,150,150,mapPreviewTexture,1.0f);
renderer . renderTextureQuad ( this - > render_mapPreviewTexture_X ,
this - > render_mapPreviewTexture_Y ,
this - > render_mapPreviewTexture_W ,
this - > render_mapPreviewTexture_H ,
mapPreviewTexture , 1.0f ) ;
2014-01-03 19:19:10 +01:00
if ( this - > zoomedMap = = true ) {
return ;
}
2012-10-15 17:06:21 +02:00
//printf("=================> Rendering map preview texture\n");
}
if ( scenarioLogoTexture ! = NULL ) {
renderer . renderTextureQuad ( 300 , 350 , 400 , 300 , scenarioLogoTexture , 1.0f ) ;
//renderer.renderBackground(scenarioLogoTexture);
}
2010-05-17 01:03:22 +02:00
renderer . renderButton ( & buttonReturn ) ;
renderer . renderButton ( & buttonPlayNow ) ;
2010-06-01 02:32:24 +02:00
renderer . renderButton ( & buttonRestoreLastSettings ) ;
2010-10-22 09:28:55 +02:00
// Get a reference to the player texture cache
std : : map < int , Texture2D * > & crcPlayerTextureCache = CacheManager : : getCachedItem < std : : map < int , Texture2D * > > ( GameConstants : : playerTextureCacheLookupKey ) ;
2010-11-06 00:12:46 +01:00
// START - this code ensure player title and player names don't overlap
int offsetPosition = 0 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-11-02 18:17:28 +01:00
FontMetrics * fontMetrics = NULL ;
if ( Renderer : : renderText3DEnabled = = false ) {
2011-11-02 20:02:25 +01:00
fontMetrics = labelPlayers [ i ] . getFont ( ) - > getMetrics ( ) ;
2011-11-02 18:17:28 +01:00
}
else {
2011-11-02 20:02:25 +01:00
fontMetrics = labelPlayers [ i ] . getFont3D ( ) - > getMetrics ( ) ;
2011-11-02 18:17:28 +01:00
}
2010-11-06 00:12:46 +01:00
if ( fontMetrics = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " fontMetrics == NULL " ) ;
2010-11-06 00:12:46 +01:00
}
2011-11-02 20:02:25 +01:00
int curWidth = ( fontMetrics - > getTextWidth ( labelPlayers [ i ] . getText ( ) ) ) ;
int newOffsetPosition = labelPlayers [ i ] . getX ( ) + curWidth + 2 ;
//printf("labelPlayers[i].getX() = %d curWidth = %d labelPlayerNames[i].getX() = %d offsetPosition = %d newOffsetPosition = %d [%s]\n",labelPlayers[i].getX(),curWidth,labelPlayerNames[i].getX(),offsetPosition,newOffsetPosition,labelPlayers[i].getText().c_str());
2010-11-06 00:12:46 +01:00
if ( labelPlayers [ i ] . getX ( ) + curWidth > = labelPlayerNames [ i ] . getX ( ) ) {
if ( offsetPosition < newOffsetPosition ) {
offsetPosition = newOffsetPosition ;
}
}
}
// END
2013-06-26 00:44:57 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
renderer . renderListBox ( & listBoxPlayerStatus ) ;
2013-06-26 00:44:57 +02:00
if ( serverInterface ! = NULL & &
serverInterface - > getServerSocket ( ) ! = NULL ) {
renderer . renderButton ( & buttonClearBlockedPlayers ) ;
}
2011-03-11 12:11:46 +01:00
}
2010-10-22 09:28:55 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-09-01 23:54:31 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
//printf("Player #%d [%s] control = %d\n",i,labelPlayerNames[i].getText().c_str(),listBoxControls[i].getSelectedItemIndex());
labelPlayers [ i ] . setVisible ( true ) ;
labelPlayerNames [ i ] . setVisible ( true ) ;
listBoxControls [ i ] . setVisible ( true ) ;
listBoxFactions [ i ] . setVisible ( true ) ;
listBoxTeams [ i ] . setVisible ( true ) ;
labelNetStatus [ i ] . setVisible ( true ) ;
}
2011-04-04 07:06:22 +02:00
if ( hasNetworkGameSettings ( ) = = true & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
2011-09-01 23:54:31 +02:00
2011-03-11 12:11:46 +01:00
renderer . renderLabel ( & labelPlayerStatus [ i ] ) ;
}
2010-10-22 09:28:55 +02:00
if ( crcPlayerTextureCache [ i ] ! = NULL ) {
// Render the player # label the player's color
Vec3f playerColor = crcPlayerTextureCache [ i ] - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ;
renderer . renderLabel ( & labelPlayers [ i ] , & playerColor ) ;
}
else {
renderer . renderLabel ( & labelPlayers [ i ] ) ;
}
2010-11-06 00:12:46 +01:00
if ( offsetPosition > 0 ) {
labelPlayerNames [ i ] . setX ( offsetPosition ) ;
}
2010-08-21 09:41:26 +02:00
renderer . renderLabel ( & labelPlayerNames [ i ] ) ;
2010-05-17 01:03:22 +02:00
renderer . renderListBox ( & listBoxControls [ i ] ) ;
2010-12-07 07:12:51 +01:00
2012-10-06 00:43:00 +02:00
if ( hasNetworkGameSettings ( ) = = true & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
renderer . renderLabel ( & labelPlayerStatus [ i ] ) ;
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
if ( serverInterface ! = NULL & &
2014-01-08 21:48:56 +01:00
serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > isConnected ( ) ) {
2012-10-06 00:43:00 +02:00
renderer . renderButton ( & buttonBlockPlayers [ i ] ) ;
}
}
}
2010-05-17 01:03:22 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
2012-10-22 17:52:08 +02:00
renderer . renderListBox ( & listBoxRMultiplier [ i ] ) ;
2010-05-17 01:03:22 +02:00
renderer . renderListBox ( & listBoxFactions [ i ] ) ;
2014-12-06 00:54:00 +01:00
int teamnumber = listBoxTeams [ i ] . getSelectedItemIndex ( ) ;
Vec3f teamcolor = Vec3f ( 1.0f , 1.0f , 1.0f ) ;
if ( teamnumber > = 0 & & teamnumber < 8 ) {
teamcolor = crcPlayerTextureCache [ teamnumber ] - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ;
}
listBoxTeams [ i ] . setTextColor ( teamcolor ) ;
2010-05-17 01:03:22 +02:00
renderer . renderListBox ( & listBoxTeams [ i ] ) ;
renderer . renderLabel ( & labelNetStatus [ i ] ) ;
}
}
2012-05-12 04:21:21 +02:00
renderer . renderLabel ( & labelLocalGameVersion ) ;
2010-07-10 08:14:31 +02:00
renderer . renderLabel ( & labelLocalIP ) ;
2010-05-17 01:03:22 +02:00
renderer . renderLabel ( & labelMap ) ;
2010-09-04 03:50:36 +02:00
2012-10-22 17:52:08 +02:00
if ( checkBoxAdvanced . getValue ( ) = = 1 ) {
2010-09-04 03:50:36 +02:00
renderer . renderLabel ( & labelFogOfWar ) ;
renderer . renderLabel ( & labelAllowObservers ) ;
2012-09-17 01:42:56 +02:00
renderer . renderLabel ( & labelFallbackCpuMultiplier ) ;
2010-09-04 03:50:36 +02:00
2011-09-21 08:51:28 +02:00
renderer . renderLabel ( & labelEnableSwitchTeamMode ) ;
renderer . renderLabel ( & labelAISwitchTeamAcceptPercent ) ;
2010-09-04 03:50:36 +02:00
renderer . renderListBox ( & listBoxFogOfWar ) ;
2012-10-22 17:52:08 +02:00
renderer . renderCheckBox ( & checkBoxAllowObservers ) ;
2011-09-21 08:51:28 +02:00
2012-10-22 17:52:08 +02:00
renderer . renderCheckBox ( & checkBoxEnableSwitchTeamMode ) ;
2011-09-21 08:51:28 +02:00
renderer . renderListBox ( & listBoxAISwitchTeamAcceptPercent ) ;
2012-09-17 01:42:56 +02:00
renderer . renderListBox ( & listBoxFallbackCpuMultiplier ) ;
2014-01-27 23:15:05 +01:00
renderer . renderLabel ( & labelAllowTeamUnitSharing ) ;
renderer . renderCheckBox ( & checkBoxAllowTeamUnitSharing ) ;
renderer . renderLabel ( & labelAllowTeamResourceSharing ) ;
renderer . renderCheckBox ( & checkBoxAllowTeamResourceSharing ) ;
2010-09-04 03:50:36 +02:00
}
2013-02-15 19:25:10 +01:00
renderer . renderLabel ( & labelAllowInGameJoinPlayer ) ;
renderer . renderCheckBox ( & checkBoxAllowInGameJoinPlayer ) ;
2010-05-17 01:03:22 +02:00
renderer . renderLabel ( & labelTileset ) ;
2010-08-28 01:08:35 +02:00
renderer . renderLabel ( & labelMapFilter ) ;
2010-05-17 01:03:22 +02:00
renderer . renderLabel ( & labelTechTree ) ;
renderer . renderLabel ( & labelControl ) ;
renderer . renderLabel ( & labelFaction ) ;
renderer . renderLabel ( & labelTeam ) ;
renderer . renderLabel ( & labelMapInfo ) ;
2010-08-28 01:08:35 +02:00
renderer . renderLabel ( & labelAdvanced ) ;
2010-12-07 07:12:51 +01:00
2010-05-17 01:03:22 +02:00
renderer . renderListBox ( & listBoxMap ) ;
renderer . renderListBox ( & listBoxTileset ) ;
2010-08-28 01:08:35 +02:00
renderer . renderListBox ( & listBoxMapFilter ) ;
2010-05-17 01:03:22 +02:00
renderer . renderListBox ( & listBoxTechTree ) ;
2012-10-22 17:52:08 +02:00
renderer . renderCheckBox ( & checkBoxAdvanced ) ;
2010-12-07 07:12:51 +01:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getEditable ( ) )
2010-05-17 01:03:22 +02:00
{
2012-10-22 17:52:08 +02:00
renderer . renderCheckBox ( & checkBoxPublishServer ) ;
2010-05-17 01:03:22 +02:00
renderer . renderLabel ( & labelPublishServer ) ;
2011-10-21 00:30:09 +02:00
renderer . renderLabel ( & labelGameName ) ;
2012-10-22 17:52:08 +02:00
if ( checkBoxAdvanced . getValue ( ) = = 1 ) {
2010-09-04 03:50:36 +02:00
renderer . renderLabel ( & labelNetworkPauseGameForLaggedClients ) ;
2012-10-22 17:52:08 +02:00
renderer . renderCheckBox ( & checkBoxNetworkPauseGameForLaggedClients ) ;
2010-09-04 03:50:36 +02:00
}
2010-05-17 01:03:22 +02:00
}
2010-07-08 10:29:51 +02:00
2012-10-15 17:06:21 +02:00
renderer . renderCheckBox ( & checkBoxScenario ) ;
renderer . renderLabel ( & labelScenario ) ;
if ( checkBoxScenario . getValue ( ) = = true ) {
renderer . renderListBox ( & listBoxScenario ) ;
}
2013-06-13 03:37:15 +02:00
renderer . renderLabel ( & labelAllowNativeLanguageTechtree ) ;
renderer . renderCheckBox ( & checkBoxAllowNativeLanguageTechtree ) ;
2011-12-26 07:29:14 +01:00
}
2010-07-08 10:29:51 +02:00
if ( program ! = NULL ) program - > renderProgramMsgBox ( ) ;
2010-09-12 07:05:08 +02:00
2010-11-01 17:44:05 +01:00
if ( enableMapPreview = = true & &
mapPreview . hasFileLoaded ( ) = = true ) {
2010-09-12 07:05:08 +02:00
2010-11-01 17:44:05 +01:00
if ( mapPreviewTexture = = NULL ) {
2011-04-13 03:11:23 +02:00
bool renderAll = ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 2 ) ;
2010-11-01 17:44:05 +01:00
//printf("=================> Rendering map preview into a texture BEFORE (%p)\n", mapPreviewTexture);
2013-12-31 08:32:06 +01:00
//renderer.renderMapPreview(&mapPreview, renderAll, 10, 350,&mapPreviewTexture);
renderer . renderMapPreview ( & mapPreview , renderAll ,
this - > render_mapPreviewTexture_X ,
this - > render_mapPreviewTexture_Y ,
& mapPreviewTexture ) ;
2010-11-01 17:44:05 +01:00
//printf("=================> Rendering map preview into a texture AFTER (%p)\n", mapPreviewTexture);
}
2010-09-12 07:05:08 +02:00
}
2010-12-07 07:12:51 +01:00
2012-10-15 17:06:21 +02:00
if ( mainMessageBox . getEnabled ( ) = = false ) {
if ( hasNetworkGameSettings ( ) = = true ) {
renderer . renderChatManager ( & chatManager ) ;
}
2011-01-03 13:41:20 +01:00
}
2014-11-24 01:10:10 +01:00
renderer . renderConsole ( & console , showFullConsole ? consoleFull : consoleStoredAndNormal ) ;
2010-04-11 03:25:06 +02:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error(szBuf);
2011-01-12 01:16:50 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2011-01-12 01:16:50 +01:00
showGeneralError = true ;
2012-03-31 10:28:42 +02:00
generalErrorToShow = szBuf ;
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
}
2011-09-01 23:54:31 +02:00
void MenuStateCustomGame : : switchSetupForSlots ( SwitchSetupRequest * * switchSetupRequests ,
ServerInterface * & serverInterface , int startIndex , int endIndex , bool onlyNetworkUnassigned ) {
for ( int i = startIndex ; i < endIndex ; + + i ) {
if ( switchSetupRequests [ i ] ! = NULL ) {
2012-07-10 04:12:07 +02:00
//printf("Switch slot = %d control = %d newIndex = %d currentindex = %d onlyNetworkUnassigned = %d\n",i,listBoxControls[i].getSelectedItemIndex(),switchSetupRequests[i]->getToFactionIndex(),switchSetupRequests[i]->getCurrentFactionIndex(),onlyNetworkUnassigned);
2011-09-01 23:54:31 +02:00
2012-01-06 07:55:27 +01:00
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 ( ) ) ;
2011-09-01 23:54:31 +02:00
if ( onlyNetworkUnassigned = = true & & listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetworkUnassigned ) {
2012-07-06 20:57:19 +02:00
if ( i < mapInfo . players | | ( i > = mapInfo . players & & listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork ) ) {
continue ;
}
2011-09-01 23:54:31 +02:00
}
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
2013-02-16 11:07:36 +01:00
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 ( ) ) ;
2011-09-01 23:54:31 +02:00
2013-02-16 11:07:36 +01:00
if ( switchSetupRequests [ i ] - > getToSlotIndex ( ) ! = - 1 ) {
int newFactionIdx = switchSetupRequests [ i ] - > getToSlotIndex ( ) ;
2011-09-01 23:54:31 +02:00
//printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex());
2013-02-16 11:07:36 +01:00
int switchFactionIdx = switchSetupRequests [ i ] - > getCurrentSlotIndex ( ) ;
2011-09-01 23:54:31 +02:00
if ( serverInterface - > switchSlot ( switchFactionIdx , newFactionIdx ) ) {
try {
2013-06-03 21:55:34 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( newFactionIdx , true ) ;
2013-06-03 21:55:34 +02:00
if ( switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = " " & &
2013-11-16 11:02:32 +01:00
( slot ! = NULL & &
switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = Lang : : getInstance ( ) . getString ( " DataMissing " , slot - > getNetworkPlayerLanguage ( ) , true ) & &
switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = " ???DataMissing??? " ) ) {
2011-09-01 23:54:31 +02:00
listBoxFactions [ newFactionIdx ] . setSelectedItem ( switchSetupRequests [ i ] - > getSelectedFactionName ( ) ) ;
}
if ( switchSetupRequests [ i ] - > getToTeam ( ) ! = - 1 ) {
listBoxTeams [ newFactionIdx ] . setSelectedItemIndex ( switchSetupRequests [ i ] - > getToTeam ( ) ) ;
}
if ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ! = " " ) {
2012-01-06 07:55:27 +01:00
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 ( ) ) ;
2011-09-01 23:54:31 +02:00
labelPlayerNames [ newFactionIdx ] . setText ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
}
if ( listBoxControls [ switchFactionIdx ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
2011-09-02 02:08:35 +02:00
serverInterface - > removeSlot ( switchFactionIdx ) ;
2011-09-01 23:54:31 +02:00
listBoxControls [ switchFactionIdx ] . setSelectedItemIndex ( ctClosed ) ;
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 [ switchFactionIdx ] . setVisible ( switchFactionIdx + 1 < = mapInfo . players ) ;
}
}
catch ( const runtime_error & e ) {
2012-01-06 07:55:27 +01:00
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 ( ) ) ;
2011-09-01 23:54:31 +02:00
}
}
}
else {
try {
2013-06-03 21:55:34 +02:00
int factionIdx = switchSetupRequests [ i ] - > getCurrentSlotIndex ( ) ;
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( factionIdx , true ) ;
2013-06-03 21:55:34 +02:00
if ( switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = " " & &
2013-11-16 11:02:32 +01:00
( slot ! = NULL & &
switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = Lang : : getInstance ( ) . getString ( " DataMissing " , slot - > getNetworkPlayerLanguage ( ) , true ) & &
switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = " ???DataMissing??? " ) ) {
2011-09-01 23:54:31 +02:00
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 ) {
2012-01-06 07:55:27 +01:00
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 ( ) ) ;
2011-09-01 23:54:31 +02:00
if ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
labelPlayerNames [ i ] . setText ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
}
else {
labelPlayerNames [ i ] . setText ( " " ) ;
}
}
}
catch ( const runtime_error & e ) {
2012-01-06 07:55:27 +01:00
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 ( ) ) ;
2011-09-01 23:54:31 +02:00
}
}
}
delete switchSetupRequests [ i ] ;
switchSetupRequests [ i ] = NULL ;
}
}
}
2010-06-23 16:49:20 +02:00
void MenuStateCustomGame : : update ( ) {
2010-09-02 23:40:43 +02:00
Chrono chrono ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2011-01-18 02:24:45 +01:00
// Test openal buffer underrun issue
//sleep(200);
// END
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-06-23 16:49:20 +02:00
2010-04-11 03:25:06 +02:00
try {
2010-06-11 06:55:49 +02:00
if ( serverInitError = = true ) {
2012-01-06 07:55:27 +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-23 16:49:20 +02:00
2010-06-11 06:55:49 +02:00
if ( showGeneralError ) {
2012-01-06 07:55:27 +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-23 16:49:20 +02:00
2010-06-11 06:55:49 +02:00
showGeneralError = false ;
mainMessageBoxState = 1 ;
showMessageBox ( generalErrorToShow , " Error " , false ) ;
}
2012-01-06 07:55:27 +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-07-12 00:41:31 +02:00
if ( this - > headlessServerMode = = false ) {
return ;
}
2010-06-11 06:55:49 +02:00
}
2010-04-11 03:25:06 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2013-06-25 22:39:15 +02:00
if ( serverInterface ! = NULL & & serverInterface - > getServerSocket ( ) ! = NULL ) {
buttonClearBlockedPlayers . setEditable ( serverInterface - > getServerSocket ( ) - > hasBlockedIPAddresses ( ) ) ;
}
2011-12-26 07:29:14 +01:00
if ( this - > autoloadScenarioName ! = " " ) {
listBoxScenario . setSelectedItem ( formatString ( this - > autoloadScenarioName ) , false ) ;
2014-10-28 21:52:10 +01:00
lastSetChangedGameSettings = time ( NULL ) ;
2014-11-10 21:53:10 +01:00
if ( serverInterface ! = NULL ) {
lastGameSettingsreceivedCount = serverInterface - > getGameSettingsUpdateCount ( ) ;
}
2011-12-26 07:29:14 +01:00
if ( listBoxScenario . getSelectedItem ( ) ! = formatString ( this - > autoloadScenarioName ) ) {
mainMessageBoxState = 1 ;
showMessageBox ( " Could not find scenario name: " + formatString ( this - > autoloadScenarioName ) , " Scenario Missing " , false ) ;
this - > autoloadScenarioName = " " ;
}
else {
loadScenarioInfo ( Scenario : : getScenarioPath ( dirList , scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] ) , & scenarioInfo ) ;
//labelInfo.setText(scenarioInfo.desc);
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
CoreData & coreData = CoreData : : getInstance ( ) ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
//launchGame();
PlayNow ( true ) ;
return ;
}
}
if ( needToLoadTextures ) {
// this delay is done to make it possible to switch faster
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , previewLoadDelayTimer ) > = 2 ) {
2011-12-26 07:29:14 +01:00
//loadScenarioPreviewTexture();
needToLoadTextures = false ;
}
}
2011-09-01 20:08:56 +02:00
//bool haveAtLeastOneNetworkClientConnected = false;
2010-05-13 00:58:00 +02:00
bool hasOneNetworkSlotOpen = false ;
2010-05-16 18:40:21 +02:00
int currentConnectionCount = 0 ;
2010-04-11 03:25:06 +02:00
Config & config = Config : : getInstance ( ) ;
2010-12-07 07:12:51 +01:00
2010-06-05 02:58:32 +02:00
bool masterServerErr = showMasterserverError ;
2010-06-23 16:49:20 +02:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-06-23 16:49:20 +02:00
2010-09-02 23:40:43 +02:00
if ( masterServerErr ) {
2012-01-06 07:55:27 +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-23 16:49:20 +02:00
2011-01-09 08:37:59 +01:00
if ( EndsWith ( masterServererErrorToShow , " wrong router setup " ) = = true ) {
2013-10-29 07:13:38 +01:00
masterServererErrorToShow = lang . getString ( " WrongRouterSetup " ) ;
2010-05-17 01:03:22 +02:00
}
2011-09-02 18:18:37 +02:00
Lang & lang = Lang : : getInstance ( ) ;
string publishText = " (disabling publish) " ;
if ( lang . hasString ( " PublishDisabled " ) = = true ) {
2013-10-29 07:13:38 +01:00
publishText = lang . getString ( " PublishDisabled " ) ;
2011-09-02 18:18:37 +02:00
}
2014-12-09 02:36:30 +01:00
masterServererErrorToShow + = " \n \n " + publishText ;
2010-05-17 22:05:31 +02:00
showMasterserverError = false ;
2010-05-17 01:03:22 +02:00
mainMessageBoxState = 1 ;
2013-10-29 07:13:38 +01:00
showMessageBox ( masterServererErrorToShow , lang . getString ( " ErrorFromMasterserver " ) , false ) ;
2010-06-23 16:49:20 +02:00
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = false ) {
2012-10-22 17:52:08 +02:00
checkBoxPublishServer . setValue ( false ) ;
2011-11-14 06:18:09 +01:00
}
2011-03-11 13:14:24 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2012-10-22 17:52:08 +02:00
serverInterface - > setPublishEnabled ( checkBoxPublishServer . getValue ( ) = = true ) ;
2010-05-17 01:03:22 +02:00
}
2010-06-11 06:55:49 +02:00
else if ( showGeneralError ) {
2012-01-06 07:55:27 +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-23 16:49:20 +02:00
2010-06-11 06:55:49 +02:00
showGeneralError = false ;
mainMessageBoxState = 1 ;
showMessageBox ( generalErrorToShow , " Error " , false ) ;
}
2010-12-07 07:12:51 +01:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-06-01 01:39:07 +02:00
2013-12-14 08:04:12 +01:00
if ( this - > headlessServerMode = = true & & serverInterface = = NULL ) {
throw megaglest_runtime_error ( " serverInterface == NULL " ) ;
}
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = true & & serverInterface - > getGameSettingsUpdateCount ( ) > lastMasterServerSettingsUpdateCount & &
2011-09-24 09:46:56 +02:00
serverInterface - > getGameSettings ( ) ! = NULL ) {
const GameSettings * settings = serverInterface - > getGameSettings ( ) ;
2011-10-01 10:04:30 +02:00
//printf("\n\n\n\n=====#1 got settings [%d] [%d]:\n%s\n",lastMasterServerSettingsUpdateCount,serverInterface->getGameSettingsUpdateCount(),settings->toString().c_str());
2011-09-24 09:46:56 +02:00
lastMasterServerSettingsUpdateCount = serverInterface - > getGameSettingsUpdateCount ( ) ;
//printf("#2 custom menu got map [%s]\n",settings->getMap().c_str());
setupUIFromGameSettings ( * settings ) ;
2011-10-01 10:04:30 +02:00
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
//printf("\n\n\n\n=====#1.1 got settings [%d] [%d]:\n%s\n",lastMasterServerSettingsUpdateCount,serverInterface->getGameSettingsUpdateCount(),gameSettings.toString().c_str());
2011-09-24 09:46:56 +02:00
}
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = true & & serverInterface - > getMasterserverAdminRequestLaunch ( ) = = true ) {
2011-10-15 03:39:59 +02:00
serverInterface - > setMasterserverAdminRequestLaunch ( false ) ;
2011-09-24 09:46:56 +02:00
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2011-09-24 09:46:56 +02:00
PlayNow ( false ) ;
return ;
}
2010-04-30 03:08:29 +02:00
// handle setting changes from clients
2010-08-23 06:33:21 +02:00
SwitchSetupRequest * * switchSetupRequests = serverInterface - > getSwitchSetupRequests ( ) ;
2011-09-01 23:54:31 +02:00
//!!!
switchSetupForSlots ( switchSetupRequests , serverInterface , 0 , mapInfo . players , false ) ;
switchSetupForSlots ( switchSetupRequests , serverInterface , mapInfo . players , GameConstants : : maxPlayers , true ) ;
2011-03-29 11:45:15 +02:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-06-01 01:39:07 +02:00
2011-03-11 12:11:46 +01:00
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
2012-10-22 19:53:48 +02:00
listBoxAISwitchTeamAcceptPercent . setEnabled ( checkBoxEnableSwitchTeamMode . getValue ( ) ) ;
2011-09-21 08:51:28 +02:00
2011-03-22 07:43:33 +01:00
int factionCount = 0 ;
2010-09-04 03:24:17 +02:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
2011-03-22 07:43:33 +01:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
int slotIndex = factionCount ;
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
switch ( gameSettings . getNetworkPlayerStatuses ( slotIndex ) ) {
case npst_BeRightBack :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( CoreData : : getInstance ( ) . getStatusBRBTexture ( ) ) ;
2011-03-22 07:43:33 +01:00
break ;
case npst_Ready :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( CoreData : : getInstance ( ) . getStatusReadyTexture ( ) ) ;
2011-03-22 07:43:33 +01:00
break ;
case npst_PickSettings :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( CoreData : : getInstance ( ) . getStatusNotReadyTexture ( ) ) ;
2011-03-22 07:43:33 +01:00
break ;
2012-09-21 17:03:13 +02:00
case npst_Disconnected :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( NULL ) ;
2012-09-21 17:03:13 +02:00
break ;
2011-03-22 07:43:33 +01:00
default :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( NULL ) ;
2011-03-22 07:43:33 +01:00
break ;
}
}
else {
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( NULL ) ;
2011-03-11 12:11:46 +01:00
}
2011-03-22 07:43:33 +01:00
factionCount + + ;
2011-03-11 12:11:46 +01:00
}
else {
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( NULL ) ;
2011-03-11 12:11:46 +01:00
}
}
2011-11-14 06:18:09 +01:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
2010-05-13 00:58:00 +02:00
hasOneNetworkSlotOpen = true ;
2010-03-13 23:00:01 +01:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > isConnected ( ) ) {
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
2014-01-08 21:48:56 +01:00
switch ( serverInterface - > getSlot ( i , true ) - > getNetworkPlayerStatus ( ) ) {
2011-03-11 12:11:46 +01:00
case npst_BeRightBack :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( CoreData : : getInstance ( ) . getStatusBRBTexture ( ) ) ;
2011-03-11 12:11:46 +01:00
break ;
case npst_Ready :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( CoreData : : getInstance ( ) . getStatusReadyTexture ( ) ) ;
2011-03-11 12:11:46 +01:00
break ;
case npst_PickSettings :
default :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( CoreData : : getInstance ( ) . getStatusNotReadyTexture ( ) ) ;
2011-03-11 12:11:46 +01:00
break ;
}
}
2014-01-08 21:48:56 +01:00
serverInterface - > getSlot ( i , true ) - > setName ( labelPlayerNames [ i ] . getText ( ) ) ;
2010-08-21 15:04:52 +02:00
2010-05-17 08:41:05 +02:00
//printf("FYI we have at least 1 client connected, slot = %d'\n",i);
2011-09-01 20:08:56 +02:00
//haveAtLeastOneNetworkClientConnected = true;
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > getConnectHasHandshaked ( ) ) {
2010-05-17 22:05:31 +02:00
currentConnectionCount + + ;
2010-12-19 00:03:53 +01:00
}
2014-01-08 21:48:56 +01:00
string label = ( serverInterface - > getSlot ( i , true ) ! = NULL ? serverInterface - > getSlot ( i , true ) - > getVersionString ( ) : " " ) ;
2010-04-11 03:25:06 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > getAllowDownloadDataSynch ( ) = = true & &
serverInterface - > getSlot ( i , true ) - > getAllowGameDataSynchCheck ( ) = = true ) {
if ( serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
2010-08-22 10:00:05 +02:00
label + = " -waiting to synch: " ;
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " map " ;
}
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " tile " ;
}
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOkTech ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " techtree " ;
}
}
2010-12-19 00:03:53 +01:00
else {
2010-08-05 07:58:14 +02:00
label + = " - data synch is ok " ;
2010-04-11 03:25:06 +02:00
}
}
2010-12-19 00:03:53 +01:00
else {
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > getAllowGameDataSynchCheck ( ) = = true & &
serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
2010-08-22 10:00:05 +02:00
label + = " -synch mismatch: " ;
2010-12-19 00:03:53 +01:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & & serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " map " ;
2010-08-22 10:00:05 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getReceivedDataSynchCheck ( ) = = true & &
2010-08-27 01:14:55 +02:00
lastMapDataSynchError ! = " map CRC mismatch, " + listBoxMap . getSelectedItem ( ) ) {
lastMapDataSynchError = " map CRC mismatch, " + listBoxMap . getSelectedItem ( ) ;
2010-08-22 10:00:05 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2011-04-05 20:39:47 +02:00
serverInterface - > sendTextMessage ( lastMapDataSynchError , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
}
2010-04-11 03:25:06 +02:00
}
2010-08-22 10:00:05 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " tile " ;
2010-08-22 10:00:05 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getReceivedDataSynchCheck ( ) = = true & &
2010-08-27 01:14:55 +02:00
lastTileDataSynchError ! = " tile CRC mismatch, " + listBoxTileset . getSelectedItem ( ) ) {
lastTileDataSynchError = " tile CRC mismatch, " + listBoxTileset . getSelectedItem ( ) ;
2010-08-22 10:00:05 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2011-04-05 20:39:47 +02:00
serverInterface - > sendTextMessage ( lastTileDataSynchError , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
}
2010-04-11 03:25:06 +02:00
}
2010-08-22 10:00:05 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckOkTech ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " techtree " ;
2010-08-22 10:00:05 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getReceivedDataSynchCheck ( ) = = true ) {
2010-08-22 10:00:05 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2014-01-08 21:48:56 +01:00
string report = serverInterface - > getSlot ( i , true ) - > getNetworkGameDataSynchCheckTechMismatchReport ( ) ;
2010-08-22 10:00:05 +02:00
if ( lastTechtreeDataSynchError ! = " techtree CRC mismatch " + report ) {
lastTechtreeDataSynchError = " techtree CRC mismatch " + report ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] report: %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , report . c_str ( ) ) ;
2010-08-22 10:00:05 +02:00
2011-04-05 20:39:47 +02:00
serverInterface - > sendTextMessage ( " techtree CRC mismatch " , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
vector < string > reportLineTokens ;
Tokenize ( report , reportLineTokens , " \n " ) ;
2013-11-19 07:14:06 +01:00
for ( int reportLine = 0 ; reportLine < ( int ) reportLineTokens . size ( ) ; + + reportLine ) {
2011-04-05 20:39:47 +02:00
serverInterface - > sendTextMessage ( reportLineTokens [ reportLine ] , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
}
}
}
}
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL ) {
serverInterface - > getSlot ( i , true ) - > setReceivedDataSynchCheck ( false ) ;
2010-04-11 03:25:06 +02:00
}
}
}
2010-03-13 23:00:01 +01:00
2010-12-19 00:03:53 +01:00
//float pingTime = serverInterface->getSlot(i)->getThreadedPingMS(serverInterface->getSlot(i)->getIpAddress().c_str());
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " %s " , label . c_str ( ) ) ;
2010-06-04 21:42:58 +02:00
labelNetStatus [ i ] . setText ( szBuf ) ;
2010-04-04 01:31:10 +02:00
}
2010-12-19 00:03:53 +01:00
else {
2012-10-06 16:56:40 +02:00
string port = " ( " + intToStr ( config . getInt ( " PortServer " ) ) + " ) " ;
2010-07-03 12:06:31 +02:00
labelNetStatus [ i ] . setText ( " --- " + port ) ;
2010-04-04 01:31:10 +02:00
}
2010-04-11 03:25:06 +02:00
}
else {
labelNetStatus [ i ] . setText ( " " ) ;
}
2010-03-13 23:00:01 +01:00
}
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-06-01 01:39:07 +02:00
2011-12-26 23:51:48 +01:00
//ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
2011-10-15 01:51:44 +02:00
2011-12-26 23:51:48 +01:00
if ( checkBoxScenario . getValue ( ) = = false ) {
2011-10-15 01:51:44 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-10-26 04:36:00 +02:00
if ( i > = mapInfo . players ) {
listBoxControls [ i ] . setEditable ( false ) ;
listBoxControls [ i ] . setEnabled ( false ) ;
2012-01-06 07:55:27 +01:00
//printf("In [%s::%s] Line: %d i = %d mapInfo.players = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,mapInfo.players);
2011-10-26 04:36:00 +02:00
}
else if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetworkUnassigned ) {
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( i , true ) ;
2011-12-26 23:51:48 +01:00
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork ) | |
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork & & ( slot = = NULL | | slot - > isConnected ( ) = = false ) ) ) {
2011-10-15 01:51:44 +02:00
listBoxControls [ i ] . setEditable ( true ) ;
listBoxControls [ i ] . setEnabled ( true ) ;
2011-12-26 23:51:48 +01:00
}
2011-10-15 01:51:44 +02:00
else {
listBoxControls [ i ] . setEditable ( false ) ;
listBoxControls [ i ] . setEnabled ( false ) ;
2011-10-26 04:36:00 +02:00
2012-01-06 07:55:27 +01:00
//printf("In [%s::%s] Line: %d i = %d mapInfo.players = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,mapInfo.players);
2011-10-15 01:51:44 +02:00
}
}
else {
listBoxControls [ i ] . setEditable ( false ) ;
listBoxControls [ i ] . setEnabled ( false ) ;
2011-10-26 04:36:00 +02:00
2012-01-06 07:55:27 +01:00
//printf("In [%s::%s] Line: %d i = %d mapInfo.players = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,mapInfo.players);
2011-10-15 01:51:44 +02:00
}
}
2011-12-26 23:51:48 +01:00
}
2011-10-15 01:51:44 +02:00
2010-06-05 02:58:32 +02:00
bool checkDataSynch = ( serverInterface - > getAllowGameDataSynchCheck ( ) = = true & &
needToSetChangedGameSettings = = true & &
2012-09-22 22:13:57 +02:00
( ( difftime ( ( long int ) time ( NULL ) , lastSetChangedGameSettings ) > = BROADCAST_SETTINGS_SECONDS ) | |
2012-07-06 00:03:15 +02:00
( this - > headlessServerMode = = true ) ) ) ;
2010-06-05 02:58:32 +02:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-04-11 03:25:06 +02:00
// Send the game settings to each client if we have at least one networked client
2010-08-31 08:38:27 +02:00
if ( checkDataSynch = = true ) {
2010-08-26 21:01:44 +02:00
serverInterface - > setGameSettings ( & gameSettings , false ) ;
2010-04-11 03:25:06 +02:00
needToSetChangedGameSettings = false ;
2010-04-22 01:13:39 +02:00
}
2010-12-07 07:12:51 +01:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-06-01 01:39:07 +02:00
2013-03-01 18:21:58 +01:00
if ( this - > headlessServerMode = = true | | hasOneNetworkSlotOpen = = true | |
checkBoxAllowInGameJoinPlayer . getValue ( ) = = true ) {
2012-11-09 22:50:01 +01:00
if ( this - > headlessServerMode = = true & &
GlobalStaticFlags : : isFlagSet ( gsft_lan_mode ) = = false ) {
2012-10-22 17:52:08 +02:00
checkBoxPublishServer . setValue ( true ) ;
2011-11-14 06:18:09 +01:00
}
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . setEditable ( true ) ;
2012-10-22 17:52:08 +02:00
checkBoxPublishServer . setEditable ( true ) ;
2011-11-14 06:18:09 +01:00
// Masterserver always needs one network slot
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = true & & hasOneNetworkSlotOpen = = false ) {
2012-07-12 00:41:31 +02:00
bool anyoneConnected = false ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( i , true ) ;
2012-07-12 00:41:31 +02:00
if ( slot ! = NULL & & slot - > isConnected ( ) = = true ) {
anyoneConnected = true ;
break ;
}
}
2011-11-14 06:18:09 +01:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2012-07-12 00:41:31 +02:00
if ( anyoneConnected = = false & & listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork ) {
2011-11-14 06:18:09 +01:00
listBoxControls [ i ] . setSelectedItemIndex ( ctNetwork ) ;
}
}
updateNetworkSlots ( ) ;
}
2010-05-13 00:58:00 +02:00
}
2011-11-14 06:18:09 +01:00
else {
2012-10-22 17:52:08 +02:00
checkBoxPublishServer . setValue ( false ) ;
checkBoxPublishServer . setEditable ( false ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . setEditable ( false ) ;
2013-11-01 20:48:04 +01:00
listBoxFallbackCpuMultiplier . setSelectedItem ( " 1.0 " ) ;
2011-03-11 13:14:24 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2012-10-22 17:52:08 +02:00
serverInterface - > setPublishEnabled ( checkBoxPublishServer . getValue ( ) = = true ) ;
2010-05-13 00:58:00 +02:00
}
2010-12-07 07:12:51 +01:00
2012-09-22 22:13:57 +02:00
bool republishToMaster = ( difftime ( ( long int ) time ( NULL ) , lastMasterserverPublishing ) > = MASTERSERVER_BROADCAST_PUBLISH_SECONDS ) ;
2010-06-05 02:58:32 +02:00
if ( republishToMaster = = true ) {
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2010-10-30 06:24:26 +02:00
needToRepublishToMasterserver = true ;
lastMasterserverPublishing = time ( NULL ) ;
}
2010-05-13 13:19:10 +02:00
}
2010-05-13 08:43:56 +02:00
2012-10-22 17:52:08 +02:00
bool callPublishNow = ( checkBoxPublishServer . getEditable ( ) & &
checkBoxPublishServer . getValue ( ) = = true & &
2010-06-05 02:58:32 +02:00
needToRepublishToMasterserver = = true ) ;
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-06-05 02:58:32 +02:00
if ( callPublishNow = = true ) {
2010-05-13 00:58:00 +02:00
// give it to me baby, aha aha ...
publishToMasterserver ( ) ;
}
2011-12-03 09:17:49 +01:00
if ( needToPublishDelayed ) {
// this delay is done to make it possible to switch over maps which are not meant to be distributed
2012-09-22 22:13:57 +02:00
if ( ( difftime ( ( long int ) time ( NULL ) , mapPublishingDelayTimer ) > = BROADCAST_MAP_DELAY_SECONDS ) | |
2012-07-06 00:03:15 +02:00
( this - > headlessServerMode = = true ) ) {
2011-12-03 09:17:49 +01:00
// after 5 seconds we are allowed to publish again!
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
// set to normal....
needToPublishDelayed = false ;
}
}
2012-07-06 00:03:15 +02:00
if ( needToPublishDelayed = = false | | headlessServerMode = = true ) {
2012-09-22 22:13:57 +02:00
bool broadCastSettings = ( difftime ( ( long int ) time ( NULL ) , lastSetChangedGameSettings ) > = BROADCAST_SETTINGS_SECONDS ) ;
2010-06-05 02:58:32 +02:00
2014-10-28 21:52:10 +01:00
if ( headlessServerMode = = true ) {
// publish settings directly when we receive them
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
if ( lastGameSettingsreceivedCount < serverInterface - > getGameSettingsUpdateCount ( ) ) {
needToBroadcastServerSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
lastGameSettingsreceivedCount = serverInterface - > getGameSettingsUpdateCount ( ) ;
}
}
2011-09-24 09:46:56 +02:00
2011-01-29 21:13:29 +01:00
if ( broadCastSettings = = true ) {
needToBroadcastServerSettings = true ;
2011-12-03 09:17:49 +01:00
lastSetChangedGameSettings = time ( NULL ) ;
2011-01-29 21:13:29 +01:00
}
2010-09-02 23:40:43 +02:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 23:00:01 +01:00
2011-12-03 09:17:49 +01:00
//broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
//if (broadCastSettings == true) {// reset timer here on bottom becasue used for different things
// lastSetChangedGameSettings = time(NULL);
//}
}
2010-03-13 23:00:01 +01:00
2011-12-03 09:17:49 +01:00
//call the chat manager
chatManager . updateNetwork ( ) ;
2010-06-05 02:58:32 +02:00
2011-12-03 09:17:49 +01:00
//console
console . update ( ) ;
2011-01-29 21:13:29 +01:00
2012-01-06 07:55:27 +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-16 18:40:21 +02:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-06-05 02:58:32 +02:00
if ( currentConnectionCount > soundConnectionCount ) {
soundConnectionCount = currentConnectionCount ;
2010-05-16 18:40:21 +02:00
SoundRenderer : : getInstance ( ) . playFx ( CoreData : : getInstance ( ) . getAttentionSound ( ) ) ;
2010-09-04 01:15:42 +02:00
//switch on music again!!
Config & config = Config : : getInstance ( ) ;
float configVolume = ( config . getInt ( " SoundVolumeMusic " ) / 100.f ) ;
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( configVolume ) ;
2010-05-16 18:40:21 +02:00
}
2010-06-05 02:58:32 +02:00
soundConnectionCount = currentConnectionCount ;
2010-06-11 03:33:43 +02:00
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-09-02 15:53:23 +02:00
if ( enableFactionTexturePreview = = true ) {
2010-10-30 05:29:29 +02:00
if ( currentTechName_factionPreview ! = gameSettings . getTech ( ) | |
currentFactionName_factionPreview ! = gameSettings . getFactionTypeName ( gameSettings . getThisFactionIndex ( ) ) ) {
currentTechName_factionPreview = gameSettings . getTech ( ) ;
currentFactionName_factionPreview = gameSettings . getFactionTypeName ( gameSettings . getThisFactionIndex ( ) ) ;
2012-09-26 00:52:07 +02:00
initFactionPreview ( & gameSettings ) ;
2010-09-02 15:53:23 +02:00
}
2010-08-31 08:38:27 +02:00
}
2012-01-06 07:55:27 +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 ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-10-02 04:17:50 +02:00
if ( autostart = = true ) {
2011-09-16 02:34:14 +02:00
autostart = false ;
2010-10-02 04:17:50 +02:00
safeMutex . ReleaseLock ( ) ;
2013-11-07 19:39:08 +01:00
safeMutexCLI . ReleaseLock ( ) ;
2011-09-16 02:34:14 +02:00
if ( autoStartSettings ! = NULL ) {
setupUIFromGameSettings ( * autoStartSettings ) ;
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
serverInterface - > setGameSettings ( autoStartSettings , false ) ;
}
else {
RestoreLastGameSettings ( ) ;
}
PlayNow ( ( autoStartSettings = = NULL ) ) ;
2011-02-12 08:34:32 +01:00
return ;
2010-10-02 04:17:50 +02:00
}
2010-04-11 03:25:06 +02:00
}
2012-11-11 00:19:42 +01:00
catch ( megaglest_runtime_error & ex ) {
//abort();
//printf("1111111bbbb ex.wantStackTrace() = %d\n",ex.wantStackTrace());
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
//printf("2222222bbbb ex.wantStackTrace() = %d\n",ex.wantStackTrace());
showGeneralError = true ;
generalErrorToShow = szBuf ;
}
2010-04-11 03:25:06 +02:00
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-03-31 10:28:42 +02:00
2010-06-11 06:55:49 +02:00
showGeneralError = true ;
generalErrorToShow = szBuf ;
2010-04-11 03:25:06 +02:00
}
2012-09-26 00:52:07 +02:00
}
void MenuStateCustomGame : : initFactionPreview ( const GameSettings * gameSettings ) {
string factionVideoUrl = " " ;
string factionVideoUrlFallback = " " ;
string factionDefinitionXML = Game : : findFactionLogoFile ( gameSettings , NULL , currentFactionName_factionPreview + " .xml " ) ;
if ( factionDefinitionXML ! = " " & & currentFactionName_factionPreview ! = GameConstants : : RANDOMFACTION_SLOTNAME & &
currentFactionName_factionPreview ! = GameConstants : : OBSERVER_SLOTNAME & & fileExists ( factionDefinitionXML ) = = true ) {
XmlTree xmlTree ;
std : : map < string , string > mapExtraTagReplacementValues ;
xmlTree . load ( factionDefinitionXML , Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) ) ;
const XmlNode * factionNode = xmlTree . getRootNode ( ) ;
if ( factionNode - > hasAttribute ( " faction-preview-video " ) = = true ) {
factionVideoUrl = factionNode - > getAttribute ( " faction-preview-video " ) - > getValue ( ) ;
}
factionVideoUrlFallback = Game : : findFactionLogoFile ( gameSettings , NULL , " preview_video.* " ) ;
if ( factionVideoUrl = = " " ) {
factionVideoUrl = factionVideoUrlFallback ;
factionVideoUrlFallback = " " ;
}
}
//printf("currentFactionName_factionPreview [%s] random [%s] observer [%s] factionVideoUrl [%s]\n",currentFactionName_factionPreview.c_str(),GameConstants::RANDOMFACTION_SLOTNAME,GameConstants::OBSERVER_SLOTNAME,factionVideoUrl.c_str());
if ( factionVideoUrl ! = " " ) {
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
if ( CoreData : : getInstance ( ) . getMenuMusic ( ) - > getVolume ( ) ! = 0 ) {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( 0 ) ;
factionVideoSwitchedOffVolume = true ;
}
if ( currentFactionLogo ! = factionVideoUrl ) {
currentFactionLogo = factionVideoUrl ;
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & &
2013-11-19 22:57:28 +01:00
: : Shared : : Graphics : : VideoPlayer : : hasBackEndVideoPlayer ( ) = = true ) {
2012-09-26 00:52:07 +02:00
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
}
string introVideoFile = factionVideoUrl ;
string introVideoFileFallback = factionVideoUrlFallback ;
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);
factionVideo = new VideoPlayer (
& Renderer : : getInstance ( ) ,
introVideoFile ,
introVideoFileFallback ,
screen ,
0 , 0 ,
screen - > w ,
screen - > h ,
screen - > format - > BitsPerPixel ,
2012-09-27 03:17:57 +02:00
true ,
2012-09-26 00:52:07 +02:00
vlcPluginsPath ,
SystemFlags : : VERBOSE_MODE_ENABLED ) ;
factionVideo - > initPlayer ( ) ;
}
}
}
else {
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
//switch on music again!!
Config & config = Config : : getInstance ( ) ;
float configVolume = ( config . getInt ( " SoundVolumeMusic " ) / 100.f ) ;
if ( factionVideoSwitchedOffVolume ) {
if ( CoreData : : getInstance ( ) . getMenuMusic ( ) - > getVolume ( ) ! = configVolume ) {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( configVolume ) ;
}
factionVideoSwitchedOffVolume = false ;
}
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
}
}
if ( factionVideo = = NULL ) {
2013-02-12 00:43:30 +01:00
string factionLogo = Game : : findFactionLogoFile ( gameSettings , NULL , GameConstants : : PREVIEW_SCREEN_FILE_FILTER ) ;
2012-09-26 00:52:07 +02:00
if ( factionLogo = = " " ) {
factionLogo = Game : : findFactionLogoFile ( gameSettings , NULL ) ;
}
if ( currentFactionLogo ! = factionLogo ) {
currentFactionLogo = factionLogo ;
loadFactionTexture ( currentFactionLogo ) ;
}
}
2010-03-13 23:00:01 +01:00
}
2011-03-29 11:45:15 +02:00
void MenuStateCustomGame : : publishToMasterserver ( ) {
2012-01-06 07:55:27 +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-23 16:49:20 +02:00
2010-05-13 00:58:00 +02:00
int slotCountUsed = 0 ;
int slotCountHumans = 0 ;
int slotCountConnectedPlayers = 0 ;
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
2010-10-11 02:53:25 +02:00
Config & config = Config : : getInstance ( ) ;
2010-06-23 16:49:20 +02:00
//string serverinfo="";
2012-07-10 04:43:54 +02:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
2010-06-23 16:49:20 +02:00
publishToServerInfo . clear ( ) ;
2012-01-06 07:55:27 +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-13 08:43:56 +02:00
2010-06-05 02:58:32 +02:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
2010-05-13 00:58:00 +02:00
slotCountUsed + + ;
}
2010-05-13 08:43:56 +02:00
2011-09-01 23:54:31 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned )
2010-05-13 00:58:00 +02:00
{
slotCountHumans + + ;
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > isConnected ( ) ) {
2010-05-13 00:58:00 +02:00
slotCountConnectedPlayers + + ;
2010-12-07 07:12:51 +01:00
}
2010-05-13 00:58:00 +02:00
}
2010-12-19 00:03:53 +01:00
else if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
2010-05-13 00:58:00 +02:00
slotCountHumans + + ;
slotCountConnectedPlayers + + ;
2010-12-07 07:12:51 +01:00
}
2010-05-13 00:58:00 +02:00
}
2010-06-23 16:49:20 +02:00
2013-06-01 04:31:12 +02:00
publishToServerInfo [ " uuid " ] = Config : : getInstance ( ) . getString ( " PlayerId " , " " ) ;
2010-05-13 00:58:00 +02:00
//?status=waiting&system=linux&info=titus
2010-06-23 16:49:20 +02:00
publishToServerInfo [ " glestVersion " ] = glestVersionString ;
2013-11-29 22:13:30 +01:00
publishToServerInfo [ " platform " ] = getPlatformNameString ( ) + " - " + getGITRevisionString ( ) ;
2010-06-23 16:49:20 +02:00
publishToServerInfo [ " binaryCompileDate " ] = getCompileDateTime ( ) ;
2010-05-13 08:43:56 +02:00
2010-05-13 00:58:00 +02:00
//game info:
2014-11-07 01:26:23 +01:00
publishToServerInfo [ " serverTitle " ] = gameSettings . getGameName ( ) ;
2010-05-13 00:58:00 +02:00
//ip is automatically set
2010-05-13 08:43:56 +02:00
2010-05-13 00:58:00 +02:00
//game setup info:
2012-07-11 07:12:10 +02:00
//publishToServerInfo["tech"] = listBoxTechTree.getSelectedItem();
publishToServerInfo [ " tech " ] = techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] ;
//publishToServerInfo["map"] = listBoxMap.getSelectedItem();
publishToServerInfo [ " map " ] = getCurrentMapFile ( ) ;
//publishToServerInfo["tileset"] = listBoxTileset.getSelectedItem();
publishToServerInfo [ " tileset " ] = tilesetFiles [ listBoxTileset . getSelectedItemIndex ( ) ] ;
2010-06-23 16:49:20 +02:00
publishToServerInfo [ " activeSlots " ] = intToStr ( slotCountUsed ) ;
publishToServerInfo [ " networkSlots " ] = intToStr ( slotCountHumans ) ;
publishToServerInfo [ " connectedClients " ] = intToStr ( slotCountConnectedPlayers ) ;
2010-12-21 06:07:10 +01:00
2012-10-06 15:45:42 +02:00
string serverPort = config . getString ( " PortServer " , intToStr ( GameConstants : : serverPort ) . c_str ( ) ) ;
string externalPort = config . getString ( " PortExternal " , serverPort . c_str ( ) ) ;
publishToServerInfo [ " externalconnectport " ] = externalPort ;
2011-01-26 22:18:26 +01:00
publishToServerInfo [ " privacyPlease " ] = intToStr ( config . getBool ( " PrivacyPlease " , " false " ) ) ;
2010-06-23 16:49:20 +02:00
2011-01-25 08:41:12 +01:00
publishToServerInfo [ " gameStatus " ] = intToStr ( game_status_waiting_for_players ) ;
if ( slotCountHumans < = slotCountConnectedPlayers ) {
publishToServerInfo [ " gameStatus " ] = intToStr ( game_status_waiting_for_start ) ;
}
2013-10-31 01:57:36 +01:00
publishToServerInfo [ " gameUUID " ] = gameSettings . getGameUUID ( ) ;
2012-01-06 07:55:27 +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-13 00:58:00 +02:00
}
2013-11-07 19:39:08 +01:00
void MenuStateCustomGame : : setupTask ( BaseThread * callingThread , void * userdata ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n setupTask callingThread [%p] userdata [%p] \n " , callingThread , userdata ) ;
if ( userdata ! = NULL ) {
int value = * ( ( int * ) & userdata ) ;
THREAD_NOTIFIER_TYPE threadType = ( THREAD_NOTIFIER_TYPE ) value ;
//printf("\n\nsetupTask callingThread [%p] userdata [%p]\n",callingThread,userdata);
if ( threadType = = tnt_MASTERSERVER ) {
MenuStateCustomGame : : setupTaskStatic ( callingThread ) ;
}
}
2012-03-05 23:53:03 +01:00
}
2013-11-07 19:39:08 +01:00
void MenuStateCustomGame : : shutdownTask ( BaseThread * callingThread , void * userdata ) {
//printf("\n\nshutdownTask callingThread [%p] userdata [%p]\n",callingThread,userdata);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n shutdownTask callingThread [%p] userdata [%p] \n " , callingThread , userdata ) ;
if ( userdata ! = NULL ) {
int value = * ( ( int * ) & userdata ) ;
THREAD_NOTIFIER_TYPE threadType = ( THREAD_NOTIFIER_TYPE ) value ;
//printf("\n\nshutdownTask callingThread [%p] userdata [%p]\n",callingThread,userdata);
if ( threadType = = tnt_MASTERSERVER ) {
MenuStateCustomGame : : shutdownTaskStatic ( callingThread ) ;
}
}
2012-03-05 23:53:03 +01:00
}
void MenuStateCustomGame : : setupTaskStatic ( BaseThread * callingThread ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-11-07 19:39:08 +01:00
2011-11-23 09:00:09 +01:00
CURL * handle = SystemFlags : : initHTTP ( ) ;
callingThread - > setGenericData < CURL > ( handle ) ;
2013-11-07 19:39:08 +01:00
2012-05-23 01:03:01 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-23 09:00:09 +01:00
}
2012-03-05 23:53:03 +01:00
void MenuStateCustomGame : : shutdownTaskStatic ( BaseThread * callingThread ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-11-07 19:39:08 +01:00
//printf("LINE: %d\n",__LINE__);
2011-11-23 09:00:09 +01:00
CURL * handle = callingThread - > getGenericData < CURL > ( ) ;
SystemFlags : : cleanupHTTP ( & handle ) ;
2013-11-07 19:39:08 +01:00
2012-05-23 01:03:01 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-11-23 09:00:09 +01:00
}
2013-11-07 19:39:08 +01:00
void MenuStateCustomGame : : simpleTask ( BaseThread * callingThread , void * userdata ) {
//printf("\n\nSimple Task callingThread [%p] userdata [%p]\n",callingThread,userdata);
int value = * ( ( int * ) & userdata ) ;
//printf("\n\nSimple Task callingThread [%p] userdata [%p] value = %d\n",callingThread,userdata,value);
2010-06-01 01:39:07 +02:00
2013-11-07 19:39:08 +01:00
THREAD_NOTIFIER_TYPE threadType = ( THREAD_NOTIFIER_TYPE ) value ;
if ( threadType = = tnt_MASTERSERVER ) {
simpleTaskForMasterServer ( callingThread ) ;
}
else if ( threadType = = tnt_CLIENTS ) {
simpleTaskForClients ( callingThread ) ;
}
}
void MenuStateCustomGame : : simpleTaskForMasterServer ( BaseThread * callingThread ) {
2011-01-02 01:39:13 +01:00
try {
2011-01-02 10:33:37 +01:00
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - A\n");
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutexThreadOwner ( callingThread - > getMutexThreadOwnerValid ( ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-02 10:33:37 +01:00
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
2011-01-02 01:39:13 +01:00
return ;
}
2010-12-05 02:52:38 +01:00
2011-01-02 10:33:37 +01:00
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - B\n");
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( callingThread - > getMutexThreadObjectAccessor ( ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-09-01 20:08:56 +02:00
bool republish = ( needToRepublishToMasterserver = = true & & publishToServerInfo . empty ( ) = = false ) ;
2011-01-02 07:46:48 +01:00
needToRepublishToMasterserver = false ;
std : : map < string , string > newPublishToServerInfo = publishToServerInfo ;
2011-01-02 01:39:13 +01:00
publishToServerInfo . clear ( ) ;
2011-09-24 09:46:56 +02:00
//printf("simpleTask broadCastSettings = %d\n",broadCastSettings);
2011-01-02 07:46:48 +01:00
if ( callingThread - > getQuitStatus ( ) = = true ) {
2011-01-02 01:39:13 +01:00
return ;
}
2010-12-07 07:12:51 +01:00
2011-01-02 10:33:37 +01:00
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - C\n");
2011-01-02 01:39:13 +01:00
if ( republish = = true ) {
2012-01-06 07:55:27 +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 01:39:07 +02:00
2014-01-25 03:20:01 +01:00
string request = Config : : getInstance ( ) . getString ( " Masterserver " ) ;
if ( request ! = " " ) {
endPathWithSlash ( request , false ) ;
}
request + = " addServerInfo.php? " ;
2010-12-20 17:45:31 +01:00
2011-11-23 09:00:09 +01:00
//CURL *handle = SystemFlags::initHTTP();
CURL * handle = callingThread - > getGenericData < CURL > ( ) ;
2012-02-25 09:46:48 +01:00
int paramIndex = 0 ;
2011-01-02 01:39:13 +01:00
for ( std : : map < string , string > : : const_iterator iterMap = newPublishToServerInfo . begin ( ) ;
2011-09-01 01:10:43 +02:00
iterMap ! = newPublishToServerInfo . end ( ) ; + + iterMap ) {
2010-12-20 17:45:31 +01:00
2011-01-02 01:39:13 +01:00
request + = iterMap - > first ;
request + = " = " ;
request + = SystemFlags : : escapeURL ( iterMap - > second , handle ) ;
2012-02-25 09:46:48 +01:00
paramIndex + + ;
2013-11-19 07:14:06 +01:00
if ( paramIndex < ( int ) newPublishToServerInfo . size ( ) ) {
2012-02-25 09:46:48 +01:00
request + = " & " ;
}
2011-01-02 01:39:13 +01:00
}
2010-06-23 16:49:20 +02:00
2013-10-31 01:57:36 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " The Lobby request is: \n %s \n " , request . c_str ( ) ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] the request is: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , request . c_str ( ) ) ;
2011-01-02 07:46:48 +01:00
safeMutex . ReleaseLock ( true ) ;
2011-01-02 10:33:37 +01:00
safeMutexThreadOwner . ReleaseLock ( ) ;
2010-12-20 22:59:46 +01:00
2011-01-02 01:39:13 +01:00
std : : string serverInfo = SystemFlags : : getHTTP ( request , handle ) ;
2011-11-23 09:00:09 +01:00
//SystemFlags::cleanupHTTP(&handle);
2010-12-20 22:59:46 +01:00
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutexThreadOwner2 ( callingThread - > getMutexThreadOwnerValid ( ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-02 10:33:37 +01:00
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner2 . isValidMutex ( ) = = false ) {
2011-01-02 07:46:48 +01:00
return ;
}
safeMutex . Lock ( ) ;
2011-01-02 10:33:37 +01:00
2011-01-02 01:39:13 +01:00
//printf("the result is:\n'%s'\n",serverInfo.c_str());
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] the result is: \n '%s' \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , serverInfo . c_str ( ) ) ;
2010-06-23 16:49:20 +02:00
2011-01-02 01:39:13 +01:00
// uncomment to enable router setup check of this server
if ( EndsWith ( serverInfo , " OK " ) = = false ) {
2011-01-02 10:33:37 +01:00
if ( callingThread - > getQuitStatus ( ) = = true ) {
return ;
}
2012-03-03 09:28:15 +01:00
// Give things another chance to see if we can get a connection from the master server
if ( tMasterserverErrorElapsed > 0 & &
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , tMasterserverErrorElapsed ) > MASTERSERVER_BROADCAST_MAX_WAIT_RESPONSE_SECONDS ) {
2012-03-03 09:28:15 +01:00
showMasterserverError = true ;
masterServererErrorToShow = ( serverInfo ! = " " ? serverInfo : " No Reply " ) ;
}
else {
if ( tMasterserverErrorElapsed = = 0 ) {
tMasterserverErrorElapsed = time ( NULL ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line %d] error checking response from masterserver elapsed seconds = %.2f / %d \n Response: \n %s \n " ,
2012-09-22 22:13:57 +02:00
extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , difftime ( ( long int ) time ( NULL ) , tMasterserverErrorElapsed ) , MASTERSERVER_BROADCAST_MAX_WAIT_RESPONSE_SECONDS , serverInfo . c_str ( ) ) ;
2012-03-03 09:28:15 +01:00
needToRepublishToMasterserver = true ;
}
2011-01-02 01:39:13 +01:00
}
2011-01-02 10:33:37 +01:00
}
else {
safeMutexThreadOwner . ReleaseLock ( ) ;
2011-01-02 01:39:13 +01:00
}
2010-06-01 01:39:07 +02:00
2012-01-06 07:55:27 +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 01:39:07 +02:00
2011-01-02 10:33:37 +01:00
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - D\n");
2010-12-07 07:12:51 +01:00
2013-11-07 19:39:08 +01:00
safeMutex . ReleaseLock ( ) ;
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - F\n");
}
catch ( const std : : exception & ex ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
if ( callingThread - > getQuitStatus ( ) = = false ) {
//throw megaglest_runtime_error(szBuf);
showGeneralError = true ;
generalErrorToShow = ex . what ( ) ;
}
}
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
}
void MenuStateCustomGame : : simpleTaskForClients ( BaseThread * callingThread ) {
try {
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - A\n");
MutexSafeWrapper safeMutexThreadOwner ( callingThread - > getMutexThreadOwnerValid ( ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
return ;
}
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - B\n");
MutexSafeWrapper safeMutex ( callingThread - > getMutexThreadObjectAccessor ( ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
bool broadCastSettings = needToBroadcastServerSettings ;
//printf("simpleTask broadCastSettings = %d\n",broadCastSettings);
needToBroadcastServerSettings = false ;
bool hasClientConnection = false ;
if ( broadCastSettings = = true ) {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( false ) ;
if ( serverInterface ! = NULL ) {
hasClientConnection = serverInterface - > hasClientConnection ( ) ;
}
}
bool needPing = ( difftime ( ( long int ) time ( NULL ) , lastNetworkPing ) > = GameConstants : : networkPingInterval ) ;
if ( callingThread - > getQuitStatus ( ) = = true ) {
return ;
}
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - C\n");
safeMutexThreadOwner . ReleaseLock ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - D\n");
2011-01-02 07:46:48 +01:00
if ( broadCastSettings = = true ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutexThreadOwner2 ( callingThread - > getMutexThreadOwnerValid ( ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-02 10:33:37 +01:00
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner2 . isValidMutex ( ) = = false ) {
return ;
}
2010-06-01 01:39:07 +02:00
2012-01-06 07:55:27 +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-09-24 09:46:56 +02:00
//printf("simpleTask broadCastSettings = %d hasClientConnection = %d\n",broadCastSettings,hasClientConnection);
2011-01-02 10:33:37 +01:00
if ( callingThread - > getQuitStatus ( ) = = true ) {
return ;
}
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( false ) ;
if ( serverInterface ! = NULL ) {
2014-10-28 21:52:10 +01:00
lastGameSettingsreceivedCount + + ;
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = false | | ( serverInterface - > getGameSettingsUpdateCount ( ) < = lastMasterServerSettingsUpdateCount ) ) {
2011-10-01 10:04:30 +02:00
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
//printf("\n\n\n\n=====#2 got settings [%d] [%d]:\n%s\n",lastMasterServerSettingsUpdateCount,serverInterface->getGameSettingsUpdateCount(),gameSettings.toString().c_str());
2012-01-06 07:55:27 +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-01 10:04:30 +02:00
2011-09-26 06:50:13 +02:00
serverInterface - > setGameSettings ( & gameSettings , false ) ;
2011-10-01 10:04:30 +02:00
lastMasterServerSettingsUpdateCount = serverInterface - > getGameSettingsUpdateCount ( ) ;
2011-09-26 06:50:13 +02:00
if ( hasClientConnection = = true ) {
2012-01-06 07:55:27 +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-09-26 06:50:13 +02:00
serverInterface - > broadcastGameSetup ( & gameSettings ) ;
}
}
2011-01-02 01:39:13 +01:00
}
}
2010-06-01 01:39:07 +02:00
2011-01-02 10:33:37 +01:00
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - E\n");
2010-12-07 07:12:51 +01:00
2011-01-02 01:39:13 +01:00
if ( needPing = = true ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutexThreadOwner2 ( callingThread - > getMutexThreadOwnerValid ( ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-02 10:33:37 +01:00
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner2 . isValidMutex ( ) = = false ) {
return ;
}
2011-01-02 01:39:13 +01:00
lastNetworkPing = time ( NULL ) ;
2010-07-09 19:12:57 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] Sending nmtPing to clients \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-20 23:06:20 +02:00
2011-01-02 10:33:37 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( false ) ;
if ( serverInterface ! = NULL ) {
2012-01-06 07:55:27 +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-01-12 01:16:50 +01:00
NetworkMessagePing * msg = new NetworkMessagePing ( GameConstants : : networkPingInterval , time ( NULL ) ) ;
//serverInterface->broadcastPing(&msg);
serverInterface - > queueBroadcastMessage ( msg ) ;
2012-01-06 07:55:27 +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-01-02 10:33:37 +01:00
}
2011-01-02 01:39:13 +01:00
}
2011-01-02 07:46:48 +01:00
safeMutex . ReleaseLock ( ) ;
2011-01-02 10:33:37 +01:00
//printf("-=-=-=-=- IN MenuStateCustomGame simpleTask - F\n");
2011-01-02 01:39:13 +01:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2011-01-02 07:46:48 +01:00
if ( callingThread - > getQuitStatus ( ) = = false ) {
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error(szBuf);
2011-01-02 07:46:48 +01:00
showGeneralError = true ;
generalErrorToShow = ex . what ( ) ;
}
2010-07-09 19:12:57 +02:00
}
2012-01-06 07:55:27 +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-13 00:58:00 +02:00
}
2011-09-10 03:45:34 +02:00
void MenuStateCustomGame : : loadGameSettings ( GameSettings * gameSettings , bool forceCloseUnusedSlots ) {
2012-01-06 07:55:27 +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 23:00:01 +01:00
int factionCount = 0 ;
2010-04-23 01:18:04 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2010-03-13 23:00:01 +01:00
2012-01-06 07:55:27 +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-31 22:49:23 +02:00
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = true & & serverInterface - > getGameSettingsUpdateCount ( ) > lastMasterServerSettingsUpdateCount & &
2011-09-24 09:46:56 +02:00
serverInterface - > getGameSettings ( ) ! = NULL ) {
const GameSettings * settings = serverInterface - > getGameSettings ( ) ;
2011-10-01 10:04:30 +02:00
//printf("\n\n\n\n=====#3 got settings [%d] [%d]:\n%s\n",lastMasterServerSettingsUpdateCount,serverInterface->getGameSettingsUpdateCount(),settings->toString().c_str());
2011-09-24 09:46:56 +02:00
lastMasterServerSettingsUpdateCount = serverInterface - > getGameSettingsUpdateCount ( ) ;
//printf("#1 custom menu got map [%s]\n",settings->getMap().c_str());
setupUIFromGameSettings ( * settings ) ;
}
2014-11-07 01:26:23 +01:00
gameSettings - > setGameName ( labelGameName . getText ( ) ) ;
2010-12-19 09:04:25 +01:00
// Test flags values
//gameSettings->setFlagTypes1(ft1_show_map_resources);
//
2011-12-26 07:29:14 +01:00
if ( checkBoxScenario . getValue ( ) = = true ) {
gameSettings - > setScenario ( scenarioInfo . name ) ;
gameSettings - > setScenarioDir ( Scenario : : getScenarioPath ( dirList , scenarioInfo . name ) ) ;
2011-12-26 08:11:52 +01:00
gameSettings - > setDefaultResources ( scenarioInfo . defaultResources ) ;
gameSettings - > setDefaultUnits ( scenarioInfo . defaultUnits ) ;
gameSettings - > setDefaultVictoryConditions ( scenarioInfo . defaultVictoryConditions ) ;
2011-12-26 07:29:14 +01:00
}
else {
gameSettings - > setScenario ( " " ) ;
gameSettings - > setScenarioDir ( " " ) ;
}
2013-10-31 01:57:36 +01:00
gameSettings - > setGameUUID ( this - > gameUUID ) ;
2011-12-28 05:46:36 +01:00
//printf("scenarioInfo.name [%s] [%s] [%s]\n",scenarioInfo.name.c_str(),listBoxMap.getSelectedItem().c_str(),getCurrentMapFile().c_str());
2010-08-30 22:02:58 +02:00
gameSettings - > setMapFilterIndex ( listBoxMapFilter . getSelectedItemIndex ( ) ) ;
gameSettings - > setDescription ( formatString ( getCurrentMapFile ( ) ) ) ;
gameSettings - > setMap ( getCurrentMapFile ( ) ) ;
2013-11-01 06:25:55 +01:00
if ( tilesetFiles . empty ( ) = = false ) {
gameSettings - > setTileset ( tilesetFiles [ listBoxTileset . getSelectedItemIndex ( ) ] ) ;
}
if ( techTreeFiles . empty ( ) = = false ) {
gameSettings - > setTech ( techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] ) ;
}
2011-09-16 02:34:14 +02:00
if ( autoStartSettings ! = NULL ) {
gameSettings - > setDefaultUnits ( autoStartSettings - > getDefaultUnits ( ) ) ;
gameSettings - > setDefaultResources ( autoStartSettings - > getDefaultResources ( ) ) ;
gameSettings - > setDefaultVictoryConditions ( autoStartSettings - > getDefaultVictoryConditions ( ) ) ;
}
2011-12-26 08:11:52 +01:00
else if ( checkBoxScenario . getValue ( ) = = false ) {
2011-09-16 02:34:14 +02:00
gameSettings - > setDefaultUnits ( true ) ;
gameSettings - > setDefaultResources ( true ) ;
gameSettings - > setDefaultVictoryConditions ( true ) ;
}
2011-12-26 08:11:52 +01:00
gameSettings - > setFogOfWar ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 0 | |
2010-12-20 22:59:46 +01:00
listBoxFogOfWar . getSelectedItemIndex ( ) = = 1 ) ;
2010-09-04 03:24:17 +02:00
2012-10-22 17:52:08 +02:00
gameSettings - > setAllowObservers ( checkBoxAllowObservers . getValue ( ) = = 1 ) ;
2010-09-04 03:24:17 +02:00
2010-12-19 09:36:59 +01:00
uint32 valueFlags1 = gameSettings - > getFlagTypes1 ( ) ;
2010-12-23 11:44:11 +01:00
if ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 1 | |
listBoxFogOfWar . getSelectedItemIndex ( ) = = 2 ) {
2010-12-19 09:36:59 +01:00
valueFlags1 | = ft1_show_map_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_show_map_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
2011-11-21 03:08:51 +01:00
//gameSettings->setEnableObserverModeAtEndGame(listBoxEnableObserverMode.getSelectedItemIndex() == 0);
gameSettings - > setEnableObserverModeAtEndGame ( true ) ;
2012-09-22 23:44:30 +02:00
//gameSettings->setPathFinderType(static_cast<PathFinderType>(listBoxPathFinderType.getSelectedItemIndex()));
2010-03-13 23:00:01 +01:00
2011-09-21 08:51:28 +02:00
valueFlags1 = gameSettings - > getFlagTypes1 ( ) ;
2012-10-22 19:53:48 +02:00
if ( checkBoxEnableSwitchTeamMode . getValue ( ) = = true ) {
2011-09-21 08:51:28 +02:00
valueFlags1 | = ft1_allow_team_switching ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_allow_team_switching ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
gameSettings - > setAiAcceptSwitchTeamPercentChance ( strToInt ( listBoxAISwitchTeamAcceptPercent . getSelectedItem ( ) ) ) ;
2012-09-17 01:42:56 +02:00
gameSettings - > setFallbackCpuMultiplier ( listBoxFallbackCpuMultiplier . getSelectedItemIndex ( ) ) ;
2011-09-21 08:51:28 +02:00
2013-02-15 19:25:10 +01:00
if ( checkBoxAllowInGameJoinPlayer . getValue ( ) = = true ) {
valueFlags1 | = ft1_allow_in_game_joining ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_allow_in_game_joining ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
2014-01-27 23:15:05 +01:00
if ( checkBoxAllowTeamUnitSharing . getValue ( ) = = true ) {
valueFlags1 | = ft1_allow_shared_team_units ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_allow_shared_team_units ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
if ( checkBoxAllowTeamResourceSharing . getValue ( ) = = true ) {
valueFlags1 | = ft1_allow_shared_team_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_allow_shared_team_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
2013-09-12 05:33:43 +02:00
if ( Config : : getInstance ( ) . getBool ( " EnableNetworkGameSynchChecks " , " false " ) = = true ) {
2013-09-19 03:19:36 +02:00
//printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n");
2013-09-18 23:43:25 +02:00
2013-09-24 21:35:35 +02:00
valueFlags1 | = ft1_network_synch_checks_verbose ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_network_synch_checks_verbose ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
2013-10-29 02:56:57 +01:00
if ( Config : : getInstance ( ) . getBool ( " EnableNetworkGameSynchMonitor " , " false " ) = = true ) {
2013-09-24 21:35:35 +02:00
//printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n");
2013-09-12 05:33:43 +02:00
valueFlags1 | = ft1_network_synch_checks ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_network_synch_checks ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
2013-06-13 03:37:15 +02:00
gameSettings - > setNetworkAllowNativeLanguageTechtree ( checkBoxAllowNativeLanguageTechtree . getValue ( ) ) ;
2010-06-25 06:06:28 +02:00
// First save Used slots
//for(int i=0; i<mapInfo.players; ++i)
2010-06-25 07:41:50 +02:00
int AIPlayerCount = 0 ;
2010-06-25 06:06:28 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2012-10-04 00:27:59 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman & & this - > headlessServerMode = = true ) {
// switch slot to network, because no human in headless mode
listBoxControls [ i ] . setSelectedItemIndex ( ctNetwork ) ;
2012-10-06 00:43:00 +02:00
updateResourceMultiplier ( i ) ;
2012-10-04 00:27:59 +02:00
}
2010-03-13 23:00:01 +01:00
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
2011-09-10 03:45:34 +02:00
if ( forceCloseUnusedSlots = = true & & ( ct = = ctNetworkUnassigned | | ct = = ctNetwork ) ) {
2013-12-14 08:04:12 +01:00
if ( serverInterface ! = NULL & &
2014-01-08 21:48:56 +01:00
( serverInterface - > getSlot ( i , true ) = = NULL | |
serverInterface - > getSlot ( i , true ) - > isConnected ( ) = = false ) ) {
2012-03-27 05:23:03 +02:00
if ( checkBoxScenario . getValue ( ) = = false ) {
2011-09-10 03:45:34 +02:00
//printf("Closed A [%d] [%s]\n",i,labelPlayerNames[i].getText().c_str());
2012-03-27 05:23:03 +02:00
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
ct = ctClosed ;
}
2011-09-10 03:45:34 +02:00
}
}
2011-10-15 01:51:44 +02:00
else if ( ct = = ctNetworkUnassigned & & i < mapInfo . players ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctNetwork ) ;
ct = ctNetwork ;
}
2011-09-10 03:45:34 +02:00
2010-06-25 06:06:28 +02:00
if ( ct ! = ctClosed ) {
int slotIndex = factionCount ;
2010-08-21 15:04:52 +02:00
gameSettings - > setFactionControl ( slotIndex , ct ) ;
2010-06-25 06:06:28 +02:00
if ( ct = = ctHuman ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, slotIndex = %d, getHumanPlayerName(i) [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , slotIndex , getHumanPlayerName ( i ) . c_str ( ) ) ;
2010-08-23 06:33:21 +02:00
2010-06-25 06:06:28 +02:00
gameSettings - > setThisFactionIndex ( slotIndex ) ;
2010-08-23 06:33:21 +02:00
gameSettings - > setNetworkPlayerName ( slotIndex , getHumanPlayerName ( i ) ) ;
2013-06-01 04:31:12 +02:00
gameSettings - > setNetworkPlayerUUID ( slotIndex , Config : : getInstance ( ) . getString ( " PlayerId " , " " ) ) ;
2013-11-02 20:05:59 +01:00
gameSettings - > setNetworkPlayerPlatform ( slotIndex , getPlatformNameString ( ) ) ;
2011-03-11 12:11:46 +01:00
gameSettings - > setNetworkPlayerStatuses ( slotIndex , getNetworkPlayerStatus ( ) ) ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
gameSettings - > setNetworkPlayerLanguages ( slotIndex , lang . getLanguage ( ) ) ;
2010-03-13 23:00:01 +01:00
}
2014-01-08 21:48:56 +01:00
else if ( serverInterface ! = NULL & & serverInterface - > getSlot ( i , true ) ! = NULL ) {
gameSettings - > setNetworkPlayerLanguages ( slotIndex , serverInterface - > getSlot ( i , true ) - > getNetworkPlayerLanguage ( ) ) ;
2011-04-05 22:19:25 +02:00
}
2012-10-06 00:43:00 +02:00
//if(slotIndex == 0) printf("slotIndex = %d, i = %d, multiplier = %d\n",slotIndex,i,listBoxRMultiplier[i].getSelectedItemIndex());
2013-06-20 21:18:29 +02:00
//printf("Line: %d multiplier index: %d slotIndex: %d\n",__LINE__,listBoxRMultiplier[i].getSelectedItemIndex(),slotIndex);
2010-11-25 23:45:08 +01:00
gameSettings - > setResourceMultiplierIndex ( slotIndex , listBoxRMultiplier [ i ] . getSelectedItemIndex ( ) ) ;
2013-06-20 21:18:29 +02:00
//printf("Line: %d multiplier index: %d slotIndex: %d\n",__LINE__,gameSettings->getResourceMultiplierIndex(slotIndex),slotIndex);
2011-03-29 11:45:15 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] . c_str ( ) ) ;
2011-03-29 11:45:15 +02:00
2010-09-04 02:32:56 +02:00
gameSettings - > setFactionTypeName ( slotIndex , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ) ;
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
listBoxTeams [ i ] . setSelectedItem ( intToStr ( GameConstants : : maxPlayers + fpt_Observer ) ) ;
}
else if ( listBoxTeams [ i ] . getSelectedItem ( ) = = intToStr ( GameConstants : : maxPlayers + fpt_Observer ) ) {
2010-10-22 19:20:55 +02:00
2012-10-13 07:06:53 +02:00
//printf("Line: %d lastSelectedTeamIndex[i] = %d \n",__LINE__,lastSelectedTeamIndex[i]);
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuEasy | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpu | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuUltra | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuMega ) & &
checkBoxScenario . getValue ( ) = = true ) {
2010-10-22 19:20:55 +02:00
}
else {
2012-10-13 07:06:53 +02:00
if ( lastSelectedTeamIndex [ i ] > = 0 & & lastSelectedTeamIndex [ i ] + 1 ! = ( GameConstants : : maxPlayers + fpt_Observer ) ) {
if ( lastSelectedTeamIndex [ i ] = = 0 ) {
lastSelectedTeamIndex [ i ] = GameConstants : : maxPlayers - 1 ;
}
else if ( lastSelectedTeamIndex [ i ] = = GameConstants : : maxPlayers - 1 ) {
lastSelectedTeamIndex [ i ] = 0 ;
}
listBoxTeams [ i ] . setSelectedItemIndex ( lastSelectedTeamIndex [ i ] ) ;
}
else {
listBoxTeams [ i ] . setSelectedItem ( intToStr ( 1 ) ) ;
}
2010-10-22 19:20:55 +02:00
}
2010-09-04 02:32:56 +02:00
}
2010-06-25 06:06:28 +02:00
gameSettings - > setTeam ( slotIndex , listBoxTeams [ i ] . getSelectedItemIndex ( ) ) ;
gameSettings - > setStartLocationIndex ( slotIndex , i ) ;
2010-09-04 02:32:56 +02:00
2013-12-15 07:37:15 +01:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
if ( serverInterface ! = NULL & &
2014-01-08 21:48:56 +01:00
serverInterface - > getSlot ( i , true ) ! = NULL & &
serverInterface - > getSlot ( i , true ) - > isConnected ( ) ) {
2011-03-11 12:11:46 +01:00
2014-01-08 21:48:56 +01:00
gameSettings - > setNetworkPlayerStatuses ( slotIndex , serverInterface - > getSlot ( i , true ) - > getNetworkPlayerStatus ( ) ) ;
2011-03-11 12:11:46 +01:00
2014-01-08 21:48:56 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, connectionSlot->getName() [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , serverInterface - > getSlot ( i , true ) - > getName ( ) . c_str ( ) ) ;
2010-08-23 06:33:21 +02:00
2014-01-08 21:48:56 +01:00
gameSettings - > setNetworkPlayerName ( slotIndex , serverInterface - > getSlot ( i , true ) - > getName ( ) ) ;
gameSettings - > setNetworkPlayerUUID ( i , serverInterface - > getSlot ( i , true ) - > getUUID ( ) ) ;
gameSettings - > setNetworkPlayerPlatform ( i , serverInterface - > getSlot ( i , true ) - > getPlatform ( ) ) ;
labelPlayerNames [ i ] . setText ( serverInterface - > getSlot ( i , true ) - > getName ( ) ) ;
2010-04-23 01:18:04 +02:00
}
2010-06-25 06:06:28 +02:00
else {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, playername unconnected \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i ) ;
2010-08-23 06:33:21 +02:00
2010-06-29 08:50:35 +02:00
gameSettings - > setNetworkPlayerName ( slotIndex , GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) ;
2010-08-23 06:33:21 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
2010-04-23 01:18:04 +02:00
}
}
2010-08-21 15:04:52 +02:00
else if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctHuman ) {
2010-06-25 07:41:50 +02:00
AIPlayerCount + + ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, playername is AI (blank) \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i ) ;
2010-08-23 06:33:21 +02:00
2012-06-12 01:50:30 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2013-10-29 07:13:38 +01:00
gameSettings - > setNetworkPlayerName ( slotIndex , lang . getString ( " AI " ) + intToStr ( AIPlayerCount ) ) ;
2010-08-23 06:33:21 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
2010-04-23 01:18:04 +02:00
}
2013-10-25 21:35:10 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
setSlotHuman ( i ) ;
}
2014-01-08 21:48:56 +01:00
if ( serverInterface ! = NULL & & serverInterface - > getSlot ( i , true ) ! = NULL ) {
gameSettings - > setNetworkPlayerUUID ( slotIndex , serverInterface - > getSlot ( i , true ) - > getUUID ( ) ) ;
gameSettings - > setNetworkPlayerPlatform ( slotIndex , serverInterface - > getSlot ( i , true ) - > getPlatform ( ) ) ;
2013-06-01 04:31:12 +02:00
}
2010-03-13 23:00:01 +01:00
factionCount + + ;
}
2010-08-23 06:33:21 +02:00
else {
//gameSettings->setNetworkPlayerName("");
2012-10-07 00:18:09 +02:00
gameSettings - > setNetworkPlayerStatuses ( factionCount , npst_None ) ;
2010-08-23 06:33:21 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
}
2010-03-13 23:00:01 +01:00
}
2010-10-08 03:41:53 +02:00
2010-06-25 06:06:28 +02:00
// Next save closed slots
int closedCount = 0 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctClosed ) {
int slotIndex = factionCount + closedCount ;
gameSettings - > setFactionControl ( slotIndex , ct ) ;
gameSettings - > setTeam ( slotIndex , listBoxTeams [ i ] . getSelectedItemIndex ( ) ) ;
gameSettings - > setStartLocationIndex ( slotIndex , i ) ;
2013-11-01 01:23:43 +01:00
//gameSettings->setResourceMultiplierIndex(slotIndex, 10);
listBoxRMultiplier [ i ] . setSelectedItem ( " 1.0 " ) ;
gameSettings - > setResourceMultiplierIndex ( slotIndex , listBoxRMultiplier [ i ] . getSelectedItemIndex ( ) ) ;
//printf("Test multiplier = %s\n",listBoxRMultiplier[i].getSelectedItem().c_str());
2010-09-11 10:09:33 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] . c_str ( ) ) ;
2011-03-29 11:45:15 +02:00
2010-06-25 06:06:28 +02:00
gameSettings - > setFactionTypeName ( slotIndex , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ) ;
gameSettings - > setNetworkPlayerName ( slotIndex , " Closed " ) ;
2013-06-01 04:31:12 +02:00
gameSettings - > setNetworkPlayerUUID ( slotIndex , " " ) ;
2013-11-02 20:05:59 +01:00
gameSettings - > setNetworkPlayerPlatform ( slotIndex , " " ) ;
2010-06-25 06:06:28 +02:00
closedCount + + ;
}
}
2010-03-13 23:00:01 +01:00
gameSettings - > setFactionCount ( factionCount ) ;
2010-10-26 23:52:00 +02:00
Config & config = Config : : getInstance ( ) ;
gameSettings - > setEnableServerControlledAI ( config . getBool ( " ServerControlledAI " , " true " ) ) ;
gameSettings - > setNetworkFramePeriod ( config . getInt ( " NetworkSendFrameCount " , " 20 " ) ) ;
2012-10-22 17:52:08 +02:00
gameSettings - > setNetworkPauseGameForLaggedClients ( ( ( checkBoxNetworkPauseGameForLaggedClients . getValue ( ) = = true ) ) ) ;
2011-01-09 05:49:21 +01:00
2013-06-23 07:23:02 +02:00
if ( gameSettings - > getTileset ( ) ! = " " ) {
// Check if client has different data, if so force a CRC refresh
2013-06-25 01:36:03 +02:00
bool forceRefresh = false ;
2013-06-23 07:23:02 +02:00
if ( checkNetworkPlayerDataSynch ( false , true , false ) = = false & &
last_Forced_CheckedCRCTilesetName ! = gameSettings - > getTileset ( ) ) {
lastCheckedCRCTilesetName = " " ;
2013-06-25 01:36:03 +02:00
forceRefresh = true ;
2013-06-23 07:23:02 +02:00
last_Forced_CheckedCRCTilesetName = gameSettings - > getTileset ( ) ;
}
if ( lastCheckedCRCTilesetName ! = gameSettings - > getTileset ( ) ) {
//console.addLine("Checking tileset CRC [" + gameSettings->getTileset() + "]");
2013-06-25 01:36:03 +02:00
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL , forceRefresh ) ;
2013-06-23 07:23:02 +02:00
if ( lastCheckedCRCTilesetValue = = 0 ) {
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL , true ) ;
2011-03-22 03:02:54 +01:00
}
2013-06-23 07:23:02 +02:00
lastCheckedCRCTilesetName = gameSettings - > getTileset ( ) ;
2011-03-19 06:11:36 +01:00
}
2013-06-23 07:23:02 +02:00
gameSettings - > setTilesetCRC ( lastCheckedCRCTilesetValue ) ;
}
2011-01-09 05:49:21 +01:00
2013-06-23 07:23:02 +02:00
if ( config . getBool ( " DisableServerLobbyTechtreeCRCCheck " , " false " ) = = false ) {
if ( gameSettings - > getTech ( ) ! = " " ) {
// Check if client has different data, if so force a CRC refresh
2013-06-25 01:36:03 +02:00
bool forceRefresh = false ;
2013-06-23 07:23:02 +02:00
if ( checkNetworkPlayerDataSynch ( false , false , true ) = = false & &
last_Forced_CheckedCRCTechtreeName ! = gameSettings - > getTech ( ) ) {
lastCheckedCRCTechtreeName = " " ;
2013-09-19 03:19:36 +02:00
forceRefresh = true ;
2013-06-23 07:23:02 +02:00
last_Forced_CheckedCRCTechtreeName = gameSettings - > getTech ( ) ;
}
2011-03-22 03:02:54 +01:00
2013-06-23 07:23:02 +02:00
if ( lastCheckedCRCTechtreeName ! = gameSettings - > getTech ( ) ) {
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
2013-06-25 01:36:03 +02:00
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /* " , " .xml " , NULL , forceRefresh ) ;
2013-06-23 07:23:02 +02:00
if ( lastCheckedCRCTechtreeValue = = 0 ) {
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /* " , " .xml " , NULL , true ) ;
}
reloadFactions ( true , ( checkBoxScenario . getValue ( ) = = true ? scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] : " " ) ) ;
factionCRCList . clear ( ) ;
for ( unsigned int factionIdx = 0 ; factionIdx < factionFiles . size ( ) ; + + factionIdx ) {
string factionName = factionFiles [ factionIdx ] ;
if ( factionName ! = GameConstants : : RANDOMFACTION_SLOTNAME & &
factionName ! = GameConstants : : OBSERVER_SLOTNAME ) {
//factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true);
uint32 factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL ) ;
if ( factionCRC = = 0 ) {
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL , true ) ;
2011-03-22 03:02:54 +01:00
}
2013-06-23 07:23:02 +02:00
factionCRCList . push_back ( make_pair ( factionName , factionCRC ) ) ;
2011-03-22 03:02:54 +01:00
}
}
2013-06-23 07:23:02 +02:00
//console.addLine("Found factions: " + intToStr(factionCRCList.size()));
lastCheckedCRCTechtreeName = gameSettings - > getTech ( ) ;
2011-03-22 03:02:54 +01:00
}
2010-03-13 23:00:01 +01:00
2013-06-23 07:23:02 +02:00
gameSettings - > setFactionCRCList ( factionCRCList ) ;
gameSettings - > setTechCRC ( lastCheckedCRCTechtreeValue ) ;
2011-03-22 03:02:54 +01:00
}
}
2011-09-24 09:46:56 +02:00
2013-06-23 07:23:02 +02:00
if ( gameSettings - > getMap ( ) ! = " " ) {
// Check if client has different data, if so force a CRC refresh
2013-09-19 08:32:47 +02:00
//bool forceRefresh = false;
2013-06-23 07:23:02 +02:00
if ( checkNetworkPlayerDataSynch ( true , false , false ) = = false & &
last_Forced_CheckedCRCMapName ! = gameSettings - > getMap ( ) ) {
lastCheckedCRCMapName = " " ;
2013-09-19 08:32:47 +02:00
//forceRefresh = true;
2013-06-23 07:23:02 +02:00
last_Forced_CheckedCRCMapName = gameSettings - > getMap ( ) ;
}
if ( lastCheckedCRCMapName ! = gameSettings - > getMap ( ) ) {
Checksum checksum ;
2013-12-17 08:54:33 +01:00
string file = Config : : getMapPath ( gameSettings - > getMap ( ) , " " , false ) ;
2013-06-23 07:23:02 +02:00
//console.addLine("Checking map CRC [" + file + "]");
checksum . addFile ( file ) ;
lastCheckedCRCMapValue = checksum . getSum ( ) ;
lastCheckedCRCMapName = gameSettings - > getMap ( ) ;
}
gameSettings - > setMapCRC ( lastCheckedCRCMapValue ) ;
}
2011-10-21 02:23:05 +02:00
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = true ) {
2011-09-24 09:46:56 +02:00
time_t clientConnectedTime = 0 ;
2011-10-21 02:23:05 +02:00
bool masterserver_admin_found = false ;
2011-09-24 09:46:56 +02:00
//printf("mapInfo.players [%d]\n",mapInfo.players);
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2012-01-06 07:55:27 +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-09-24 09:46:56 +02:00
2012-06-22 03:57:59 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
2012-01-06 07:55:27 +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-09-24 09:46:56 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & & serverInterface - > getSlot ( i , true ) - > isConnected ( ) ) {
2012-01-06 07:55:27 +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-09-24 09:46:56 +02:00
2011-09-25 07:38:35 +02:00
//printf("slot = %d serverInterface->getSlot(i)->getConnectedTime() = %d session key [%d]\n",i,serverInterface->getSlot(i)->getConnectedTime(),serverInterface->getSlot(i)->getSessionKey());
2011-09-24 09:46:56 +02:00
2012-04-16 21:29:37 +02:00
if ( clientConnectedTime = = 0 | |
2014-01-08 21:48:56 +01:00
( serverInterface - > getSlot ( i , true ) - > getConnectedTime ( ) > 0 & & serverInterface - > getSlot ( i , true ) - > getConnectedTime ( ) < clientConnectedTime ) ) {
clientConnectedTime = serverInterface - > getSlot ( i , true ) - > getConnectedTime ( ) ;
gameSettings - > setMasterserver_admin ( serverInterface - > getSlot ( i , true ) - > getSessionKey ( ) ) ;
gameSettings - > setMasterserver_admin_faction_index ( serverInterface - > getSlot ( i , true ) - > getPlayerIndex ( ) ) ;
labelGameName . setText ( serverInterface - > getSlot ( i , true ) - > getName ( ) + " controls " ) ;
2012-11-10 07:37:23 +01:00
//printf("slot = %d, admin key [%d] slot connected time[" MG_SIZE_T_SPECIFIER "] clientConnectedTime [" MG_SIZE_T_SPECIFIER "]\n",i,gameSettings->getMasterserver_admin(),serverInterface->getSlot(i)->getConnectedTime(),clientConnectedTime);
2011-09-24 09:46:56 +02:00
}
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getSessionKey ( ) = = gameSettings - > getMasterserver_admin ( ) ) {
2011-10-21 01:27:39 +02:00
masterserver_admin_found = true ;
}
2011-09-24 09:46:56 +02:00
}
}
}
2012-06-30 21:31:52 +02:00
if ( masterserver_admin_found = = false ) {
for ( int i = mapInfo . players ; i < GameConstants : : maxPlayers ; + + i ) {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2013-11-19 07:14:06 +01:00
//ConnectionSlot *slot = serverInterface->getSlot(i);
2012-06-30 21:31:52 +02:00
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & & serverInterface - > getSlot ( i , true ) - > isConnected ( ) ) {
2012-06-30 21:31:52 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
//printf("slot = %d serverInterface->getSlot(i)->getConnectedTime() = %d session key [%d]\n",i,serverInterface->getSlot(i)->getConnectedTime(),serverInterface->getSlot(i)->getSessionKey());
if ( clientConnectedTime = = 0 | |
2014-01-08 21:48:56 +01:00
( serverInterface - > getSlot ( i , true ) - > getConnectedTime ( ) > 0 & & serverInterface - > getSlot ( i , true ) - > getConnectedTime ( ) < clientConnectedTime ) ) {
clientConnectedTime = serverInterface - > getSlot ( i , true ) - > getConnectedTime ( ) ;
gameSettings - > setMasterserver_admin ( serverInterface - > getSlot ( i , true ) - > getSessionKey ( ) ) ;
gameSettings - > setMasterserver_admin_faction_index ( serverInterface - > getSlot ( i , true ) - > getPlayerIndex ( ) ) ;
labelGameName . setText ( serverInterface - > getSlot ( i , true ) - > getName ( ) + " controls " ) ;
2012-11-10 07:37:23 +01:00
//printf("slot = %d, admin key [%d] slot connected time[" MG_SIZE_T_SPECIFIER "] clientConnectedTime [" MG_SIZE_T_SPECIFIER "]\n",i,gameSettings->getMasterserver_admin(),serverInterface->getSlot(i)->getConnectedTime(),clientConnectedTime);
2012-06-30 21:31:52 +02:00
}
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > getSessionKey ( ) = = gameSettings - > getMasterserver_admin ( ) ) {
2012-06-30 21:31:52 +02:00
masterserver_admin_found = true ;
}
}
}
}
if ( masterserver_admin_found = = false )
2011-10-21 02:23:05 +02:00
{
2012-11-02 18:48:25 +01:00
labelGameName . setText ( " Headless: " + defaultPlayerName ) ;
2011-10-21 02:23:05 +02:00
}
2011-09-24 09:46:56 +02:00
}
2011-10-21 01:44:01 +02:00
2012-01-06 07:55:27 +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 23:00:01 +01:00
}
2010-05-31 21:57:10 +02:00
void MenuStateCustomGame : : saveGameSettingsToFile ( std : : string fileName ) {
2012-01-06 07:55:27 +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-31 21:57:10 +02:00
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
2012-10-22 17:52:08 +02:00
CoreData : : getInstance ( ) . saveGameSettingsToFile ( fileName , & gameSettings , checkBoxAdvanced . getValue ( ) ) ;
2011-12-03 09:17:49 +01:00
2012-01-06 07:55:27 +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-31 21:57:10 +02:00
}
2014-01-25 19:07:15 +01:00
void MenuStateCustomGame : : KeepCurrentHumanPlayerSlots ( GameSettings & gameSettings ) {
//look for human players
2014-01-27 04:22:27 +01:00
bool foundValidHumanControlTypeInFile = false ;
for ( int index2 = 0 ; index2 < GameConstants : : maxPlayers ; + + index2 ) {
ControlType ctFile = static_cast < ControlType > ( gameSettings . getFactionControl ( index2 ) ) ;
if ( ctFile = = ctHuman ) {
ControlType ctUI = static_cast < ControlType > ( listBoxControls [ index2 ] . getSelectedItemIndex ( ) ) ;
if ( ctUI ! = ctNetwork & & ctUI ! = ctNetworkUnassigned ) {
foundValidHumanControlTypeInFile = true ;
//printf("Human found in file [%d]\n",index2);
}
else if ( labelPlayerNames [ index2 ] . getText ( ) = = " " ) {
foundValidHumanControlTypeInFile = true ;
}
}
}
2014-01-25 19:07:15 +01:00
for ( int index = 0 ; index < GameConstants : : maxPlayers ; + + index ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ index ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman ) {
//printf("Human found in UI [%d] and file [%d]\n",index,foundControlType);
2014-01-27 04:22:27 +01:00
if ( foundValidHumanControlTypeInFile = = false ) {
2014-01-25 19:07:15 +01:00
gameSettings . setFactionControl ( index , ctHuman ) ;
2014-01-27 04:22:27 +01:00
gameSettings . setNetworkPlayerName ( index , getHumanPlayerName ( ) ) ;
2014-01-25 19:07:15 +01:00
}
}
2014-01-30 05:26:25 +01:00
ControlType ctFile = static_cast < ControlType > ( gameSettings . getFactionControl ( index ) ) ;
if ( ctFile = = ctHuman ) {
gameSettings . setFactionControl ( index , ctHuman ) ;
}
2014-01-25 19:07:15 +01:00
}
}
2010-05-31 21:57:10 +02:00
GameSettings MenuStateCustomGame : : loadGameSettingsFromFile ( std : : string fileName ) {
2012-01-06 07:55:27 +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-31 21:57:10 +02:00
GameSettings gameSettings ;
2011-04-20 00:53:37 +02:00
GameSettings originalGameSettings ;
loadGameSettings ( & originalGameSettings ) ;
2010-05-31 21:57:10 +02:00
try {
2011-12-03 09:17:49 +01:00
CoreData : : getInstance ( ) . loadGameSettingsFromFile ( fileName , & gameSettings ) ;
2014-01-25 19:07:15 +01:00
KeepCurrentHumanPlayerSlots ( gameSettings ) ;
2014-01-25 08:50:32 +01:00
2012-10-07 02:34:45 +02:00
// correct game settings for headless:
if ( this - > headlessServerMode = = true ) {
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
if ( gameSettings . getFactionControl ( i ) = = ctHuman ) {
gameSettings . setFactionControl ( i , ctNetwork ) ;
}
}
}
2011-04-20 00:53:37 +02:00
setupUIFromGameSettings ( gameSettings ) ;
}
catch ( const exception & ex ) {
2012-01-06 07:55:27 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ERROR = [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-03-31 10:28:42 +02:00
2011-04-20 00:53:37 +02:00
showMessageBox ( ex . what ( ) , " Error " , false ) ;
2010-08-30 22:02:58 +02:00
2011-04-20 00:53:37 +02:00
setupUIFromGameSettings ( originalGameSettings ) ;
gameSettings = originalGameSettings ;
}
2010-05-31 21:57:10 +02:00
2012-01-06 07:55:27 +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 01:39:07 +02:00
2011-04-20 00:53:37 +02:00
return gameSettings ;
}
2010-05-31 21:57:10 +02:00
2011-04-20 00:53:37 +02:00
void MenuStateCustomGame : : setupUIFromGameSettings ( const GameSettings & gameSettings ) {
2013-05-01 02:44:29 +02:00
string humanPlayerName = getHumanPlayerName ( ) ;
2011-12-28 05:46:36 +01:00
string scenarioDir = " " ;
2011-12-26 07:29:14 +01:00
checkBoxScenario . setValue ( ( gameSettings . getScenario ( ) ! = " " ) ) ;
if ( checkBoxScenario . getValue ( ) = = true ) {
listBoxScenario . setSelectedItem ( formatString ( gameSettings . getScenario ( ) ) ) ;
2011-12-26 08:11:52 +01:00
loadScenarioInfo ( Scenario : : getScenarioPath ( dirList , scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] ) , & scenarioInfo ) ;
2011-12-28 05:46:36 +01:00
scenarioDir = Scenario : : getScenarioDir ( dirList , gameSettings . getScenario ( ) ) ;
2011-12-26 08:11:52 +01:00
//printf("scenarioInfo.fogOfWar = %d scenarioInfo.fogOfWar_exploredFlag = %d\n",scenarioInfo.fogOfWar,scenarioInfo.fogOfWar_exploredFlag);
if ( scenarioInfo . fogOfWar = = false & & scenarioInfo . fogOfWar_exploredFlag = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 2 ) ;
}
else if ( scenarioInfo . fogOfWar_exploredFlag = = true ) {
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
else {
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ;
}
2011-12-26 07:29:14 +01:00
}
2011-12-28 05:46:36 +01:00
setupMapList ( gameSettings . getScenario ( ) ) ;
2013-06-13 03:37:15 +02:00
setupTechList ( gameSettings . getScenario ( ) , false ) ;
2011-12-28 05:46:36 +01:00
setupTilesetList ( gameSettings . getScenario ( ) ) ;
if ( checkBoxScenario . getValue ( ) = = true ) {
//string file = Scenario::getScenarioPath(dirList, gameSettings.getScenario());
//loadScenarioInfo(file, &scenarioInfo);
//printf("#6.1 about to load map [%s]\n",scenarioInfo.mapName.c_str());
2013-12-17 08:54:33 +01:00
//loadMapInfo(Config::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
2011-12-28 05:46:36 +01:00
//printf("#6.2\n");
listBoxMapFilter . setSelectedItemIndex ( 0 ) ;
listBoxMap . setItems ( formattedPlayerSortedMaps [ mapInfo . players ] ) ;
listBoxMap . setSelectedItem ( formatString ( scenarioInfo . mapName ) ) ;
}
else {
2012-01-06 07:55:27 +01:00
if ( gameSettings . getMapFilterIndex ( ) = = 0 ) {
listBoxMapFilter . setSelectedItemIndex ( 0 ) ;
}
else {
listBoxMapFilter . setSelectedItem ( intToStr ( gameSettings . getMapFilterIndex ( ) ) ) ;
}
2011-12-28 05:46:36 +01:00
listBoxMap . setItems ( formattedPlayerSortedMaps [ gameSettings . getMapFilterIndex ( ) ] ) ;
}
//printf("gameSettings.getMap() [%s] [%s]\n",gameSettings.getMap().c_str(),listBoxMap.getSelectedItem().c_str());
2011-12-26 07:29:14 +01:00
2011-04-20 00:53:37 +02:00
string mapFile = gameSettings . getMap ( ) ;
2011-09-25 07:38:35 +02:00
if ( find ( mapFiles . begin ( ) , mapFiles . end ( ) , mapFile ) ! = mapFiles . end ( ) ) {
mapFile = formatString ( mapFile ) ;
listBoxMap . setSelectedItem ( mapFile ) ;
2010-05-31 21:57:10 +02:00
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( getCurrentMapFile ( ) , scenarioDir , true ) , & mapInfo , true ) ;
2011-09-25 07:38:35 +02:00
labelMapInfo . setText ( mapInfo . desc ) ;
}
2010-05-31 21:57:10 +02:00
2011-04-20 00:53:37 +02:00
string tilesetFile = gameSettings . getTileset ( ) ;
2011-09-25 07:38:35 +02:00
if ( find ( tilesetFiles . begin ( ) , tilesetFiles . end ( ) , tilesetFile ) ! = tilesetFiles . end ( ) ) {
tilesetFile = formatString ( tilesetFile ) ;
listBoxTileset . setSelectedItem ( tilesetFile ) ;
}
2010-05-31 21:57:10 +02:00
2011-04-20 00:53:37 +02:00
string techtreeFile = gameSettings . getTech ( ) ;
2011-09-25 07:38:35 +02:00
if ( find ( techTreeFiles . begin ( ) , techTreeFiles . end ( ) , techtreeFile ) ! = techTreeFiles . end ( ) ) {
techtreeFile = formatString ( techtreeFile ) ;
listBoxTechTree . setSelectedItem ( techtreeFile ) ;
}
2010-12-21 06:07:10 +01:00
2012-01-06 07:55:27 +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-21 20:21:40 +02:00
2011-04-20 00:53:37 +02:00
//gameSettings->setDefaultUnits(true);
//gameSettings->setDefaultResources(true);
//gameSettings->setDefaultVictoryConditions(true);
2010-05-31 21:57:10 +02:00
2011-04-20 00:53:37 +02:00
//FogOfWar
2011-12-26 08:11:52 +01:00
if ( checkBoxScenario . getValue ( ) = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ; // default is 0!
if ( gameSettings . getFogOfWar ( ) = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 2 ) ;
}
2011-09-16 02:34:14 +02:00
2011-12-26 08:11:52 +01:00
if ( ( gameSettings . getFlagTypes1 ( ) & ft1_show_map_resources ) = = ft1_show_map_resources ) {
if ( gameSettings . getFogOfWar ( ) = = true ) {
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
2011-04-20 00:53:37 +02:00
}
}
2010-06-05 09:52:14 +02:00
2012-01-06 07:55:27 +01:00
//printf("In [%s::%s line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2011-09-16 02:34:14 +02:00
2012-10-22 17:52:08 +02:00
checkBoxAllowObservers . setValue ( gameSettings . getAllowObservers ( ) = = true ? true : false ) ;
2013-10-29 07:13:38 +01:00
//listBoxEnableObserverMode.setSelectedItem(gameSettings.getEnableObserverModeAtEndGame() == true ? lang.getString("Yes") : lang.getString("No"));
2011-09-21 08:51:28 +02:00
2012-10-22 17:52:08 +02:00
checkBoxEnableSwitchTeamMode . setValue ( ( gameSettings . getFlagTypes1 ( ) & ft1_allow_team_switching ) = = ft1_allow_team_switching ? true : false ) ;
2011-09-21 08:51:28 +02:00
listBoxAISwitchTeamAcceptPercent . setSelectedItem ( intToStr ( gameSettings . getAiAcceptSwitchTeamPercentChance ( ) ) ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . setSelectedItemIndex ( gameSettings . getFallbackCpuMultiplier ( ) ) ;
2011-09-21 08:51:28 +02:00
2013-02-15 19:25:10 +01:00
checkBoxAllowInGameJoinPlayer . setValue ( ( gameSettings . getFlagTypes1 ( ) & ft1_allow_in_game_joining ) = = ft1_allow_in_game_joining ? true : false ) ;
2014-01-27 23:15:05 +01:00
checkBoxAllowTeamUnitSharing . setValue ( ( gameSettings . getFlagTypes1 ( ) & ft1_allow_shared_team_units ) = = ft1_allow_shared_team_units ? true : false ) ;
checkBoxAllowTeamResourceSharing . setValue ( ( gameSettings . getFlagTypes1 ( ) & ft1_allow_shared_team_resources ) = = ft1_allow_shared_team_resources ? true : false ) ;
2013-02-15 19:25:10 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
if ( serverInterface ! = NULL ) {
serverInterface - > setAllowInGameConnections ( checkBoxAllowInGameJoinPlayer . getValue ( ) = = true ) ;
}
2013-06-13 03:37:15 +02:00
checkBoxAllowNativeLanguageTechtree . setValue ( gameSettings . getNetworkAllowNativeLanguageTechtree ( ) ) ;
2012-09-22 23:44:30 +02:00
//listBoxPathFinderType.setSelectedItemIndex(gameSettings.getPathFinderType());
2010-05-31 21:57:10 +02:00
2013-10-29 07:13:38 +01:00
//listBoxEnableServerControlledAI.setSelectedItem(gameSettings.getEnableServerControlledAI() == true ? lang.getString("Yes") : lang.getString("No"));
2010-07-16 18:53:19 +02:00
2013-10-29 07:13:38 +01:00
//labelNetworkFramePeriod.setText(lang.getString("NetworkFramePeriod"));
2010-07-16 18:53:19 +02:00
2011-04-20 00:53:37 +02:00
//listBoxNetworkFramePeriod.setSelectedItem(intToStr(gameSettings.getNetworkFramePeriod()/10*10));
2010-05-31 21:57:10 +02:00
2012-01-06 07:55:27 +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-31 21:57:10 +02:00
2012-10-22 17:52:08 +02:00
checkBoxNetworkPauseGameForLaggedClients . setValue ( gameSettings . getNetworkPauseGameForLaggedClients ( ) ) ;
2010-05-31 21:57:10 +02:00
2012-01-06 07:55:27 +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-31 21:57:10 +02:00
2011-12-28 05:46:36 +01:00
reloadFactions ( false , ( checkBoxScenario . getValue ( ) = = true ? scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] : " " ) ) ;
2011-10-01 10:04:30 +02:00
//reloadFactions(true);
2010-05-31 21:57:10 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d] gameSettings.getFactionCount() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , gameSettings . getFactionCount ( ) ) ;
2010-08-23 06:33:21 +02:00
2011-04-20 00:53:37 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-10-01 10:04:30 +02:00
int slotIndex = gameSettings . getStartLocationIndex ( i ) ;
if ( gameSettings . getFactionControl ( i ) < listBoxControls [ slotIndex ] . getItemCount ( ) ) {
listBoxControls [ slotIndex ] . setSelectedItemIndex ( gameSettings . getFactionControl ( i ) ) ;
2011-09-07 18:55:49 +02:00
}
2011-09-16 02:34:14 +02:00
2012-10-06 00:43:00 +02:00
//if(slotIndex == 0) printf("#2 slotIndex = %d, i = %d, multiplier = %d\n",slotIndex,i,listBoxRMultiplier[i].getSelectedItemIndex());
2011-10-01 10:04:30 +02:00
updateResourceMultiplier ( slotIndex ) ;
2012-10-06 00:43:00 +02:00
//if(slotIndex == 0) printf("#3 slotIndex = %d, i = %d, multiplier = %d\n",slotIndex,i,listBoxRMultiplier[i].getSelectedItemIndex());
2011-10-01 10:04:30 +02:00
listBoxRMultiplier [ slotIndex ] . setSelectedItemIndex ( gameSettings . getResourceMultiplierIndex ( i ) ) ;
2011-09-16 02:34:14 +02:00
2012-10-06 00:43:00 +02:00
//if(slotIndex == 0) printf("#4 slotIndex = %d, i = %d, multiplier = %d\n",slotIndex,i,listBoxRMultiplier[i].getSelectedItemIndex());
2011-10-01 10:04:30 +02:00
listBoxTeams [ slotIndex ] . setSelectedItemIndex ( gameSettings . getTeam ( i ) ) ;
2011-09-16 02:34:14 +02:00
2011-10-01 10:04:30 +02:00
lastSelectedTeamIndex [ slotIndex ] = listBoxTeams [ slotIndex ] . getSelectedItemIndex ( ) ;
2010-08-23 06:33:21 +02:00
2011-04-20 00:53:37 +02:00
string factionName = gameSettings . getFactionTypeName ( i ) ;
factionName = formatString ( factionName ) ;
2010-06-01 01:39:07 +02:00
2011-10-01 10:04:30 +02:00
//printf("\n\n\n*** setupUIFromGameSettings A, i = %d, startLoc = %d, factioncontrol = %d, factionName [%s]\n",i,gameSettings.getStartLocationIndex(i),gameSettings.getFactionControl(i),factionName.c_str());
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] factionName = [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , factionName . c_str ( ) ) ;
2010-10-08 03:41:53 +02:00
2011-10-01 10:04:30 +02:00
if ( listBoxFactions [ slotIndex ] . hasItem ( factionName ) = = true ) {
listBoxFactions [ slotIndex ] . setSelectedItem ( factionName ) ;
2011-09-07 18:55:49 +02:00
}
else {
2011-10-01 10:04:30 +02:00
listBoxFactions [ slotIndex ] . setSelectedItem ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
2011-09-07 18:55:49 +02:00
}
2010-10-30 06:24:26 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, gameSettings.getNetworkPlayerName(i) [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , gameSettings . getNetworkPlayerName ( i ) . c_str ( ) ) ;
2010-06-01 01:39:07 +02:00
2012-09-21 00:24:15 +02:00
//labelPlayerNames[slotIndex].setText(gameSettings.getNetworkPlayerName(i));
2011-04-20 00:53:37 +02:00
}
2010-05-31 21:57:10 +02:00
2011-04-20 00:53:37 +02:00
//SetActivePlayerNameEditor();
2010-05-31 21:57:10 +02:00
2011-04-20 00:53:37 +02:00
updateControlers ( ) ;
updateNetworkSlots ( ) ;
2010-06-12 21:01:16 +02:00
2013-05-01 02:44:29 +02:00
if ( this - > headlessServerMode = = false & & humanPlayerName ! = " " ) {
for ( int index = 0 ; index < GameConstants : : maxPlayers ; + + index ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ index ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman ) {
if ( humanPlayerName ! = labelPlayerNames [ index ] . getText ( ) ) {
//printf("Player name changing from [%s] to [%s]\n",labelPlayerNames[index].getText().c_str(),humanPlayerName.c_str());
labelPlayerNames [ index ] . setText ( " " ) ;
labelPlayerNames [ index ] . setText ( humanPlayerName ) ;
}
}
}
}
if ( hasNetworkGameSettings ( ) = = true ) {
2011-04-20 00:53:37 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2010-03-13 23:00:01 +01:00
// ============ PRIVATE ===========================
2010-08-23 06:33:21 +02:00
bool MenuStateCustomGame : : hasNetworkGameSettings ( ) {
2010-03-13 23:00:01 +01:00
bool hasNetworkSlot = false ;
2010-04-11 03:25:06 +02:00
try {
2011-09-01 23:54:31 +02:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2010-04-11 03:25:06 +02:00
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
2011-03-11 12:11:46 +01:00
if ( ct ! = ctClosed ) {
2011-09-01 23:54:31 +02:00
if ( ct = = ctNetwork | | ct = = ctNetworkUnassigned ) {
2010-04-11 03:25:06 +02:00
hasNetworkSlot = true ;
break ;
}
2010-03-13 23:00:01 +01:00
}
}
2011-09-01 23:54:31 +02:00
if ( hasNetworkSlot = = false ) {
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct ! = ctClosed ) {
if ( ct = = ctNetworkUnassigned ) {
hasNetworkSlot = true ;
break ;
}
}
}
}
2010-03-13 23:00:01 +01:00
}
2010-04-11 03:25:06 +02:00
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-01-06 07:55:27 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-03-31 10:28:42 +02:00
2010-06-11 06:55:49 +02:00
showGeneralError = true ;
2012-03-31 10:28:42 +02:00
generalErrorToShow = szBuf ;
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
return hasNetworkSlot ;
}
2010-09-12 07:05:08 +02:00
void MenuStateCustomGame : : loadMapInfo ( string file , MapInfo * mapInfo , bool loadMapPreview ) {
2011-12-05 06:26:48 +01:00
try {
Lang & lang = Lang : : getInstance ( ) ;
2013-10-29 07:13:38 +01:00
if ( MapPreview : : loadMapInfo ( file , mapInfo , lang . getString ( " MaxPlayers " ) , lang . getString ( " Size " ) , true ) = = true ) {
2011-12-05 06:26:48 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) ! = NULL & &
2011-12-05 06:26:48 +01:00
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) ) {
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) - > isConnected ( ) = = true ) {
2011-12-05 06:26:48 +01:00
if ( i + 1 > mapInfo - > players & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetworkUnassigned ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctNetworkUnassigned ) ;
}
}
}
labelPlayers [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
labelPlayerNames [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
listBoxControls [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
listBoxFactions [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
listBoxTeams [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
labelNetStatus [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
}
// Not painting properly so this is on hold
if ( loadMapPreview = = true ) {
2012-01-06 07:55:27 +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-12-05 06:26:48 +01:00
mapPreview . loadFromFile ( file . c_str ( ) ) ;
//printf("Loading map preview MAP\n");
cleanupMapPreviewTexture ( ) ;
}
}
}
catch ( exception & e ) {
2012-01-06 07:55:27 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] loading map [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) , file . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Error loading map file: [ " + file + " ] msg: " + e . what ( ) ) ;
2011-12-05 06:26:48 +01:00
}
2010-03-13 23:00:01 +01:00
}
2011-04-14 18:04:42 +02:00
void MenuStateCustomGame : : updateControlers ( ) {
2010-04-11 03:25:06 +02:00
try {
bool humanPlayer = false ;
2010-03-13 23:00:01 +01:00
2011-04-14 18:04:42 +02:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
2010-04-11 03:25:06 +02:00
humanPlayer = true ;
}
2010-03-13 23:00:01 +01:00
}
2011-04-14 18:04:42 +02:00
if ( humanPlayer = = false ) {
2012-07-06 00:03:15 +02:00
if ( this - > headlessServerMode = = false ) {
2012-07-24 21:29:15 +02:00
bool foundNewSlotForHuman = false ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctClosed ) {
2013-10-25 21:35:10 +02:00
setSlotHuman ( i ) ;
2012-07-24 21:29:15 +02:00
foundNewSlotForHuman = true ;
break ;
}
}
if ( foundNewSlotForHuman = = false ) {
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctClosed | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuEasy | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpu | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuUltra | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuMega ) {
2013-10-25 21:35:10 +02:00
setSlotHuman ( i ) ;
2012-07-24 21:29:15 +02:00
foundNewSlotForHuman = true ;
break ;
}
}
}
if ( foundNewSlotForHuman = = false ) {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( 0 , true ) ;
2012-07-24 21:29:15 +02:00
if ( slot ! = NULL & & slot - > isConnected ( ) = = true ) {
serverInterface - > removeSlot ( 0 ) ;
}
2013-10-25 21:35:10 +02:00
setSlotHuman ( 0 ) ;
2012-07-24 21:29:15 +02:00
}
2011-09-24 23:07:15 +02:00
}
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
2011-04-14 18:04:42 +02:00
for ( int i = mapInfo . players ; i < GameConstants : : maxPlayers ; + + i ) {
2011-09-01 23:54:31 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetworkUnassigned ) {
//printf("Closed A [%d] [%s]\n",i,labelPlayerNames[i].getText().c_str());
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
}
2010-04-11 03:25:06 +02:00
}
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2010-03-13 23:00:01 +01:00
}
}
void MenuStateCustomGame : : closeUnusedSlots ( ) {
2010-04-11 03:25:06 +02:00
try {
2012-03-27 05:23:03 +02:00
if ( checkBoxScenario . getValue ( ) = = false ) {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2012-07-27 02:39:13 +02:00
//for(int i= 0; i<mapInfo.players; ++i){
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2012-03-27 05:23:03 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
2014-01-08 21:48:56 +01:00
if ( serverInterface - > getSlot ( i , true ) = = NULL | |
serverInterface - > getSlot ( i , true ) - > isConnected ( ) = = false | |
serverInterface - > getSlot ( i , true ) - > getConnectHasHandshaked ( ) = = false ) {
2012-03-27 05:23:03 +02:00
//printf("Closed A [%d] [%s]\n",i,labelPlayerNames[i].getText().c_str());
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
}
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
}
2012-03-27 05:23:03 +02:00
updateNetworkSlots ( ) ;
2010-03-13 23:00:01 +01:00
}
2010-04-11 03:25:06 +02:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2010-03-13 23:00:01 +01:00
}
}
2010-08-23 06:33:21 +02:00
void MenuStateCustomGame : : updateNetworkSlots ( ) {
2010-04-11 03:25:06 +02:00
try {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2010-03-13 23:00:01 +01:00
2010-12-21 06:07:10 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
if ( hasCheckedForUPNP = = false ) {
2014-01-04 00:10:30 +01:00
if ( checkBoxPublishServer . getValue ( ) = = true | |
this - > headlessServerMode = = true ) {
hasCheckedForUPNP = true ;
serverInterface - > getServerSocket ( ) - > NETdiscoverUPnPDevices ( ) ;
}
2010-12-21 06:07:10 +01:00
}
}
else {
hasCheckedForUPNP = false ;
}
2010-10-23 06:00:39 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( i , true ) ;
2012-07-27 02:39:13 +02:00
//printf("A i = %d control type = %d slot [%p]\n",i,listBoxControls[i].getSelectedItemIndex(),slot);
if ( slot = = NULL & &
2010-08-23 06:33:21 +02:00
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
2010-06-24 03:23:18 +02:00
try {
serverInterface - > addSlot ( i ) ;
}
catch ( const std : : exception & ex ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2010-06-24 03:23:18 +02:00
showGeneralError = true ;
if ( serverInterface - > isPortBound ( ) = = false ) {
2013-10-29 07:13:38 +01:00
generalErrorToShow = Lang : : getInstance ( ) . getString ( " ErrorBindingPort " ) + " : " + intToStr ( serverInterface - > getBindPort ( ) ) ;
2010-06-24 03:23:18 +02:00
}
else {
generalErrorToShow = ex . what ( ) ;
}
// Revert network to CPU
2010-08-23 06:33:21 +02:00
listBoxControls [ i ] . setSelectedItemIndex ( ctCpu ) ;
2010-06-24 03:23:18 +02:00
}
2010-04-11 03:25:06 +02:00
}
2014-01-08 21:48:56 +01:00
slot = serverInterface - > getSlot ( i , true ) ;
2012-03-20 21:31:41 +01:00
if ( slot ! = NULL ) {
2012-07-27 02:39:13 +02:00
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork ) | |
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork & &
slot - > isConnected ( ) = = false & & i > = mapInfo . players ) ) {
2012-03-20 21:31:41 +01:00
if ( slot - > getCanAcceptConnections ( ) = = true ) {
slot - > setCanAcceptConnections ( false ) ;
2011-09-01 23:54:31 +02:00
}
2012-03-20 21:31:41 +01:00
if ( slot - > isConnected ( ) = = true ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetworkUnassigned ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctNetworkUnassigned ) ;
}
}
else {
serverInterface - > removeSlot ( i ) ;
2011-09-01 23:54:31 +02:00
2012-03-20 21:31:41 +01:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
}
2011-09-01 23:54:31 +02:00
}
}
2012-03-20 21:31:41 +01:00
else if ( slot - > getCanAcceptConnections ( ) = = false ) {
slot - > setCanAcceptConnections ( true ) ;
}
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
}
}
2010-04-11 03:25:06 +02:00
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error(szBuf);
2010-06-11 06:55:49 +02:00
showGeneralError = true ;
2012-03-31 10:28:42 +02:00
generalErrorToShow = szBuf ;
2010-06-11 06:55:49 +02:00
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
}
2011-06-26 03:55:08 +02:00
void MenuStateCustomGame : : keyDown ( SDL_KeyboardEvent key ) {
2011-09-26 06:26:44 +02:00
if ( isMasterserverMode ( ) = = true ) {
return ;
}
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2012-07-26 08:27:00 +02:00
bool handled = keyDownEditLabel ( key , & activeInputLabel ) ;
if ( handled = = true ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-08-23 06:33:21 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
2010-08-21 09:41:26 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
}
else {
//send key to the chat manager
2011-01-03 13:41:20 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
chatManager . keyDown ( key ) ;
}
2012-11-15 00:51:18 +01:00
if ( chatManager . getEditEnabled ( ) = = false & &
2013-11-19 22:57:28 +01:00
( : : Shared : : Platform : : Window : : isKeyStateModPressed ( KMOD_SHIFT ) = = false ) ) {
2010-08-28 03:52:57 +02:00
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-08-21 09:41:26 +02:00
showFullConsole = true ;
}
2010-09-04 01:15:42 +02:00
//Toggle music
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ToggleMusic")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " ToggleMusic " ) , key ) = = true ) {
2010-09-04 01:15:42 +02:00
Config & config = Config : : getInstance ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2010-12-07 07:12:51 +01:00
2010-09-04 01:15:42 +02:00
float configVolume = ( config . getInt ( " SoundVolumeMusic " ) / 100.f ) ;
float currentVolume = CoreData : : getInstance ( ) . getMenuMusic ( ) - > getVolume ( ) ;
if ( currentVolume > 0 ) {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( 0.f ) ;
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " GameMusic " ) + " " + lang . getString ( " Off " ) ) ;
2010-09-04 01:15:42 +02:00
}
else {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( configVolume ) ;
//If the config says zero, use the default music volume
//gameMusic->setVolume(configVolume ? configVolume : 0.9);
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " GameMusic " ) ) ;
2010-09-04 01:15:42 +02:00
}
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("SaveGUILayout")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " SaveGUILayout " ) , key ) = = true ) {
2010-09-09 23:07:39 +02:00
bool saved = GraphicComponent : : saveAllCustomProperties ( containerName ) ;
Lang & lang = Lang : : getInstance ( ) ;
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " GUILayoutSaved " ) + " [ " + ( saved ? lang . getString ( " Yes " ) : lang . getString ( " No " ) ) + " ] " ) ;
2010-09-09 23:07:39 +02:00
}
2010-06-11 06:55:49 +02:00
}
2010-06-09 00:50:37 +02:00
}
2010-03-13 23:00:01 +01:00
}
2011-06-26 03:55:08 +02:00
void MenuStateCustomGame : : keyPress ( SDL_KeyboardEvent c ) {
2011-09-26 06:26:44 +02:00
if ( isMasterserverMode ( ) = = true ) {
return ;
}
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2012-07-26 08:27:00 +02:00
bool handled = keyPressEditLabel ( c , & activeInputLabel ) ;
if ( handled = = true & & & labelGameName ! = activeInputLabel ) {
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2012-07-26 08:27:00 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
2010-08-21 09:41:26 +02:00
}
2011-10-21 00:30:09 +02:00
}
2010-08-21 09:41:26 +02:00
}
else {
2011-01-03 13:41:20 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
chatManager . keyPress ( c ) ;
}
2010-08-21 09:41:26 +02:00
}
2010-03-13 23:00:01 +01:00
}
2011-06-26 03:55:08 +02:00
void MenuStateCustomGame : : keyUp ( SDL_KeyboardEvent key ) {
2011-09-26 06:26:44 +02:00
if ( isMasterserverMode ( ) = = true ) {
return ;
}
2010-08-21 15:04:52 +02:00
if ( activeInputLabel = = NULL ) {
2011-01-03 13:41:20 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
chatManager . keyUp ( key ) ;
}
2010-08-28 03:52:57 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2010-09-09 23:07:39 +02:00
if ( chatManager . getEditEnabled ( ) ) {
2010-08-21 09:41:26 +02:00
//send key to the chat manager
2011-01-03 13:41:20 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
chatManager . keyUp ( key ) ;
}
2010-08-21 09:41:26 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ShowFullConsole")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " ShowFullConsole " ) , key ) = = true ) {
2010-08-21 09:41:26 +02:00
showFullConsole = false ;
}
2010-06-09 00:50:37 +02:00
}
2010-06-08 02:00:28 +02:00
}
2010-05-17 01:03:22 +02:00
void MenuStateCustomGame : : showMessageBox ( const string & text , const string & header , bool toggle ) {
if ( ! toggle ) {
mainMessageBox . setEnabled ( false ) ;
}
if ( ! mainMessageBox . getEnabled ( ) ) {
mainMessageBox . setText ( text ) ;
mainMessageBox . setHeader ( header ) ;
mainMessageBox . setEnabled ( true ) ;
}
else {
mainMessageBox . setEnabled ( false ) ;
}
}
2010-08-30 22:02:58 +02:00
void MenuStateCustomGame : : switchToNextMapGroup ( const int direction ) {
int i = listBoxMapFilter . getSelectedItemIndex ( ) ;
// if there are no maps for the current selection we switch to next selection
while ( formattedPlayerSortedMaps [ i ] . empty ( ) ) {
i = i + direction ;
2010-12-07 07:12:51 +01:00
if ( i > GameConstants : : maxPlayers ) {
2010-08-30 22:02:58 +02:00
i = 0 ;
}
if ( i < 0 ) {
i = GameConstants : : maxPlayers ;
}
}
listBoxMapFilter . setSelectedItemIndex ( i ) ;
listBoxMap . setItems ( formattedPlayerSortedMaps [ i ] ) ;
}
string MenuStateCustomGame : : getCurrentMapFile ( ) {
int i = listBoxMapFilter . getSelectedItemIndex ( ) ;
int mapIndex = listBoxMap . getSelectedItemIndex ( ) ;
2013-11-01 06:25:55 +01:00
if ( playerSortedMaps [ i ] . empty ( ) = = false ) {
return playerSortedMaps [ i ] . at ( mapIndex ) ;
}
return " " ;
2010-08-30 22:02:58 +02:00
}
2010-08-23 06:33:21 +02:00
void MenuStateCustomGame : : setActiveInputLabel ( GraphicLabel * newLable ) {
2012-07-26 08:27:00 +02:00
MenuState : : setActiveInputLabel ( newLable , & activeInputLabel ) ;
2010-08-21 09:41:26 +02:00
}
2010-08-21 15:04:52 +02:00
string MenuStateCustomGame : : getHumanPlayerName ( int index ) {
2010-08-23 06:33:21 +02:00
string result = defaultPlayerName ;
2010-08-21 15:04:52 +02:00
if ( index < 0 ) {
2010-08-23 06:33:21 +02:00
for ( int j = 0 ; j < GameConstants : : maxPlayers ; + + j ) {
if ( listBoxControls [ j ] . getSelectedItemIndex ( ) > = 0 ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ j ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman ) {
index = j ;
break ;
}
2010-08-21 15:04:52 +02:00
}
2010-08-21 09:41:26 +02:00
}
}
2010-08-23 06:33:21 +02:00
if ( index > = 0 & & index < GameConstants : : maxPlayers & &
labelPlayerNames [ index ] . getText ( ) ! = " " & &
labelPlayerNames [ index ] . getText ( ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
2010-08-21 15:04:52 +02:00
result = labelPlayerNames [ index ] . getText ( ) ;
2010-08-23 06:33:21 +02:00
if ( activeInputLabel ! = NULL ) {
size_t found = result . find_last_of ( " _ " ) ;
if ( found ! = string : : npos ) {
result = result . substr ( 0 , found ) ;
}
}
2010-08-21 15:04:52 +02:00
}
2010-10-08 19:17:22 +02:00
2010-08-21 09:41:26 +02:00
return result ;
}
2010-08-31 08:38:27 +02:00
void MenuStateCustomGame : : loadFactionTexture ( string filepath ) {
2012-01-06 07:55:27 +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-31 08:38:27 +02:00
2010-08-31 22:31:20 +02:00
if ( enableFactionTexturePreview = = true ) {
if ( filepath = = " " ) {
2011-01-26 10:09:59 +01:00
factionTexture = NULL ;
2010-08-31 22:31:20 +02:00
}
else {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] filepath = [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , filepath . c_str ( ) ) ;
2011-03-29 11:45:15 +02:00
2012-09-25 09:05:52 +02:00
factionTexture = Renderer : : findTexture ( filepath ) ;
2011-03-29 11:45:15 +02:00
2012-01-06 07:55:27 +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-31 22:31:20 +02:00
}
2010-08-31 08:38:27 +02:00
}
}
2010-11-01 17:44:05 +01:00
void MenuStateCustomGame : : cleanupMapPreviewTexture ( ) {
2012-01-06 07:55:27 +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-11-01 17:44:05 +01:00
//printf("CLEANUP map preview texture\n");
if ( mapPreviewTexture ! = NULL ) {
2012-01-06 07:55:27 +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-11-01 17:44:05 +01:00
mapPreviewTexture - > end ( ) ;
2012-01-06 07:55:27 +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-11-01 17:44:05 +01:00
delete mapPreviewTexture ;
mapPreviewTexture = NULL ;
}
2012-01-06 07:55:27 +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-11-01 17:44:05 +01:00
}
2011-03-11 12:11:46 +01:00
int32 MenuStateCustomGame : : getNetworkPlayerStatus ( ) {
int32 result = npst_None ;
switch ( listBoxPlayerStatus . getSelectedItemIndex ( ) ) {
case 2 :
result = npst_Ready ;
break ;
case 1 :
result = npst_BeRightBack ;
break ;
case 0 :
default :
result = npst_PickSettings ;
break ;
}
return result ;
}
2011-12-26 07:29:14 +01:00
void MenuStateCustomGame : : loadScenarioInfo ( string file , ScenarioInfo * scenarioInfo ) {
//printf("Load scenario file [%s]\n",file.c_str());
2013-05-21 22:28:42 +02:00
bool isTutorial = Scenario : : isGameTutorial ( file ) ;
Scenario : : loadScenarioInfo ( file , scenarioInfo , isTutorial ) ;
2011-12-26 07:29:14 +01:00
//cleanupPreviewTexture();
previewLoadDelayTimer = time ( NULL ) ;
needToLoadTextures = true ;
}
2011-04-20 18:25:16 +02:00
bool MenuStateCustomGame : : isInSpecialKeyCaptureEvent ( ) {
bool result = ( chatManager . getEditEnabled ( ) | | activeInputLabel ! = NULL ) ;
return result ;
}
2011-12-26 07:29:14 +01:00
void MenuStateCustomGame : : processScenario ( ) {
try {
if ( checkBoxScenario . getValue ( ) = = true ) {
//printf("listBoxScenario.getSelectedItemIndex() = %d [%s] scenarioFiles.size() = %d\n",listBoxScenario.getSelectedItemIndex(),listBoxScenario.getSelectedItem().c_str(),scenarioFiles.size());
loadScenarioInfo ( Scenario : : getScenarioPath ( dirList , scenarioFiles [ listBoxScenario . getSelectedItemIndex ( ) ] ) , & scenarioInfo ) ;
2011-12-28 05:46:36 +01:00
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenarioInfo . name ) ;
2011-12-26 07:29:14 +01:00
2011-12-26 08:11:52 +01:00
//printf("scenarioInfo.fogOfWar = %d scenarioInfo.fogOfWar_exploredFlag = %d\n",scenarioInfo.fogOfWar,scenarioInfo.fogOfWar_exploredFlag);
if ( scenarioInfo . fogOfWar = = false & & scenarioInfo . fogOfWar_exploredFlag = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 2 ) ;
}
else if ( scenarioInfo . fogOfWar_exploredFlag = = true ) {
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
else {
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ;
}
2013-06-13 03:37:15 +02:00
setupTechList ( scenarioInfo . name , false ) ;
2011-12-26 07:29:14 +01:00
listBoxTechTree . setSelectedItem ( formatString ( scenarioInfo . techTreeName ) ) ;
2011-12-28 05:46:36 +01:00
reloadFactions ( false , scenarioInfo . name ) ;
2011-12-26 07:29:14 +01:00
2011-12-28 05:46:36 +01:00
setupTilesetList ( scenarioInfo . name ) ;
2011-12-26 07:29:14 +01:00
listBoxTileset . setSelectedItem ( formatString ( scenarioInfo . tilesetName ) ) ;
2011-12-28 05:46:36 +01:00
setupMapList ( scenarioInfo . name ) ;
2011-12-26 07:29:14 +01:00
listBoxMap . setSelectedItem ( formatString ( scenarioInfo . mapName ) ) ;
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( getCurrentMapFile ( ) , scenarioDir , true ) , & mapInfo , true ) ;
2011-12-26 07:29:14 +01:00
labelMapInfo . setText ( mapInfo . desc ) ;
2011-12-28 05:46:36 +01:00
//printf("scenarioInfo.name [%s] [%s]\n",scenarioInfo.name.c_str(),listBoxMap.getSelectedItem().c_str());
2012-03-31 08:05:20 +02:00
// Loop twice to set the human slot or else it closes network slots in some cases
for ( int humanIndex = 0 ; humanIndex < 2 ; + + humanIndex ) {
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
listBoxRMultiplier [ i ] . setSelectedItem ( floatToStr ( scenarioInfo . resourceMultipliers [ i ] , 1 ) ) ;
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2014-01-08 21:48:56 +01:00
ConnectionSlot * slot = serverInterface - > getSlot ( i , true ) ;
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
int selectedControlItemIndex = listBoxControls [ i ] . getSelectedItemIndex ( ) ;
if ( selectedControlItemIndex ! = ctNetwork | |
( selectedControlItemIndex = = ctNetwork & & ( slot = = NULL | | slot - > isConnected ( ) = = false ) ) ) {
}
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
listBoxControls [ i ] . setSelectedItemIndex ( scenarioInfo . factionControls [ i ] ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
// Skip over networkunassigned
//if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned &&
// selectedControlItemIndex != ctNetworkUnassigned) {
// listBoxControls[i].mouseClick(x, y);
//}
//look for human players
int humanIndex1 = - 1 ;
int humanIndex2 = - 1 ;
for ( int j = 0 ; j < GameConstants : : maxPlayers ; + + j ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ j ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman ) {
if ( humanIndex1 = = - 1 ) {
humanIndex1 = j ;
}
else {
humanIndex2 = j ;
}
2011-12-26 07:29:14 +01:00
}
}
2012-03-31 08:05:20 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , humanIndex1 , humanIndex2 ) ;
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
//no human
if ( humanIndex1 = = - 1 & & humanIndex2 = = - 1 ) {
2013-10-25 21:35:10 +02:00
setSlotHuman ( i ) ;
2012-03-31 08:05:20 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d, labelPlayerNames[i].getText() [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , labelPlayerNames [ i ] . getText ( ) . c_str ( ) ) ;
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
//printf("humanIndex1 = %d humanIndex2 = %d i = %d listBoxControls[i].getSelectedItemIndex() = %d\n",humanIndex1,humanIndex2,i,listBoxControls[i].getSelectedItemIndex());
}
//2 humans
else if ( humanIndex1 ! = - 1 & & humanIndex2 ! = - 1 ) {
int closeSlotIndex = ( humanIndex1 = = i ? humanIndex2 : humanIndex1 ) ;
int humanSlotIndex = ( closeSlotIndex = = humanIndex1 ? humanIndex2 : humanIndex1 ) ;
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
string origPlayName = labelPlayerNames [ closeSlotIndex ] . getText ( ) ;
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] closeSlotIndex = %d, origPlayName [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , closeSlotIndex , origPlayName . c_str ( ) ) ;
//printf("humanIndex1 = %d humanIndex2 = %d i = %d closeSlotIndex = %d humanSlotIndex = %d\n",humanIndex1,humanIndex2,i,closeSlotIndex,humanSlotIndex);
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
listBoxControls [ closeSlotIndex ] . setSelectedItemIndex ( ctClosed ) ;
labelPlayerNames [ humanSlotIndex ] . setText ( ( origPlayName ! = " " ? origPlayName : getHumanPlayerName ( ) ) ) ;
2011-12-28 05:46:36 +01:00
}
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct ! = ctClosed ) {
//updateNetworkSlots();
//updateResourceMultiplier(i);
updateResourceMultiplier ( i ) ;
//printf("Setting scenario faction i = %d [ %s]\n",i,scenarioInfo.factionTypeNames[i].c_str());
listBoxFactions [ i ] . setSelectedItem ( formatString ( scenarioInfo . factionTypeNames [ i ] ) ) ;
//printf("DONE Setting scenario faction i = %d [ %s]\n",i,scenarioInfo.factionTypeNames[i].c_str());
// Disallow CPU players to be observers
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) & &
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuEasy | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpu | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuUltra | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuMega ) ) {
listBoxFactions [ i ] . setSelectedItemIndex ( 0 ) ;
}
//
listBoxTeams [ i ] . setSelectedItem ( intToStr ( scenarioInfo . teams [ i ] ) ) ;
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
if ( listBoxTeams [ i ] . getSelectedItemIndex ( ) + 1 ! = ( GameConstants : : maxPlayers + fpt_Observer ) ) {
lastSelectedTeamIndex [ i ] = listBoxTeams [ i ] . getSelectedItemIndex ( ) ;
}
2012-10-13 07:06:53 +02:00
// Alow Neutral cpu players
else if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuEasy | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpu | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuUltra | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuMega ) {
lastSelectedTeamIndex [ i ] = listBoxTeams [ i ] . getSelectedItemIndex ( ) ;
}
2012-03-31 08:05:20 +02:00
}
else {
lastSelectedTeamIndex [ i ] = - 1 ;
2011-12-28 05:46:36 +01:00
}
}
2011-12-26 07:29:14 +01:00
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2012-03-31 08:05:20 +02:00
needToRepublishToMasterserver = true ;
}
2011-12-26 07:29:14 +01:00
2012-03-31 08:05:20 +02:00
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ; ;
}
2011-12-26 07:29:14 +01:00
}
}
updateControlers ( ) ;
updateNetworkSlots ( ) ;
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-11-07 19:39:08 +01:00
MutexSafeWrapper safeMutexCLI ( ( publishToClientsThread ! = NULL ? publishToClientsThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2012-10-22 17:52:08 +02:00
if ( checkBoxPublishServer . getValue ( ) = = true ) {
2011-12-26 07:29:14 +01:00
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
//labelInfo.setText(scenarioInfo.desc);
}
2011-12-28 05:46:36 +01:00
else {
setupMapList ( " " ) ;
listBoxMap . setSelectedItem ( formatString ( formattedPlayerSortedMaps [ 0 ] [ 0 ] ) ) ;
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( getCurrentMapFile ( ) , " " , true ) , & mapInfo , true ) ;
2011-12-28 05:46:36 +01:00
labelMapInfo . setText ( mapInfo . desc ) ;
2013-06-13 03:37:15 +02:00
setupTechList ( " " , false ) ;
2011-12-28 05:46:36 +01:00
reloadFactions ( false , " " ) ;
setupTilesetList ( " " ) ;
}
2011-12-26 23:51:48 +01:00
SetupUIForScenarios ( ) ;
2011-12-26 07:29:14 +01:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-26 07:29:14 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
mainMessageBoxState = 1 ;
2012-03-31 10:28:42 +02:00
showMessageBox ( szBuf , " Error detected " , false ) ;
2011-12-26 07:29:14 +01:00
}
}
2011-12-26 23:51:48 +01:00
void MenuStateCustomGame : : SetupUIForScenarios ( ) {
2011-12-28 05:46:36 +01:00
try {
if ( checkBoxScenario . getValue ( ) = = true ) {
// START - Disable changes to controls while in Scenario mode
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxControls [ i ] . setEditable ( false ) ;
listBoxFactions [ i ] . setEditable ( false ) ;
listBoxRMultiplier [ i ] . setEditable ( false ) ;
listBoxTeams [ i ] . setEditable ( false ) ;
}
listBoxFogOfWar . setEditable ( false ) ;
2012-10-22 17:52:08 +02:00
checkBoxAllowObservers . setEditable ( false ) ;
2012-09-22 23:44:30 +02:00
//listBoxPathFinderType.setEditable(false);
2012-10-22 17:52:08 +02:00
checkBoxEnableSwitchTeamMode . setEditable ( false ) ;
2011-12-28 05:46:36 +01:00
listBoxAISwitchTeamAcceptPercent . setEditable ( false ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . setEditable ( false ) ;
2011-12-28 05:46:36 +01:00
listBoxMap . setEditable ( false ) ;
listBoxTileset . setEditable ( false ) ;
listBoxMapFilter . setEditable ( false ) ;
listBoxTechTree . setEditable ( false ) ;
// END - Disable changes to controls while in Scenario mode
}
else {
// START - Disable changes to controls while in Scenario mode
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxControls [ i ] . setEditable ( true ) ;
listBoxFactions [ i ] . setEditable ( true ) ;
listBoxRMultiplier [ i ] . setEditable ( true ) ;
listBoxTeams [ i ] . setEditable ( true ) ;
}
listBoxFogOfWar . setEditable ( true ) ;
2012-10-22 17:52:08 +02:00
checkBoxAllowObservers . setEditable ( true ) ;
2012-09-22 23:44:30 +02:00
//listBoxPathFinderType.setEditable(true);
2012-10-22 17:52:08 +02:00
checkBoxEnableSwitchTeamMode . setEditable ( true ) ;
2011-12-28 05:46:36 +01:00
listBoxAISwitchTeamAcceptPercent . setEditable ( true ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . setEditable ( true ) ;
2011-12-28 05:46:36 +01:00
listBoxMap . setEditable ( true ) ;
listBoxTileset . setEditable ( true ) ;
listBoxMapFilter . setEditable ( true ) ;
listBoxTechTree . setEditable ( true ) ;
// END - Disable changes to controls while in Scenario mode
2011-12-26 23:51:48 +01:00
}
}
2011-12-28 05:46:36 +01:00
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
}
int MenuStateCustomGame : : setupMapList ( string scenario ) {
int initialMapSelection = 0 ;
try {
Config & config = Config : : getInstance ( ) ;
vector < string > invalidMapList ;
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > pathList = config . getPathListForType ( ptMaps , scenarioDir ) ;
vector < string > allMaps = MapPreview : : findAllValidMaps ( pathList , scenarioDir , false , true , & invalidMapList ) ;
if ( scenario ! = " " ) {
vector < string > allMaps2 = MapPreview : : findAllValidMaps ( config . getPathListForType ( ptMaps , " " ) , " " , false , true , & invalidMapList ) ;
copy ( allMaps2 . begin ( ) , allMaps2 . end ( ) , std : : inserter ( allMaps , allMaps . begin ( ) ) ) ;
std : : sort ( allMaps . begin ( ) , allMaps . end ( ) ) ;
}
if ( allMaps . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " No maps were found! " ) ;
2011-12-28 05:46:36 +01:00
}
vector < string > results ;
copy ( allMaps . begin ( ) , allMaps . end ( ) , std : : back_inserter ( results ) ) ;
mapFiles = results ;
for ( unsigned int i = 0 ; i < GameConstants : : maxPlayers + 1 ; + + i ) {
playerSortedMaps [ i ] . clear ( ) ;
formattedPlayerSortedMaps [ i ] . clear ( ) ;
}
copy ( mapFiles . begin ( ) , mapFiles . end ( ) , std : : back_inserter ( playerSortedMaps [ 0 ] ) ) ;
copy ( playerSortedMaps [ 0 ] . begin ( ) , playerSortedMaps [ 0 ] . end ( ) , std : : back_inserter ( formattedPlayerSortedMaps [ 0 ] ) ) ;
std : : for_each ( formattedPlayerSortedMaps [ 0 ] . begin ( ) , formattedPlayerSortedMaps [ 0 ] . end ( ) , FormatString ( ) ) ;
//printf("#5\n");
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) mapFiles . size ( ) ; i + + ) { // fetch info and put map in right list
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( mapFiles . at ( i ) , scenarioDir , false ) , & mapInfo , false ) ;
2011-12-28 05:46:36 +01:00
if ( GameConstants : : maxPlayers + 1 < = mapInfo . players ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-12-17 08:54:33 +01:00
snprintf ( szBuf , 8096 , " Sorted map list [%d] does not match \n current map playercount [%d] \n for file [%s] \n map [%s] " , GameConstants : : maxPlayers + 1 , mapInfo . players , Config : : getMapPath ( mapFiles . at ( i ) , " " , false ) . c_str ( ) , mapInfo . desc . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
playerSortedMaps [ mapInfo . players ] . push_back ( mapFiles . at ( i ) ) ;
formattedPlayerSortedMaps [ mapInfo . players ] . push_back ( formatString ( mapFiles . at ( i ) ) ) ;
if ( config . getString ( " InitialMap " , " Conflict " ) = = formattedPlayerSortedMaps [ mapInfo . players ] . back ( ) ) {
initialMapSelection = i ;
}
}
//printf("#6 scenario [%s] [%s]\n",scenario.c_str(),scenarioDir.c_str());
if ( scenario ! = " " ) {
string file = Scenario : : getScenarioPath ( dirList , scenario ) ;
loadScenarioInfo ( file , & scenarioInfo ) ;
//printf("#6.1 about to load map [%s]\n",scenarioInfo.mapName.c_str());
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( scenarioInfo . mapName , scenarioDir , true ) , & mapInfo , false ) ;
2011-12-28 05:46:36 +01:00
//printf("#6.2\n");
listBoxMapFilter . setSelectedItem ( intToStr ( mapInfo . players ) ) ;
listBoxMap . setItems ( formattedPlayerSortedMaps [ mapInfo . players ] ) ;
}
else {
listBoxMapFilter . setSelectedItemIndex ( 0 ) ;
listBoxMap . setItems ( formattedPlayerSortedMaps [ 0 ] ) ;
}
//printf("#7\n");
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
//abort();
}
return initialMapSelection ;
}
2013-06-13 03:37:15 +02:00
int MenuStateCustomGame : : setupTechList ( string scenario , bool forceLoad ) {
2011-12-28 05:46:36 +01:00
int initialTechSelection = 0 ;
try {
Config & config = Config : : getInstance ( ) ;
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > results ;
vector < string > techPaths = config . getPathListForType ( ptTechs , scenarioDir ) ;
findDirs ( techPaths , results ) ;
if ( results . empty ( ) ) {
2013-11-01 06:25:55 +01:00
//throw megaglest_runtime_error("No tech-trees were found!");
printf ( " No tech-trees were found (custom)! \n " ) ;
2011-12-28 05:46:36 +01:00
}
techTreeFiles = results ;
2013-06-13 03:37:15 +02:00
vector < string > translatedTechs ;
2011-12-28 05:46:36 +01:00
for ( unsigned int i = 0 ; i < results . size ( ) ; i + + ) {
//printf("TECHS i = %d results [%s] scenario [%s]\n",i,results[i].c_str(),scenario.c_str());
results . at ( i ) = formatString ( results . at ( i ) ) ;
if ( config . getString ( " InitialTechTree " , " Megapack " ) = = results . at ( i ) ) {
initialTechSelection = i ;
}
2013-06-13 03:37:15 +02:00
string txTech = techTree - > getTranslatedName ( techTreeFiles . at ( i ) , forceLoad ) ;
2013-06-16 03:14:04 +02:00
translatedTechs . push_back ( formatString ( txTech ) ) ;
2011-12-28 05:46:36 +01:00
}
2013-06-13 03:37:15 +02:00
listBoxTechTree . setItems ( results , translatedTechs ) ;
2011-12-28 05:46:36 +01:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
return initialTechSelection ;
}
void MenuStateCustomGame : : reloadFactions ( bool keepExistingSelectedItem , string scenario ) {
try {
Config & config = Config : : getInstance ( ) ;
2013-11-06 00:35:11 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2011-12-28 05:46:36 +01:00
vector < string > results ;
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > techPaths = config . getPathListForType ( ptTechs , scenarioDir ) ;
//printf("#1 techPaths.size() = %d scenarioDir [%s] [%s]\n",techPaths.size(),scenario.c_str(),scenarioDir.c_str());
2013-11-01 06:25:55 +01:00
if ( listBoxTechTree . getItemCount ( ) > 0 ) {
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) techPaths . size ( ) ; idx + + ) {
2013-11-01 06:25:55 +01:00
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
string factionPath = techPath + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " /factions/ " ;
findDirs ( factionPath , results , false , false ) ;
2011-12-28 05:46:36 +01:00
2013-11-01 06:25:55 +01:00
//printf("idx = %d factionPath [%s] results.size() = %d\n",idx,factionPath.c_str(),results.size());
2011-12-28 05:46:36 +01:00
2013-11-01 06:25:55 +01:00
if ( results . empty ( ) = = false ) {
break ;
}
2011-12-28 05:46:36 +01:00
}
}
if ( results . empty ( ) = = true ) {
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
2011-12-28 05:46:36 +01:00
showGeneralError = true ;
2013-11-01 06:25:55 +01:00
if ( listBoxTechTree . getItemCount ( ) > 0 ) {
generalErrorToShow = " [#2] There are no factions for the tech tree [ " + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " ] " ;
}
else {
generalErrorToShow = " [#2] There are no factions since there is no tech tree! " ;
}
2011-12-28 05:46:36 +01:00
}
2013-11-06 00:35:11 +01:00
// results.push_back(formatString(GameConstants::RANDOMFACTION_SLOTNAME));
//
// // Add special Observer Faction
// if(checkBoxAllowObservers.getValue() == 1) {
// results.push_back(formatString(GameConstants::OBSERVER_SLOTNAME));
// }
2011-12-28 05:46:36 +01:00
2013-06-13 23:20:55 +02:00
vector < string > translatedFactionNames ;
2011-12-28 05:46:36 +01:00
factionFiles = results ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) results . size ( ) ; + + i ) {
2011-12-28 05:46:36 +01:00
results [ i ] = formatString ( results [ i ] ) ;
2013-11-01 06:25:55 +01:00
string translatedString = " " ;
if ( listBoxTechTree . getItemCount ( ) > 0 ) {
translatedString = techTree - > getTranslatedFactionName ( techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] , factionFiles [ i ] ) ;
}
2013-10-29 22:41:45 +01:00
//printf("translatedString=%s formatString(results[i])=%s \n",translatedString.c_str(),formatString(results[i]).c_str() );
2013-11-03 22:55:50 +01:00
if ( toLower ( translatedString ) = = toLower ( results [ i ] ) ) {
translatedFactionNames . push_back ( results [ i ] ) ;
2013-10-25 21:35:10 +02:00
}
else {
2013-11-03 22:55:50 +01:00
translatedFactionNames . push_back ( results [ i ] + " ( " + translatedString + " ) " ) ;
2013-10-25 21:35:10 +02:00
}
2011-12-28 05:46:36 +01:00
//printf("FACTIONS i = %d results [%s]\n",i,results[i].c_str());
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " Tech [%s] has faction [%s] \n " , techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] . c_str ( ) , results [ i ] . c_str ( ) ) ;
}
2013-11-06 00:35:11 +01:00
results . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
factionFiles . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
translatedFactionNames . push_back ( " * " + lang . getString ( " Random " , " " , true ) + " * " ) ;
// Add special Observer Faction
if ( checkBoxAllowObservers . getValue ( ) = = 1 ) {
results . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
factionFiles . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
translatedFactionNames . push_back ( " * " + lang . getString ( " Observer " , " " , true ) + " * " ) ;
}
2011-12-28 05:46:36 +01:00
2011-12-26 23:51:48 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-12-28 05:46:36 +01:00
int originalIndex = listBoxFactions [ i ] . getSelectedItemIndex ( ) ;
string originalValue = ( listBoxFactions [ i ] . getItemCount ( ) > 0 ? listBoxFactions [ i ] . getSelectedItem ( ) : " " ) ;
2013-06-13 23:20:55 +02:00
listBoxFactions [ i ] . setItems ( results , translatedFactionNames ) ;
2011-12-28 05:46:36 +01:00
if ( keepExistingSelectedItem = = false | |
2012-10-22 17:52:08 +02:00
( checkBoxAllowObservers . getValue ( ) = = 0 & &
2011-12-28 05:46:36 +01:00
originalValue = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ) {
listBoxFactions [ i ] . setSelectedItemIndex ( i % results . size ( ) ) ;
if ( originalValue = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) & &
listBoxFactions [ i ] . getSelectedItem ( ) ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
if ( listBoxTeams [ i ] . getSelectedItem ( ) = = intToStr ( GameConstants : : maxPlayers + fpt_Observer ) ) {
listBoxTeams [ i ] . setSelectedItem ( intToStr ( 1 ) ) ;
}
}
}
2013-11-19 07:14:06 +01:00
else if ( originalIndex < ( int ) results . size ( ) ) {
2011-12-28 05:46:36 +01:00
listBoxFactions [ i ] . setSelectedItemIndex ( originalIndex ) ;
}
}
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
}
2013-10-25 21:35:10 +02:00
void MenuStateCustomGame : : setSlotHuman ( int i ) {
2013-11-02 23:30:16 +01:00
if ( labelPlayerNames [ i ] . getEditable ( ) ) {
return ;
}
2013-10-25 21:35:10 +02:00
listBoxControls [ i ] . setSelectedItemIndex ( ctHuman ) ;
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ i ] . setSelectedItem ( " 1.0 " ) ;
2013-10-25 21:35:10 +02:00
labelPlayerNames [ i ] . setText ( getHumanPlayerName ( ) ) ;
for ( int j = 0 ; j < GameConstants : : maxPlayers ; + + j ) {
labelPlayerNames [ j ] . setEditable ( false ) ;
}
labelPlayerNames [ i ] . setEditable ( true ) ;
}
2011-12-28 05:46:36 +01:00
void MenuStateCustomGame : : setupTilesetList ( string scenario ) {
try {
Config & config = Config : : getInstance ( ) ;
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > results ;
findDirs ( config . getPathListForType ( ptTilesets , scenarioDir ) , results ) ;
if ( results . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " No tile-sets were found! " ) ;
2011-12-26 23:51:48 +01:00
}
2011-12-28 05:46:36 +01:00
tilesetFiles = results ;
std : : for_each ( results . begin ( ) , results . end ( ) , FormatString ( ) ) ;
listBoxTileset . setItems ( results ) ;
2011-12-26 23:51:48 +01:00
}
2011-12-28 05:46:36 +01:00
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
2011-12-26 23:51:48 +01:00
}
2010-03-13 23:00:01 +01:00
} } //end namespace