2009-11-29 17:01:31 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* Eliot
|
2012-01-17 00:27:32 +01:00
|
|
|
* Copyright (C) 2009-2012 Olivier Teulière
|
2009-11-29 17:01:31 +01:00
|
|
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <fstream>
|
2012-03-28 23:21:24 +02:00
|
|
|
#include <algorithm>
|
2012-10-06 18:18:21 +02:00
|
|
|
#include <boost/format.hpp>
|
2009-11-29 17:01:31 +01:00
|
|
|
#include <SAX/XMLReader.hpp>
|
|
|
|
#include <SAX/InputSource.hpp>
|
|
|
|
|
2012-04-04 21:37:51 +02:00
|
|
|
// Remove spurious defines from libarabica, to avoid compilation warnings.
|
|
|
|
// Libarabica should not export them via public headers...
|
|
|
|
#undef PACKAGE
|
|
|
|
#undef PACKAGE_BUGREPORT
|
|
|
|
#undef PACKAGE_NAME
|
|
|
|
#undef PACKAGE_STRING
|
|
|
|
#undef PACKAGE_TARNAME
|
|
|
|
#undef PACKAGE_VERSION
|
|
|
|
#undef VERSION
|
|
|
|
|
2012-10-06 18:18:21 +02:00
|
|
|
#include "config.h"
|
|
|
|
#if ENABLE_NLS
|
|
|
|
# include <libintl.h>
|
|
|
|
# define _(String) gettext(String)
|
|
|
|
#else
|
|
|
|
# define _(String) String
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
#include "xml_reader.h"
|
|
|
|
#include "dic.h"
|
|
|
|
#include "game_exception.h"
|
2011-08-27 19:21:26 +02:00
|
|
|
#include "game_params.h"
|
2009-11-29 17:01:31 +01:00
|
|
|
#include "game_factory.h"
|
|
|
|
#include "training.h"
|
|
|
|
#include "duplicate.h"
|
|
|
|
#include "freegame.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "ai_percent.h"
|
|
|
|
#include "encoding.h"
|
2012-02-25 23:16:42 +01:00
|
|
|
#include "game_rack_cmd.h"
|
2009-11-29 17:01:31 +01:00
|
|
|
#include "game_move_cmd.h"
|
|
|
|
#include "player_rack_cmd.h"
|
|
|
|
#include "player_move_cmd.h"
|
2012-05-20 21:31:45 +02:00
|
|
|
#include "player_event_cmd.h"
|
2012-01-17 17:43:04 +01:00
|
|
|
#include "master_move_cmd.h"
|
2009-11-29 17:01:31 +01:00
|
|
|
#include "navigation.h"
|
2012-03-22 08:33:19 +01:00
|
|
|
#include "header.h"
|
2009-11-29 17:01:31 +01:00
|
|
|
|
2012-04-04 21:53:54 +02:00
|
|
|
// Current version of our save game format. Bump it when it becomes
|
|
|
|
// incompatible (and keep it in sync with xml_writer.cpp)
|
|
|
|
#define CURRENT_XML_VERSION "2"
|
|
|
|
|
2012-10-06 18:18:21 +02:00
|
|
|
#define FMT1(s, a1) (boost::format(s) % (a1)).str()
|
|
|
|
#define FMT2(s, a1, a2) (boost::format(s) % (a1) % (a2)).str()
|
|
|
|
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
using namespace std;
|
|
|
|
|
2011-01-30 00:47:20 +01:00
|
|
|
INIT_LOGGER(game, XmlReader);
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
|
|
|
|
Game * XmlReader::read(const string &iFileName, const Dictionary &iDic)
|
|
|
|
{
|
2011-01-30 00:47:20 +01:00
|
|
|
LOG_INFO("Parsing savegame '" << iFileName << "'");
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
ifstream is(iFileName.c_str());
|
|
|
|
if (!is.is_open())
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(FMT1(_("Cannot open file '%1%'"), iFileName));
|
2009-11-29 17:01:31 +01:00
|
|
|
|
|
|
|
XmlReader handler(iDic);
|
|
|
|
|
|
|
|
// Set up of the parser
|
|
|
|
Arabica::SAX::XMLReader<std::string> parser;
|
|
|
|
parser.setContentHandler(handler);
|
|
|
|
parser.setErrorHandler(handler);
|
|
|
|
|
|
|
|
// Parsing
|
|
|
|
Arabica::SAX::InputSource<std::string> source(is);
|
|
|
|
parser.parse(source);
|
|
|
|
|
|
|
|
Game *game = handler.getGame();
|
|
|
|
if (game == NULL)
|
|
|
|
throw LoadGameException(handler.errorMessage);
|
2011-01-30 00:47:20 +01:00
|
|
|
|
|
|
|
LOG_INFO("Savegame parsed successfully");
|
2009-11-29 17:01:31 +01:00
|
|
|
return game;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static wstring fromUtf8(const string &str)
|
|
|
|
{
|
2011-07-30 21:46:47 +02:00
|
|
|
return readFromUTF8(str, "Loading game");
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int toInt(const string &str)
|
|
|
|
{
|
|
|
|
if (str.empty())
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(_("Invalid string to int conversion: empty string received"));
|
2009-11-29 17:01:31 +01:00
|
|
|
return atoi(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-24 00:19:20 +02:00
|
|
|
static Player & getPlayer(map<string, Player*> &players,
|
|
|
|
const string &id, const string &iTag)
|
2009-11-29 17:01:31 +01:00
|
|
|
{
|
|
|
|
if (players.find(id) == players.end())
|
2012-10-24 00:19:20 +02:00
|
|
|
throw LoadGameException(FMT2(_("Invalid player ID: %1% (processing tag '%2%')"), id, iTag));
|
2009-11-29 17:01:31 +01:00
|
|
|
return *players[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Move buildMove(const Game &iGame, map<string, string> &attr,
|
|
|
|
bool checkRack)
|
|
|
|
{
|
|
|
|
// Build the Move object
|
|
|
|
string type = attr["type"];
|
|
|
|
if (type == "valid")
|
|
|
|
{
|
2010-03-06 17:53:37 +01:00
|
|
|
wstring word = iGame.getDic().convertFromInput(fromUtf8(attr["word"]));
|
2009-11-29 17:01:31 +01:00
|
|
|
Round round;
|
|
|
|
int res = iGame.checkPlayedWord(fromUtf8(attr["coord"]),
|
2010-03-06 17:53:37 +01:00
|
|
|
word, round, checkRack);
|
2009-11-29 17:01:31 +01:00
|
|
|
if (res != 0)
|
|
|
|
{
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(FMT2(_("Invalid move marked as valid: %1% (%2%)"),
|
|
|
|
attr["word"], attr["coord"]));
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
return Move(round);
|
|
|
|
}
|
|
|
|
else if (type == "invalid")
|
|
|
|
{
|
|
|
|
return Move(fromUtf8(attr["word"]),
|
|
|
|
fromUtf8(attr["coord"]));
|
|
|
|
}
|
|
|
|
else if (type == "change")
|
|
|
|
{
|
|
|
|
return Move(fromUtf8(attr["letters"]));
|
|
|
|
}
|
|
|
|
else if (type == "pass")
|
|
|
|
{
|
|
|
|
return Move(L"");
|
|
|
|
}
|
2012-01-17 00:27:32 +01:00
|
|
|
else if (type == "none")
|
|
|
|
{
|
|
|
|
return Move();
|
|
|
|
}
|
2009-11-29 17:01:31 +01:00
|
|
|
else
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(FMT1(_("Invalid move type: %1%"), type));
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Game * XmlReader::getGame()
|
|
|
|
{
|
|
|
|
return m_game;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlReader::startElement(const string& namespaceURI,
|
|
|
|
const string& localName,
|
|
|
|
const string& qName,
|
|
|
|
const Arabica::SAX::Attributes<string>& atts)
|
|
|
|
{
|
|
|
|
(void) namespaceURI;
|
|
|
|
(void) qName;
|
2012-05-20 21:31:45 +02:00
|
|
|
LOG_TRACE("Start Element: " << (localName.empty() ? qName : namespaceURI + ":" + localName));
|
2011-01-30 00:47:20 +01:00
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
m_data.clear();
|
|
|
|
const string &tag = localName;
|
2012-04-04 21:53:54 +02:00
|
|
|
if (tag == "EliotGame")
|
|
|
|
{
|
|
|
|
// Make sure that we are loading the correct XML format
|
|
|
|
for (int i = 0; i < atts.getLength(); ++i)
|
|
|
|
{
|
|
|
|
if (atts.getLocalName(i) == "format" &&
|
|
|
|
atts.getValue(i) != CURRENT_XML_VERSION)
|
|
|
|
{
|
|
|
|
LOG_ERROR("Incompatible save game format: current="
|
|
|
|
<< CURRENT_XML_VERSION
|
|
|
|
<< " savegame=" << atts.getValue(i));
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(_("This saved game is not compatible with the current version of Eliot."));
|
2012-04-04 21:53:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (tag == "Dictionary")
|
2012-03-22 08:33:19 +01:00
|
|
|
{
|
|
|
|
m_context = "Dictionary";
|
|
|
|
}
|
|
|
|
else if (tag == "Player")
|
2009-11-29 17:01:31 +01:00
|
|
|
{
|
|
|
|
m_context = "Player";
|
|
|
|
for (int i = 0; i < atts.getLength(); ++i)
|
|
|
|
{
|
|
|
|
m_attributes[atts.getLocalName(i)] = atts.getValue(i);
|
|
|
|
}
|
|
|
|
}
|
2012-02-25 23:16:42 +01:00
|
|
|
else if (tag == "GameRack" || tag == "PlayerRack" ||
|
2012-05-20 21:31:45 +02:00
|
|
|
tag == "PlayerMove" || tag == "GameMove" || tag == "MasterMove" ||
|
2012-10-05 17:51:01 +02:00
|
|
|
tag == "Warning" || tag == "Penalty" || tag == "Solo" || tag == "EndGame")
|
2009-11-29 17:01:31 +01:00
|
|
|
{
|
|
|
|
m_attributes.clear();
|
|
|
|
for (int i = 0; i < atts.getLength(); ++i)
|
|
|
|
{
|
|
|
|
m_attributes[atts.getLocalName(i)] = atts.getValue(i);
|
|
|
|
}
|
|
|
|
}
|
2012-04-16 20:30:35 +02:00
|
|
|
else if (tag == "Turn")
|
|
|
|
{
|
|
|
|
if (m_firstTurn)
|
|
|
|
m_firstTurn = false;
|
|
|
|
else
|
|
|
|
m_game->accessNavigation().newTurn();
|
|
|
|
}
|
2012-10-23 23:58:31 +02:00
|
|
|
// For backwards compatibility ("playerid" was used in saved games
|
|
|
|
// before release 2.1, with XML version 2)
|
|
|
|
if (m_attributes["playerid"] != "")
|
|
|
|
m_attributes["playerId"] = m_attributes["playerid"];
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlReader::endElement(const string& namespaceURI,
|
|
|
|
const string& localName,
|
|
|
|
const string&)
|
|
|
|
{
|
|
|
|
(void) namespaceURI;
|
2012-05-20 21:31:45 +02:00
|
|
|
LOG_TRACE("endElement: " << namespaceURI << ":" << localName << "(" << m_data << ")");
|
2011-01-30 00:47:20 +01:00
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
const string &tag = localName;
|
2012-03-22 08:33:19 +01:00
|
|
|
|
|
|
|
// Dictionary section
|
|
|
|
if (m_context == "Dictionary")
|
|
|
|
{
|
|
|
|
if (tag == "Letters")
|
|
|
|
{
|
2012-03-28 23:21:24 +02:00
|
|
|
const wdstring & displayLetters = m_dic.convertToDisplay(m_dic.getHeader().getLetters());
|
|
|
|
// Remove spaces
|
|
|
|
string::iterator it;
|
|
|
|
it = remove(m_data.begin(), m_data.end(), L' ');
|
|
|
|
m_data.erase(it, m_data.end());
|
|
|
|
// Compare
|
|
|
|
if (displayLetters != fromUtf8(m_data))
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(_("The current dictionary is different from the one used in the saved game"));
|
2012-03-22 08:33:19 +01:00
|
|
|
}
|
|
|
|
else if (tag == "WordNb")
|
|
|
|
{
|
2012-04-04 21:37:51 +02:00
|
|
|
if (m_dic.getHeader().getNbWords() != (unsigned)toInt(m_data))
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(_("The current dictionary is different from the one used in the saved game"));
|
2012-03-22 08:33:19 +01:00
|
|
|
}
|
|
|
|
else if (tag == "Dictionary")
|
|
|
|
m_context = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
if (tag == "Mode")
|
|
|
|
{
|
2011-08-27 19:21:26 +02:00
|
|
|
// The game should not be created yet
|
|
|
|
if (m_game != NULL)
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(_("The 'Mode' tag should be the first one to be closed"));
|
2011-08-27 19:21:26 +02:00
|
|
|
|
|
|
|
// Differ game creation until after we have read the variant
|
2011-08-28 18:20:00 +02:00
|
|
|
if (m_data == "duplicate")
|
2011-08-28 19:16:59 +02:00
|
|
|
m_params.setMode(GameParams::kDUPLICATE);
|
2011-08-28 18:20:00 +02:00
|
|
|
else if (m_data == "freegame")
|
2011-08-28 19:16:59 +02:00
|
|
|
m_params.setMode(GameParams::kFREEGAME);
|
2011-08-28 18:20:00 +02:00
|
|
|
else if (m_data == "training")
|
2011-08-28 19:16:59 +02:00
|
|
|
m_params.setMode(GameParams::kTRAINING);
|
2012-03-05 01:27:56 +01:00
|
|
|
else if (m_data == "arbitration")
|
|
|
|
m_params.setMode(GameParams::kARBITRATION);
|
2011-08-28 18:20:00 +02:00
|
|
|
else
|
|
|
|
throw GameException("Invalid game mode: " + m_data);
|
2009-11-29 17:01:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag == "Variant")
|
|
|
|
{
|
2011-08-27 19:21:26 +02:00
|
|
|
// The game should not be created yet
|
|
|
|
if (m_game != NULL)
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(_("The 'Variant' tag should be right after the 'Mode' one"));
|
2011-08-27 19:21:26 +02:00
|
|
|
|
2011-08-28 17:29:39 +02:00
|
|
|
if (m_data == "bingo")
|
2011-08-28 19:24:37 +02:00
|
|
|
m_params.addVariant(GameParams::kJOKER);
|
2011-08-28 17:29:39 +02:00
|
|
|
else if (m_data == "explosive")
|
2011-08-28 19:24:37 +02:00
|
|
|
m_params.addVariant(GameParams::kEXPLOSIVE);
|
2011-08-28 17:29:39 +02:00
|
|
|
else if (m_data == "7among8")
|
2011-08-28 19:24:37 +02:00
|
|
|
m_params.addVariant(GameParams::k7AMONG8);
|
2011-08-28 17:29:39 +02:00
|
|
|
else if (m_data != "")
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(FMT1(_("Invalid game variant: %1%"), m_data));
|
2011-08-27 19:21:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the game
|
|
|
|
if (m_game == NULL)
|
|
|
|
{
|
2011-08-28 19:16:59 +02:00
|
|
|
m_game = GameFactory::Instance()->createGame(m_params);
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
|
2011-08-28 18:20:00 +02:00
|
|
|
if (m_context == "Player")
|
2009-11-29 17:01:31 +01:00
|
|
|
{
|
|
|
|
if (tag == "Name")
|
|
|
|
m_attributes["name"] = m_data;
|
|
|
|
else if (tag == "Type")
|
|
|
|
m_attributes["type"] = m_data;
|
|
|
|
else if (tag == "Level")
|
|
|
|
m_attributes["level"] = m_data;
|
2012-10-22 17:35:29 +02:00
|
|
|
else if (tag == "TableNb")
|
|
|
|
m_attributes["tablenb"] = m_data;
|
2009-11-29 17:01:31 +01:00
|
|
|
else if (tag == "Player")
|
|
|
|
{
|
|
|
|
if (m_players.find(m_attributes["id"]) != m_players.end())
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(FMT1(_("A player ID must be unique: %1%"), m_attributes["id"]));
|
2009-11-29 17:01:31 +01:00
|
|
|
// Create the player
|
|
|
|
Player *p;
|
|
|
|
if (m_attributes["type"] == "human")
|
|
|
|
p = new HumanPlayer();
|
|
|
|
else if (m_attributes["type"] == "computer")
|
|
|
|
{
|
|
|
|
int level = toInt(m_attributes["level"]);
|
|
|
|
p = new AIPercent(0.01 * level);
|
|
|
|
}
|
|
|
|
else
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(FMT1(_("Invalid player type: %1%"), m_attributes["type"]));
|
2009-11-29 17:01:31 +01:00
|
|
|
m_players[m_attributes["id"]] = p;
|
|
|
|
|
|
|
|
// Set the name
|
|
|
|
p->setName(fromUtf8(m_attributes["name"]));
|
2012-10-22 17:35:29 +02:00
|
|
|
// Ste the table number
|
|
|
|
if (m_attributes["tablenb"] != "")
|
|
|
|
p->setTableNb(toInt(m_attributes["tablenb"]));
|
2009-11-29 17:01:31 +01:00
|
|
|
|
|
|
|
m_game->addPlayer(p);
|
|
|
|
|
|
|
|
m_context = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-25 23:16:42 +01:00
|
|
|
else if (tag == "GameRack")
|
|
|
|
{
|
|
|
|
// Build a rack for the correct player
|
|
|
|
const wstring &rackStr = m_dic.convertFromInput(fromUtf8(m_data));
|
|
|
|
PlayedRack pldrack;
|
|
|
|
if (!m_dic.validateLetters(rackStr, L"-+"))
|
|
|
|
{
|
2012-10-06 18:18:21 +02:00
|
|
|
throw LoadGameException(FMT1(_("Rack invalid for the current dictionary: %1%"), m_data));
|
2012-02-25 23:16:42 +01:00
|
|
|
}
|
|
|
|
pldrack.setManual(rackStr);
|
|
|
|
LOG_DEBUG("loaded rack: " << lfw(pldrack.toString()));
|
|
|
|
|
|
|
|
GameRackCmd *cmd = new GameRackCmd(*m_game, pldrack);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
LOG_DEBUG("rack: " << lfw(pldrack.toString()));
|
|
|
|
}
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
else if (tag == "PlayerRack")
|
|
|
|
{
|
|
|
|
// Build a rack for the correct player
|
2010-03-06 17:53:37 +01:00
|
|
|
const wstring &rackStr = m_dic.convertFromInput(fromUtf8(m_data));
|
2009-11-29 17:01:31 +01:00
|
|
|
PlayedRack pldrack;
|
2010-03-06 17:53:37 +01:00
|
|
|
if (!m_dic.validateLetters(rackStr, L"-+"))
|
2009-11-29 17:01:31 +01:00
|
|
|
{
|
2012-10-06 20:34:49 +02:00
|
|
|
throw LoadGameException(FMT1(_("Rack invalid for the current dictionary: %1%"), m_data));
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
2010-03-06 17:53:37 +01:00
|
|
|
pldrack.setManual(rackStr);
|
2011-07-30 21:48:05 +02:00
|
|
|
LOG_DEBUG("loaded rack: " << lfw(pldrack.toString()));
|
2009-11-29 17:01:31 +01:00
|
|
|
|
2012-10-24 00:19:20 +02:00
|
|
|
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
2009-11-29 17:01:31 +01:00
|
|
|
PlayerRackCmd *cmd = new PlayerRackCmd(p, pldrack);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
2011-07-30 21:48:05 +02:00
|
|
|
LOG_DEBUG("rack: " << lfw(pldrack.toString()));
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 17:43:04 +01:00
|
|
|
else if (tag == "MasterMove")
|
|
|
|
{
|
|
|
|
const Move &move = buildMove(*m_game, m_attributes, false);
|
|
|
|
Duplicate *duplicateGame = dynamic_cast<Duplicate*>(m_game);
|
|
|
|
if (duplicateGame == NULL)
|
|
|
|
{
|
2012-10-06 20:34:49 +02:00
|
|
|
throw LoadGameException(_("The 'MasterMove' tag should only be present for duplicate games"));
|
2012-01-17 17:43:04 +01:00
|
|
|
}
|
|
|
|
MasterMoveCmd *cmd = new MasterMoveCmd(*duplicateGame, move);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
}
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
else if (tag == "PlayerMove")
|
|
|
|
{
|
|
|
|
const Move &move = buildMove(*m_game, m_attributes, /*XXX:true*/false);
|
2012-10-24 00:19:20 +02:00
|
|
|
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
2009-11-29 17:01:31 +01:00
|
|
|
PlayerMoveCmd *cmd = new PlayerMoveCmd(p, move);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (tag == "GameMove")
|
|
|
|
{
|
|
|
|
const Move &move = buildMove(*m_game, m_attributes, false);
|
2012-10-24 00:19:20 +02:00
|
|
|
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
2009-11-29 17:01:31 +01:00
|
|
|
GameMoveCmd *cmd = new GameMoveCmd(*m_game, move, p.getId());
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
}
|
|
|
|
|
2012-05-20 21:31:45 +02:00
|
|
|
else if (tag == "Warning")
|
|
|
|
{
|
2012-10-24 00:19:20 +02:00
|
|
|
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
2012-05-20 21:31:45 +02:00
|
|
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::WARNING);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (tag == "Penalty")
|
|
|
|
{
|
2012-10-24 00:19:20 +02:00
|
|
|
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
2012-05-20 21:31:45 +02:00
|
|
|
int points = toInt(m_attributes["points"]);
|
|
|
|
LOG_ERROR("points=" << points);
|
|
|
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::PENALTY, points);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (tag == "Solo")
|
|
|
|
{
|
2012-10-24 00:19:20 +02:00
|
|
|
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
2012-05-20 21:31:45 +02:00
|
|
|
int points = toInt(m_attributes["points"]);
|
|
|
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::SOLO, points);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
}
|
|
|
|
|
2012-10-05 17:51:01 +02:00
|
|
|
else if (tag == "EndGame")
|
|
|
|
{
|
2012-10-24 00:19:20 +02:00
|
|
|
Player &p = getPlayer(m_players, m_attributes["playerId"], tag);
|
2012-10-05 17:51:01 +02:00
|
|
|
int points = toInt(m_attributes["points"]);
|
|
|
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::END_GAME, points);
|
|
|
|
m_game->accessNavigation().addAndExecute(cmd);
|
|
|
|
}
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlReader::characters(const string& ch)
|
|
|
|
{
|
|
|
|
m_data += ch;
|
2012-05-20 21:31:45 +02:00
|
|
|
LOG_TRACE("Characters: " << ch);
|
2009-11-29 17:01:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlReader::warning(const Arabica::SAX::SAXParseException<string>& exception)
|
|
|
|
{
|
|
|
|
errorMessage = string("warning: ") + exception.what();
|
2011-01-30 00:47:20 +01:00
|
|
|
LOG_WARN(errorMessage);
|
2009-11-29 17:01:31 +01:00
|
|
|
//throw LoadGameException(string("warning: ") + exception.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlReader::error(const Arabica::SAX::SAXParseException<string>& exception)
|
|
|
|
{
|
|
|
|
errorMessage = string("error: ") + exception.what();
|
2011-01-30 00:47:20 +01:00
|
|
|
LOG_ERROR(errorMessage);
|
2009-11-29 17:01:31 +01:00
|
|
|
//throw LoadGameException(string("error: ") + exception.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlReader::fatalError(const Arabica::SAX::SAXParseException<string>& exception)
|
|
|
|
{
|
|
|
|
errorMessage = string("fatal error: ") + exception.what();
|
2011-01-30 00:47:20 +01:00
|
|
|
LOG_FATAL(errorMessage);
|
2009-11-29 17:01:31 +01:00
|
|
|
//throw LoadGameException(string("fatal error: ") + exception.what());
|
|
|
|
}
|
|
|
|
|