2011-01-20 16:56:30 +01:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2011-12-28 05:46:36 +01:00
// Copyright (C) 2001-2005 Martiño Figueroa
2011-01-20 16:56:30 +01:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
# include "scenario.h"
# include <stdexcept>
# include "logger.h"
# include "xml_parser.h"
# include "util.h"
# include "game_util.h"
# include <stdio.h>
2011-03-13 09:23:43 +01:00
# include "platform_common.h"
2011-05-07 00:12:16 +02:00
# include "properties.h"
2011-10-06 20:04:59 +02:00
# include "lang.h"
2012-01-05 01:45:17 +01:00
# include "socket.h"
2011-10-06 20:04:59 +02:00
# include "config.h"
2012-04-14 23:21:09 +02:00
# include "platform_util.h"
2011-03-13 09:23:43 +01:00
# include "leak_dumper.h"
2011-01-20 16:56:30 +01:00
using namespace Shared : : Xml ;
using namespace Shared : : Util ;
2011-03-13 09:23:43 +01:00
using namespace Shared : : PlatformCommon ;
2011-01-20 16:56:30 +01:00
using namespace std ;
namespace Glest { namespace Game {
// =====================================================
// class Scenario
// =====================================================
Scenario : : ~ Scenario ( ) {
}
2011-01-09 05:49:21 +01:00
Checksum Scenario : : load ( const string & path ) {
2011-10-06 20:04:59 +02:00
//printf("[%s:%s] Line: %d path [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
2011-01-20 16:56:30 +01:00
Checksum scenarioChecksum ;
try {
2011-01-09 05:49:21 +01:00
scenarioChecksum . addFile ( path ) ;
checksumValue . addFile ( path ) ;
2011-01-20 16:56:30 +01:00
string name = cutLastExt ( lastDir ( path ) ) ;
2011-11-02 18:17:28 +01:00
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , Lang : : getInstance ( ) . get ( " LogScreenGameLoadingScenario " , " " , true ) . c_str ( ) , formatString ( name ) . c_str ( ) ) ;
2011-11-02 18:17:28 +01:00
Logger : : getInstance ( ) . add ( szBuf , true ) ;
2011-01-20 16:56:30 +01:00
2011-10-06 20:04:59 +02:00
Scenario : : loadScenarioInfo ( path , & info ) ;
2011-01-20 16:56:30 +01:00
//parse xml
XmlTree xmlTree ;
2011-05-07 00:12:16 +02:00
xmlTree . load ( path , Properties : : getTagReplacementValues ( ) ) ;
2011-01-20 16:56:30 +01:00
const XmlNode * scenarioNode = xmlTree . getRootNode ( ) ;
const XmlNode * scriptsNode = scenarioNode - > getChild ( " scripts " ) ;
for ( int i = 0 ; i < scriptsNode - > getChildCount ( ) ; + + i ) {
const XmlNode * scriptNode = scriptsNode - > getChild ( i ) ;
scripts . push_back ( Script ( getFunctionName ( scriptNode ) , scriptNode - > getText ( ) ) ) ;
}
}
//Exception handling (conversions and so on);
2012-03-31 22:58:33 +02:00
catch ( const exception & ex ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error loading scenario [%s]: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , path . c_str ( ) , ex . what ( ) ) ;
2012-03-31 22:58:33 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-01-09 05:49:21 +01:00
}
2011-01-20 16:56:30 +01:00
return scenarioChecksum ;
}
2010-03-18 22:26:40 +01:00
int Scenario : : getScenarioPathIndex ( const vector < string > dirList , const string & scenarioName ) {
int iIndex = 0 ;
for ( int idx = 0 ; idx < dirList . size ( ) ; idx + + ) {
2011-03-13 09:23:43 +01:00
string currentPath = dirList [ idx ] ;
endPathWithSlash ( currentPath ) ;
string scenarioFile = currentPath + scenarioName + " / " + scenarioName + " .xml " ;
2010-03-18 22:26:40 +01:00
if ( fileExists ( scenarioFile ) = = true ) {
iIndex = idx ;
break ;
}
}
return iIndex ;
}
2011-01-20 16:56:30 +01:00
2011-12-28 05:46:36 +01:00
string Scenario : : getScenarioDir ( const vector < string > dir , const string & scenarioName ) {
string scenarioDir = " " ;
for ( int idx = 0 ; idx < dir . size ( ) ; idx + + ) {
string currentPath = dir [ idx ] ;
endPathWithSlash ( currentPath ) ;
string scenarioFile = currentPath + scenarioName + " / " + scenarioName + " .xml " ;
//printf("\n[%s:%s] Line: %d scenarioName [%s] scenarioFile [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioName.c_str(),scenarioFile.c_str());
if ( fileExists ( scenarioFile ) = = true ) {
scenarioDir = currentPath + scenarioName + " / " ;
break ;
}
}
return scenarioDir ;
}
2010-03-20 13:11:46 +01:00
string Scenario : : getScenarioPath ( const vector < string > dirList , const string & scenarioName , bool getMatchingRootScenarioPathOnly ) {
2010-03-18 22:26:40 +01:00
string scenarioFile = " " ;
for ( int idx = 0 ; idx < dirList . size ( ) ; idx + + ) {
2011-03-13 09:23:43 +01:00
string currentPath = dirList [ idx ] ;
endPathWithSlash ( currentPath ) ;
scenarioFile = currentPath + scenarioName + " / " + scenarioName + " .xml " ;
2011-10-06 20:04:59 +02:00
//printf("\n[%s:%s] Line: %d scenarioName [%s] scenarioFile [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioName.c_str(),scenarioFile.c_str());
2010-03-18 22:26:40 +01:00
if ( fileExists ( scenarioFile ) = = true ) {
2010-03-20 13:11:46 +01:00
if ( getMatchingRootScenarioPathOnly = = true ) {
scenarioFile = dirList [ idx ] ;
}
2010-03-18 22:26:40 +01:00
break ;
}
2010-03-20 13:11:46 +01:00
else {
scenarioFile = " " ;
}
2010-03-18 22:26:40 +01:00
}
2011-01-09 05:49:21 +01:00
2011-01-20 16:56:30 +01:00
return scenarioFile ;
}
2010-03-18 22:26:40 +01:00
string Scenario : : getScenarioPath ( const string & dir , const string & scenarioName ) {
2011-03-13 09:23:43 +01:00
string currentPath = dir ;
endPathWithSlash ( currentPath ) ;
string scenarioFile = currentPath + scenarioName + " / " + scenarioName + " .xml " ;
2010-03-18 22:26:40 +01:00
return scenarioFile ;
}
2011-01-20 16:56:30 +01:00
string Scenario : : getFunctionName ( const XmlNode * scriptNode ) {
string name = scriptNode - > getName ( ) ;
for ( int i = 0 ; i < scriptNode - > getAttributeCount ( ) ; + + i ) {
name + = " _ " + scriptNode - > getAttribute ( i ) - > getValue ( ) ;
}
return name ;
}
2011-10-06 20:04:59 +02:00
void Scenario : : loadScenarioInfo ( string file , ScenarioInfo * scenarioInfo ) {
//printf("[%s:%s] Line: %d file [%s]\n",__FILE__,__FUNCTION__,__LINE__,file.c_str());
2012-07-18 02:35:39 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] file [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , file . c_str ( ) ) ;
//printf("In [%s::%s Line: %d] file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,file.c_str());
2011-10-06 20:04:59 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2013-02-09 08:17:10 +01:00
string scenarioDir = cutLastFile ( formatPath ( file ) ) ;
string scenarioName = extractLastDirectoryFromPath ( scenarioDir ) ;
scenarioDir = cutLastFile ( scenarioDir ) ;
2011-10-06 20:04:59 +02:00
XmlTree xmlTree ;
xmlTree . load ( file , Properties : : getTagReplacementValues ( ) ) ;
const XmlNode * scenarioNode = xmlTree . getRootNode ( ) ;
2012-07-18 02:04:24 +02:00
if ( scenarioNode = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " scenarioNode == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
2011-10-06 20:04:59 +02:00
const XmlNode * difficultyNode = scenarioNode - > getChild ( " difficulty " ) ;
2012-07-18 02:04:24 +02:00
if ( difficultyNode = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " difficultyNode == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
2011-10-06 20:04:59 +02:00
scenarioInfo - > difficulty = difficultyNode - > getAttribute ( " value " ) - > getIntValue ( ) ;
if ( scenarioInfo - > difficulty < dVeryEasy | | scenarioInfo - > difficulty > dInsane ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Invalid difficulty value specified in scenario: %d must be between %d and %d " , scenarioInfo - > difficulty , dVeryEasy , dInsane ) ;
2011-10-06 20:04:59 +02:00
throw std : : runtime_error ( szBuf ) ;
}
const XmlNode * playersNode = scenarioNode - > getChild ( " players " ) ;
2012-07-18 02:04:24 +02:00
if ( playersNode = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " playersNode == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
2011-10-06 20:04:59 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
XmlNode * playerNode = NULL ;
2012-10-06 09:06:40 +02:00
//string factionTypeName="";
2011-10-06 20:04:59 +02:00
ControlType factionControl ;
2012-03-30 07:53:33 +02:00
if ( playersNode - > hasChildAtIndex ( " player " , i ) ) {
2011-10-06 20:04:59 +02:00
playerNode = playersNode - > getChild ( " player " , i ) ;
2012-07-18 02:04:24 +02:00
if ( playerNode = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " playerNode == NULL for index = %d for file [%s] \n " , i , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
2011-10-06 20:04:59 +02:00
factionControl = strToControllerType ( playerNode - > getAttribute ( " control " ) - > getValue ( ) ) ;
2011-12-26 07:29:14 +01:00
if ( playerNode - > getAttribute ( " resource_multiplier " , false ) ! = NULL ) {
2011-10-06 20:04:59 +02:00
// if a multiplier exists use it
scenarioInfo - > resourceMultipliers [ i ] = playerNode - > getAttribute ( " resource_multiplier " ) - > getFloatValue ( ) ;
}
else {
// if no multiplier exists use defaults
scenarioInfo - > resourceMultipliers [ i ] = GameConstants : : normalMultiplier ;
if ( factionControl = = ctCpuEasy ) {
scenarioInfo - > resourceMultipliers [ i ] = GameConstants : : easyMultiplier ;
}
if ( factionControl = = ctCpuUltra ) {
scenarioInfo - > resourceMultipliers [ i ] = GameConstants : : ultraMultiplier ;
}
else if ( factionControl = = ctCpuMega ) {
scenarioInfo - > resourceMultipliers [ i ] = GameConstants : : megaMultiplier ;
}
}
}
else {
factionControl = ctClosed ;
}
scenarioInfo - > factionControls [ i ] = factionControl ;
2011-12-28 05:46:36 +01:00
if ( factionControl ! = ctClosed ) {
2011-10-06 20:04:59 +02:00
int teamIndex = playerNode - > getAttribute ( " team " ) - > getIntValue ( ) ;
2012-03-30 07:53:33 +02:00
if ( teamIndex < 1 | | teamIndex > GameConstants : : maxPlayers + GameConstants : : specialFactions ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Invalid team value specified in scenario: %d must be between %d and %d " , teamIndex , 1 , GameConstants : : maxPlayers ) ;
2011-10-06 20:04:59 +02:00
throw std : : runtime_error ( szBuf ) ;
}
2012-03-30 07:53:33 +02:00
scenarioInfo - > teams [ i ] = teamIndex ;
2011-10-06 20:04:59 +02:00
scenarioInfo - > factionTypeNames [ i ] = playerNode - > getAttribute ( " faction " ) - > getValue ( ) ;
}
2011-12-28 05:46:36 +01:00
else {
scenarioInfo - > teams [ i ] = 0 ;
scenarioInfo - > factionTypeNames [ i ] = " " ;
}
2011-10-06 20:04:59 +02:00
2012-07-18 02:04:24 +02:00
if ( scenarioNode - > getChild ( " map " ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " map == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
if ( scenarioNode - > getChild ( " tileset " ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " tileset == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
if ( scenarioNode - > getChild ( " tech-tree " ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " tech-tree == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
if ( scenarioNode - > getChild ( " default-units " ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " default-units == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
if ( scenarioNode - > getChild ( " default-resources " ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " default-resources == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
if ( scenarioNode - > getChild ( " default-victory-conditions " ) = = NULL ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " default-victory-conditions == NULL for file [%s] \n " , file . c_str ( ) ) ;
2012-07-18 02:04:24 +02:00
throw std : : runtime_error ( szBuf ) ;
}
2011-10-06 20:04:59 +02:00
scenarioInfo - > mapName = scenarioNode - > getChild ( " map " ) - > getAttribute ( " value " ) - > getValue ( ) ;
scenarioInfo - > tilesetName = scenarioNode - > getChild ( " tileset " ) - > getAttribute ( " value " ) - > getValue ( ) ;
scenarioInfo - > techTreeName = scenarioNode - > getChild ( " tech-tree " ) - > getAttribute ( " value " ) - > getValue ( ) ;
scenarioInfo - > defaultUnits = scenarioNode - > getChild ( " default-units " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
scenarioInfo - > defaultResources = scenarioNode - > getChild ( " default-resources " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
scenarioInfo - > defaultVictoryConditions = scenarioNode - > getChild ( " default-victory-conditions " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
}
//add player info
2013-02-09 08:17:10 +01:00
scenarioInfo - > desc = lang . get ( " PlayerFaction " ) + " : " ;
2011-10-06 20:04:59 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
if ( scenarioInfo - > factionControls [ i ] = = ctHuman ) {
scenarioInfo - > desc + = formatString ( scenarioInfo - > factionTypeNames [ i ] ) ;
break ;
}
}
//add misc info
string difficultyString = " Difficulty " + intToStr ( scenarioInfo - > difficulty ) ;
scenarioInfo - > desc + = " \n " ;
scenarioInfo - > desc + = lang . get ( " Difficulty " ) + " : " + lang . get ( difficultyString ) + " \n " ;
scenarioInfo - > desc + = lang . get ( " Map " ) + " : " + formatString ( scenarioInfo - > mapName ) + " \n " ;
scenarioInfo - > desc + = lang . get ( " Tileset " ) + " : " + formatString ( scenarioInfo - > tilesetName ) + " \n " ;
scenarioInfo - > desc + = lang . get ( " TechTree " ) + " : " + formatString ( scenarioInfo - > techTreeName ) + " \n " ;
2013-02-09 08:17:10 +01:00
//look for description and append it
lang . loadScenarioStrings ( scenarioDir , scenarioName . c_str ( ) ) ;
2013-02-09 18:18:34 +01:00
//string tmp_description = lang.getScenarioString("DESCRIPTION");
string tmp_description = " " ;
if ( lang . hasScenarioString ( " DESCRIPTION " ) = = true ) {
tmp_description = lang . getScenarioString ( " DESCRIPTION " ) ;
}
if ( tmp_description ! = " " ) {
scenarioInfo - > desc + = lang . get ( " Description " ) + " : \n " + tmp_description + " \n " ;
2013-02-09 08:17:10 +01:00
}
2013-02-12 03:10:00 +01:00
scenarioInfo - > namei18n = " " ;
if ( lang . hasScenarioString ( " SCENARIO_NAME " ) = = true ) {
scenarioInfo - > namei18n = lang . getScenarioString ( " SCENARIO_NAME " ) ;
//printf("scenarioInfo->namei18n [%s]\n",scenarioInfo->namei18n.c_str());
}
else if ( lang . hasScenarioString ( " TUTORIAL_NAME " ) = = true ) {
scenarioInfo - > namei18n = lang . getScenarioString ( " TUTORIAL_NAME " ) ;
//printf("scenarioInfo->namei18n [%s]\n",scenarioInfo->namei18n.c_str());
}
2011-10-06 20:04:59 +02:00
if ( scenarioNode - > hasChild ( " fog-of-war " ) = = true ) {
if ( scenarioNode - > getChild ( " fog-of-war " ) - > getAttribute ( " value " ) - > getValue ( ) = = " explored " ) {
scenarioInfo - > fogOfWar = true ;
scenarioInfo - > fogOfWar_exploredFlag = true ;
}
else {
scenarioInfo - > fogOfWar = scenarioNode - > getChild ( " fog-of-war " ) - > getAttribute ( " value " ) - > getBoolValue ( ) ;
scenarioInfo - > fogOfWar_exploredFlag = false ;
}
//printf("\nFOG OF WAR is set to [%d]\n",scenarioInfo->fogOfWar);
}
else {
scenarioInfo - > fogOfWar = true ;
scenarioInfo - > fogOfWar_exploredFlag = false ;
}
scenarioInfo - > file = file ;
scenarioInfo - > name = extractFileFromDirectoryPath ( file ) ;
scenarioInfo - > name = cutLastExt ( scenarioInfo - > name ) ;
//scenarioLogoTexture = NULL;
//cleanupPreviewTexture();
//previewLoadDelayTimer=time(NULL);
//needToLoadTextures=true;
}
ControlType Scenario : : strToControllerType ( const string & str ) {
if ( str = = " closed " ) {
return ctClosed ;
}
else if ( str = = " cpu-easy " ) {
return ctCpuEasy ;
}
else if ( str = = " cpu " ) {
return ctCpu ;
}
else if ( str = = " cpu-ultra " ) {
return ctCpuUltra ;
}
else if ( str = = " cpu-mega " ) {
return ctCpuMega ;
}
else if ( str = = " human " ) {
return ctHuman ;
}
2011-12-26 07:29:14 +01:00
else if ( str = = " network " ) {
return ctNetwork ;
}
2011-10-06 20:04:59 +02:00
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Invalid controller value specified in scenario: [%s] must be one of the following: closed, cpu-easy, cpu, cpu-ultra, cpu-mega, human " , str . c_str ( ) ) ;
2011-10-06 20:04:59 +02:00
throw std : : runtime_error ( szBuf ) ;
}
2012-01-05 01:45:17 +01:00
string Scenario : : controllerTypeToStr ( const ControlType & ct ) {
string controlString = " " ;
Lang & lang = Lang : : getInstance ( ) ;
switch ( ct ) {
case ctCpuEasy :
controlString = lang . get ( " CpuEasy " ) ;
break ;
case ctCpu :
controlString = lang . get ( " Cpu " ) ;
break ;
case ctCpuUltra :
controlString = lang . get ( " CpuUltra " ) ;
break ;
case ctCpuMega :
controlString = lang . get ( " CpuMega " ) ;
break ;
case ctNetwork :
controlString = lang . get ( " Network " ) ;
break ;
case ctHuman :
controlString = lang . get ( " Human " ) ;
break ;
case ctNetworkCpuEasy :
controlString = lang . get ( " NetworkCpuEasy " ) ;
break ;
case ctNetworkCpu :
controlString = lang . get ( " NetworkCpu " ) ;
break ;
case ctNetworkCpuUltra :
controlString = lang . get ( " NetworkCpuUltra " ) ;
break ;
case ctNetworkCpuMega :
controlString = lang . get ( " NetworkCpuMega " ) ;
break ;
default :
printf ( " Error control = %d \n " , ct ) ;
//assert(false);
2012-09-22 22:13:57 +02:00
break ;
2012-01-05 01:45:17 +01:00
}
return controlString ;
}
2011-12-28 05:46:36 +01:00
void Scenario : : loadGameSettings ( const vector < string > & dirList ,
const ScenarioInfo * scenarioInfo , GameSettings * gameSettings ,
string scenarioDescription ) {
2011-10-06 20:04:59 +02:00
int factionCount = 0 ;
gameSettings - > setDescription ( scenarioDescription ) ;
gameSettings - > setMap ( scenarioInfo - > mapName ) ;
gameSettings - > setTileset ( scenarioInfo - > tilesetName ) ;
gameSettings - > setTech ( scenarioInfo - > techTreeName ) ;
gameSettings - > setScenario ( scenarioInfo - > name ) ;
gameSettings - > setScenarioDir ( Scenario : : getScenarioPath ( dirList , scenarioInfo - > name ) ) ;
gameSettings - > setDefaultUnits ( scenarioInfo - > defaultUnits ) ;
gameSettings - > setDefaultResources ( scenarioInfo - > defaultResources ) ;
gameSettings - > setDefaultVictoryConditions ( scenarioInfo - > defaultVictoryConditions ) ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
ControlType ct = static_cast < ControlType > ( scenarioInfo - > factionControls [ i ] ) ;
if ( ct ! = ctClosed ) {
if ( ct = = ctHuman ) {
gameSettings - > setThisFactionIndex ( factionCount ) ;
2012-01-05 01:45:17 +01:00
if ( gameSettings - > getNetworkPlayerName ( i ) = = " " ) {
gameSettings - > setNetworkPlayerName ( i , Config : : getInstance ( ) . getString ( " NetPlayerName " , Socket : : getHostName ( ) . c_str ( ) ) ) ;
}
}
else {
if ( gameSettings - > getNetworkPlayerName ( i ) = = " " ) {
gameSettings - > setNetworkPlayerName ( i , controllerTypeToStr ( ct ) ) ;
}
2011-10-06 20:04:59 +02:00
}
gameSettings - > setFactionControl ( factionCount , ct ) ;
gameSettings - > setResourceMultiplierIndex ( factionCount , ( scenarioInfo - > resourceMultipliers [ i ] - 0.5f ) / 0.1f ) ;
gameSettings - > setTeam ( factionCount , scenarioInfo - > teams [ i ] - 1 ) ;
gameSettings - > setStartLocationIndex ( factionCount , i ) ;
gameSettings - > setFactionTypeName ( factionCount , scenarioInfo - > factionTypeNames [ i ] ) ;
factionCount + + ;
}
}
gameSettings - > setFactionCount ( factionCount ) ;
gameSettings - > setFogOfWar ( scenarioInfo - > fogOfWar ) ;
uint32 valueFlags1 = gameSettings - > getFlagTypes1 ( ) ;
if ( scenarioInfo - > fogOfWar = = false | | scenarioInfo - > fogOfWar_exploredFlag ) {
valueFlags1 | = ft1_show_map_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_show_map_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
gameSettings - > setPathFinderType ( static_cast < PathFinderType > ( Config : : getInstance ( ) . getInt ( " ScenarioPathFinderType " , intToStr ( pfBasic ) . c_str ( ) ) ) ) ;
}
2011-01-20 16:56:30 +01:00
} } //end namespace