void CTownHandler::loadStructure(CTown &town, const JsonNode & source) { auto ret = new CStructure; if (source["id"].isNull()) { ret->building = nullptr; ret->buildable = nullptr; } else { ret->building = town.buildings[BuildingID(source["id"].Float())]; if (source["builds"].isNull()) ret->buildable = ret->building; else ret->buildable = town.buildings[BuildingID(source["builds"].Float())]; } ret->pos.x = source["x"].Float(); ret->pos.y = source["y"].Float(); ret->pos.z = source["z"].Float(); ret->hiddenUpgrade = source["hidden"].Bool(); ret->defName = source["animation"].String(); ret->borderName = source["border"].String(); ret->areaName = source["area"].String(); town.clientInfo.structures.push_back(ret); }
void CTownHandler::loadBuilding(CTown &town, const JsonNode & source) { auto ret = new CBuilding; static const std::string modes [] = {"normal", "auto", "special", "grail"}; ret->mode = static_cast<CBuilding::EBuildMode>(boost::find(modes, source["mode"].String()) - modes); ret->town = &town; ret->bid = BuildingID(source["id"].Float()); ret->name = source["name"].String(); ret->description = source["description"].String(); ret->resources = TResources(source["cost"]); for(const JsonNode &building : source["requires"].Vector()) ret->requirements.insert(BuildingID(building.Float())); if (!source["upgrades"].isNull()) { ret->requirements.insert(BuildingID(source["upgrades"].Float())); ret->upgrade = BuildingID(source["upgrades"].Float()); } else ret->upgrade = BuildingID::NONE; town.buildings[ret->bid] = ret; }
std::string CComponent::getDescription() { switch(compType) { case primskill: return (subtype < 4)? CGI->generaltexth->arraytxt[2+subtype] //Primary skill : CGI->generaltexth->allTexts[149]; //mana case secskill: return CGI->generaltexth->skillInfoTexts[subtype][val-1]; case resource: return CGI->generaltexth->allTexts[242]; case creature: return ""; case artifact: { std::unique_ptr<CArtifactInstance> art; if (subtype != ArtifactID::SPELL_SCROLL) { art.reset(CArtifactInstance::createNewArtifactInstance(subtype)); } else { art.reset(CArtifactInstance::createScroll(static_cast<SpellID>(val))); } return art->getEffectiveDescription(); } case experience: return CGI->generaltexth->allTexts[241]; case spell: return CGI->spellh->objects[subtype]->getLevelInfo(val).description; case morale: return CGI->generaltexth->heroscrn[ 4 - (val>0) + (val<0)]; case luck: return CGI->generaltexth->heroscrn[ 7 - (val>0) + (val<0)]; case building: return CGI->townh->factions[subtype]->town->buildings[BuildingID(val)]->Description(); case hero: return ""; case flag: return ""; } assert(0); return ""; }
void CTownInstanceConstructor::afterLoadFinalization() { assert(faction); for (auto entry : filtersJson.Struct()) { filters[entry.first] = LogicalExpression<BuildingID>(entry.second, [this](const JsonNode & node) { return BuildingID(VLC->modh->identifiers.getIdentifier("building." + faction->identifier, node.Vector()[0]).get()); }); } }
void CTownHandler::loadTownHall(CTown &town, const JsonNode & source) { for(const JsonNode &row : source.Vector()) { std::vector< std::vector<BuildingID> > hallRow; for(const JsonNode &box : row.Vector()) { std::vector<BuildingID> hallBox; for(const JsonNode &value : box.Vector()) { hallBox.push_back(BuildingID(value.Float())); } hallRow.push_back(hallBox); } town.clientInfo.hallSlots.push_back(hallRow); } }
std::string CComponent::getSubtitleInternal() { //FIXME: some of these are horrible (e.g creature) switch(compType) { case primskill: return boost::str(boost::format("%+d %s") % val % (subtype < 4 ? CGI->generaltexth->primarySkillNames[subtype] : CGI->generaltexth->allTexts[387])); case secskill: return CGI->generaltexth->levels[val-1] + "\n" + CGI->generaltexth->skillName[subtype]; case resource: return boost::lexical_cast<std::string>(val); case creature: return (val? boost::lexical_cast<std::string>(val) + " " : "") + CGI->creh->creatures[subtype]->*(val != 1 ? &CCreature::namePl : &CCreature::nameSing); case artifact: return CGI->arth->artifacts[subtype]->Name(); case experience: { if(subtype == 1) //+1 level - tree of knowledge { std::string level = CGI->generaltexth->allTexts[442]; boost::replace_first(level, "1", boost::lexical_cast<std::string>(val)); return level; } else { return boost::lexical_cast<std::string>(val); //amount of experience OR level required for seer hut; } } case spell: return CGI->spellh->objects[subtype]->name; case morale: return ""; case luck: return ""; case building: { auto building = CGI->townh->factions[subtype]->town->buildings[BuildingID(val)]; if(!building) { logGlobal->errorStream() << boost::format("Town of faction %s has no building #%d") % CGI->townh->factions[subtype]->town->faction->name % val; return (boost::format("Missing building #%d") % val).str(); } return building->Name(); } case hero: return ""; case flag: return CGI->generaltexth->capColors[subtype]; } assert(0); return ""; }