void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward { switch (rewardType) { case EXPERIENCE: { TExpType expVal = h->calculateXp(rVal); cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, expVal, false); break; } case MANA_POINTS: { cb->setManaPoints(h->id, h->mana+rVal); break; } case MORALE_BONUS: case LUCK_BONUS: { Bonus hb(Bonus::ONE_WEEK, (rewardType == 3 ? Bonus::MORALE : Bonus::LUCK), Bonus::OBJECT, rVal, h->id.getNum(), "", -1); GiveBonus gb; gb.id = h->id.getNum(); gb.bonus = hb; cb->giveHeroBonus(&gb); } break; case RESOURCES: cb->giveResource(h->getOwner(), static_cast<Res::ERes>(rID), rVal); break; case PRIMARY_SKILL: cb->changePrimSkill(h, static_cast<PrimarySkill::PrimarySkill>(rID), rVal, false); break; case SECONDARY_SKILL: cb->changeSecSkill(h, SecondarySkill(rID), rVal, false); break; case ARTIFACT: cb->giveHeroNewArtifact(h, VLC->arth->artifacts[rID],ArtifactPosition::FIRST_AVAILABLE); break; case SPELL: { std::set<SpellID> spell; spell.insert (SpellID(rID)); cb->changeSpells(h, true, spell); } break; case CREATURE: { CCreatureSet creatures; creatures.setCreature(SlotID(0), CreatureID(rID), rVal); cb->giveCreatures(this, h, creatures, false); } break; default: break; } }
void CHeroHandler::loadHeroArmy(CHero * hero, const JsonNode & node) { assert(node["army"].Vector().size() <= 3); // anything bigger is useless - army initialization uses up to 3 slots hero->initialArmy.resize(node["army"].Vector().size()); for (size_t i=0; i< hero->initialArmy.size(); i++) { const JsonNode & source = node["army"].Vector()[i]; hero->initialArmy[i].minAmount = source["min"].Float(); hero->initialArmy[i].maxAmount = source["max"].Float(); assert(hero->initialArmy[i].minAmount <= hero->initialArmy[i].maxAmount); VLC->modh->identifiers.requestIdentifier("creature", source["creature"], [=](si32 creature) { hero->initialArmy[i].creature = CreatureID(creature); }); } }
void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source) { town.clientInfo.siegePrefix = source["imagePrefix"].String(); VLC->modh->identifiers.requestIdentifier("creature", source["shooter"], [&town](si32 creature) { town.clientInfo.siegeShooter = CreatureID(creature); }); town.clientInfo.siegeShooterCropHeight = source["shooterHeight"].Float(); auto & pos = town.clientInfo.siegePositions; pos.resize(21); pos[8] = JsonToPoint(source["towers"]["top"]["tower"]); pos[17] = JsonToPoint(source["towers"]["top"]["battlement"]); pos[20] = JsonToPoint(source["towers"]["top"]["creature"]); pos[2] = JsonToPoint(source["towers"]["keep"]["tower"]); pos[15] = JsonToPoint(source["towers"]["keep"]["battlement"]); pos[18] = JsonToPoint(source["towers"]["keep"]["creature"]); pos[3] = JsonToPoint(source["towers"]["bottom"]["tower"]); pos[16] = JsonToPoint(source["towers"]["bottom"]["battlement"]); pos[19] = JsonToPoint(source["towers"]["bottom"]["creature"]); pos[9] = JsonToPoint(source["gate"]["gate"]); pos[10] = JsonToPoint(source["gate"]["arch"]); pos[7] = JsonToPoint(source["walls"]["upper"]); pos[6] = JsonToPoint(source["walls"]["upperMid"]); pos[5] = JsonToPoint(source["walls"]["bottomMid"]); pos[4] = JsonToPoint(source["walls"]["bottom"]); pos[13] = JsonToPoint(source["moat"]["moat"]); pos[14] = JsonToPoint(source["moat"]["bank"]); pos[11] = JsonToPoint(source["static"]["bottom"]); pos[12] = JsonToPoint(source["static"]["top"]); pos[1] = JsonToPoint(source["static"]["background"]); }
CFaction * CTownHandler::loadFromJson(const JsonNode &source) { auto faction = new CFaction(); faction->name = source["name"].String(); VLC->modh->identifiers.requestIdentifier ("creature", source["commander"], [=](si32 commanderID) { faction->commander = CreatureID(commanderID); }); faction->creatureBg120 = source["creatureBackground"]["120px"].String(); faction->creatureBg130 = source["creatureBackground"]["130px"].String(); faction->nativeTerrain = ETerrainType(vstd::find_pos(GameConstants::TERRAIN_NAMES, source["nativeTerrain"].String())); int alignment = vstd::find_pos(EAlignment::names, source["alignment"].String()); if (alignment == -1) faction->alignment = EAlignment::NEUTRAL; else faction->alignment = static_cast<EAlignment::EAlignment>(alignment); if (!source["town"].isNull()) { faction->town = new CTown; faction->town->faction = faction; loadTown(*faction->town, source["town"]); } else faction->town = nullptr; if (!source["puzzleMap"].isNull()) loadPuzzle(*faction, source["puzzleMap"]); return faction; }
void CTownHandler::loadTown(CTown &town, const JsonNode & source) { auto resIter = boost::find(GameConstants::RESOURCE_NAMES, source["primaryResource"].String()); if (resIter == std::end(GameConstants::RESOURCE_NAMES)) town.primaryRes = Res::WOOD_AND_ORE; //Wood + Ore else town.primaryRes = resIter - std::begin(GameConstants::RESOURCE_NAMES); VLC->modh->identifiers.requestIdentifier("creature", source["warMachine"], [&town](si32 creature) { town.warMachine = CArtHandler::creatureToMachineID(CreatureID(creature)); }); town.moatDamage = source["moatDamage"].Float(); town.mageLevel = source["mageGuild"].Float(); town.names = source["names"].convertTo<std::vector<std::string> >(); // Horde building creature level for(const JsonNode &node : source["horde"].Vector()) { town.hordeLvl[town.hordeLvl.size()] = node.Float(); } const JsonVector & creatures = source["creatures"].Vector(); town.creatures.resize(creatures.size()); for (size_t i=0; i< creatures.size(); i++) { const JsonVector & level = creatures[i].Vector(); town.creatures[i].resize(level.size()); for (size_t j=0; j<level.size(); j++) { VLC->modh->identifiers.requestIdentifier("creature", level[j], [=, &town](si32 creature) { town.creatures[i][j] = CreatureID(creature); }); } } /// set chance of specific hero class to appear in this town for(auto &node : source["tavern"].Struct()) { int chance = node.second.Float(); VLC->modh->identifiers.requestIdentifier(node.second.meta, "heroClass",node.first, [=, &town](si32 classID) { VLC->heroh->classes.heroClasses[classID]->selectionProbability[town.faction->index] = chance; }); } for(auto &node : source["guildSpells"].Struct()) { int chance = node.second.Float(); VLC->modh->identifiers.requestIdentifier(node.second.meta, "spell", node.first, [=, &town](si32 spellID) { SpellID(spellID).toSpell()->probabilities[town.faction->index] = chance; }); } for (const JsonNode &d : source["adventureMap"]["dwellings"].Vector()) { town.dwellings.push_back (d["graphics"].String()); town.dwellingNames.push_back (d["name"].String()); } loadBuildings(town, source["buildings"]); loadClientData(town,source); }