diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index 41b3cdd1f..769573692 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2005 Martiño Figueroa +// Copyright (C) 2001-2005 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -143,10 +143,19 @@ void MenuStateScenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo } const XmlNode *playersNode= scenarioNode->getChild("players"); + for(int i= 0; igetChild("player", i); - ControlType factionControl = strToControllerType( playerNode->getAttribute("control")->getValue() ); - string factionTypeName; + XmlNode* playerNode; + string factionTypeName; + ControlType factionControl; + + if(playersNode->hasChildAtIndex("player",i)){ + playerNode = playersNode->getChild("player", i); + factionControl = strToControllerType( playerNode->getAttribute("control")->getValue() ); + } + else{ + factionControl=ctClosed; + } scenarioInfo->factionControls[i] = factionControl; diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index 46d70f2f2..883f67c50 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -109,6 +109,7 @@ public: XmlAttribute *getAttribute(const string &name) const; XmlNode *getChild(int i) const; XmlNode *getChild(const string &childName, int childIndex=0) const; + bool hasChildAtIndex(const string &childName, int childIndex=0) const; bool hasChild(const string &childName) const; XmlNode *getParent() const; diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index 3c29a10a4..ade984720 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -269,6 +269,24 @@ XmlNode *XmlNode::getChild(const string &childName, int i) const{ throw runtime_error("Node \""+getName()+"\" doesn't have "+intToStr(i+1)+" children named \""+childName+"\"\n\nTree: "+getTreeString()); } +bool XmlNode::hasChildAtIndex(const string &childName, int i) const +{ + int count= 0; + for(int j = 0; j < children.size(); ++j) + { + if(children[j]->getName()==childName) + { + if(count==i){ + return true; + } + count++; + } + } + + return false; +} + + bool XmlNode::hasChild(const string &childName) const { int count= 0;