1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Reverting r2327

http://forum.vcmi.eu/viewtopic.php?t=410
This commit is contained in:
Michał W. Urbańczyk 2011-08-30 06:19:07 +00:00
parent 33719696d8
commit 835bd1fbeb
7 changed files with 501 additions and 487 deletions

View File

@ -121,10 +121,12 @@ static void setButton(ButtonInfo &button, const JsonNode &g)
button.playerColoured = g["playerColoured"].Float(); button.playerColoured = g["playerColoured"].Float();
button.defName = g["graphic"].String(); button.defName = g["graphic"].String();
const JsonVector &defs_vec = g["additionalDefs"].Vector(); if (!g["additionalDefs"].isNull()) {
const JsonVector &defs_vec = g["additionalDefs"].Vector();
BOOST_FOREACH(const JsonNode &def, defs_vec) { BOOST_FOREACH(const JsonNode &def, defs_vec) {
button.additionalDefs.push_back(def.String()); button.additionalDefs.push_back(def.String());
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -479,6 +479,7 @@ void CCreatureHandler::loadCreatures()
for (JsonVector::const_iterator it = creatures_vec.begin(); it!=creatures_vec.end(); ++it) { for (JsonVector::const_iterator it = creatures_vec.begin(); it!=creatures_vec.end(); ++it) {
const JsonNode &creature = *it; const JsonNode &creature = *it;
int creatureID = creature["id"].Float(); int creatureID = creature["id"].Float();
const JsonNode *value;
/* A creature can have several names. */ /* A creature can have several names. */
const JsonVector &names_vec = creature["name"].Vector(); const JsonVector &names_vec = creature["name"].Vector();
@ -494,11 +495,20 @@ void CCreatureHandler::loadCreatures()
c->faction = creature["faction"].Float(); c->faction = creature["faction"].Float();
c->animDefName = creature["defname"].String(); c->animDefName = creature["defname"].String();
c->upgrades.insert(creature["upgrade"].Float()); value = &creature["upgrade"];
idToProjectile[creatureID] = creature["projectile_defname"].String(); if (!value->isNull())
idToProjectileSpin[creatureID] = creature["projectile_spin"].Bool(); c->upgrades.insert(value->Float());
if (creature["turret_shooter"].Bool(false)) value = &creature["projectile_defname"];
if (!value->isNull()) {
idToProjectile[creatureID] = value->String();
value = &creature["projectile_spin"];
idToProjectileSpin[creatureID] = value->Bool();
}
value = &creature["turret_shooter"];
if (!value->isNull() && value->Bool())
factionToTurretCreature[c->faction] = creatureID; factionToTurretCreature[c->faction] = creatureID;
} }

View File

@ -290,24 +290,29 @@ void CHeroHandler::loadHeroes()
int hid = hero["id"].Float(); int hid = hero["id"].Float();
const JsonNode *value; const JsonNode *value;
//sex: 0=male, 1=female heroes[hid]->sex = hero["sex"].Float();
heroes[hid]->sex = !hero["female"].Bool(false);
BOOST_FOREACH(const JsonNode &set, hero["skill_set"].Vector()) { BOOST_FOREACH(const JsonNode &set, hero["skill_set"].Vector()) {
heroes[hid]->secSkillsInit.push_back(std::make_pair(set["skill"].Float(), set["level"].Float(1))); heroes[hid]->secSkillsInit.push_back(std::make_pair(set["skill"].Float(), set["level"].Float()));
} }
heroes[hid]->startingSpell = hero["spell"].Float(-1); value = &hero["spell"];
if (!value->isNull()) {
heroes[hid]->startingSpell = value->Float();
}
BOOST_FOREACH(const JsonNode &specialty, hero["specialties"].Vector()) { value = &hero["specialties"];
SSpecialtyInfo dummy; if (!value->isNull()) {
BOOST_FOREACH(const JsonNode &specialty, value->Vector()) {
SSpecialtyInfo dummy;
dummy.type = specialty["type"].Float(); dummy.type = specialty["type"].Float();
dummy.val = specialty["val"].Float(0); dummy.val = specialty["val"].Float();
dummy.subtype = specialty["subtype"].Float(0); dummy.subtype = specialty["subtype"].Float();
dummy.additionalinfo = specialty["info"].Float(0); dummy.additionalinfo = specialty["info"].Float();
heroes[hid]->spec.push_back(dummy); //put a copy of dummy heroes[hid]->spec.push_back(dummy); //put a copy of dummy
}
} }
} }

View File

@ -62,6 +62,7 @@ void CTownHandler::loadStructures()
// Read buildings coordinates for that city // Read buildings coordinates for that city
BOOST_FOREACH(const JsonNode &node, town_node["defnames"].Vector()) { BOOST_FOREACH(const JsonNode &node, town_node["defnames"].Vector()) {
Structure *vinya = new Structure; Structure *vinya = new Structure;
const JsonNode *value;
vinya->group = -1; vinya->group = -1;
vinya->townID = townID; vinya->townID = townID;
@ -72,8 +73,13 @@ void CTownHandler::loadStructures()
vinya->pos.y = node["y"].Float(); vinya->pos.y = node["y"].Float();
vinya->pos.z = 0; vinya->pos.z = 0;
vinya->borderName = node["border"].String(); value = &node["border"];
vinya->areaName = node["area"].String(); if (!value->isNull())
vinya->borderName = value->String();
value = &node["area"];
if (!value->isNull())
vinya->areaName = value->String();
town[vinya->ID] = vinya; town[vinya->ID] = vinya;
} }

View File

@ -125,42 +125,32 @@ JsonMap & JsonNode::Struct()
} }
const bool & JsonNode::Bool(const bool &value) const const bool & JsonNode::Bool() const
{ {
if (isNull())
return value;
assert(type == DATA_BOOL); assert(type == DATA_BOOL);
return data.Bool; return data.Bool;
} }
const float & JsonNode::Float(const float &value) const const float & JsonNode::Float() const
{ {
if (isNull())
return value;
assert(type == DATA_FLOAT); assert(type == DATA_FLOAT);
return data.Float; return data.Float;
} }
const std::string & JsonNode::String(const std::string &value) const const std::string & JsonNode::String() const
{ {
if (isNull())
return value;
assert(type == DATA_STRING); assert(type == DATA_STRING);
return *data.String; return *data.String;
} }
const JsonVector & JsonNode::Vector(const JsonVector &value) const const JsonVector & JsonNode::Vector() const
{ {
if (isNull())
return value;
assert(type == DATA_VECTOR); assert(type == DATA_VECTOR);
return *data.Vector; return *data.Vector;
} }
const JsonMap & JsonNode::Struct(const JsonMap &value) const const JsonMap & JsonNode::Struct() const
{ {
if (isNull())
return value;
assert(type == DATA_STRUCT); assert(type == DATA_STRUCT);
return *data.Struct; return *data.Struct;
} }

View File

@ -60,18 +60,19 @@ public:
//non-const accessors, node will change type on type mismatch //non-const accessors, node will change type on type mismatch
bool & Bool(); bool & Bool();
int & Int();
float & Float(); float & Float();
std::string & String(); std::string & String();
JsonVector & Vector(); JsonVector & Vector();
JsonMap & Struct(); JsonMap & Struct();
//const accessors, will cause assertion failure on type mismatch //const accessors, will cause assertion failure on type mismatch
//if node is null then default value will be returned instead const bool & Bool() const;
const bool & Bool(const bool &value = false) const; const int & Int() const;
const float & Float(const float &value = 0) const; const float & Float() const;
const std::string & String(const std::string &value = "") const; const std::string & String() const;
const JsonVector & Vector(const JsonVector &value = JsonVector()) const; const JsonVector & Vector() const;
const JsonMap & Struct(const JsonMap &value = JsonMap()) const; const JsonMap & Struct() const;
//formatted output of this node in JSON format //formatted output of this node in JSON format
void write(std::ostream &out, std::string prefix="") const; void write(std::ostream &out, std::string prefix="") const;