void CHeroHandler::loadHeroSkills(CHero * hero, const JsonNode & node) { for(const JsonNode &set : node["skills"].Vector()) { int skillLevel = boost::range::find(NSecondarySkill::levels, set["level"].String()) - std::begin(NSecondarySkill::levels); if (skillLevel < SecSkillLevel::LEVELS_SIZE) { size_t currentIndex = hero->secSkillsInit.size(); hero->secSkillsInit.push_back(std::make_pair(SecondarySkill(-1), skillLevel)); VLC->modh->identifiers.requestIdentifier("skill", set["skill"], [=](si32 id) { hero->secSkillsInit[currentIndex].first = SecondarySkill(id); }); } else { logGlobal->errorStream() << "Unknown skill level: " <<set["level"].String(); } } // spellbook is considered present if hero have "spellbook" entry even when this is an empty set (0 spells) hero->haveSpellBook = !node["spellbook"].isNull(); for(const JsonNode & spell : node["spellbook"].Vector()) { VLC->modh->identifiers.requestIdentifier("spell", spell, [=](si32 spellID) { hero->spells.insert(SpellID(spellID)); }); } }
CArtifactInstance * CArtifactInstance::createArtifact(CMap * map, int aid, int spellID) { CArtifactInstance * a = nullptr; if(aid >= 0) { if(spellID < 0) { a = CArtifactInstance::createNewArtifactInstance(aid); } else { a = CArtifactInstance::createScroll(SpellID(spellID).toSpell()); } } else //FIXME: create combined artifact instance for random combined artifacts, just in case { a = new CArtifactInstance(); //random, empty } map->addNewArtifactInstance(a); //TODO make it nicer if(a->artType && (!!a->artType->constituents)) { CCombinedArtifactInstance * comb = dynamic_cast<CCombinedArtifactInstance *>(a); for(CCombinedArtifactInstance::ConstituentInfo & ci : comb->constituentsInfo) { map->addNewArtifactInstance(ci.art); } } return a; }
SpellID CArtifactInstance::getGivenSpellID() const { const auto b = getBonusLocalFirst(Selector::type(Bonus::SPELL)); if(!b) { logGlobal->warnStream() << "Warning: " << nodeName() << " doesn't bear any spell!"; return SpellID::NONE; } return SpellID(b->subtype); }
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 CPrivilagedInfoCallback::getAllowedSpells(std::vector<SpellID> &out, ui16 level) { for (ui32 i = 0; i < gs->map->allowedSpell.size(); i++) //spellh size appears to be greater (?) { const CSpell *spell = SpellID(i).toSpell(); if (isAllowed (0, spell->id) && spell->level == level) { out.push_back(spell->id); } } }
std::vector<BattleHex> SpellCreatedObstacle::getAffectedTiles() const { switch(obstacleType) { case QUICKSAND: case LAND_MINE: case FIRE_WALL: return std::vector<BattleHex>(1, pos); case FORCE_FIELD: return SpellID(SpellID::FORCE_FIELD).toSpell()->rangeInHexes(pos, spellLevel, casterSide); //TODO Fire Wall default: assert(0); return std::vector<BattleHex>(); } }
std::string CBonusTypeHandler::bonusToGraphics(const Bonus* bonus) const { std::string fileName; bool fullPath = false; switch (bonus->type) { case Bonus::SECONDARY_SKILL_PREMY: if (bonus->subtype == SecondarySkill::RESISTANCE) { fileName = "E_DWARF.bmp"; } break; case Bonus::SPELL_IMMUNITY: { fullPath = true; const CSpell * sp = SpellID(bonus->subtype).toSpell(); fileName = sp->getIconImmune(); break; } case Bonus::FIRE_IMMUNITY: switch (bonus->subtype) { case 0: fileName = "E_SPFIRE.bmp"; break; //all case 1: fileName = "E_SPFIRE1.bmp"; break; //not positive case 2: fileName = "E_FIRE.bmp"; break; //direct damage } break; case Bonus::WATER_IMMUNITY: switch (bonus->subtype) { case 0: fileName = "E_SPWATER.bmp"; break; //all case 1: fileName = "E_SPWATER1.bmp"; break; //not positive case 2: fileName = "E_SPCOLD.bmp"; break; //direct damage } break; case Bonus::AIR_IMMUNITY: switch (bonus->subtype) { case 0: fileName = "E_SPAIR.bmp"; break; //all case 1: fileName = "E_SPAIR1.bmp"; break; //not positive case 2: fileName = "E_LIGHT.bmp"; break;//direct damage } break; case Bonus::EARTH_IMMUNITY: switch (bonus->subtype) { case 0: fileName = "E_SPEATH.bmp"; break; //all case 1: case 2: //no specific icon for direct damage immunity fileName = "E_SPEATH1.bmp"; break; //not positive } break; case Bonus::LEVEL_SPELL_IMMUNITY: { if (vstd::iswithin(bonus->val, 1 , 5)) { fileName = "E_SPLVL" + boost::lexical_cast<std::string>(bonus->val) + ".bmp"; } break; } default: { const CBonusType& bt = bonusTypes[bonus->type]; fileName = bt.icon; fullPath = true; break; } } if(!fileName.empty() && !fullPath) fileName = "zvs/Lib1.res/" + fileName; return fileName; }
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); }