1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Refactor quests progress

This commit is contained in:
nordsoft 2023-10-11 21:10:42 +02:00
parent 22c9eecd7d
commit 7ccd4cdcb2
7 changed files with 38 additions and 30 deletions

View File

@ -25,7 +25,7 @@ namespace AIPathfinding
return dynamic_cast<const IQuestObject *>(questInfo.obj)->checkQuest(node->actor->hero);
}
return questInfo.quest->progress == CQuest::NOT_ACTIVE
return questInfo.quest->activeForPlayers.count(node->actor->hero->getOwner())
|| questInfo.quest->checkQuest(node->actor->hero);
}

View File

@ -25,7 +25,7 @@ TGoalVec CompleteQuest::getAllPossibleSubgoals()
{
TGoalVec solutions;
if(q.quest->progress != CQuest::COMPLETE)
if(!q.quest->isCompleted)
{
logAi->debug("Trying to realize quest: %s", questToString());

View File

@ -152,7 +152,7 @@ void CQuestLog::recreateLabelList()
if (quests[i].quest->questName == CQuest::missionName(0))
continue;
if (quests[i].quest->progress == CQuest::COMPLETE)
if (quests[i].quest->isCompleted)
{
completeMissing = false;
if (hideComplete)
@ -180,7 +180,7 @@ void CQuestLog::recreateLabelList()
labels.push_back(label);
// Select latest active quest
if (quests[i].quest->progress != CQuest::COMPLETE)
if(!quests[i].quest->isCompleted)
selectQuest(i, currentLabel);
currentLabel = static_cast<int>(labels.size());

View File

@ -38,7 +38,7 @@ std::map <PlayerColor, std::set <ui8> > CGKeys::playerKeyMap;
//TODO: Remove constructor
CQuest::CQuest():
qid(-1),
progress(NOT_ACTIVE),
isCompleted(false),
lastDay(-1),
killTarget(ObjectInstanceID::NONE),
textOption(0),
@ -451,13 +451,11 @@ void CGSeerHut::initObj(CRandomGenerator & rand)
CRewardableObject::initObj(rand);
quest->progress = CQuest::NOT_ACTIVE;
setObjToKill();
quest->defineQuestName();
if(quest->mission == Rewardable::Limiter{} && quest->killTarget == ObjectInstanceID::NONE)
quest->progress = CQuest::COMPLETE;
quest->isCompleted = true;
if(quest->questName == quest->missionName(0))
{
@ -484,13 +482,15 @@ void CGSeerHut::getRolloverText(MetaString &text, bool onHover) const
std::string CGSeerHut::getHoverText(PlayerColor player) const
{
std::string hoverName = getObjectName();
if(ID == Obj::SEER_HUT && quest->progress != CQuest::NOT_ACTIVE)
if(ID == Obj::SEER_HUT && quest->activeForPlayers.count(player))
{
hoverName = VLC->generaltexth->allTexts[347];
boost::algorithm::replace_first(hoverName, "%s", seerName);
}
if(quest->progress/* & quest->missionType*/) //rollover when the quest is active
if(quest->activeForPlayers.count(player)
&& (quest->mission != Rewardable::Limiter{}
|| quest->killTarget != ObjectInstanceID::NONE)) //rollover when the quest is active
{
MetaString ms;
getRolloverText (ms, true);
@ -499,13 +499,21 @@ std::string CGSeerHut::getHoverText(PlayerColor player) const
return hoverName;
}
void CGSeerHut::setPropertyDer (ui8 what, ui32 val)
void CGSeerHut::setPropertyDer(ui8 what, ui32 val)
{
switch(what)
{
case CGSeerHut::OBJPROP_VISITED:
quest->progress = static_cast<CQuest::EProgress>(val);
case CGSeerHut::SEERHUT_VISITED:
{
quest->activeForPlayers.emplace(val);
break;
}
case CGSeerHut::SEERHUT_COMPLETE:
{
quest->isCompleted = val;
quest->activeForPlayers.clear();
break;
}
}
}
@ -514,7 +522,7 @@ void CGSeerHut::newTurn(CRandomGenerator & rand) const
CRewardableObject::newTurn(rand);
if(quest->lastDay >= 0 && quest->lastDay <= cb->getDate() - 1) //time is up
{
cb->setObjProperty (id, CGSeerHut::OBJPROP_VISITED, CQuest::COMPLETE);
cb->setObjProperty (id, CGSeerHut::SEERHUT_COMPLETE, true);
}
}
@ -522,14 +530,14 @@ void CGSeerHut::onHeroVisit(const CGHeroInstance * h) const
{
InfoWindow iw;
iw.player = h->getOwner();
if(quest->progress < CQuest::COMPLETE)
if(!quest->isCompleted)
{
bool firstVisit = !quest->progress;
bool firstVisit = !quest->activeForPlayers.count(h->getOwner());
bool failRequirements = !checkQuest(h);
if(firstVisit)
{
cb->setObjProperty(id, CGSeerHut::OBJPROP_VISITED, CQuest::IN_PROGRESS);
cb->setObjProperty(id, CGSeerHut::SEERHUT_VISITED, h->getOwner());
AddQuest aq;
aq.quest = QuestInfo (quest, this, visitablePos());
@ -612,10 +620,7 @@ void CGSeerHut::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer)
if(answer)
{
quest->completeQuest(cb, hero);
if(quest && quest->repeatedQuest)
cb->setObjProperty(id, CGSeerHut::OBJPROP_VISITED, CQuest::NOT_ACTIVE);
else
cb->setObjProperty(id, CGSeerHut::OBJPROP_VISITED, CQuest::COMPLETE); //mission complete
cb->setObjProperty(id, CGSeerHut::SEERHUT_COMPLETE, !quest->repeatedQuest); //mission complete
}
}

View File

@ -21,12 +21,6 @@ class DLL_LINKAGE CQuest final
{
public:
enum EProgress {
NOT_ACTIVE,
IN_PROGRESS,
COMPLETE
};
static const std::string & missionName(int index);
static const std::string & missionState(int index);
@ -34,11 +28,12 @@ public:
si32 qid; //unique quest id for serialization / identification
EProgress progress;
si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
ObjectInstanceID killTarget;
Rewardable::Limiter mission;
bool repeatedQuest;
bool isCompleted;
std::set<PlayerColor> activeForPlayers;
// following fields are used only for kill creature/hero missions, the original
// objects became inaccessible after their removal, so we need to store info
@ -75,7 +70,8 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & qid;
h & progress;
h & isCompleted;
h & activeForPlayers;
h & lastDay;
h & textOption;
h & stackToKill;
@ -143,7 +139,8 @@ public:
h & seerName;
}
protected:
static constexpr int OBJPROP_VISITED = 10;
static constexpr int SEERHUT_VISITED = 10;
static constexpr int SEERHUT_COMPLETE = 11;
void setPropertyDer(ui8 what, ui32 val) override;

View File

@ -57,6 +57,11 @@ bool operator==(const Rewardable::Limiter & l, const Rewardable::Limiter & r)
&& l.anyOf == r.anyOf;
}
bool operator!=(const Rewardable::Limiter & l, const Rewardable::Limiter & r)
{
return !(l == r);
}
bool Rewardable::Limiter::heroAllowed(const CGHeroInstance * hero) const
{
if(dayOfWeek != 0)

View File

@ -113,5 +113,6 @@ struct DLL_LINKAGE Limiter final
}
bool DLL_LINKAGE operator== (const Rewardable::Limiter & l, const Rewardable::Limiter & r);
bool DLL_LINKAGE operator!= (const Rewardable::Limiter & l, const Rewardable::Limiter & r);
VCMI_LIB_NAMESPACE_END