1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Fix 2405 quest timeout mechanics

This commit is contained in:
Vadim Markovtsev 2016-01-29 09:28:37 +03:00
parent b7fbbfdebe
commit 30d64e3e3c

View File

@ -45,20 +45,20 @@ static std::string & visitedTxt(const bool visited)
return VLC->generaltexth->allTexts[id]; return VLC->generaltexth->allTexts[id];
} }
bool CQuest::checkQuest (const CGHeroInstance * h) const bool CQuest::checkQuest(const CGHeroInstance * h) const
{ {
switch (missionType) switch (missionType)
{ {
case MISSION_NONE: case MISSION_NONE:
return true; return true;
case MISSION_LEVEL: case MISSION_LEVEL:
if (m13489val <= h->level) if(m13489val <= h->level)
return true; return true;
return false; return false;
case MISSION_PRIMARY_STAT: case MISSION_PRIMARY_STAT:
for (int i = 0; i < GameConstants::PRIMARY_SKILLS; ++i) for(int i = 0; i < GameConstants::PRIMARY_SKILLS; ++i)
{ {
if (h->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(i)) < m2stats[i]) if(h->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(i)) < m2stats[i])
return false; return false;
} }
return true; return true;
@ -68,9 +68,9 @@ bool CQuest::checkQuest (const CGHeroInstance * h) const
return true; return true;
return false; return false;
case MISSION_ART: case MISSION_ART:
for (auto & elem : m5arts) for(auto & elem : m5arts)
{ {
if (h->hasArt(elem, false, true)) if(h->hasArt(elem, false, true))
continue; continue;
return false; //if the artifact was not found return false; //if the artifact was not found
} }
@ -80,31 +80,31 @@ bool CQuest::checkQuest (const CGHeroInstance * h) const
std::vector<CStackBasicDescriptor>::const_iterator cre; std::vector<CStackBasicDescriptor>::const_iterator cre;
TSlots::const_iterator it; TSlots::const_iterator it;
ui32 count; ui32 count;
for (cre = m6creatures.begin(); cre != m6creatures.end(); ++cre) for(cre = m6creatures.begin(); cre != m6creatures.end(); ++cre)
{ {
for (count = 0, it = h->Slots().begin(); it != h->Slots().end(); ++it) for(count = 0, it = h->Slots().begin(); it != h->Slots().end(); ++it)
{ {
if (it->second->type == cre->type) if(it->second->type == cre->type)
count += it->second->count; count += it->second->count;
} }
if (count < cre->count) //not enough creatures of this kind if(count < cre->count) //not enough creatures of this kind
return false; return false;
} }
} }
return true; return true;
case MISSION_RESOURCES: case MISSION_RESOURCES:
for (Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, +1)) //including Mithril ? for(Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, +1)) //including Mithril ?
{ //Quest has no direct access to callback { //Quest has no direct access to callback
if (h->cb->getResource (h->tempOwner, i) < m7resources[i]) if(h->cb->getResource (h->tempOwner, i) < m7resources[i])
return false; return false;
} }
return true; return true;
case MISSION_HERO: case MISSION_HERO:
if (m13489val == h->type->ID.getNum()) if(m13489val == h->type->ID.getNum())
return true; return true;
return false; return false;
case MISSION_PLAYER: case MISSION_PLAYER:
if (m13489val == h->getOwner().getNum()) if(m13489val == h->getOwner().getNum())
return true; return true;
return false; return false;
default: default:
@ -112,17 +112,17 @@ bool CQuest::checkQuest (const CGHeroInstance * h) const
} }
} }
void CQuest::getVisitText (MetaString &iwText, std::vector<Component> &components, bool isCustom, bool firstVisit, const CGHeroInstance * h) const void CQuest::getVisitText(MetaString &iwText, std::vector<Component> &components, bool isCustom, bool firstVisit, const CGHeroInstance * h) const
{ {
std::string text; std::string text;
bool failRequirements = (h ? !checkQuest(h) : true); bool failRequirements = (h ? !checkQuest(h) : true);
if (firstVisit) if(firstVisit)
{ {
isCustom = isCustomFirst; isCustom = isCustomFirst;
iwText << (text = firstVisitText); iwText << (text = firstVisitText);
} }
else if (failRequirements) else if(failRequirements)
{ {
isCustom = isCustomNext; isCustom = isCustomNext;
iwText << (text = nextVisitText); iwText << (text = nextVisitText);
@ -131,15 +131,15 @@ void CQuest::getVisitText (MetaString &iwText, std::vector<Component> &component
{ {
case MISSION_LEVEL: case MISSION_LEVEL:
components.push_back(Component (Component::EXPERIENCE, 0, m13489val, 0)); components.push_back(Component (Component::EXPERIENCE, 0, m13489val, 0));
if (!isCustom) if(!isCustom)
iwText.addReplacement(m13489val); iwText.addReplacement(m13489val);
break; break;
case MISSION_PRIMARY_STAT: case MISSION_PRIMARY_STAT:
{ {
MetaString loot; MetaString loot;
for (int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
if (m2stats[i]) if(m2stats[i])
{ {
components.push_back(Component (Component::PRIM_SKILL, i, m2stats[i], 0)); components.push_back(Component (Component::PRIM_SKILL, i, m2stats[i], 0));
loot << "%d %s"; loot << "%d %s";
@ -153,19 +153,19 @@ void CQuest::getVisitText (MetaString &iwText, std::vector<Component> &component
break; break;
case MISSION_KILL_HERO: case MISSION_KILL_HERO:
components.push_back(Component(Component::HERO_PORTRAIT, heroPortrait, 0, 0)); components.push_back(Component(Component::HERO_PORTRAIT, heroPortrait, 0, 0));
if (!isCustom) if(!isCustom)
addReplacements(iwText, text); addReplacements(iwText, text);
break; break;
case MISSION_HERO: case MISSION_HERO:
//FIXME: portrait may not match hero, if custom portrait was set in map editor //FIXME: portrait may not match hero, if custom portrait was set in map editor
components.push_back(Component (Component::HERO_PORTRAIT, VLC->heroh->heroes[m13489val]->imageIndex, 0, 0)); components.push_back(Component (Component::HERO_PORTRAIT, VLC->heroh->heroes[m13489val]->imageIndex, 0, 0));
if (!isCustom) if(!isCustom)
iwText.addReplacement(VLC->heroh->heroes[m13489val]->name); iwText.addReplacement(VLC->heroh->heroes[m13489val]->name);
break; break;
case MISSION_KILL_CREATURE: case MISSION_KILL_CREATURE:
{ {
components.push_back(Component(stackToKill)); components.push_back(Component(stackToKill));
if (!isCustom) if(!isCustom)
{ {
addReplacements(iwText, text); addReplacements(iwText, text);
} }
@ -174,35 +174,35 @@ void CQuest::getVisitText (MetaString &iwText, std::vector<Component> &component
case MISSION_ART: case MISSION_ART:
{ {
MetaString loot; MetaString loot;
for (auto & elem : m5arts) for(auto & elem : m5arts)
{ {
components.push_back(Component (Component::ARTIFACT, elem, 0, 0)); components.push_back(Component (Component::ARTIFACT, elem, 0, 0));
loot << "%s"; loot << "%s";
loot.addReplacement(MetaString::ART_NAMES, elem); loot.addReplacement(MetaString::ART_NAMES, elem);
} }
if (!isCustom) if(!isCustom)
iwText.addReplacement(loot.buildList()); iwText.addReplacement(loot.buildList());
} }
break; break;
case MISSION_ARMY: case MISSION_ARMY:
{ {
MetaString loot; MetaString loot;
for (auto & elem : m6creatures) for(auto & elem : m6creatures)
{ {
components.push_back(Component(elem)); components.push_back(Component(elem));
loot << "%s"; loot << "%s";
loot.addReplacement(elem); loot.addReplacement(elem);
} }
if (!isCustom) if(!isCustom)
iwText.addReplacement(loot.buildList()); iwText.addReplacement(loot.buildList());
} }
break; break;
case MISSION_RESOURCES: case MISSION_RESOURCES:
{ {
MetaString loot; MetaString loot;
for (int i = 0; i < 7; ++i) for(int i = 0; i < 7; ++i)
{ {
if (m7resources[i]) if(m7resources[i])
{ {
components.push_back(Component (Component::RESOURCE, i, m7resources[i], 0)); components.push_back(Component (Component::RESOURCE, i, m7resources[i], 0));
loot << "%d %s"; loot << "%d %s";
@ -210,29 +210,29 @@ void CQuest::getVisitText (MetaString &iwText, std::vector<Component> &component
loot.addReplacement(MetaString::RES_NAMES, i); loot.addReplacement(MetaString::RES_NAMES, i);
} }
} }
if (!isCustom) if(!isCustom)
iwText.addReplacement(loot.buildList()); iwText.addReplacement(loot.buildList());
} }
break; break;
case MISSION_PLAYER: case MISSION_PLAYER:
components.push_back(Component (Component::FLAG, m13489val, 0, 0)); components.push_back(Component (Component::FLAG, m13489val, 0, 0));
if (!isCustom) if(!isCustom)
iwText.addReplacement(VLC->generaltexth->colors[m13489val]); iwText.addReplacement(VLC->generaltexth->colors[m13489val]);
break; break;
} }
} }
void CQuest::getRolloverText (MetaString &ms, bool onHover) const void CQuest::getRolloverText(MetaString &ms, bool onHover) const
{ {
// Quests with MISSION_NONE type don't have a text for them // Quests with MISSION_NONE type don't have a text for them
assert(missionType != MISSION_NONE); assert(missionType != MISSION_NONE);
if (onHover) if(onHover)
ms << "\n\n"; ms << "\n\n";
ms << VLC->generaltexth->quests[missionType-1][onHover ? 3 : 4][textOption]; ms << VLC->generaltexth->quests[missionType-1][onHover ? 3 : 4][textOption];
switch (missionType) switch(missionType)
{ {
case MISSION_LEVEL: case MISSION_LEVEL:
ms.addReplacement(boost::lexical_cast<std::string>(m13489val)); ms.addReplacement(boost::lexical_cast<std::string>(m13489val));
@ -306,10 +306,10 @@ void CQuest::getRolloverText (MetaString &ms, bool onHover) const
} }
} }
void CQuest::getCompletionText (MetaString &iwText, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h) const void CQuest::getCompletionText(MetaString &iwText, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h) const
{ {
iwText << completedText; iwText << completedText;
switch (missionType) switch(missionType)
{ {
case CQuest::MISSION_LEVEL: case CQuest::MISSION_LEVEL:
if (!isCustomComplete) if (!isCustomComplete)
@ -398,14 +398,14 @@ CGSeerHut::CGSeerHut() : IQuestObject()
void CGSeerHut::setObjToKill() void CGSeerHut::setObjToKill()
{ {
if (quest->missionType == CQuest::MISSION_KILL_CREATURE) if(quest->missionType == CQuest::MISSION_KILL_CREATURE)
{ {
quest->stackToKill = getCreatureToKill(false)->getStack(SlotID(0)); //FIXME: stacks tend to disappear (desync?) on server :? quest->stackToKill = getCreatureToKill(false)->getStack(SlotID(0)); //FIXME: stacks tend to disappear (desync?) on server :?
assert(quest->stackToKill.type); assert(quest->stackToKill.type);
quest->stackToKill.count = 0; //no count in info window quest->stackToKill.count = 0; //no count in info window
quest->stackDirection = checkDirection(); quest->stackDirection = checkDirection();
} }
else if (quest->missionType == CQuest::MISSION_KILL_HERO) else if(quest->missionType == CQuest::MISSION_KILL_HERO)
{ {
quest->heroName = getHeroToKill(false)->name; quest->heroName = getHeroToKill(false)->name;
quest->heroPortrait = getHeroToKill(false)->portrait; quest->heroPortrait = getHeroToKill(false)->portrait;
@ -424,13 +424,13 @@ void CGSeerHut::initObj()
init(); init();
quest->progress = CQuest::NOT_ACTIVE; quest->progress = CQuest::NOT_ACTIVE;
if (quest->missionType) if(quest->missionType)
{ {
if (!quest->isCustomFirst) if(!quest->isCustomFirst)
quest->firstVisitText = VLC->generaltexth->quests[quest->missionType-1][0][quest->textOption]; quest->firstVisitText = VLC->generaltexth->quests[quest->missionType-1][0][quest->textOption];
if (!quest->isCustomNext) if(!quest->isCustomNext)
quest->nextVisitText = VLC->generaltexth->quests[quest->missionType-1][1][quest->textOption]; quest->nextVisitText = VLC->generaltexth->quests[quest->missionType-1][1][quest->textOption];
if (!quest->isCustomComplete) if(!quest->isCustomComplete)
quest->completedText = VLC->generaltexth->quests[quest->missionType-1][2][quest->textOption]; quest->completedText = VLC->generaltexth->quests[quest->missionType-1][2][quest->textOption];
} }
else else
@ -440,23 +440,23 @@ void CGSeerHut::initObj()
} }
} }
void CGSeerHut::getRolloverText (MetaString &text, bool onHover) const void CGSeerHut::getRolloverText(MetaString &text, bool onHover) const
{ {
quest->getRolloverText (text, onHover);//TODO: simplify? quest->getRolloverText (text, onHover);//TODO: simplify?
if (!onHover) if(!onHover)
text.addReplacement(seerName); text.addReplacement(seerName);
} }
std::string CGSeerHut::getHoverText(PlayerColor player) const std::string CGSeerHut::getHoverText(PlayerColor player) const
{ {
std::string hoverName = getObjectName(); std::string hoverName = getObjectName();
if (ID == Obj::SEER_HUT && quest->progress != CQuest::NOT_ACTIVE) if(ID == Obj::SEER_HUT && quest->progress != CQuest::NOT_ACTIVE)
{ {
hoverName = VLC->generaltexth->allTexts[347]; hoverName = VLC->generaltexth->allTexts[347];
boost::algorithm::replace_first(hoverName,"%s", seerName); boost::algorithm::replace_first(hoverName, "%s", seerName);
} }
if (quest->progress & quest->missionType) //rollover when the quest is active if(quest->progress & quest->missionType) //rollover when the quest is active
{ {
MetaString ms; MetaString ms;
getRolloverText (ms, true); getRolloverText (ms, true);
@ -495,7 +495,7 @@ void IQuestObject::getVisitText (MetaString &text, std::vector<Component> &compo
void CGSeerHut::getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h) const void CGSeerHut::getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h) const
{ {
quest->getCompletionText (text, components, isCustom, h); quest->getCompletionText (text, components, isCustom, h);
switch (rewardType) switch(rewardType)
{ {
case EXPERIENCE: components.push_back(Component (Component::EXPERIENCE, 0, h->calculateXp(rVal), 0)); case EXPERIENCE: components.push_back(Component (Component::EXPERIENCE, 0, h->calculateXp(rVal), 0));
break; break;
@ -522,7 +522,7 @@ void CGSeerHut::getCompletionText(MetaString &text, std::vector<Component> &comp
void CGSeerHut::setPropertyDer (ui8 what, ui32 val) void CGSeerHut::setPropertyDer (ui8 what, ui32 val)
{ {
switch (what) switch(what)
{ {
case 10: case 10:
quest->progress = static_cast<CQuest::Eprogress>(val); quest->progress = static_cast<CQuest::Eprogress>(val);
@ -532,44 +532,44 @@ void CGSeerHut::setPropertyDer (ui8 what, ui32 val)
void CGSeerHut::newTurn() const void CGSeerHut::newTurn() const
{ {
if (quest->lastDay >= 0 && quest->lastDay < cb->getDate()-1) //time is up if(quest->lastDay >= 0 && quest->lastDay <= cb->getDate() - 1) //time is up
{ {
cb->setObjProperty (id, CGSeerHut::OBJPROP_VISITED, CQuest::COMPLETE); cb->setObjProperty (id, CGSeerHut::OBJPROP_VISITED, CQuest::COMPLETE);
} }
} }
void CGSeerHut::onHeroVisit( const CGHeroInstance * h ) const void CGSeerHut::onHeroVisit(const CGHeroInstance * h) const
{ {
InfoWindow iw; InfoWindow iw;
iw.player = h->getOwner(); iw.player = h->getOwner();
if (quest->progress < CQuest::COMPLETE) if(quest->progress < CQuest::COMPLETE)
{ {
bool firstVisit = !quest->progress; bool firstVisit = !quest->progress;
bool failRequirements = !checkQuest(h); bool failRequirements = !checkQuest(h);
bool isCustom=false; bool isCustom = false;
if (firstVisit) if(firstVisit)
{ {
isCustom = quest->isCustomFirst; isCustom = quest->isCustomFirst;
cb->setObjProperty (id, CGSeerHut::OBJPROP_VISITED, CQuest::IN_PROGRESS); cb->setObjProperty(id, CGSeerHut::OBJPROP_VISITED, CQuest::IN_PROGRESS);
AddQuest aq; AddQuest aq;
aq.quest = QuestInfo (quest, this, visitablePos()); aq.quest = QuestInfo (quest, this, visitablePos());
aq.player = h->tempOwner; aq.player = h->tempOwner;
cb->sendAndApply (&aq); //TODO: merge with setObjProperty? cb->sendAndApply(&aq); //TODO: merge with setObjProperty?
} }
else if (failRequirements) else if(failRequirements)
{ {
isCustom = quest->isCustomNext; isCustom = quest->isCustomNext;
} }
if (firstVisit || failRequirements) if(firstVisit || failRequirements)
{ {
getVisitText (iw.text, iw.components, isCustom, firstVisit, h); getVisitText (iw.text, iw.components, isCustom, firstVisit, h);
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
} }
if (!failRequirements) // propose completion, also on first visit if(!failRequirements) // propose completion, also on first visit
{ {
BlockingDialog bd (true, false); BlockingDialog bd (true, false);
bd.player = h->getOwner(); bd.player = h->getOwner();
@ -818,12 +818,12 @@ void CGBorderGuard::getRolloverText (MetaString &text, bool onHover) const
text << VLC->generaltexth->tentColors[subID] << " " << VLC->objtypeh->getObjectName(Obj::KEYMASTER); text << VLC->generaltexth->tentColors[subID] << " " << VLC->objtypeh->getObjectName(Obj::KEYMASTER);
} }
bool CGBorderGuard::checkQuest (const CGHeroInstance * h) const bool CGBorderGuard::checkQuest(const CGHeroInstance * h) const
{ {
return wasMyColorVisited (h->tempOwner); return wasMyColorVisited (h->tempOwner);
} }
void CGBorderGuard::onHeroVisit( const CGHeroInstance * h ) const void CGBorderGuard::onHeroVisit(const CGHeroInstance * h) const
{ {
if (wasMyColorVisited (h->getOwner()) ) if (wasMyColorVisited (h->getOwner()) )
{ {
@ -851,7 +851,7 @@ void CGBorderGuard::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answ
cb->removeObject(this); cb->removeObject(this);
} }
void CGBorderGate::onHeroVisit( const CGHeroInstance * h ) const //TODO: passability void CGBorderGate::onHeroVisit(const CGHeroInstance * h) const //TODO: passability
{ {
if (!wasMyColorVisited (h->getOwner()) ) if (!wasMyColorVisited (h->getOwner()) )
{ {