mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Implemented basic version of configurable Witch Hut
This commit is contained in:
@ -842,98 +842,6 @@ void CGArtifact::serializeJsonOptions(JsonSerializeFormat& handler)
|
||||
}
|
||||
}
|
||||
|
||||
void CGWitchHut::initObj(CRandomGenerator & rand)
|
||||
{
|
||||
if (allowedAbilities.empty()) //this can happen for RMG and RoE maps.
|
||||
{
|
||||
auto defaultAllowed = VLC->skillh->getDefaultAllowed();
|
||||
|
||||
// Necromancy and Leadership can't be learned by default
|
||||
defaultAllowed[SecondarySkill::NECROMANCY] = false;
|
||||
defaultAllowed[SecondarySkill::LEADERSHIP] = false;
|
||||
|
||||
for(int i = 0; i < defaultAllowed.size(); i++)
|
||||
if (defaultAllowed[i] && cb->isAllowed(2, i))
|
||||
allowedAbilities.insert(SecondarySkill(i));
|
||||
}
|
||||
ability = *RandomGeneratorUtil::nextItem(allowedAbilities, rand);
|
||||
}
|
||||
|
||||
void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.type = EInfoWindowMode::AUTO;
|
||||
iw.player = h->getOwner();
|
||||
if(!wasVisited(h->tempOwner))
|
||||
cb->setObjProperty(id, CGWitchHut::OBJPROP_VISITED, h->tempOwner.getNum());
|
||||
ui32 txt_id;
|
||||
if(h->getSecSkillLevel(SecondarySkill(ability))) //you already know this skill
|
||||
{
|
||||
txt_id =172;
|
||||
}
|
||||
else if(!h->canLearnSkill()) //already all skills slots used
|
||||
{
|
||||
txt_id = 173;
|
||||
}
|
||||
else //give sec skill
|
||||
{
|
||||
iw.components.emplace_back(Component::EComponentType::SEC_SKILL, ability, 1, 0);
|
||||
txt_id = 171;
|
||||
cb->changeSecSkill(h, SecondarySkill(ability), 1, true);
|
||||
}
|
||||
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT,txt_id);
|
||||
iw.text.replaceLocalString(EMetaText::SEC_SKILL_NAME, ability);
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
|
||||
std::string CGWitchHut::getHoverText(PlayerColor player) const
|
||||
{
|
||||
std::string hoverName = getObjectName();
|
||||
if(wasVisited(player))
|
||||
{
|
||||
hoverName += "\n" + VLC->generaltexth->allTexts[356]; // + (learn %s)
|
||||
boost::algorithm::replace_first(hoverName, "%s", VLC->skillh->getByIndex(ability)->getNameTranslated());
|
||||
}
|
||||
return hoverName;
|
||||
}
|
||||
|
||||
std::string CGWitchHut::getHoverText(const CGHeroInstance * hero) const
|
||||
{
|
||||
std::string hoverName = getHoverText(hero->tempOwner);
|
||||
if(wasVisited(hero->tempOwner) && hero->getSecSkillLevel(SecondarySkill(ability))) //hero knows that ability
|
||||
hoverName += "\n\n" + VLC->generaltexth->allTexts[357]; // (Already learned)
|
||||
return hoverName;
|
||||
}
|
||||
|
||||
void CGWitchHut::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
{
|
||||
//TODO: unify allowed abilities with others - make them std::vector<bool>
|
||||
|
||||
std::vector<bool> temp;
|
||||
size_t skillCount = VLC->skillh->size();
|
||||
temp.resize(skillCount, false);
|
||||
|
||||
auto standard = VLC->skillh->getDefaultAllowed(); //todo: for WitchHut default is all except Leadership and Necromancy
|
||||
|
||||
if(handler.saving)
|
||||
{
|
||||
for(SecondarySkill i(0); i < SecondarySkill(skillCount); ++i)
|
||||
if(vstd::contains(allowedAbilities, i))
|
||||
temp[i] = true;
|
||||
}
|
||||
|
||||
handler.serializeLIC("allowedSkills", &CSkillHandler::decodeSkill, &CSkillHandler::encodeSkill, standard, temp);
|
||||
|
||||
if(!handler.saving)
|
||||
{
|
||||
allowedAbilities.clear();
|
||||
for(si32 i = 0; i < skillCount; ++i)
|
||||
if(temp[i])
|
||||
allowedAbilities.insert(SecondarySkill(i));
|
||||
}
|
||||
}
|
||||
|
||||
void CGObservatory::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
InfoWindow iw;
|
||||
|
Reference in New Issue
Block a user