2010-03-13 23:00:01 +01:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Marti<74> o Figueroa
//
// 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"
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"
2011-02-16 00:53:48 +01:00
# include "leak_dumper.h"
2010-03-13 23:00:01 +01:00
namespace Glest { namespace Game {
using namespace Shared : : Util ;
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
// =====================================================
2010-10-02 04:17:50 +02:00
MenuStateCustomGame : : MenuStateCustomGame ( Program * program , MainMenu * mainMenu , bool openNetworkSlots , bool parentMenuIsMasterserver , bool autostart ) :
2010-09-09 23:07:39 +02:00
MenuState ( program , mainMenu , " new-game " )
2010-03-13 23:00:01 +01:00
{
2010-10-02 04:17:50 +02:00
this - > autostart = autostart ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] autostart = %d \n " , __FILE__ , __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 = " " ;
lastCheckedCRCTilesetValue = - 1 ;
lastCheckedCRCTechtreeValue = - 1 ;
lastCheckedCRCMapValue = - 1 ;
2010-05-17 08:41:05 +02:00
publishToMasterserverThread = 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
2010-09-09 00:37:24 +02:00
mainMessageBox . registerGraphicComponent ( containerName , " mainMessageBox " ) ;
2010-06-11 06:55:49 +02:00
mainMessageBox . init ( lang . get ( " Ok " ) ) ;
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
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 ;
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2011-03-11 13:14:24 +01:00
//throw runtime_error(szBuf);
2010-06-11 06:55:49 +02:00
showGeneralError = true ;
generalErrorToShow = ex . what ( ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-03 23:07:55 +02:00
2010-05-16 18:40:21 +02:00
parentMenuIsMs = parentMenuIsMasterserver ;
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 ;
2010-05-17 01:03:22 +02:00
showMasterserverError = false ;
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
2010-11-09 00:15:50 +01:00
vector < string > teamItems , controlItems , results , rMultiplier ;
2010-03-13 23:00:01 +01:00
//create
2010-09-09 00:37:24 +02:00
buttonReturn . registerGraphicComponent ( containerName , " buttonReturn " ) ;
2010-06-08 02:00:28 +02:00
buttonReturn . init ( 250 , 180 , 125 ) ;
2010-09-09 00:37:24 +02:00
buttonRestoreLastSettings . registerGraphicComponent ( containerName , " buttonRestoreLastSettings " ) ;
2010-06-08 02:00:28 +02:00
buttonRestoreLastSettings . init ( 250 + 130 , 180 , 200 ) ;
2010-09-09 00:37:24 +02:00
buttonPlayNow . registerGraphicComponent ( containerName , " buttonPlayNow " ) ;
2010-06-08 02:00:28 +02:00
buttonPlayNow . init ( 250 + 130 + 205 , 180 , 125 ) ;
2010-06-01 02:32:24 +02:00
2010-09-04 13:49:54 +02:00
int labelOffset = 23 ;
2010-08-28 01:08:35 +02:00
int setupPos = 590 ;
2010-06-04 02:33:34 +02:00
int mapHeadPos = 330 ;
2010-09-04 13:49:54 +02:00
int mapPos = mapHeadPos - labelOffset ;
int aHeadPos = mapHeadPos - 80 ;
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
2010-03-13 23:00:01 +01:00
//map listBox
2010-03-25 13:15:10 +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)
set < string > allMaps ;
2010-03-27 08:09:34 +01:00
findAll ( config . getPathListForType ( ptMaps ) , " *.gbm " , results , true , false ) ;
copy ( results . begin ( ) , results . end ( ) , std : : inserter ( allMaps , allMaps . begin ( ) ) ) ;
results . clear ( ) ;
findAll ( config . getPathListForType ( ptMaps ) , " *.mgm " , results , true , false ) ;
copy ( results . begin ( ) , results . end ( ) , std : : inserter ( allMaps , allMaps . begin ( ) ) ) ;
results . clear ( ) ;
2010-12-07 07:12:51 +01:00
2010-03-27 08:09:34 +01:00
if ( allMaps . empty ( ) ) {
throw runtime_error ( " No maps were found! " ) ;
2010-03-13 23:00:01 +01:00
}
2010-03-27 08:09:34 +01:00
copy ( allMaps . begin ( ) , allMaps . end ( ) , std : : back_inserter ( results ) ) ;
mapFiles = results ;
2010-12-07 07:12:51 +01:00
2010-08-30 22:02:58 +02:00
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 ( ) ) ;
2010-12-07 07:12:51 +01:00
2010-08-30 22:02:58 +02:00
for ( int i = 0 ; i < mapFiles . size ( ) ; i + + )
{ // fetch info and put map in right list
2010-09-17 10:26:22 +02:00
loadMapInfo ( Map : : getMapPath ( mapFiles . at ( i ) , " " , false ) , & mapInfo , false ) ;
2010-08-30 22:02:58 +02:00
playerSortedMaps [ mapInfo . players ] . push_back ( mapFiles . at ( i ) ) ;
formattedPlayerSortedMaps [ mapInfo . players ] . push_back ( formatString ( mapFiles . at ( i ) ) ) ;
}
2010-03-27 08:09:34 +01:00
2010-09-09 00:37:24 +02:00
labelLocalIP . registerGraphicComponent ( containerName , " labelLocalIP " ) ;
2010-10-11 02:53:25 +02:00
labelLocalIP . init ( 210 , networkHeadPos + labelOffset ) ;
2010-07-10 08:14:31 +02:00
string ipText = " none " ;
std : : vector < std : : string > ipList = Socket : : getLocalIPAddressList ( ) ;
if ( ipList . size ( ) > 0 ) {
ipText = " " ;
for ( int idx = 0 ; idx < ipList . size ( ) ; idx + + ) {
string ip = ipList [ idx ] ;
if ( ipText ! = " " ) {
ipText + = " , " ;
}
ipText + = ip ;
}
}
2010-10-11 02:53:25 +02:00
string externalPort = config . getString ( " MasterServerExternalPort " , " 61357 " ) ;
string serverPort = config . getString ( " ServerPort " , " 61357 " ) ;
labelLocalIP . setText ( lang . get ( " LanIP " ) + ipText + " ( " + serverPort + " / " + externalPort + " ) " ) ;
2010-12-21 06:07:10 +01:00
ServerSocket : : setExternalPort ( strToInt ( externalPort ) ) ;
2010-07-10 08:14:31 +02:00
2010-08-28 01:08:35 +02:00
// Map
xoffset = 70 ;
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 ) ;
labelMap . setText ( lang . get ( " Map " ) + " : " ) ;
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 ) ;
2010-08-30 22:02:58 +02:00
listBoxMap . setItems ( formattedPlayerSortedMaps [ 0 ] ) ;
2010-09-09 00:37:24 +02:00
labelMapInfo . registerGraphicComponent ( containerName , " labelMapInfo " ) ;
2010-09-04 13:49:54 +02:00
labelMapInfo . init ( xoffset + 100 , mapPos - labelOffset , 200 , 40 ) ;
2010-12-07 07:12:51 +01:00
2010-08-28 01:08:35 +02:00
// MapFilter
2010-09-09 00:37:24 +02:00
labelMapFilter . registerGraphicComponent ( containerName , " labelMapFilter " ) ;
2010-08-28 01:08:35 +02:00
labelMapFilter . init ( xoffset + 310 , mapHeadPos ) ;
labelMapFilter . setText ( lang . get ( " MapFilter " ) + " : " ) ;
2010-09-09 00:37:24 +02:00
listBoxMapFilter . registerGraphicComponent ( containerName , " listBoxMapFilter " ) ;
2010-08-28 01:08:35 +02:00
listBoxMapFilter . init ( xoffset + 310 , mapPos , 80 ) ;
2010-09-01 02:25:46 +02:00
listBoxMapFilter . pushBackItem ( " - " ) ;
2010-08-30 22:02:58 +02:00
for ( int i = 1 ; i < GameConstants : : maxPlayers + 1 ; + + i ) {
listBoxMapFilter . pushBackItem ( intToStr ( i ) ) ;
}
listBoxMapFilter . setSelectedItemIndex ( 0 ) ;
2010-12-07 07:12:51 +01:00
2010-08-28 01:08:35 +02:00
//tileset listBox
findDirs ( config . getPathListForType ( ptTilesets ) , results ) ;
if ( results . empty ( ) ) {
throw runtime_error ( " No tile-sets were found! " ) ;
}
tilesetFiles = results ;
std : : for_each ( results . begin ( ) , results . end ( ) , FormatString ( ) ) ;
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 ) ;
listBoxTileset . setItems ( results ) ;
2010-12-27 01:59:57 +01:00
srand ( time ( NULL ) ) ;
2011-01-02 01:39:13 +01:00
listBoxTileset . setSelectedItemIndex ( rand ( ) % listBoxTileset . getItemCount ( ) ) ;
2010-09-09 00:37:24 +02:00
labelTileset . registerGraphicComponent ( containerName , " labelTileset " ) ;
2010-08-28 01:08:35 +02:00
labelTileset . init ( xoffset + 460 , mapHeadPos ) ;
labelTileset . setText ( lang . get ( " Tileset " ) ) ;
2010-12-07 07:12:51 +01:00
2010-08-28 01:08:35 +02:00
//tech Tree listBox
findDirs ( config . getPathListForType ( ptTechs ) , results ) ;
if ( results . empty ( ) ) {
throw runtime_error ( " No tech-trees were found! " ) ;
}
techTreeFiles = results ;
std : : for_each ( results . begin ( ) , results . end ( ) , FormatString ( ) ) ;
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 ) ;
listBoxTechTree . setItems ( results ) ;
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 ) ;
labelTechTree . setText ( lang . get ( " 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 ) ;
labelFogOfWar . setText ( lang . get ( " FogOfWar " ) ) ;
listBoxFogOfWar . registerGraphicComponent ( containerName , " listBoxFogOfWar " ) ;
listBoxFogOfWar . init ( xoffset + 100 , aPos , 130 ) ;
listBoxFogOfWar . pushBackItem ( lang . get ( " Enabled " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . get ( " Explored " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . get ( " Disabled " ) ) ;
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 ) ;
2010-09-04 13:49:54 +02:00
labelAllowObservers . setText ( lang . get ( " AllowObservers " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxAllowObservers . registerGraphicComponent ( containerName , " listBoxAllowObservers " ) ;
2010-12-20 22:59:46 +01:00
listBoxAllowObservers . init ( xoffset + 310 , aPos , 80 ) ;
2010-09-04 13:49:54 +02:00
listBoxAllowObservers . pushBackItem ( lang . get ( " No " ) ) ;
listBoxAllowObservers . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxAllowObservers . setSelectedItemIndex ( 0 ) ;
2010-12-07 07:12:51 +01:00
2010-09-04 13:49:54 +02:00
// View Map At End Of Game
2010-09-09 00:37:24 +02:00
labelEnableObserverMode . registerGraphicComponent ( containerName , " labelEnableObserverMode " ) ;
2010-08-28 01:08:35 +02:00
labelEnableObserverMode . init ( xoffset + 460 , aHeadPos , 80 ) ;
2010-09-09 00:37:24 +02:00
listBoxEnableObserverMode . registerGraphicComponent ( containerName , " listBoxEnableObserverMode " ) ;
2010-09-04 13:49:54 +02:00
listBoxEnableObserverMode . init ( xoffset + 460 , aPos , 80 ) ;
2010-05-31 12:20:18 +02:00
listBoxEnableObserverMode . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxEnableObserverMode . pushBackItem ( lang . get ( " No " ) ) ;
listBoxEnableObserverMode . setSelectedItemIndex ( 0 ) ;
2010-09-04 03:24:17 +02:00
// Which Pathfinder
2010-09-09 00:37:24 +02:00
labelPathFinderType . registerGraphicComponent ( containerName , " labelPathFinderType " ) ;
2010-08-28 01:08:35 +02:00
labelPathFinderType . init ( xoffset + 650 , aHeadPos , 80 ) ;
2010-07-21 20:21:40 +02:00
labelPathFinderType . setText ( lang . get ( " PathFinderType " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxPathFinderType . registerGraphicComponent ( containerName , " listBoxPathFinderType " ) ;
2010-08-28 01:08:35 +02:00
listBoxPathFinderType . init ( xoffset + 650 , aPos , 150 ) ;
2010-07-21 20:21:40 +02:00
listBoxPathFinderType . pushBackItem ( lang . get ( " PathFinderTypeRegular " ) ) ;
listBoxPathFinderType . pushBackItem ( lang . get ( " PathFinderTypeRoutePlanner " ) ) ;
listBoxPathFinderType . setSelectedItemIndex ( 0 ) ;
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 ) ;
2010-08-28 01:08:35 +02:00
labelAdvanced . setText ( lang . get ( " AdvancedGameOptions " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxAdvanced . registerGraphicComponent ( containerName , " listBoxAdvanced " ) ;
2010-09-04 13:49:54 +02:00
listBoxAdvanced . init ( 810 , 80 - labelOffset , 80 ) ;
2010-08-28 01:08:35 +02:00
listBoxAdvanced . pushBackItem ( lang . get ( " No " ) ) ;
2010-09-04 03:50:36 +02:00
listBoxAdvanced . pushBackItem ( lang . get ( " Yes " ) ) ;
2010-08-28 01:08:35 +02:00
listBoxAdvanced . setSelectedItemIndex ( 0 ) ;
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 ) ;
2010-05-13 09:22:33 +02:00
labelPublishServer . setText ( lang . get ( " PublishServer " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxPublishServer . registerGraphicComponent ( containerName , " listBoxPublishServer " ) ;
2010-10-11 02:53:25 +02:00
listBoxPublishServer . init ( 50 , networkPos , 100 ) ;
2010-05-13 00:58:00 +02:00
listBoxPublishServer . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxPublishServer . pushBackItem ( lang . get ( " No " ) ) ;
2011-03-11 13:14:24 +01:00
if ( openNetworkSlots ) {
2010-06-04 02:33:34 +02:00
listBoxPublishServer . setSelectedItemIndex ( 0 ) ;
2011-03-11 13:14:24 +01:00
}
else {
2010-06-04 02:33:34 +02:00
listBoxPublishServer . setSelectedItemIndex ( 1 ) ;
2011-03-11 13:14:24 +01:00
}
2010-06-04 02:33:34 +02:00
2010-06-08 02:00:28 +02:00
// Network Frame Period
2010-10-26 23:52:00 +02:00
//labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod");
//labelNetworkFramePeriod.init(xoffset+230, networkHeadPos, 80);
//labelNetworkFramePeriod.setText(lang.get("NetworkFramePeriod"));
//listBoxNetworkFramePeriod.registerGraphicComponent(containerName,"listBoxNetworkFramePeriod");
//listBoxNetworkFramePeriod.init(xoffset+230, networkPos, 80);
//listBoxNetworkFramePeriod.pushBackItem("10");
//listBoxNetworkFramePeriod.pushBackItem("20");
//listBoxNetworkFramePeriod.pushBackItem("30");
//listBoxNetworkFramePeriod.pushBackItem("40");
//listBoxNetworkFramePeriod.setSelectedItem("20");
// Network Pause for lagged clients
2010-09-09 00:37:24 +02:00
labelNetworkPauseGameForLaggedClients . registerGraphicComponent ( containerName , " labelNetworkPauseGameForLaggedClients " ) ;
2010-10-11 02:53:25 +02:00
labelNetworkPauseGameForLaggedClients . init ( xoffset + 380 , networkHeadPos , 80 ) ;
2010-07-16 18:53:19 +02:00
labelNetworkPauseGameForLaggedClients . setText ( lang . get ( " NetworkPauseGameForLaggedClients " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxNetworkPauseGameForLaggedClients . registerGraphicComponent ( containerName , " listBoxNetworkPauseGameForLaggedClients " ) ;
2010-10-11 02:53:25 +02:00
listBoxNetworkPauseGameForLaggedClients . init ( xoffset + 380 , networkPos , 80 ) ;
2010-07-16 18:53:19 +02:00
listBoxNetworkPauseGameForLaggedClients . pushBackItem ( lang . get ( " No " ) ) ;
listBoxNetworkPauseGameForLaggedClients . pushBackItem ( lang . get ( " Yes " ) ) ;
2010-08-28 01:08:35 +02:00
listBoxNetworkPauseGameForLaggedClients . setSelectedItem ( lang . get ( " Yes " ) ) ;
2010-07-16 18:53:19 +02:00
2010-06-08 02:00:28 +02:00
2010-06-04 02:33:34 +02:00
// Enable Server Controlled AI
2010-10-26 23:52:00 +02:00
//labelEnableServerControlledAI.registerGraphicComponent(containerName,"labelEnableServerControlledAI");
//labelEnableServerControlledAI.init(xoffset+550, networkHeadPos, 80);
//labelEnableServerControlledAI.setText(lang.get("EnableServerControlledAI"));
2010-09-09 00:37:24 +02:00
2010-10-26 23:52:00 +02:00
//listBoxEnableServerControlledAI.registerGraphicComponent(containerName,"listBoxEnableServerControlledAI");
//listBoxEnableServerControlledAI.init(xoffset+550, networkPos, 80);
//listBoxEnableServerControlledAI.pushBackItem(lang.get("Yes"));
//listBoxEnableServerControlledAI.pushBackItem(lang.get("No"));
//listBoxEnableServerControlledAI.setSelectedItemIndex(0);
2010-05-13 00:58:00 +02:00
2010-11-06 00:12:46 +01:00
2010-03-13 23:00:01 +01:00
//list boxes
2010-11-09 00:15:50 +01:00
xoffset = 100 ;
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
labelPlayerStatus [ i ] . registerGraphicComponent ( containerName , " labelPlayerStatus " + intToStr ( i ) ) ;
labelPlayerStatus [ i ] . init ( 10 , setupPos - 30 - i * rowHeight , 60 ) ;
2010-09-09 00:37:24 +02:00
labelPlayers [ i ] . registerGraphicComponent ( containerName , " labelPlayers " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
labelPlayers [ i ] . init ( xoffset + 0 , setupPos - 30 - i * rowHeight ) ;
2010-09-09 00:37:24 +02:00
labelPlayerNames [ i ] . registerGraphicComponent ( containerName , " labelPlayerNames " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
labelPlayerNames [ i ] . init ( xoffset + 50 , 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 ) ) ;
2010-11-09 00:15:50 +01:00
listBoxControls [ i ] . init ( xoffset + 210 , setupPos - 30 - i * rowHeight ) ;
2010-12-07 07:12:51 +01:00
2010-11-09 00:15:50 +01:00
listBoxRMultiplier [ i ] . registerGraphicComponent ( containerName , " listBoxRMultiplier " + intToStr ( i ) ) ;
listBoxRMultiplier [ i ] . init ( xoffset + 350 , 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 ) ) ;
2010-11-09 00:15:50 +01:00
listBoxFactions [ i ] . init ( xoffset + 430 , setupPos - 30 - i * rowHeight , 150 ) ;
2010-09-09 00:37:24 +02:00
listBoxTeams [ i ] . registerGraphicComponent ( containerName , " listBoxTeams " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
listBoxTeams [ i ] . init ( xoffset + 590 , setupPos - 30 - i * rowHeight , 60 ) ;
2010-09-09 00:37:24 +02:00
labelNetStatus [ i ] . registerGraphicComponent ( containerName , " labelNetStatus " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
labelNetStatus [ i ] . init ( xoffset + 670 , setupPos - 30 - i * rowHeight , 60 ) ;
2010-03-13 23:00:01 +01:00
}
2010-11-09 00:15:50 +01:00
labelControl . registerGraphicComponent ( containerName , " labelControl " ) ;
labelControl . init ( xoffset + 210 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2010-08-28 01:08:35 +02:00
labelControl . setText ( lang . get ( " Control " ) ) ;
2010-12-07 07:12:51 +01:00
2010-11-09 00:15:50 +01:00
labelRMultiplier . registerGraphicComponent ( containerName , " labelRMultiplier " ) ;
labelRMultiplier . init ( xoffset + 350 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
//labelRMultiplier.setText(lang.get("RMultiplier"));
2010-12-07 07:12:51 +01:00
2010-09-09 00:37:24 +02:00
labelFaction . registerGraphicComponent ( containerName , " labelFaction " ) ;
2010-11-09 00:15:50 +01:00
labelFaction . init ( xoffset + 430 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2010-08-28 01:08:35 +02:00
labelFaction . setText ( lang . get ( " Faction " ) ) ;
2010-09-09 00:37:24 +02:00
labelTeam . registerGraphicComponent ( containerName , " labelTeam " ) ;
2010-11-09 00:15:50 +01:00
labelTeam . init ( xoffset + 590 , setupPos , 50 , GraphicListBox : : defH , true ) ;
2010-08-28 01:08:35 +02:00
labelTeam . setText ( lang . get ( " Team " ) ) ;
2010-12-07 07:12:51 +01:00
2010-06-04 02:33:34 +02:00
labelControl . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2010-11-09 00:15:50 +01:00
labelRMultiplier . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2010-06-04 02:33:34 +02:00
labelFaction . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelTeam . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2010-12-07 07:12:51 +01:00
2010-03-13 23:00:01 +01:00
//texts
buttonReturn . setText ( lang . get ( " Return " ) ) ;
buttonPlayNow . setText ( lang . get ( " PlayNow " ) ) ;
2010-06-01 02:32:24 +02:00
buttonRestoreLastSettings . setText ( lang . get ( " ReloadLastGameSettings " ) ) ;
2010-03-13 23:00:01 +01:00
controlItems . push_back ( lang . get ( " Closed " ) ) ;
controlItems . push_back ( lang . get ( " CpuEasy " ) ) ;
controlItems . push_back ( lang . get ( " Cpu " ) ) ;
controlItems . push_back ( lang . get ( " CpuUltra " ) ) ;
controlItems . push_back ( lang . get ( " CpuMega " ) ) ;
controlItems . push_back ( lang . get ( " Network " ) ) ;
controlItems . push_back ( lang . get ( " Human " ) ) ;
2010-12-07 07:12:51 +01:00
2010-11-09 00:15:50 +01:00
for ( int i = 0 ; i < 45 ; + + i ) {
2010-11-25 23:45:08 +01:00
rMultiplier . push_back ( floatToStr ( 0.5f + 0.1f * i , 1 ) ) ;
2010-11-09 00:15:50 +01:00
}
2010-12-07 07:12:51 +01:00
2010-09-14 21:10:37 +02:00
if ( config . getBool ( " EnableNetworkCpu " , " false " ) = = true ) {
controlItems . push_back ( lang . get ( " NetworkCpuEasy " ) ) ;
controlItems . push_back ( lang . get ( " NetworkCpu " ) ) ;
controlItems . push_back ( lang . get ( " NetworkCpuUltra " ) ) ;
controlItems . push_back ( lang . get ( " NetworkCpuMega " ) ) ;
}
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
2010-10-15 01:22:09 +02:00
reloadFactions ( false ) ;
2010-03-13 23:00:01 +01:00
2010-03-18 22:26:40 +01:00
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
2011-03-13 09:23:43 +01:00
endPathWithSlash ( techPath ) ;
findAll ( techPath + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " /factions/*. " , results , false , false ) ;
2010-03-18 22:26:40 +01:00
if ( results . size ( ) > 0 ) {
break ;
}
}
if ( results . size ( ) = = 0 ) {
2011-01-02 01:39:13 +01:00
//throw runtime_error("(1)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
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
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-03-11 12:11:46 +01:00
labelPlayerStatus [ i ] . setText ( " " ) ;
2010-03-13 23:00:01 +01:00
labelPlayers [ i ] . setText ( lang . get ( " Player " ) + " " + intToStr ( i ) ) ;
2010-08-21 09:41:26 +02:00
labelPlayerNames [ i ] . setText ( " * " ) ;
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 ) ;
listBoxRMultiplier [ i ] . setSelectedItemIndex ( 5 ) ;
2010-03-13 23:00:01 +01:00
labelNetStatus [ i ] . setText ( " " ) ;
}
2010-05-31 12:20:18 +02:00
labelEnableObserverMode . setText ( lang . get ( " EnableObserverMode " ) ) ;
2010-12-07 07:12:51 +01:00
2010-05-31 12:20:18 +02:00
2010-09-12 07:05:08 +02:00
loadMapInfo ( Map : : getMapPath ( getCurrentMapFile ( ) ) , & mapInfo , true ) ;
2010-03-13 23:00:01 +01:00
labelMapInfo . setText ( mapInfo . desc ) ;
2010-06-01 01:39:07 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 23:00:01 +01:00
//init controllers
2010-06-11 06:55:49 +02:00
if ( serverInitError = = false ) {
listBoxControls [ 0 ] . setSelectedItemIndex ( ctHuman ) ;
2010-08-21 09:41:26 +02:00
labelPlayerNames [ 0 ] . setText ( " " ) ;
labelPlayerNames [ 0 ] . setText ( getHumanPlayerName ( ) ) ;
2010-06-11 06:55:49 +02:00
if ( openNetworkSlots ) {
for ( int i = 1 ; i < mapInfo . players ; + + i ) {
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
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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 ) ;
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
serverInterface - > setGameSettings ( & gameSettings , false ) ;
}
2010-06-01 01:39:07 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-11-11 02:24:48 +01:00
updateAllResourceMultiplier ( ) ;
2011-03-11 12:11:46 +01:00
listBoxPlayerStatus . registerGraphicComponent ( containerName , " listBoxPlayerStatus " ) ;
listBoxPlayerStatus . init ( 10 , 600 , 150 ) ;
vector < string > playerStatuses ;
playerStatuses . push_back ( lang . get ( " PlayerStatusSetup " ) ) ;
playerStatuses . push_back ( lang . get ( " PlayerStatusBeRightBack " ) ) ;
playerStatuses . push_back ( lang . get ( " PlayerStatusReady " ) ) ;
listBoxPlayerStatus . setItems ( playerStatuses ) ;
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
2010-09-04 02:44:53 +02:00
console . addLine ( lang . get ( " To switch off music press " ) + " - \" " + configKeys . getCharKey ( " 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 ) ;
2011-02-06 08:01:54 +01:00
publishToMasterserverThread = new SimpleTaskThread ( this , 0 , 200 ) ;
2010-06-18 22:04:05 +02:00
publishToMasterserverThread - > setUniqueID ( __FILE__ ) ;
2010-05-13 08:43:56 +02:00
publishToMasterserverThread - > start ( ) ;
2010-06-01 01:39:07 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-13 08:43:56 +02:00
}
2011-01-02 10:33:37 +01:00
void MenuStateCustomGame : : cleanup ( ) {
//printf("IN MenuStateCustomGame cleanup - A\n");
2011-01-02 07:46:48 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( publishToMasterserverThread ! = NULL ) {
2010-12-07 07:12:51 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-01-02 10:33:37 +01:00
//printf("IN MenuStateCustomGame cleanup - B\n");
needToBroadcastServerSettings = false ;
needToRepublishToMasterserver = false ;
lastNetworkPing = time ( NULL ) ;
publishToMasterserverThread - > setThreadOwnerValid ( false ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( publishToMasterserverThread - > canShutdown ( true ) = = true & &
publishToMasterserverThread - > shutdownAndWait ( ) = = true ) {
//printf("IN MenuStateCustomGame cleanup - C\n");
2011-01-02 07:46:48 +01:00
delete publishToMasterserverThread ;
}
2011-01-02 10:33:37 +01:00
//printf("IN MenuStateCustomGame cleanup - D\n");
2011-01-02 07:46:48 +01:00
publishToMasterserverThread = NULL ;
}
2010-06-01 01:39:07 +02:00
2011-01-02 10:33:37 +01:00
//printf("IN MenuStateCustomGame cleanup - E\n");
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 23:00:01 +01:00
}
2011-01-02 10:33:37 +01:00
MenuStateCustomGame : : ~ MenuStateCustomGame ( ) {
//printf("IN MenuStateCustomGame Destructor - A\n");
cleanup ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2011-01-02 07:46:48 +01:00
void MenuStateCustomGame : : returnToParentMenu ( ) {
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-16 18:40:21 +02:00
needToBroadcastServerSettings = false ;
needToRepublishToMasterserver = false ;
2011-01-02 10:33:37 +01:00
lastNetworkPing = time ( NULL ) ;
2010-06-18 22:04:05 +02:00
bool returnToMasterServerMenu = parentMenuIsMs ;
2010-06-05 02:58:32 +02:00
2011-01-02 10:33:37 +01:00
/*
2010-12-05 02:52:38 +01:00
if ( publishToMasterserverThread ! = NULL & &
2011-01-02 07:46:48 +01:00
publishToMasterserverThread - > canShutdown ( ) = = true & &
2010-12-05 02:52:38 +01:00
publishToMasterserverThread - > shutdownAndWait ( ) = = true ) {
2011-01-02 10:33:37 +01:00
publishToMasterserverThread - > setThreadOwnerValid ( false ) ;
2010-12-05 02:52:38 +01:00
delete publishToMasterserverThread ;
2010-12-07 07:12:51 +01:00
publishToMasterserverThread = NULL ;
2010-12-05 02:52:38 +01:00
}
2011-01-02 10:33:37 +01:00
*/
2010-12-07 07:12:51 +01:00
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-11 05:17:38 +02:00
if ( returnToMasterServerMenu ) {
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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 ) ) ;
}
2010-06-05 02:58:32 +02:00
else {
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-16 18:40:21 +02:00
}
2010-03-13 23:00:01 +01:00
void MenuStateCustomGame : : mouseClick ( int x , int y , MouseButton mouseButton ) {
2011-01-02 01:39:13 +01:00
try {
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
int oldListBoxMapfilterIndex = listBoxMapFilter . getSelectedItemIndex ( ) ;
if ( mainMessageBox . getEnabled ( ) ) {
int button = 1 ;
if ( mainMessageBox . mouseClick ( x , y , button ) )
{
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
if ( button = = 1 )
{
mainMessageBox . setEnabled ( false ) ;
}
}
}
else if ( buttonReturn . mouseClick ( x , y ) | | serverInitError = = true ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-02 01:39:13 +01:00
needToBroadcastServerSettings = false ;
needToRepublishToMasterserver = false ;
2011-01-02 10:33:37 +01:00
lastNetworkPing = time ( NULL ) ;
2011-01-02 01:39:13 +01:00
safeMutex . ReleaseLock ( ) ;
2011-01-02 10:33:37 +01:00
/*
2011-01-02 01:39:13 +01:00
if ( publishToMasterserverThread ! = NULL & &
2011-01-02 07:46:48 +01:00
publishToMasterserverThread - > canShutdown ( ) = = true & &
2011-01-02 01:39:13 +01:00
publishToMasterserverThread - > shutdownAndWait ( ) = = true ) {
2011-01-02 10:33:37 +01:00
publishToMasterserverThread - > setThreadOwnerValid ( false ) ;
2011-01-02 01:39:13 +01:00
delete publishToMasterserverThread ;
publishToMasterserverThread = NULL ;
}
2011-01-02 10:33:37 +01:00
*/
2010-12-07 07:12:51 +01:00
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-05 09:52:14 +02:00
2011-01-02 01:39:13 +01:00
returnToParentMenu ( ) ;
}
else if ( buttonPlayNow . mouseClick ( x , y ) & & buttonPlayNow . getEnabled ( ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-11 06:55:49 +02:00
2011-01-02 01:39:13 +01:00
PlayNow ( ) ;
2011-02-12 08:34:32 +01:00
return ;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2011-01-02 01:39:13 +01:00
}
else if ( buttonRestoreLastSettings . mouseClick ( x , y ) & & buttonRestoreLastSettings . getEnabled ( ) ) {
RestoreLastGameSettings ( ) ;
}
else if ( listBoxMap . mouseClick ( x , y ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , getCurrentMapFile ( ) . c_str ( ) ) ;
2010-06-05 17:48:50 +02:00
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-03-13 23:00:01 +01:00
2011-01-02 01:39:13 +01:00
loadMapInfo ( Map : : getMapPath ( getCurrentMapFile ( ) , " " , false ) , & mapInfo , true ) ;
labelMapInfo . setText ( mapInfo . desc ) ;
updateControlers ( ) ;
updateNetworkSlots ( ) ;
2010-06-04 23:46:10 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-03-13 23:00:01 +01:00
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
2011-01-29 21:13:29 +01:00
//delay publishing for 5 seconds
2011-01-31 00:01:55 +01:00
needToPublishDelayed = true ;
2011-01-29 21:13:29 +01:00
mapPublishingDelayTimer = time ( NULL ) ;
2011-01-02 01:39:13 +01:00
}
2010-03-27 08:09:34 +01:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 & & listBoxFogOfWar . mouseClick ( x , y ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2011-02-08 06:54:05 +01:00
cleanupMapPreviewTexture ( ) ;
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-05-13 08:43:56 +02:00
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
2011-01-02 01:39:13 +01:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-09-04 03:24:17 +02:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 & & listBoxAllowObservers . mouseClick ( x , y ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-09-04 03:24:17 +02:00
2011-01-02 01:39:13 +01:00
reloadFactions ( true ) ;
2010-09-04 03:24:17 +02:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-05-31 12:20:18 +02:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 & & listBoxEnableObserverMode . mouseClick ( x , y ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-05-31 12:20:18 +02:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-07-21 20:21:40 +02:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 & & listBoxPathFinderType . mouseClick ( x , y ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-07-21 20:21:40 +02:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-06-03 03:10:40 +02:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxAdvanced . mouseClick ( x , y ) ) {
//TODO
2010-03-13 23:00:01 +01:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxTileset . mouseClick ( x , y ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-09-02 01:15:08 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true )
{
2011-01-31 00:01:55 +01:00
//delay publishing for 5 seconds
needToPublishDelayed = true ;
mapPublishingDelayTimer = time ( NULL ) ;
2011-01-02 01:39:13 +01:00
}
}
else if ( listBoxMapFilter . mouseClick ( x , y ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-02 01:39:13 +01:00
switchToNextMapGroup ( listBoxMapFilter . getSelectedItemIndex ( ) - oldListBoxMapfilterIndex ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , getCurrentMapFile ( ) . c_str ( ) ) ;
loadMapInfo ( Map : : getMapPath ( getCurrentMapFile ( ) ) , & mapInfo , true ) ;
labelMapInfo . setText ( mapInfo . desc ) ;
updateControlers ( ) ;
updateNetworkSlots ( ) ;
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-03-13 23:00:01 +01:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-03-13 23:00:01 +01:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxTechTree . mouseClick ( x , y ) ) {
reloadFactions ( false ) ;
2010-03-13 23:00:01 +01:00
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-30 06:24:26 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-05-13 08:43:56 +02:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-03-13 23:00:01 +01:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxPublishServer . mouseClick ( x , y ) & & listBoxPublishServer . getEditable ( ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-02 01:39:13 +01:00
needToRepublishToMasterserver = true ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
2011-03-11 13:14:24 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
serverInterface - > setPublishEnabled ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) ;
2010-08-05 01:39:12 +02:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 & & listBoxNetworkPauseGameForLaggedClients . mouseClick ( x , y ) ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-08-05 01:39:12 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-12-07 07:12:51 +01:00
2011-01-02 01:39:13 +01:00
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
}
else {
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-12-07 07:12:51 +01:00
2011-01-02 01:39:13 +01:00
if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 ) {
// set multiplier
if ( listBoxRMultiplier [ i ] . mouseClick ( x , y ) ) {
}
}
2010-08-23 06:33:21 +02:00
2011-01-02 01:39:13 +01:00
//ensure thet only 1 human player is present
if ( listBoxControls [ i ] . mouseClick ( x , y ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//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 ;
}
}
}
2010-03-13 23:00:01 +01:00
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , humanIndex1 , humanIndex2 ) ;
2010-08-23 06:33:21 +02:00
2011-01-02 01:39:13 +01:00
//no human
if ( humanIndex1 = = - 1 & & humanIndex2 = = - 1 ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctHuman ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d, labelPlayerNames[i].getText() [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , labelPlayerNames [ i ] . getText ( ) . c_str ( ) ) ;
}
//2 humans
else if ( humanIndex1 ! = - 1 & & humanIndex2 ! = - 1 ) {
int closeSlotIndex = ( humanIndex1 = = i ? humanIndex2 : humanIndex1 ) ;
int humanSlotIndex = ( closeSlotIndex = = humanIndex1 ? humanIndex2 : humanIndex1 ) ;
2010-08-23 06:33:21 +02:00
2011-01-02 01:39:13 +01:00
string origPlayName = labelPlayerNames [ closeSlotIndex ] . getText ( ) ;
2010-08-23 06:33:21 +02:00
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] closeSlotIndex = %d, origPlayName [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , closeSlotIndex , origPlayName . c_str ( ) ) ;
2010-08-23 06:33:21 +02:00
2011-01-02 01:39:13 +01:00
listBoxControls [ closeSlotIndex ] . setSelectedItemIndex ( ctClosed ) ;
labelPlayerNames [ humanSlotIndex ] . setText ( ( origPlayName ! = " " ? origPlayName : getHumanPlayerName ( ) ) ) ;
}
updateNetworkSlots ( ) ;
2010-03-13 23:00:01 +01:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-10-30 06:24:26 +02:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
updateResourceMultiplier ( i ) ;
2010-03-13 23:00:01 +01:00
}
2011-01-02 01:39:13 +01:00
else if ( listBoxFactions [ i ] . mouseClick ( x , y ) ) {
2011-01-25 01:42:09 +01: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 ) ;
}
//
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-03-13 23:00:01 +01:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-03-13 23:00:01 +01:00
}
2011-01-02 01:39:13 +01:00
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-10-30 06:24:26 +02:00
2011-01-02 01:39:13 +01:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-05-13 08:43:56 +02:00
2011-01-02 01:39:13 +01:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ; ;
}
2010-03-13 23:00:01 +01:00
}
2011-01-02 01:39:13 +01:00
else if ( labelPlayerNames [ i ] . mouseClick ( x , y ) ) {
SetActivePlayerNameEditor ( ) ;
}
}
}
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true & & listBoxPlayerStatus . mouseClick ( x , y ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
if ( hasNetworkGameSettings ( ) = = true ) {
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
2011-01-02 01:39:13 +01:00
}
catch ( const std : : exception & ex ) {
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
//throw runtime_error(szBuf);
showGeneralError = true ;
generalErrorToShow = szBuf ;
2010-03-13 23:00:01 +01:00
}
2010-05-31 21:57:10 +02:00
2010-04-12 23:40:57 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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 ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ index ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman | | ct = = ctNetwork | | ct = = ctClosed ) {
2010-12-11 01:20:31 +01:00
listBoxRMultiplier [ index ] . setSelectedItemIndex ( ( GameConstants : : normalMultiplier - 0.5f ) * 10 ) ;
2010-11-11 02:24:48 +01:00
listBoxRMultiplier [ index ] . setEnabled ( false ) ;
}
else if ( ct = = ctCpuEasy | | ct = = ctNetworkCpuEasy )
{
2010-12-11 01:20:31 +01:00
listBoxRMultiplier [ index ] . setSelectedItemIndex ( ( GameConstants : : easyMultiplier - 0.5f ) * 10 ) ;
2010-11-11 02:24:48 +01:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
else if ( ct = = ctCpu | | ct = = ctNetworkCpu ) {
2010-12-11 01:20:31 +01:00
listBoxRMultiplier [ index ] . setSelectedItemIndex ( ( GameConstants : : normalMultiplier - 0.5f ) * 10 ) ;
2010-11-11 02:24:48 +01:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
else if ( ct = = ctCpuUltra | | ct = = ctNetworkCpuUltra )
{
2010-12-11 01:20:31 +01:00
listBoxRMultiplier [ index ] . setSelectedItemIndex ( ( GameConstants : : ultraMultiplier - 0.5f ) * 10 ) ;
2010-11-11 02:24:48 +01:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
else if ( ct = = ctCpuMega | | ct = = ctNetworkCpuMega )
{
2010-12-11 01:20:31 +01:00
listBoxRMultiplier [ index ] . setSelectedItemIndex ( ( GameConstants : : megaMultiplier - 0.5f ) * 10 ) ;
2010-11-11 02:24:48 +01:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
listBoxRMultiplier [ index ] . setEditable ( listBoxRMultiplier [ index ] . getEnabled ( ) ) ;
2011-01-03 03:35:09 +01:00
listBoxRMultiplier [ index ] . setVisible ( listBoxRMultiplier [ index ] . getEnabled ( ) ) ;
2010-11-11 02:24:48 +01:00
}
2010-10-08 03:41:53 +02:00
void MenuStateCustomGame : : SetActivePlayerNameEditor ( ) {
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctHuman ) {
setActiveInputLabel ( & labelPlayerNames [ i ] ) ;
break ;
}
}
}
2010-10-02 04:17:50 +02:00
void MenuStateCustomGame : : RestoreLastGameSettings ( ) {
// Ensure we have set the gamesettings at least once
GameSettings gameSettings = loadGameSettingsFromFile ( " lastCustomGamSettings.mgg " ) ;
if ( gameSettings . getMap ( ) = = " " ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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__ ) ) ;
2010-10-30 06:24:26 +02:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
}
2010-10-02 04:17:50 +02:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
void MenuStateCustomGame : : PlayNow ( ) {
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > getMutexThreadObjectAccessor ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2010-10-02 04:17:50 +02:00
saveGameSettingsToFile ( " lastCustomGamSettings.mgg " ) ;
closeUnusedSlots ( ) ;
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
std : : vector < string > randomFactionSelectionList ;
int RandomCount = 0 ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
// Check for random faction selection and choose the faction now
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
if ( listBoxFactions [ i ] . getSelectedItem ( ) = = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , i ) ;
// Max 1000 tries to get a random, unused faction
for ( int findRandomFaction = 1 ; findRandomFaction < 1000 ; + + findRandomFaction ) {
srand ( time ( NULL ) + findRandomFaction ) ;
int selectedFactionIndex = rand ( ) % listBoxFactions [ i ] . getItemCount ( ) ;
string selectedFactionName = listBoxFactions [ i ] . getItem ( selectedFactionIndex ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] selectedFactionName [%s] selectedFactionIndex = %d, findRandomFaction = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , selectedFactionName . c_str ( ) , selectedFactionIndex , findRandomFaction ) ;
if ( selectedFactionName ! = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) & &
selectedFactionName ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) & &
std : : find ( randomFactionSelectionList . begin ( ) , randomFactionSelectionList . end ( ) , selectedFactionName ) = = randomFactionSelectionList . end ( ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
listBoxFactions [ i ] . setSelectedItem ( selectedFactionName ) ;
randomFactionSelectionList . push_back ( selectedFactionName ) ;
break ;
}
}
if ( listBoxFactions [ i ] . getSelectedItem ( ) = = formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] RandomCount = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , RandomCount ) ;
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
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d, listBoxFactions[i].getSelectedItem() [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , listBoxFactions [ i ] . getSelectedItem ( ) . c_str ( ) ) ;
RandomCount + + ;
}
}
}
if ( RandomCount > 0 ) {
needToSetChangedGameSettings = true ;
}
safeMutex . ReleaseLock ( true ) ;
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
// Send the game settings to each client if we have at least one networked client
safeMutex . Lock ( ) ;
bool dataSynchCheckOk = true ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & & serverInterface - > getSlot ( i ) - > isConnected ( ) & &
serverInterface - > getSlot ( i ) - > getAllowGameDataSynchCheck ( ) = = true & &
serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
2010-10-02 04:17:50 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
dataSynchCheckOk = false ;
break ;
}
}
}
if ( dataSynchCheckOk = = false ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
mainMessageBoxState = 1 ;
showMessageBox ( " You cannot start the game because \n one or more clients do not have the same game data! " , " Data Mismatch Error " , false ) ;
safeMutex . ReleaseLock ( ) ;
return ;
}
else {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( ( hasNetworkGameSettings ( ) = = true & &
needToSetChangedGameSettings = = true ) | | ( RandomCount > 0 ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 ) ;
}
2010-10-24 00:06:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
// Tell the server Interface whether or not to publish game status updates to masterserver
serverInterface - > setNeedToRepublishToMasterserver ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) ;
2010-10-02 04:17:50 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
bool bOkToStart = serverInterface - > launchGame ( & gameSettings ) ;
if ( bOkToStart = = true ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( listBoxPublishServer . getEditable ( ) & &
listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
needToRepublishToMasterserver = true ;
lastMasterserverPublishing = 0 ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
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 ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
assert ( program ! = NULL ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-01-02 10:33:37 +01:00
cleanup ( ) ;
2011-02-12 08:34:32 +01:00
Game * newGame = new Game ( program , & gameSettings ) ;
program - > setState ( newGame ) ;
2010-10-02 04:17:50 +02:00
return ;
}
else {
safeMutex . ReleaseLock ( ) ;
}
}
}
2010-03-13 23:00:01 +01:00
void MenuStateCustomGame : : mouseMove ( int x , int y , const MouseState * ms ) {
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 ) ;
2010-03-13 23:00:01 +01:00
2010-08-21 09:41:26 +02:00
bool editingPlayerName = false ;
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 ) ;
listBoxFactions [ i ] . mouseMove ( x , y ) ;
listBoxTeams [ i ] . mouseMove ( x , y ) ;
2010-08-21 09:41:26 +02:00
if ( labelPlayerNames [ i ] . mouseMove ( x , y ) = = true ) {
editingPlayerName = true ;
}
2010-03-13 23:00:01 +01:00
}
2010-08-21 09:41:26 +02:00
if ( editingPlayerName = = false ) {
setActiveInputLabel ( NULL ) ;
}
2010-03-13 23:00:01 +01:00
listBoxMap . mouseMove ( x , y ) ;
2010-09-04 03:50:36 +02:00
if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 ) {
listBoxFogOfWar . mouseMove ( x , y ) ;
listBoxAllowObservers . mouseMove ( x , y ) ;
listBoxEnableObserverMode . mouseMove ( x , y ) ;
2010-10-26 23:52:00 +02:00
//listBoxEnableServerControlledAI.mouseMove(x, y);
//labelNetworkFramePeriod.mouseMove(x, y);
//listBoxNetworkFramePeriod.mouseMove(x, y);
2010-09-04 03:50:36 +02:00
labelNetworkPauseGameForLaggedClients . mouseMove ( x , y ) ;
listBoxNetworkPauseGameForLaggedClients . mouseMove ( x , y ) ;
labelPathFinderType . mouseMove ( x , y ) ;
listBoxPathFinderType . 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 ) ;
2010-05-13 00:58:00 +02:00
listBoxPublishServer . mouseMove ( x , y ) ;
2010-07-21 20:21:40 +02:00
2010-08-28 01:08:35 +02:00
listBoxAdvanced . mouseMove ( x , y ) ;
2010-03-13 23:00:01 +01:00
}
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
2010-08-31 08:38:27 +02:00
if ( factionTexture ! = NULL ) {
2010-11-10 01:45:26 +01:00
renderer . renderTextureQuad ( 800 , 600 , 200 , 150 , factionTexture , 0.7f ) ;
2010-11-01 17:44:05 +01:00
}
if ( mapPreviewTexture ! = NULL ) {
2011-02-08 21:17:16 +01:00
renderer . renderTextureQuad ( 5 , 185 , 150 , 150 , mapPreviewTexture , 1.0f ) ;
2010-11-01 17:44:05 +01:00
//printf("=================> Rendering map preview texture\n");
2010-08-31 08:38:27 +02:00
}
2010-05-17 01:03:22 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
2010-06-01 01:39:07 +02:00
renderer . renderMessageBox ( & mainMessageBox ) ;
2010-03-13 23:00:01 +01:00
}
2010-05-17 01:03:22 +02:00
else
2010-05-13 00:58:00 +02:00
{
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 ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
const FontMetrics * fontMetrics = CoreData : : getInstance ( ) . getMenuFontNormal ( ) - > getMetrics ( ) ;
if ( fontMetrics = = NULL ) {
throw runtime_error ( " fontMetrics == NULL " ) ;
}
int curWidth = ( metrics . toVirtualX ( fontMetrics - > getTextWidth ( labelPlayers [ i ] . getText ( ) ) ) ) ;
if ( labelPlayers [ i ] . getX ( ) + curWidth > = labelPlayerNames [ i ] . getX ( ) ) {
int newOffsetPosition = labelPlayers [ i ] . getX ( ) + curWidth + 2 ;
if ( offsetPosition < newOffsetPosition ) {
offsetPosition = newOffsetPosition ;
}
}
}
// END
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
renderer . renderListBox ( & listBoxPlayerStatus ) ;
}
2010-10-22 09:28:55 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
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 ) ;
// Blend the color with white so make it more readable
2010-11-02 21:19:56 +01:00
//Vec4f newColor(1.f, 1.f, 1.f, 0.57f);
//renderer.renderLabel(&labelPlayers[i],&newColor);
2010-10-22 09:28:55 +02:00
//int quadWidth = labelPlayerNames[i].getX() - labelPlayers[i].getX() - 5;
//renderer.renderTextureQuad(labelPlayers[i].getX(), labelPlayers[i].getY(), quadWidth, labelPlayers[i].getH(), crcPlayerTextureCache[i],1.0f,&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
2010-05-17 01:03:22 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
2011-01-03 03:35:09 +01:00
if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 ) {
2010-11-11 02:24:48 +01:00
renderer . renderListBox ( & listBoxRMultiplier [ i ] ) ;
2010-12-07 07:12:51 +01:00
}
2010-05-17 01:03:22 +02:00
renderer . renderListBox ( & listBoxFactions [ i ] ) ;
renderer . renderListBox ( & listBoxTeams [ i ] ) ;
renderer . renderLabel ( & labelNetStatus [ i ] ) ;
}
}
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
if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 ) {
renderer . renderLabel ( & labelFogOfWar ) ;
renderer . renderLabel ( & labelAllowObservers ) ;
renderer . renderLabel ( & labelEnableObserverMode ) ;
renderer . renderLabel ( & labelPathFinderType ) ;
renderer . renderListBox ( & listBoxFogOfWar ) ;
renderer . renderListBox ( & listBoxAllowObservers ) ;
renderer . renderListBox ( & listBoxEnableObserverMode ) ;
renderer . renderListBox ( & listBoxPathFinderType ) ;
}
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 ) ;
2010-11-09 00:15:50 +01:00
//renderer.renderLabel(&labelRMultiplier);
2010-05-17 01:03:22 +02:00
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 ) ;
2010-08-28 01:08:35 +02:00
renderer . renderListBox ( & listBoxAdvanced ) ;
2010-12-07 07:12:51 +01:00
2010-09-04 03:50:36 +02:00
2010-05-17 01:03:22 +02:00
if ( listBoxPublishServer . getEditable ( ) )
{
renderer . renderListBox ( & listBoxPublishServer ) ;
renderer . renderLabel ( & labelPublishServer ) ;
2010-09-04 03:50:36 +02:00
if ( listBoxAdvanced . getSelectedItemIndex ( ) = = 1 ) {
2010-10-26 23:52:00 +02:00
//renderer.renderListBox(&listBoxEnableServerControlledAI);
//renderer.renderLabel(&labelEnableServerControlledAI);
//renderer.renderLabel(&labelNetworkFramePeriod);
//renderer.renderListBox(&listBoxNetworkFramePeriod);
2010-09-04 03:50:36 +02:00
renderer . renderLabel ( & labelNetworkPauseGameForLaggedClients ) ;
renderer . renderListBox ( & listBoxNetworkPauseGameForLaggedClients ) ;
}
2010-05-17 01:03:22 +02:00
}
2010-05-13 00:58:00 +02: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
int mouseX = mainMenu - > getMouseX ( ) ;
int mouseY = mainMenu - > getMouseY ( ) ;
int mouse2dAnim = mainMenu - > getMouse2dAnim ( ) ;
renderer . renderMouse2d ( mouseX , mouseY , mouse2dAnim ) ;
2010-12-21 16:55:37 +01:00
bool renderAll = ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 2 ) ;
2010-11-01 17:44:05 +01:00
if ( mapPreviewTexture = = NULL ) {
//printf("=================> Rendering map preview into a texture BEFORE (%p)\n", mapPreviewTexture);
renderer . renderMapPreview ( & mapPreview , renderAll , 10 , 350 , & mapPreviewTexture ) ;
//printf("=================> Rendering map preview into a texture AFTER (%p)\n", mapPreviewTexture);
}
2011-02-08 06:54:05 +01:00
//else {
//renderer.renderMapPreview(&mapPreview, renderAll, 10, 350);
//}
2010-09-12 07:05:08 +02:00
}
2010-12-07 07:12:51 +01:00
2011-01-03 13:41:20 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
renderer . renderChatManager ( & chatManager ) ;
}
2010-09-15 01:02:50 +02:00
renderer . renderConsole ( & console , showFullConsole , true ) ;
2010-04-11 03:25:06 +02:00
}
catch ( const std : : exception & ex ) {
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-01-12 01:16:50 +01:00
//throw runtime_error(szBuf);
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2011-01-25 08:41:12 +01:00
//throw runtime_error(szBuf);
2011-01-12 01:16:50 +01:00
showGeneralError = true ;
generalErrorToShow = ex . what ( ) ;
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
}
2010-06-23 16:49:20 +02:00
void MenuStateCustomGame : : update ( ) {
2010-09-02 23:40:43 +02:00
Chrono chrono ;
chrono . start ( ) ;
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__ ) ) ;
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 ) {
2010-06-23 16:49:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-11 06:55:49 +02:00
if ( showGeneralError ) {
2010-06-23 16:49:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-11 06:55:49 +02:00
showGeneralError = false ;
mainMessageBoxState = 1 ;
showMessageBox ( generalErrorToShow , " Error " , false ) ;
}
2010-06-23 16:49:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-11 06:55:49 +02:00
return ;
}
2010-04-11 03:25:06 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-06-23 16:49:20 +02:00
2010-04-11 03:25:06 +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
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-06-23 16:49:20 +02:00
2010-09-02 23:40:43 +02:00
if ( masterServerErr ) {
2010-06-23 16:49:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-01-09 08:37:59 +01:00
if ( EndsWith ( masterServererErrorToShow , " wrong router setup " ) = = true ) {
2010-06-24 03:23:18 +02:00
masterServererErrorToShow = lang . get ( " WrongRouterSetup " ) ;
2010-05-17 01:03:22 +02:00
}
2011-01-09 08:37:59 +01:00
masterServererErrorToShow + = " (disabling publish) " ;
2010-05-17 22:05:31 +02:00
showMasterserverError = false ;
2010-05-17 01:03:22 +02:00
mainMessageBoxState = 1 ;
showMessageBox ( masterServererErrorToShow , lang . get ( " ErrorFromMasterserver " ) , false ) ;
2010-06-23 16:49:20 +02:00
listBoxPublishServer . setSelectedItemIndex ( 1 ) ;
2011-03-11 13:14:24 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
serverInterface - > setPublishEnabled ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) ;
2010-05-17 01:03:22 +02:00
}
2010-06-11 06:55:49 +02:00
else if ( showGeneralError ) {
2010-06-23 16:49:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-11 06:55:49 +02:00
showGeneralError = false ;
mainMessageBoxState = 1 ;
showMessageBox ( generalErrorToShow , " Error " , false ) ;
}
2010-12-07 07:12:51 +01:00
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-06-01 01:39:07 +02:00
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 ( ) ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2010-08-21 15:04:52 +02:00
if ( switchSetupRequests [ i ] ! = NULL ) {
2010-08-23 06:33:21 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] switchSetupRequests[i]->getSwitchFlags() = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , switchSetupRequests [ i ] - > getSwitchFlags ( ) ) ;
2010-05-17 08:41:05 +02:00
2010-08-21 15:04:52 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
2010-10-08 03:41:53 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] switchSetupRequests[i]->getToFactionIndex() = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , switchSetupRequests [ i ] - > getToFactionIndex ( ) ) ;
2010-04-30 03:08:29 +02:00
//printf("switchSetupRequests[i]->getSelectedFactionName()=%s\n",switchSetupRequests[i]->getSelectedFactionName().c_str());
//printf("switchSetupRequests[i]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam());
2010-12-07 07:12:51 +01:00
2010-08-23 06:33:21 +02:00
if ( switchSetupRequests [ i ] - > getToFactionIndex ( ) ! = - 1 ) {
int newFactionIdx = switchSetupRequests [ i ] - > getToFactionIndex ( ) ;
2010-08-21 15:04:52 +02:00
2010-04-30 03:08:29 +02:00
//printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex());
2010-08-23 06:33:21 +02:00
int switchFactionIdx = switchSetupRequests [ i ] - > getCurrentFactionIndex ( ) ;
if ( serverInterface - > switchSlot ( switchFactionIdx , newFactionIdx ) ) {
2010-04-30 03:08:29 +02:00
try {
2010-09-04 02:32:56 +02:00
if ( switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = " " ) {
2010-08-23 06:33:21 +02:00
listBoxFactions [ newFactionIdx ] . setSelectedItem ( switchSetupRequests [ i ] - > getSelectedFactionName ( ) ) ;
2010-04-30 03:08:29 +02:00
}
2010-08-23 06:33:21 +02:00
if ( switchSetupRequests [ i ] - > getToTeam ( ) ! = - 1 ) {
listBoxTeams [ newFactionIdx ] . setSelectedItemIndex ( switchSetupRequests [ i ] - > getToTeam ( ) ) ;
}
if ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ! = " " ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] i = %d, labelPlayerNames[newFactionIdx].getText() [%s] switchSetupRequests[i]->getNetworkPlayerName() [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , labelPlayerNames [ newFactionIdx ] . getText ( ) . c_str ( ) , switchSetupRequests [ i ] - > getNetworkPlayerName ( ) . c_str ( ) ) ;
labelPlayerNames [ newFactionIdx ] . setText ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
2010-10-08 17:20:24 +02:00
//SetActivePlayerNameEditor();
2010-08-21 15:04:52 +02:00
}
2010-04-30 03:08:29 +02:00
}
catch ( const runtime_error & e ) {
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
2010-04-30 03:08:29 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] caught exception error = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
}
}
}
2010-08-23 06:33:21 +02:00
else {
2010-04-30 03:08:29 +02:00
try {
2010-08-23 06:33:21 +02:00
if ( switchSetupRequests [ i ] - > getSelectedFactionName ( ) ! = " " ) {
2010-04-30 03:08:29 +02:00
listBoxFactions [ i ] . setSelectedItem ( switchSetupRequests [ i ] - > getSelectedFactionName ( ) ) ;
}
2010-08-23 06:33:21 +02:00
if ( switchSetupRequests [ i ] - > getToTeam ( ) ! = - 1 ) {
2010-08-21 15:04:52 +02:00
listBoxTeams [ i ] . setSelectedItemIndex ( switchSetupRequests [ i ] - > getToTeam ( ) ) ;
}
2010-08-23 06:33:21 +02:00
if ( ( switchSetupRequests [ i ] - > getSwitchFlags ( ) & ssrft_NetworkPlayerName ) = = ssrft_NetworkPlayerName ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, switchSetupRequests[i]->getSwitchFlags() = %d, switchSetupRequests[i]->getNetworkPlayerName() [%s], labelPlayerNames[i].getText() [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , switchSetupRequests [ i ] - > getSwitchFlags ( ) , switchSetupRequests [ i ] - > getNetworkPlayerName ( ) . c_str ( ) , labelPlayerNames [ i ] . getText ( ) . c_str ( ) ) ;
if ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
labelPlayerNames [ i ] . setText ( switchSetupRequests [ i ] - > getNetworkPlayerName ( ) ) ;
}
else {
labelPlayerNames [ i ] . setText ( " " ) ;
}
2010-10-08 17:20:24 +02:00
//SetActivePlayerNameEditor();
2010-08-23 06:33:21 +02:00
//switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName);
}
2010-04-30 03:08:29 +02:00
}
catch ( const runtime_error & e ) {
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
2010-04-30 03:08:29 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] caught exception error = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
}
}
}
delete switchSetupRequests [ i ] ;
switchSetupRequests [ i ] = NULL ;
}
}
2010-12-07 07:12:51 +01:00
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
2010-06-01 01:39:07 +02:00
2011-03-11 12:11:46 +01:00
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
2010-09-04 03:24:17 +02:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-06-01 01:39:07 +02:00
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
switch ( gameSettings . getNetworkPlayerStatuses ( i ) ) {
case npst_BeRightBack :
labelPlayerStatus [ i ] . setText ( lang . get ( " PlayerStatusBeRightBack " ) ) ;
break ;
case npst_Ready :
labelPlayerStatus [ i ] . setText ( lang . get ( " PlayerStatusReady " ) ) ;
break ;
case npst_PickSettings :
labelPlayerStatus [ i ] . setText ( lang . get ( " PlayerStatusSetup " ) ) ;
break ;
default :
labelPlayerStatus [ i ] . setText ( " " ) ;
break ;
}
}
else {
labelPlayerStatus [ i ] . setText ( " " ) ;
}
}
2010-08-23 06:33:21 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-05-13 00:58:00 +02:00
hasOneNetworkSlotOpen = true ;
2010-03-13 23:00:01 +01:00
2010-04-11 03:25:06 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__);
2010-03-13 23:00:01 +01:00
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > isConnected ( ) ) {
2011-03-11 12:11:46 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
switch ( serverInterface - > getSlot ( i ) - > getNetworkPlayerStatus ( ) ) {
case npst_BeRightBack :
labelPlayerStatus [ i ] . setText ( lang . get ( " PlayerStatusBeRightBack " ) ) ;
break ;
case npst_Ready :
labelPlayerStatus [ i ] . setText ( lang . get ( " PlayerStatusReady " ) ) ;
break ;
case npst_PickSettings :
default :
labelPlayerStatus [ i ] . setText ( lang . get ( " PlayerStatusSetup " ) ) ;
break ;
}
}
2010-12-19 00:03:53 +01:00
serverInterface - > getSlot ( i ) - > 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);
2010-04-11 03:25:06 +02:00
haveAtLeastOneNetworkClientConnected = true ;
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > getConnectHasHandshaked ( ) ) {
2010-05-17 22:05:31 +02:00
currentConnectionCount + + ;
2010-12-19 00:03:53 +01:00
}
2010-04-11 03:25:06 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B - ctNetwork\n",__FILE__,__FUNCTION__);
2010-12-19 00:03:53 +01:00
string label = ( serverInterface - > getSlot ( i ) ! = NULL ? serverInterface - > getSlot ( i ) - > getVersionString ( ) : " " ) ;
2010-04-11 03:25:06 +02:00
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > getAllowDownloadDataSynch ( ) = = true & &
serverInterface - > getSlot ( i ) - > getAllowGameDataSynchCheck ( ) = = true ) {
if ( serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
2010-08-22 10:00:05 +02:00
label + = " -waiting to synch: " ;
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " map " ;
}
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " tile " ;
}
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) - > 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 {
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > getAllowGameDataSynchCheck ( ) = = true & &
serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
2010-08-22 10:00:05 +02:00
label + = " -synch mismatch: " ;
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & & serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " map " ;
2010-08-22 10:00:05 +02:00
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) - > 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 ( ) ;
serverInterface - > sendTextMessage ( lastMapDataSynchError , - 1 , true ) ;
}
2010-04-11 03:25:06 +02:00
}
2010-08-22 10:00:05 +02:00
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " tile " ;
2010-08-22 10:00:05 +02:00
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) - > 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 ( ) ;
serverInterface - > sendTextMessage ( lastTileDataSynchError , - 1 , true ) ;
}
2010-04-11 03:25:06 +02:00
}
2010-08-22 10:00:05 +02:00
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckOkTech ( ) = = false ) {
2010-04-11 03:25:06 +02:00
label = label + " techtree " ;
2010-08-22 10:00:05 +02:00
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) - > getReceivedDataSynchCheck ( ) = = true ) {
2010-08-22 10:00:05 +02:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
2010-12-19 00:03:53 +01:00
string report = serverInterface - > getSlot ( i ) - > getNetworkGameDataSynchCheckTechMismatchReport ( ) ;
2010-08-22 10:00:05 +02:00
if ( lastTechtreeDataSynchError ! = " techtree CRC mismatch " + report ) {
lastTechtreeDataSynchError = " techtree CRC mismatch " + report ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] report: %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , report . c_str ( ) ) ;
serverInterface - > sendTextMessage ( " techtree CRC mismatch " , - 1 , true ) ;
vector < string > reportLineTokens ;
Tokenize ( report , reportLineTokens , " \n " ) ;
for ( int reportLine = 0 ; reportLine < reportLineTokens . size ( ) ; + + reportLine ) {
serverInterface - > sendTextMessage ( reportLineTokens [ reportLine ] , - 1 , true ) ;
}
}
}
}
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL ) {
serverInterface - > getSlot ( i ) - > 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());
2010-06-04 21:42:58 +02:00
char szBuf [ 1024 ] = " " ;
2010-07-02 04:50:20 +02:00
//sprintf(szBuf,"%s, ping = %.2fms",label.c_str(),pingTime);
sprintf ( szBuf , " %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 {
2010-07-03 12:06:31 +02:00
string port = intToStr ( config . getInt ( " ServerPort " ) ) ;
if ( port ! = intToStr ( GameConstants : : serverPort ) ) {
port = port + " " + lang . get ( " NonStandardPort " ) + " !) " ;
2010-04-11 03:25:06 +02:00
}
else
{
2010-07-03 12:06:31 +02:00
port = port + " ) " ;
2010-04-11 03:25:06 +02:00
}
2010-07-03 12:06:31 +02:00
port = " ( " + port ;
labelNetStatus [ i ] . setText ( " --- " + port ) ;
2010-04-04 01:31:10 +02:00
}
2010-03-13 23:00:01 +01:00
2010-04-11 03:25:06 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END - ctNetwork\n",__FILE__,__FUNCTION__);
}
else {
labelNetStatus [ i ] . setText ( " " ) ;
}
2010-03-13 23:00:01 +01:00
}
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-06-01 01:39:07 +02:00
2010-06-05 02:58:32 +02:00
bool checkDataSynch = ( serverInterface - > getAllowGameDataSynchCheck ( ) = = true & &
//haveAtLeastOneNetworkClientConnected == true &&
needToSetChangedGameSettings = = true & &
difftime ( time ( NULL ) , lastSetChangedGameSettings ) > = 2 ) ;
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
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
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-06-01 01:39:07 +02:00
2010-07-03 12:53:13 +02:00
if ( hasOneNetworkSlotOpen ) {
2010-05-13 00:58:00 +02:00
//listBoxPublishServer.setSelectedItemIndex(0);
listBoxPublishServer . setEditable ( true ) ;
2010-10-26 23:52:00 +02:00
//listBoxEnableServerControlledAI.setEditable(true);
2010-05-13 00:58:00 +02:00
}
else
{
listBoxPublishServer . setSelectedItemIndex ( 1 ) ;
listBoxPublishServer . setEditable ( false ) ;
2011-03-11 13:14:24 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
serverInterface - > setPublishEnabled ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) ;
2010-10-26 23:52:00 +02:00
//listBoxEnableServerControlledAI.setEditable(false);
2010-05-13 00:58:00 +02:00
}
2010-12-07 07:12:51 +01:00
2010-06-05 02:58:32 +02:00
bool republishToMaster = ( difftime ( time ( NULL ) , lastMasterserverPublishing ) > = 5 ) ;
if ( republishToMaster = = true ) {
2010-10-30 06:24:26 +02:00
if ( listBoxPublishServer . getSelectedItemIndex ( ) = = 0 ) {
needToRepublishToMasterserver = true ;
lastMasterserverPublishing = time ( NULL ) ;
}
2010-05-13 13:19:10 +02:00
}
2010-05-13 08:43:56 +02:00
2010-06-05 02:58:32 +02:00
bool callPublishNow = ( listBoxPublishServer . getEditable ( ) & &
listBoxPublishServer . getSelectedItemIndex ( ) = = 0 & &
needToRepublishToMasterserver = = true ) ;
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
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-01-31 00:01:55 +01:00
if ( needToPublishDelayed ) {
2011-01-29 21:13:29 +01:00
// this delay is done to make it possible to switch over maps which are not meant to be distributed
if ( difftime ( time ( NULL ) , mapPublishingDelayTimer ) > = 5 ) {
// after 5 seconds we are allowed to publish again!
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
// set to normal....
2011-01-31 00:01:55 +01:00
needToPublishDelayed = false ;
2011-01-29 21:13:29 +01:00
}
}
2011-01-31 00:01:55 +01:00
if ( ! needToPublishDelayed ) {
2011-01-29 21:13:29 +01:00
bool broadCastSettings = ( difftime ( time ( NULL ) , lastSetChangedGameSettings ) > = 2 ) ;
2010-06-05 02:58:32 +02:00
2011-01-29 21:13:29 +01:00
if ( broadCastSettings = = true ) {
needToBroadcastServerSettings = true ;
}
2010-09-02 23:40:43 +02:00
2011-01-29 21:13:29 +01:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-03-13 23:00:01 +01:00
2011-01-29 21:13:29 +01:00
//call the chat manager
chatManager . updateNetwork ( ) ;
2010-03-13 23:00:01 +01:00
2011-01-29 21:13:29 +01:00
//console
console . update ( ) ;
2010-06-05 02:58:32 +02:00
2011-01-29 21:13:29 +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-04-22 01:13:39 +02:00
}
2011-01-29 21:13:29 +01:00
2010-06-01 01:39:07 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-16 18:40:21 +02:00
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
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
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
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 ( ) ) ;
string factionLogo = Game : : findFactionLogoFile ( & gameSettings , NULL , " preview_screen.* " ) ;
if ( factionLogo = = " " ) {
factionLogo = Game : : findFactionLogoFile ( & gameSettings , NULL ) ;
}
if ( currentFactionLogo ! = factionLogo ) {
currentFactionLogo = factionLogo ;
loadFactionTexture ( currentFactionLogo ) ;
}
2010-09-02 15:53:23 +02:00
}
2010-08-31 08:38:27 +02:00
}
2010-09-03 00:17:14 +02:00
if ( chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-09-02 23:40:43 +02:00
if ( chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-10-02 04:17:50 +02:00
if ( autostart = = true ) {
safeMutex . ReleaseLock ( ) ;
RestoreLastGameSettings ( ) ;
PlayNow ( ) ;
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
}
catch ( const std : : exception & ex ) {
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
//throw runtime_error(szBuf);
showGeneralError = true ;
generalErrorToShow = szBuf ;
2010-04-11 03:25:06 +02:00
}
2010-07-16 18:53:19 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-13 23:00:01 +01:00
}
2010-05-13 00:58:00 +02:00
void MenuStateCustomGame : : publishToMasterserver ( )
{
2010-06-23 16:49:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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="";
publishToServerInfo . clear ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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
2010-05-13 00:58:00 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork )
{
slotCountHumans + + ;
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > 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
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 ;
publishToServerInfo [ " platform " ] = getPlatformNameString ( ) ;
publishToServerInfo [ " binaryCompileDate " ] = getCompileDateTime ( ) ;
2010-05-13 08:43:56 +02:00
2010-05-13 00:58:00 +02:00
//game info:
2010-08-21 15:04:52 +02:00
publishToServerInfo [ " serverTitle " ] = getHumanPlayerName ( ) + " 's game " ;
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:
2010-06-23 16:49:20 +02:00
publishToServerInfo [ " tech " ] = listBoxTechTree . getSelectedItem ( ) ;
publishToServerInfo [ " map " ] = listBoxMap . getSelectedItem ( ) ;
publishToServerInfo [ " tileset " ] = listBoxTileset . getSelectedItem ( ) ;
publishToServerInfo [ " activeSlots " ] = intToStr ( slotCountUsed ) ;
publishToServerInfo [ " networkSlots " ] = intToStr ( slotCountHumans ) ;
publishToServerInfo [ " connectedClients " ] = intToStr ( slotCountConnectedPlayers ) ;
2010-12-21 06:07:10 +01:00
2010-10-11 02:53:25 +02:00
string externalport = config . getString ( " MasterServerExternalPort " , " 61357 " ) ;
2010-07-03 12:06:31 +02:00
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 ) ;
}
2010-06-23 16:49:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-13 00:58:00 +02:00
}
2011-01-02 07:46:48 +01:00
void MenuStateCustomGame : : simpleTask ( BaseThread * callingThread ) {
2010-06-01 01:39:07 +02:00
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-01-02 07:46:48 +01:00
bool republish = ( needToRepublishToMasterserver = = true & & publishToServerInfo . size ( ) ! = 0 ) ;
needToRepublishToMasterserver = false ;
std : : map < string , string > newPublishToServerInfo = publishToServerInfo ;
2011-01-02 01:39:13 +01:00
publishToServerInfo . clear ( ) ;
2011-01-02 07:46:48 +01:00
bool broadCastSettings = needToBroadcastServerSettings ;
needToBroadcastServerSettings = false ;
bool hasClientConnection = false ;
2011-01-02 10:33:37 +01:00
2011-01-02 07:46:48 +01:00
if ( broadCastSettings = = true ) {
2011-01-02 10:33:37 +01:00
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( false ) ;
if ( serverInterface ! = NULL ) {
hasClientConnection = serverInterface - > hasClientConnection ( ) ;
}
2011-01-02 01:39:13 +01:00
}
2011-01-02 10:33:37 +01:00
bool needPing = ( difftime ( time ( NULL ) , lastNetworkPing ) > = GameConstants : : networkPingInterval ) ;
2010-08-20 23:06:20 +02:00
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 ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-01 01:39:07 +02:00
2011-01-02 01:39:13 +01:00
string request = Config : : getInstance ( ) . getString ( " Masterserver " ) + " addServerInfo.php? " ;
2010-12-20 17:45:31 +01:00
2011-01-02 01:39:13 +01:00
CURL * handle = SystemFlags : : initHTTP ( ) ;
for ( std : : map < string , string > : : const_iterator iterMap = newPublishToServerInfo . begin ( ) ;
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 ) ;
request + = " & " ;
}
2010-06-23 16:49:20 +02:00
2011-01-02 01:39:13 +01:00
//printf("the request is:\n%s\n",request.c_str());
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] the request is: \n %s \n " , __FILE__ , __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 ) ;
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());
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] the result is: \n '%s' \n " , __FILE__ , __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 ;
}
2011-01-02 01:39:13 +01:00
showMasterserverError = true ;
masterServererErrorToShow = ( serverInfo ! = " " ? serverInfo : " No Reply " ) ;
}
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
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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
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
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
2011-01-02 10:33:37 +01:00
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-21 15:04:52 +02:00
2011-01-02 10:33:37 +01:00
if ( callingThread - > getQuitStatus ( ) = = true ) {
return ;
}
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( false ) ;
if ( serverInterface ! = NULL ) {
serverInterface - > setGameSettings ( & gameSettings , false ) ;
}
2010-05-17 08:41:05 +02:00
2011-01-02 10:33:37 +01:00
if ( hasClientConnection = = true & & serverInterface ! = NULL ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-01-02 01:39:13 +01:00
serverInterface - > broadcastGameSetup ( & gameSettings ) ;
}
}
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
2011-01-02 01:39:13 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] Sending nmtPing to clients \n " , __FILE__ , __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 ) {
2011-01-12 01:16:50 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
NetworkMessagePing * msg = new NetworkMessagePing ( GameConstants : : networkPingInterval , time ( NULL ) ) ;
//serverInterface->broadcastPing(&msg);
serverInterface - > queueBroadcastMessage ( msg ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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 ) {
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2011-01-02 07:46:48 +01:00
if ( callingThread - > getQuitStatus ( ) = = false ) {
2011-01-25 08:41:12 +01:00
//throw runtime_error(szBuf);
2011-01-02 07:46:48 +01:00
showGeneralError = true ;
generalErrorToShow = ex . what ( ) ;
}
2010-07-09 19:12:57 +02:00
}
2010-06-01 01:39:07 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-13 00:58:00 +02:00
}
2010-05-31 21:57:10 +02:00
void MenuStateCustomGame : : loadGameSettings ( GameSettings * gameSettings ) {
2010-06-11 03:33:43 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d \n " , __FILE__ , __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
2010-05-31 22:49:23 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-12-19 09:04:25 +01:00
// Test flags values
//gameSettings->setFlagTypes1(ft1_show_map_resources);
//
2010-08-30 22:02:58 +02:00
gameSettings - > setMapFilterIndex ( listBoxMapFilter . getSelectedItemIndex ( ) ) ;
gameSettings - > setDescription ( formatString ( getCurrentMapFile ( ) ) ) ;
gameSettings - > setMap ( getCurrentMapFile ( ) ) ;
2010-03-13 23:00:01 +01:00
gameSettings - > setTileset ( tilesetFiles [ listBoxTileset . getSelectedItemIndex ( ) ] ) ;
gameSettings - > setTech ( techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] ) ;
gameSettings - > setDefaultUnits ( true ) ;
gameSettings - > setDefaultResources ( true ) ;
gameSettings - > setDefaultVictoryConditions ( true ) ;
2010-12-20 22:59:46 +01:00
gameSettings - > setFogOfWar ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 0 | |
listBoxFogOfWar . getSelectedItemIndex ( ) = = 1 ) ;
2010-09-04 03:24:17 +02:00
gameSettings - > setAllowObservers ( listBoxAllowObservers . getSelectedItemIndex ( ) = = 1 ) ;
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 ) ;
}
2010-05-31 12:20:18 +02:00
gameSettings - > setEnableObserverModeAtEndGame ( listBoxEnableObserverMode . getSelectedItemIndex ( ) = = 0 ) ;
2010-07-21 20:21:40 +02:00
gameSettings - > setPathFinderType ( static_cast < PathFinderType > ( listBoxPathFinderType . getSelectedItemIndex ( ) ) ) ;
2010-03-13 23:00:01 +01:00
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 ) {
2010-03-13 23:00:01 +01:00
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
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 ) {
2010-08-23 06:33:21 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, slotIndex = %d, getHumanPlayerName(i) [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , slotIndex , getHumanPlayerName ( i ) . c_str ( ) ) ;
2010-06-25 06:06:28 +02:00
gameSettings - > setThisFactionIndex ( slotIndex ) ;
2010-08-23 06:33:21 +02:00
gameSettings - > setNetworkPlayerName ( slotIndex , getHumanPlayerName ( i ) ) ;
2011-03-11 12:11:46 +01:00
gameSettings - > setNetworkPlayerStatuses ( slotIndex , getNetworkPlayerStatus ( ) ) ;
2010-03-13 23:00:01 +01:00
}
2010-11-25 23:45:08 +01:00
gameSettings - > setResourceMultiplierIndex ( slotIndex , listBoxRMultiplier [ i ] . getSelectedItemIndex ( ) ) ;
2010-09-11 10:09:33 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] . c_str ( ) ) ;
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
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-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
2010-06-25 06:06:28 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
2010-12-19 00:03:53 +01:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
serverInterface - > getSlot ( i ) - > isConnected ( ) ) {
2011-03-11 12:11:46 +01:00
gameSettings - > setNetworkPlayerStatuses ( slotIndex , serverInterface - > getSlot ( i ) - > getNetworkPlayerStatus ( ) ) ;
2010-12-19 00:03:53 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, connectionSlot->getName() [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , serverInterface - > getSlot ( i ) - > getName ( ) . c_str ( ) ) ;
2010-08-23 06:33:21 +02:00
2010-12-19 00:03:53 +01:00
gameSettings - > setNetworkPlayerName ( slotIndex , serverInterface - > getSlot ( i ) - > getName ( ) ) ;
labelPlayerNames [ i ] . setText ( serverInterface - > getSlot ( i ) - > getName ( ) ) ;
2010-04-23 01:18:04 +02:00
}
2010-06-25 06:06:28 +02:00
else {
2010-08-23 06:33:21 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, playername unconnected \n " , __FILE__ , __FUNCTION__ , __LINE__ , i ) ;
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 + + ;
2010-08-23 06:33:21 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, playername is AI (blank) \n " , __FILE__ , __FUNCTION__ , __LINE__ , i ) ;
2010-06-25 07:41:50 +02:00
gameSettings - > setNetworkPlayerName ( slotIndex , string ( " AI " ) + intToStr ( AIPlayerCount ) ) ;
2010-08-23 06:33:21 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
2010-04-23 01:18:04 +02:00
}
2010-06-25 06:06:28 +02:00
2010-03-13 23:00:01 +01:00
factionCount + + ;
}
2010-08-23 06:33:21 +02:00
else {
//gameSettings->setNetworkPlayerName("");
2011-03-11 12:11:46 +01:00
gameSettings - > setNetworkPlayerStatuses ( factionCount , 0 ) ;
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 ) ;
2010-11-25 23:45:08 +01:00
gameSettings - > setResourceMultiplierIndex ( slotIndex , 10 ) ;
2010-09-11 10:09:33 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] . c_str ( ) ) ;
2010-06-25 06:06:28 +02:00
gameSettings - > setFactionTypeName ( slotIndex , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ) ;
gameSettings - > setNetworkPlayerName ( slotIndex , " Closed " ) ;
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 " ) ) ;
2010-10-21 19:42:45 +02:00
gameSettings - > setNetworkPauseGameForLaggedClients ( ( ( listBoxNetworkPauseGameForLaggedClients . getSelectedItemIndex ( ) ! = 0 ) ) ) ;
2011-01-09 05:49:21 +01:00
2011-03-22 03:02:54 +01:00
if ( hasNetworkGameSettings ( ) = = true ) {
if ( gameSettings - > getTileset ( ) ! = " " ) {
if ( lastCheckedCRCTilesetName ! = gameSettings - > getTileset ( ) ) {
//console.addLine("Checking tileset CRC [" + gameSettings->getTileset() + "]");
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL ) ;
lastCheckedCRCTilesetName = gameSettings - > getTileset ( ) ;
}
gameSettings - > setTilesetCRC ( lastCheckedCRCTilesetValue ) ;
2011-03-19 06:11:36 +01:00
}
2011-01-09 05:49:21 +01:00
2011-03-22 03:02:54 +01:00
if ( config . getBool ( " DisableServerLobbyTechtreeCRCCheck " , " false " ) = = false ) {
if ( gameSettings - > getTech ( ) ! = " " ) {
if ( lastCheckedCRCTechtreeName ! = gameSettings - > getTech ( ) ) {
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /* " , " .xml " , NULL ) ;
reloadFactions ( true ) ;
factionCRCList . clear ( ) ;
for ( unsigned int factionIdx = 0 ; factionIdx < factionFiles . size ( ) ; + + factionIdx ) {
string factionName = factionFiles [ factionIdx ] ;
int32 factionCRC = 0 ;
if ( factionName ! = GameConstants : : RANDOMFACTION_SLOTNAME & &
factionName ! = GameConstants : : OBSERVER_SLOTNAME ) {
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL , true ) ;
}
factionCRCList . push_back ( make_pair ( factionName , factionCRC ) ) ;
}
//console.addLine("Found factions: " + intToStr(factionCRCList.size()));
lastCheckedCRCTechtreeName = gameSettings - > getTech ( ) ;
}
2011-03-10 00:09:32 +01:00
2011-03-22 03:02:54 +01:00
gameSettings - > setFactionCRCList ( factionCRCList ) ;
gameSettings - > setTechCRC ( lastCheckedCRCTechtreeValue ) ;
}
}
2010-03-13 23:00:01 +01:00
2011-03-22 03:02:54 +01:00
if ( gameSettings - > getMap ( ) ! = " " ) {
if ( lastCheckedCRCMapName ! = gameSettings - > getMap ( ) ) {
Checksum checksum ;
string file = Map : : getMapPath ( gameSettings - > getMap ( ) , " " , false ) ;
//console.addLine("Checking map CRC [" + file + "]");
checksum . addFile ( file ) ;
lastCheckedCRCMapValue = checksum . getSum ( ) ;
lastCheckedCRCMapName = gameSettings - > getMap ( ) ;
}
gameSettings - > setMapCRC ( lastCheckedCRCMapValue ) ;
}
}
2010-04-11 03:25:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-13 23:00:01 +01:00
}
2010-05-31 21:57:10 +02:00
void MenuStateCustomGame : : saveGameSettingsToFile ( std : : string fileName ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-10 08:26:43 +01:00
Config & config = Config : : getInstance ( ) ;
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
2011-03-13 09:23:43 +01:00
endPathWithSlash ( userData ) ;
2010-05-31 21:57:10 +02:00
}
2011-03-10 08:26:43 +01:00
fileName = userData + fileName ;
2010-05-31 21:57:10 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] fileName = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , fileName . c_str ( ) ) ;
GameSettings gameSettings ;
loadGameSettings ( & gameSettings ) ;
std : : ofstream saveGameFile ;
saveGameFile . open ( fileName . c_str ( ) , ios_base : : out | ios_base : : trunc ) ;
//int factionCount= 0;
//ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
saveGameFile < < " Description= " < < gameSettings . getDescription ( ) < < std : : endl ;
2010-12-07 07:12:51 +01:00
2010-08-30 22:02:58 +02:00
saveGameFile < < " MapFilterIndex= " < < gameSettings . getMapFilterIndex ( ) < < std : : endl ;
2010-05-31 21:57:10 +02:00
saveGameFile < < " Map= " < < gameSettings . getMap ( ) < < std : : endl ;
saveGameFile < < " Tileset= " < < gameSettings . getTileset ( ) < < std : : endl ;
saveGameFile < < " TechTree= " < < gameSettings . getTech ( ) < < std : : endl ;
saveGameFile < < " DefaultUnits= " < < gameSettings . getDefaultUnits ( ) < < std : : endl ;
saveGameFile < < " DefaultResources= " < < gameSettings . getDefaultResources ( ) < < std : : endl ;
saveGameFile < < " DefaultVictoryConditions= " < < gameSettings . getDefaultVictoryConditions ( ) < < std : : endl ;
saveGameFile < < " FogOfWar= " < < gameSettings . getFogOfWar ( ) < < std : : endl ;
2010-11-11 02:24:48 +01:00
saveGameFile < < " AdvancedIndex= " < < listBoxAdvanced . getSelectedItemIndex ( ) < < std : : endl ;
2010-09-04 03:24:17 +02:00
saveGameFile < < " AllowObservers= " < < gameSettings . getAllowObservers ( ) < < std : : endl ;
2010-12-19 09:36:59 +01:00
saveGameFile < < " FlagTypes1= " < < gameSettings . getFlagTypes1 ( ) < < std : : endl ;
2010-05-31 21:57:10 +02:00
saveGameFile < < " EnableObserverModeAtEndGame= " < < gameSettings . getEnableObserverModeAtEndGame ( ) < < std : : endl ;
2010-07-21 20:21:40 +02:00
saveGameFile < < " PathFinderType= " < < gameSettings . getPathFinderType ( ) < < std : : endl ;
2010-06-03 03:10:40 +02:00
saveGameFile < < " EnableServerControlledAI= " < < gameSettings . getEnableServerControlledAI ( ) < < std : : endl ;
2010-06-05 09:52:14 +02:00
saveGameFile < < " NetworkFramePeriod= " < < gameSettings . getNetworkFramePeriod ( ) < < std : : endl ;
2010-07-16 18:53:19 +02:00
saveGameFile < < " NetworkPauseGameForLaggedClients= " < < gameSettings . getNetworkPauseGameForLaggedClients ( ) < < std : : endl ;
2010-05-31 21:57:10 +02:00
saveGameFile < < " FactionThisFactionIndex= " < < gameSettings . getThisFactionIndex ( ) < < std : : endl ;
saveGameFile < < " FactionCount= " < < gameSettings . getFactionCount ( ) < < std : : endl ;
2010-06-25 06:06:28 +02:00
//for(int i = 0; i < gameSettings.getFactionCount(); ++i) {
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
int slotIndex = gameSettings . getStartLocationIndex ( i ) ;
saveGameFile < < " FactionControlForIndex " < < slotIndex < < " = " < < gameSettings . getFactionControl ( i ) < < std : : endl ;
2010-11-25 23:45:08 +01:00
saveGameFile < < " ResourceMultiplierIndex " < < slotIndex < < " = " < < gameSettings . getResourceMultiplierIndex ( i ) < < std : : endl ;
2010-06-25 06:06:28 +02:00
saveGameFile < < " FactionTeamForIndex " < < slotIndex < < " = " < < gameSettings . getTeam ( i ) < < std : : endl ;
saveGameFile < < " FactionStartLocationForIndex " < < slotIndex < < " = " < < gameSettings . getStartLocationIndex ( i ) < < std : : endl ;
saveGameFile < < " FactionTypeNameForIndex " < < slotIndex < < " = " < < gameSettings . getFactionTypeName ( i ) < < std : : endl ;
saveGameFile < < " FactionPlayerNameForIndex " < < slotIndex < < " = " < < gameSettings . getNetworkPlayerName ( i ) < < std : : endl ;
2010-05-31 21:57:10 +02:00
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
GameSettings MenuStateCustomGame : : loadGameSettingsFromFile ( std : : string fileName ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
GameSettings gameSettings ;
2011-03-10 08:26:43 +01:00
Config & config = Config : : getInstance ( ) ;
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
2011-03-13 09:23:43 +01:00
endPathWithSlash ( userData ) ;
2010-05-31 21:57:10 +02:00
}
2011-03-10 08:26:43 +01:00
fileName = userData + fileName ;
2010-05-31 21:57:10 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] fileName = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , fileName . c_str ( ) ) ;
if ( fileExists ( fileName ) = = false ) {
return gameSettings ;
}
try {
Properties properties ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] fileName = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , fileName . c_str ( ) ) ;
properties . load ( fileName ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] fileName = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , fileName . c_str ( ) ) ;
2010-08-30 23:06:43 +02:00
gameSettings . setMapFilterIndex ( properties . getInt ( " MapFilterIndex " , " 0 " ) ) ;
2010-05-31 21:57:10 +02:00
gameSettings . setDescription ( properties . getString ( " Description " ) ) ;
gameSettings . setMap ( properties . getString ( " Map " ) ) ;
gameSettings . setTileset ( properties . getString ( " Tileset " ) ) ;
gameSettings . setTech ( properties . getString ( " TechTree " ) ) ;
gameSettings . setDefaultUnits ( properties . getBool ( " DefaultUnits " ) ) ;
gameSettings . setDefaultResources ( properties . getBool ( " DefaultResources " ) ) ;
gameSettings . setDefaultVictoryConditions ( properties . getBool ( " DefaultVictoryConditions " ) ) ;
gameSettings . setFogOfWar ( properties . getBool ( " FogOfWar " ) ) ;
2010-11-11 02:24:48 +01:00
listBoxAdvanced . setSelectedItemIndex ( properties . getInt ( " AdvancedIndex " , " 0 " ) ) ;
2010-12-07 07:12:51 +01:00
2010-09-04 03:24:17 +02:00
gameSettings . setAllowObservers ( properties . getBool ( " AllowObservers " , " false " ) ) ;
2010-12-19 09:36:59 +01:00
gameSettings . setFlagTypes1 ( properties . getInt ( " FlagTypes1 " , " 0 " ) ) ;
2010-05-31 21:57:10 +02:00
gameSettings . setEnableObserverModeAtEndGame ( properties . getBool ( " EnableObserverModeAtEndGame " ) ) ;
2010-07-21 20:21:40 +02:00
gameSettings . setPathFinderType ( static_cast < PathFinderType > ( properties . getInt ( " PathFinderType " , intToStr ( pfBasic ) . c_str ( ) ) ) ) ;
2010-10-26 23:52:00 +02:00
gameSettings . setEnableServerControlledAI ( properties . getBool ( " EnableServerControlledAI " , " true " ) ) ;
gameSettings . setNetworkFramePeriod ( properties . getInt ( " NetworkFramePeriod " , intToStr ( GameConstants : : networkFramePeriod ) . c_str ( ) ) ) ;
2010-07-16 18:53:19 +02:00
gameSettings . setNetworkPauseGameForLaggedClients ( properties . getBool ( " NetworkPauseGameForLaggedClients " , " false " ) ) ;
2010-05-31 21:57:10 +02:00
gameSettings . setThisFactionIndex ( properties . getInt ( " FactionThisFactionIndex " ) ) ;
gameSettings . setFactionCount ( properties . getInt ( " FactionCount " ) ) ;
2010-06-25 06:06:28 +02:00
//for(int i = 0; i < gameSettings.getFactionCount(); ++i) {
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
gameSettings . setFactionControl ( i , ( ControlType ) properties . getInt ( string ( " FactionControlForIndex " ) + intToStr ( i ) , intToStr ( ctClosed ) . c_str ( ) ) ) ;
2010-11-25 23:45:08 +01:00
gameSettings . setResourceMultiplierIndex ( i , properties . getInt ( string ( " ResourceMultiplierIndex " ) + intToStr ( i ) , " 5 " ) ) ;
2010-06-25 06:06:28 +02:00
gameSettings . setTeam ( i , properties . getInt ( string ( " FactionTeamForIndex " ) + intToStr ( i ) , " 0 " ) ) ;
gameSettings . setStartLocationIndex ( i , properties . getInt ( string ( " FactionStartLocationForIndex " ) + intToStr ( i ) , intToStr ( i ) . c_str ( ) ) ) ;
gameSettings . setFactionTypeName ( i , properties . getString ( string ( " FactionTypeNameForIndex " ) + intToStr ( i ) , " ? " ) ) ;
2010-09-11 10:09:33 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, factionTypeName [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , gameSettings . getFactionTypeName ( i ) . c_str ( ) ) ;
2010-09-28 22:15:54 +02:00
if ( gameSettings . getFactionControl ( i ) = = ctHuman ) {
gameSettings . setNetworkPlayerName ( i , properties . getString ( string ( " FactionPlayerNameForIndex " ) + intToStr ( i ) , " " ) ) ;
}
else {
gameSettings . setNetworkPlayerName ( i , " " ) ;
}
2010-05-31 21:57:10 +02:00
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-30 22:02:58 +02:00
listBoxMapFilter . setSelectedItemIndex ( gameSettings . getMapFilterIndex ( ) ) ;
listBoxMap . setItems ( formattedPlayerSortedMaps [ gameSettings . getMapFilterIndex ( ) ] ) ;
2010-05-31 21:57:10 +02:00
string mapFile = gameSettings . getMap ( ) ;
mapFile = formatString ( mapFile ) ;
listBoxMap . setSelectedItem ( mapFile ) ;
2010-09-12 07:05:08 +02:00
loadMapInfo ( Map : : getMapPath ( getCurrentMapFile ( ) ) , & mapInfo , true ) ;
2010-06-01 01:39:07 +02:00
labelMapInfo . setText ( mapInfo . desc ) ;
2010-05-31 21:57:10 +02:00
string tilesetFile = gameSettings . getTileset ( ) ;
tilesetFile = formatString ( tilesetFile ) ;
listBoxTileset . setSelectedItem ( tilesetFile ) ;
string techtreeFile = gameSettings . getTech ( ) ;
techtreeFile = formatString ( techtreeFile ) ;
listBoxTechTree . setSelectedItem ( techtreeFile ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//gameSettings->setDefaultUnits(true);
//gameSettings->setDefaultResources(true);
//gameSettings->setDefaultVictoryConditions(true);
2010-06-01 01:39:07 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2010-12-21 06:07:10 +01:00
2010-12-20 22:59:46 +01:00
//FogOfWar
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ; // default is 0!
if ( gameSettings . getFogOfWar ( ) = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 2 ) ;
}
if ( ( gameSettings . getFlagTypes1 ( ) & ft1_show_map_resources ) = = ft1_show_map_resources ) {
2010-12-23 11:44:11 +01:00
if ( gameSettings . getFogOfWar ( ) = = true ) {
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
2010-12-20 22:59:46 +01:00
}
2010-12-21 06:07:10 +01:00
2010-09-04 03:24:17 +02:00
listBoxAllowObservers . setSelectedItem ( gameSettings . getAllowObservers ( ) = = true ? lang . get ( " Yes " ) : lang . get ( " No " ) ) ;
2010-05-31 21:57:10 +02:00
listBoxEnableObserverMode . setSelectedItem ( gameSettings . getEnableObserverModeAtEndGame ( ) = = true ? lang . get ( " Yes " ) : lang . get ( " No " ) ) ;
2010-07-21 20:21:40 +02:00
listBoxPathFinderType . setSelectedItemIndex ( gameSettings . getPathFinderType ( ) ) ;
2010-10-26 23:52:00 +02:00
//listBoxEnableServerControlledAI.setSelectedItem(gameSettings.getEnableServerControlledAI() == true ? lang.get("Yes") : lang.get("No"));
2010-05-31 21:57:10 +02:00
2010-10-26 23:52:00 +02:00
//labelNetworkFramePeriod.setText(lang.get("NetworkFramePeriod"));
2010-07-03 12:53:13 +02:00
2010-10-26 23:52:00 +02:00
//listBoxNetworkFramePeriod.setSelectedItem(intToStr(gameSettings.getNetworkFramePeriod()/10*10));
2010-06-05 09:52:14 +02:00
2010-05-31 21:57:10 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-16 18:53:19 +02:00
listBoxNetworkPauseGameForLaggedClients . setSelectedItemIndex ( gameSettings . getNetworkPauseGameForLaggedClients ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-10-15 01:22:09 +02:00
reloadFactions ( false ) ;
2010-05-31 21:57:10 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d] gameSettings.getFactionCount() = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , gameSettings . getFactionCount ( ) ) ;
2010-06-25 06:06:28 +02:00
//for(int i = 0; i < gameSettings.getFactionCount(); ++i) {
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-05-31 21:57:10 +02:00
listBoxControls [ i ] . setSelectedItemIndex ( gameSettings . getFactionControl ( i ) ) ;
2010-11-11 02:24:48 +01:00
updateResourceMultiplier ( i ) ;
2010-11-25 23:45:08 +01:00
listBoxRMultiplier [ i ] . setSelectedItemIndex ( gameSettings . getResourceMultiplierIndex ( i ) ) ;
2010-05-31 21:57:10 +02:00
listBoxTeams [ i ] . setSelectedItemIndex ( gameSettings . getTeam ( i ) ) ;
2010-10-22 19:20:55 +02:00
lastSelectedTeamIndex [ i ] = listBoxTeams [ i ] . getSelectedItemIndex ( ) ;
2010-05-31 21:57:10 +02:00
string factionName = gameSettings . getFactionTypeName ( i ) ;
factionName = formatString ( factionName ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] factionName = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , factionName . c_str ( ) ) ;
listBoxFactions [ i ] . setSelectedItem ( factionName ) ;
2010-08-23 06:33:21 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, gameSettings.getNetworkPlayerName(i) [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , i , gameSettings . getNetworkPlayerName ( i ) . c_str ( ) ) ;
labelPlayerNames [ i ] . setText ( gameSettings . getNetworkPlayerName ( i ) ) ;
2010-05-31 21:57:10 +02:00
}
2010-06-01 01:39:07 +02:00
2010-10-08 17:20:24 +02:00
//SetActivePlayerNameEditor();
2010-10-08 03:41:53 +02:00
2010-06-01 01:39:07 +02:00
updateControlers ( ) ;
updateNetworkSlots ( ) ;
2010-10-30 06:24:26 +02:00
//if(listBoxPublishServer.getSelectedItemIndex() == 0) {
// needToRepublishToMasterserver = true;
//}
2010-06-01 01:39:07 +02:00
if ( hasNetworkGameSettings ( ) = = true )
{
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-05-31 21:57:10 +02:00
}
catch ( const exception & ex ) {
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-05-31 21:57:10 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ERROR = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
showMessageBox ( ex . what ( ) , " Error " , false ) ;
gameSettings = GameSettings ( ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-12 21:01:16 +02:00
return gameSettings ;
2010-05-31 21:57:10 +02:00
}
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 {
for ( int i = 0 ; i < mapInfo . players ; + + i )
2010-03-13 23:00:01 +01:00
{
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 ) {
if ( ct = = ctNetwork ) {
2010-04-11 03:25:06 +02:00
hasNetworkSlot = true ;
break ;
}
2010-03-13 23:00:01 +01:00
}
}
}
2010-04-11 03:25:06 +02:00
catch ( const std : : exception & ex ) {
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
showGeneralError = true ;
generalErrorToShow = ex . what ( ) ;
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 ) {
2010-03-13 23:00:01 +01:00
Lang & lang = Lang : : getInstance ( ) ;
try {
FILE * f = fopen ( file . c_str ( ) , " rb " ) ;
if ( f = = NULL )
throw runtime_error ( " Can't open file " ) ;
MapFileHeader header ;
size_t readBytes = fread ( & header , sizeof ( MapFileHeader ) , 1 , f ) ;
mapInfo - > size . x = header . width ;
mapInfo - > size . y = header . height ;
2011-02-08 04:50:59 +01:00
mapInfo - > players = header . maxFactions ;
2010-03-13 23:00:01 +01:00
mapInfo - > desc = lang . get ( " MaxPlayers " ) + " : " + intToStr ( mapInfo - > players ) + " \n " ;
mapInfo - > desc + = lang . get ( " Size " ) + " : " + intToStr ( mapInfo - > size . x ) + " x " + intToStr ( mapInfo - > size . y ) ;
fclose ( f ) ;
2010-09-11 08:08:50 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
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 ) ;
}
2010-09-12 07:05:08 +02:00
// Not painting properly so this is on hold
if ( loadMapPreview = = true ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
mapPreview . loadFromFile ( file . c_str ( ) ) ;
2010-11-01 17:44:05 +01:00
//printf("Loading map preview MAP\n");
cleanupMapPreviewTexture ( ) ;
2010-09-12 07:05:08 +02:00
}
2010-03-13 23:00:01 +01:00
}
2010-10-06 22:22:06 +02:00
catch ( exception & e ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] loading map [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , e . what ( ) , file . c_str ( ) ) ;
2010-09-12 07:05:08 +02:00
throw runtime_error ( " Error loading map file: [ " + file + " ] msg: " + e . what ( ) ) ;
2010-03-13 23:00:01 +01:00
}
}
2010-10-15 01:22:09 +02:00
void MenuStateCustomGame : : reloadFactions ( bool keepExistingSelectedItem ) {
2010-03-13 23:00:01 +01:00
vector < string > results ;
2010-03-18 22:26:40 +01:00
Config & config = Config : : getInstance ( ) ;
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
2011-03-13 09:23:43 +01:00
endPathWithSlash ( techPath ) ;
findAll ( techPath + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " /factions/*. " , results , false , false ) ;
2010-03-18 22:26:40 +01:00
if ( results . size ( ) > 0 ) {
break ;
}
}
if ( results . size ( ) = = 0 ) {
2011-01-02 01:39:13 +01:00
//throw runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
showGeneralError = true ;
generalErrorToShow = " [#2] There are no factions for the tech tree [ " + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " ] " ;
2010-03-13 23:00:01 +01:00
}
2010-09-03 09:12:40 +02:00
2010-10-15 01:22:09 +02:00
results . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
2010-09-03 09:12:40 +02:00
// Add special Observer Faction
2010-09-04 03:24:17 +02:00
//Lang &lang= Lang::getInstance();
if ( listBoxAllowObservers . getSelectedItemIndex ( ) = = 1 ) {
results . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
}
2010-09-03 09:12:40 +02:00
2010-03-18 22:26:40 +01:00
factionFiles = results ;
for ( int i = 0 ; i < results . size ( ) ; + + i ) {
results [ i ] = formatString ( results [ i ] ) ;
2010-03-20 00:26:00 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " Tech [%s] has faction [%s] \n " , techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] . c_str ( ) , results [ i ] . c_str ( ) ) ;
2010-03-18 22:26:40 +01:00
}
2010-09-03 09:12:40 +02:00
2010-03-18 22:26:40 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-10-15 01:22:09 +02:00
int originalIndex = listBoxFactions [ i ] . getSelectedItemIndex ( ) ;
//printf("[a] i = %d, originalIndex = %d\n",i,originalIndex);
2010-10-15 02:12:17 +02:00
string originalValue = ( listBoxFactions [ i ] . getItemCount ( ) > 0 ? listBoxFactions [ i ] . getSelectedItem ( ) : " " ) ;
//printf("[a1] i = %d, originalValue = [%s]\n",i,originalValue.c_str());
2010-10-15 01:22:09 +02:00
listBoxFactions [ i ] . setItems ( results ) ;
if ( keepExistingSelectedItem = = false | |
( listBoxAllowObservers . getSelectedItemIndex ( ) = = 0 & &
2010-10-15 02:12:17 +02:00
originalValue = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ) {
2010-10-15 01:22:09 +02:00
listBoxFactions [ i ] . setSelectedItemIndex ( i % results . size ( ) ) ;
2010-10-15 02:12:17 +02:00
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 ) ) ;
}
}
2010-10-15 01:22:09 +02:00
//printf("[b] i = %d, listBoxFactions[i].getSelectedItemIndex() = %d\n",i,listBoxFactions[i].getSelectedItemIndex());
}
else if ( originalIndex < results . size ( ) ) {
listBoxFactions [ i ] . setSelectedItemIndex ( originalIndex ) ;
//printf("[c] i = %d, originalIndex = %d\n",i,originalIndex);
}
2010-03-18 22:26:40 +01:00
}
2010-03-13 23:00:01 +01:00
}
void MenuStateCustomGame : : updateControlers ( ) {
2010-04-11 03:25:06 +02:00
try {
bool humanPlayer = false ;
2010-03-13 23:00:01 +01:00
2010-04-11 03:25:06 +02:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
humanPlayer = true ;
}
2010-03-13 23:00:01 +01:00
}
2010-04-11 03:25:06 +02:00
if ( ! humanPlayer ) {
listBoxControls [ 0 ] . setSelectedItemIndex ( ctHuman ) ;
}
2010-03-13 23:00:01 +01:00
2010-04-11 03:25:06 +02:00
for ( int i = mapInfo . players ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
}
}
catch ( const std : : exception & ex ) {
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2010-04-11 03:25:06 +02:00
throw runtime_error ( szBuf ) ;
2010-03-13 23:00:01 +01:00
}
}
void MenuStateCustomGame : : closeUnusedSlots ( ) {
2010-04-11 03:25:06 +02:00
try {
ServerInterface * serverInterface = NetworkManager : : getInstance ( ) . getServerInterface ( ) ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2010-12-19 00:03:53 +01:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
if ( serverInterface - > getSlot ( i ) = = NULL | |
serverInterface - > getSlot ( i ) - > isConnected ( ) = = false ) {
2010-04-11 03:25:06 +02:00
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
}
2010-03-13 23:00:01 +01:00
}
}
2010-04-11 03:25:06 +02:00
updateNetworkSlots ( ) ;
}
catch ( const std : : exception & ex ) {
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2010-04-11 03:25:06 +02:00
throw 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 ) {
hasCheckedForUPNP = true ;
serverInterface - > getServerSocket ( ) - > NETdiscoverUPnPDevices ( ) ;
}
}
else {
hasCheckedForUPNP = false ;
}
2010-10-23 06:00:39 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-08-23 06:33:21 +02:00
if ( serverInterface - > getSlot ( i ) = = NULL & &
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
2010-06-24 03:23:18 +02:00
try {
serverInterface - > addSlot ( i ) ;
}
catch ( const std : : exception & ex ) {
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2010-06-24 03:23:18 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
showGeneralError = true ;
if ( serverInterface - > isPortBound ( ) = = false ) {
generalErrorToShow = Lang : : getInstance ( ) . get ( " ErrorBindingPort " ) + " : " + intToStr ( serverInterface - > getBindPort ( ) ) ;
}
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
}
2010-08-23 06:33:21 +02:00
if ( serverInterface - > getSlot ( i ) ! = NULL & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork ) {
2010-04-11 03:25:06 +02:00
serverInterface - > removeSlot ( i ) ;
}
2010-03-13 23:00:01 +01:00
}
}
2010-04-11 03:25:06 +02:00
catch ( const std : : exception & ex ) {
2011-01-02 01:39:13 +01:00
char szBuf [ 4096 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] Error detected: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2010-06-11 06:55:49 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2011-01-25 08:41:12 +01:00
//throw runtime_error(szBuf);
2010-06-11 06:55:49 +02:00
showGeneralError = true ;
generalErrorToShow = ex . what ( ) ;
2010-04-11 03:25:06 +02:00
}
2010-03-13 23:00:01 +01:00
}
2010-08-21 09:41:26 +02:00
void MenuStateCustomGame : : keyDown ( char key ) {
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2010-10-08 18:19:09 +02:00
string text = activeInputLabel - > getText ( ) ;
if ( key = = vkBack & & text . length ( ) > 0 ) {
size_t found = text . find_last_of ( " _ " ) ;
if ( found = = string : : npos ) {
2010-10-08 03:41:53 +02:00
text . erase ( text . end ( ) - 1 ) ;
2010-08-21 09:41:26 +02:00
}
2010-10-08 18:19:09 +02:00
else {
if ( text . size ( ) > 1 ) {
text . erase ( text . end ( ) - 2 ) ;
}
}
2010-10-08 03:41:53 +02:00
2010-08-21 09:41:26 +02:00
activeInputLabel - > setText ( text ) ;
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > 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 ) ;
}
2010-09-09 23:07:39 +02:00
if ( chatManager . getEditEnabled ( ) = = false ) {
2010-08-28 03:52:57 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
if ( key = = configKeys . getCharKey ( " ShowFullConsole " ) ) {
2010-08-21 09:41:26 +02:00
showFullConsole = true ;
}
2010-09-04 01:15:42 +02:00
//Toggle music
else if ( key = = configKeys . getCharKey ( " ToggleMusic " ) ) {
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 ) ;
console . addLine ( lang . get ( " GameMusic " ) + " " + lang . get ( " Off " ) ) ;
}
else {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( configVolume ) ;
//If the config says zero, use the default music volume
//gameMusic->setVolume(configVolume ? configVolume : 0.9);
console . addLine ( lang . get ( " GameMusic " ) ) ;
}
}
2010-09-09 23:07:39 +02:00
else if ( key = = configKeys . getCharKey ( " SaveGUILayout " ) ) {
bool saved = GraphicComponent : : saveAllCustomProperties ( containerName ) ;
Lang & lang = Lang : : getInstance ( ) ;
console . addLine ( lang . get ( " GUILayoutSaved " ) + " [ " + ( saved ? lang . get ( " Yes " ) : lang . get ( " No " ) ) + " ] " ) ;
}
2010-06-11 06:55:49 +02:00
}
2010-06-09 00:50:37 +02:00
}
2010-03-13 23:00:01 +01:00
}
2010-08-21 09:41:26 +02:00
void MenuStateCustomGame : : keyPress ( char c ) {
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2010-08-21 09:41:26 +02:00
int maxTextSize = 16 ;
2010-10-08 03:41:53 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-08-23 06:33:21 +02:00
if ( & labelPlayerNames [ i ] = = activeInputLabel ) {
2010-10-08 03:41:53 +02:00
if ( ( c > = ' 0 ' & & c < = ' 9 ' ) | | ( c > = ' a ' & & c < = ' z ' ) | | ( c > = ' A ' & & c < = ' Z ' ) | |
( c = = ' - ' ) | | ( c = = ' ( ' ) | | ( c = = ' ) ' ) ) {
if ( activeInputLabel - > getText ( ) . size ( ) < maxTextSize ) {
2010-08-21 09:41:26 +02:00
string text = activeInputLabel - > getText ( ) ;
text . insert ( text . end ( ) - 1 , c ) ;
activeInputLabel - > setText ( text ) ;
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutex ( ( publishToMasterserverThread ! = NULL ? publishToMasterserverThread - > 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 {
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
}
2010-08-21 09:41:26 +02:00
void MenuStateCustomGame : : keyUp ( char key ) {
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
}
2010-08-28 03:52:57 +02:00
else if ( key = = configKeys . getCharKey ( " ShowFullConsole " ) ) {
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 ( ) ;
return playerSortedMaps [ i ] . at ( mapIndex ) ;
}
2010-08-23 06:33:21 +02:00
void MenuStateCustomGame : : setActiveInputLabel ( GraphicLabel * newLable ) {
2010-10-08 19:17:22 +02:00
2010-10-08 03:41:53 +02:00
if ( newLable ! = NULL ) {
2010-08-21 09:41:26 +02:00
string text = newLable - > getText ( ) ;
2010-10-08 03:41:53 +02:00
size_t found = text . find_last_of ( " _ " ) ;
if ( found = = string : : npos ) {
text + = " _ " ;
2010-08-21 09:41:26 +02:00
}
newLable - > setText ( text ) ;
}
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL & & activeInputLabel - > getText ( ) . empty ( ) = = false ) {
2010-08-21 09:41:26 +02:00
string text = activeInputLabel - > getText ( ) ;
2010-10-08 03:41:53 +02:00
size_t found = text . find_last_of ( " _ " ) ;
if ( found ! = string : : npos ) {
text = text . substr ( 0 , found ) ;
2010-08-21 09:41:26 +02:00
}
activeInputLabel - > setText ( text ) ;
}
2010-10-08 03:41:53 +02:00
activeInputLabel = newLable ;
2010-10-08 19:17:22 +02:00
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
//printf("\nIn [%s::%s Line: %d] index = %d\n",__FILE__,__FUNCTION__,__LINE__,index);
//fflush(stdout);
2010-10-08 19:17:22 +02:00
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-21 15:04:52 +02:00
//printf("\nIn [%s::%s Line: %d] index = %d, labelPlayerNames[index].getText() = [%s]\n",__FILE__,__FUNCTION__,__LINE__,index,(index >= 0 ? labelPlayerNames[index].getText().c_str() : "?"));
//fflush(stdout);
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 ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] filepath = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , filepath . c_str ( ) ) ;
2011-01-26 10:09:59 +01:00
factionTexture = Renderer : : findFactionLogoTexture ( filepath ) ;
2010-08-31 22:31:20 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2010-08-31 08:38:27 +02:00
}
}
2010-11-01 17:44:05 +01:00
void MenuStateCustomGame : : cleanupMapPreviewTexture ( ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//printf("CLEANUP map preview texture\n");
if ( mapPreviewTexture ! = NULL ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
mapPreviewTexture - > end ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
delete mapPreviewTexture ;
mapPreviewTexture = NULL ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
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 ;
}
2010-03-13 23:00:01 +01:00
} } //end namespace