1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-29 00:41:38 +02:00

Zmiany do Programming challenge.

This commit is contained in:
Michał W. Urbańczyk
2011-09-27 21:54:40 +00:00
parent 5d4cfc0d0f
commit bdd66b6537
21 changed files with 588 additions and 82 deletions

View File

@ -31,6 +31,7 @@
#include "CMapInfo.h"
#include "BattleState.h"
#include "../lib/JsonNode.h"
#include <boost/algorithm/string/predicate.hpp>
boost::rand48 ran;
class CGObjectInstance;
@ -939,9 +940,18 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
DuelParameters dp;
try
{
CLoadFile lf(scenarioOps->mapname);
lf >> dp;
success = true;
if(boost::algorithm::ends_with(scenarioOps->mapname, ".json"))
{
tlog0 << "Loading duel settings from JSON file: " << scenarioOps->mapname << std::endl;
dp = DuelParameters::fromJSON(scenarioOps->mapname);
tlog0 << "JSON file has been succesfully read!\n";
}
else
{
CLoadFile lf(scenarioOps->mapname);
lf >> dp;
success = true;
}
}
catch(...)
{}
@ -2694,6 +2704,28 @@ DuelParameters::DuelParameters()
bfieldType = 15;
}
DuelParameters DuelParameters::fromJSON(const std::string &fname)
{
DuelParameters ret;
const JsonNode duelData(fname);
ret.terType = duelData["terType"].Float();
ret.bfieldType = duelData["bfieldType"].Float();
BOOST_FOREACH(const JsonNode &n, duelData["sides"].Vector())
{
SideSettings &ss = ret.sides[(int)n["side"].Float()];
int i = 0;
BOOST_FOREACH(const JsonNode &stackNode, n["army"].Vector())
{
ss.stacks[i].type = stackNode.Vector()[0].Float();
ss.stacks[i].count = stackNode.Vector()[1].Float();
i++;
}
}
return ret;
}
TeamState::TeamState()
{
setNodeType(TEAM);