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

Rename GetObj->VisitObj to reflect new functionality

This commit is contained in:
Dydzio 2018-08-10 16:42:55 +02:00
parent f2ba500e90
commit 3961b4ac93
6 changed files with 38 additions and 38 deletions

View File

@ -415,7 +415,7 @@ float FuzzyHelper::evaluate(Goals::VisitTile & g)
{
return visitTileEngine.evaluate(g);
}
float FuzzyHelper::evaluate(Goals::GetObj & g)
float FuzzyHelper::evaluate(Goals::VisitObj & g)
{
return getObjEngine.evaluate(g);
}
@ -523,7 +523,7 @@ GetObjEngine::GetObjEngine()
float GetObjEngine::evaluate(Goals::AbstractGoal & goal)
{
auto g = dynamic_cast<Goals::GetObj &>(goal);
auto g = dynamic_cast<Goals::VisitObj &>(goal);
if(!g.hero)
return 0;

View File

@ -88,7 +88,7 @@ public:
float evaluate(Goals::Explore & g);
float evaluate(Goals::RecruitHero & g);
float evaluate(Goals::VisitTile & g);
float evaluate(Goals::GetObj & g);
float evaluate(Goals::VisitObj & g);
float evaluate(Goals::VisitHero & g);
float evaluate(Goals::BuildThis & g);
float evaluate(Goals::DigAtTile & g);

View File

@ -350,7 +350,7 @@ TSubgoal Win::whatToDoToAchieve()
return sptr(Goals::Conquer());
return sptr(Goals::GetObj(goal.object->id.getNum()));
return sptr(Goals::VisitObj(goal.object->id.getNum()));
}
else
{
@ -404,7 +404,7 @@ TSubgoal Win::whatToDoToAchieve()
return sptr(Goals::DigAtTile(grailPos));
} //TODO: use FIND_OBJ
else if(const CGObjectInstance * obj = ai->getUnvisitedObj(objWithID<Obj::OBELISK>)) //there are unvisited Obelisks
return sptr(Goals::GetObj(obj->id.getNum()));
return sptr(Goals::VisitObj(obj->id.getNum()));
else
return sptr(Goals::Explore());
}
@ -414,7 +414,7 @@ TSubgoal Win::whatToDoToAchieve()
{
if(goal.object)
{
return sptr(Goals::GetObj(goal.object->id.getNum()));
return sptr(Goals::VisitObj(goal.object->id.getNum()));
}
else
{
@ -489,7 +489,7 @@ TSubgoal FindObj::whatToDoToAchieve()
}
}
if(o && ai->isAccessible(o->pos)) //we don't use isAccessibleForHero as we don't know which hero it is
return sptr(Goals::GetObj(o->id.getNum()));
return sptr(Goals::VisitObj(o->id.getNum()));
else
return sptr(Goals::Explore());
}
@ -507,12 +507,12 @@ bool Goals::FindObj::fulfillsMe(TSubgoal goal)
return false;
}
std::string GetObj::completeMessage() const
std::string VisitObj::completeMessage() const
{
return "hero " + hero.get()->name + " captured Object ID = " + boost::lexical_cast<std::string>(objid);
}
TGoalVec GetObj::getAllPossibleSubgoals()
TGoalVec VisitObj::getAllPossibleSubgoals()
{
TGoalVec goalList;
const CGObjectInstance * obj = cb->getObjInstance(ObjectInstanceID(objid));
@ -527,7 +527,7 @@ TGoalVec GetObj::getAllPossibleSubgoals()
if(ai->isAccessibleForHero(pos, hero))
{
if(isSafeToVisit(hero, pos))
goalList.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(hero)));
goalList.push_back(sptr(Goals::VisitObj(obj->id.getNum()).sethero(hero)));
else
goalList.push_back(sptr(Goals::GatherArmy(evaluateDanger(pos, hero.h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true)));
@ -541,7 +541,7 @@ TGoalVec GetObj::getAllPossibleSubgoals()
if(ai->isAccessibleForHero(pos, h))
{
if(isSafeToVisit(hero, pos))
goalList.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h)));
goalList.push_back(sptr(Goals::VisitObj(obj->id.getNum()).sethero(h)));
else
goalList.push_back(sptr(Goals::GatherArmy(evaluateDanger(pos, h) * SAFE_ATTACK_CONSTANT).sethero(hero).setisAbstract(true)));
}
@ -556,7 +556,7 @@ TGoalVec GetObj::getAllPossibleSubgoals()
return goalList;
}
TSubgoal GetObj::whatToDoToAchieve()
TSubgoal VisitObj::whatToDoToAchieve()
{
auto bestGoal = fh->chooseSolution(getAllPossibleSubgoals());
@ -566,21 +566,21 @@ TSubgoal GetObj::whatToDoToAchieve()
return bestGoal;
}
Goals::GetObj::GetObj(int Objid) : CGoal(Goals::GET_OBJ)
Goals::VisitObj::VisitObj(int Objid) : CGoal(Goals::GET_OBJ)
{
objid = Objid;
tile = ai->myCb->getObjInstance(ObjectInstanceID(objid))->visitablePos();
priority = 3;
}
bool Goals::GetObj::operator==(AbstractGoal & g)
bool Goals::VisitObj::operator==(AbstractGoal & g)
{
if (g.goalType != goalType)
return false;
return g.objid == objid;
}
bool GetObj::fulfillsMe(TSubgoal goal)
bool VisitObj::fulfillsMe(TSubgoal goal)
{
if(goal->goalType == Goals::VISIT_TILE)
{
@ -731,7 +731,7 @@ TGoalVec ClearWayTo::getAllPossibleSubgoals()
if(shouldVisit(h, topObj))
{
//do NOT use VISIT_TILE, as tile with quets guard can't be visited
ret.push_back(sptr(Goals::GetObj(topObj->id.getNum()).sethero(h))); //TODO: Recheck this code - object visit became elementar goal
ret.push_back(sptr(Goals::VisitObj(topObj->id.getNum()).sethero(h))); //TODO: Recheck this code - object visit became elementar goal
continue; //do not try to visit tile or gather army
}
else
@ -1148,7 +1148,7 @@ TGoalVec Goals::CollectRes::getAllPossibleSubgoals()
if (dest != t) //there is something blocking our way
ret.push_back(sptr(Goals::ClearWayTo(dest, h).setisAbstract(true)));
else
ret.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h).setisAbstract(true)));
ret.push_back(sptr(Goals::VisitObj(obj->id.getNum()).sethero(h).setisAbstract(true)));
}
else //we need to get army in order to pick that object
ret.push_back(sptr(Goals::GatherArmy(evaluateDanger(dest, h) * SAFE_ATTACK_CONSTANT).sethero(h).setisAbstract(true)));
@ -1234,7 +1234,7 @@ TSubgoal Goals::CollectRes::whatToDoToTrade()
auto objid = m->o->id.getNum();
if (backObj->tempOwner != ai->playerID) //top object not owned
{
return sptr(Goals::GetObj(objid)); //just go there
return sptr(Goals::VisitObj(objid)); //just go there
}
else //either it's our town, or we have hero there
{
@ -1340,7 +1340,7 @@ TSubgoal GatherTroops::whatToDoToAchieve()
if(!nearest)
throw cannotFulfillGoalException("Cannot find nearest dwelling!");
return sptr(Goals::GetObj(nearest->id.getNum()));
return sptr(Goals::VisitObj(nearest->id.getNum()));
}
else
return sptr(Goals::Explore());
@ -1422,7 +1422,7 @@ TGoalVec Conquer::getAllPossibleSubgoals()
}
else //just get that object
{
ret.push_back(sptr(Goals::GetObj(obj->id.getNum()).sethero(h).setisAbstract(true)));
ret.push_back(sptr(Goals::VisitObj(obj->id.getNum()).sethero(h).setisAbstract(true)));
}
}
}
@ -1642,7 +1642,7 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
TSubgoal AbstractGoal::goVisitOrLookFor(const CGObjectInstance * obj)
{
if(obj)
return sptr(Goals::GetObj(obj->id.getNum()));
return sptr(Goals::VisitObj(obj->id.getNum()));
else
return sptr(Goals::Explore());
}

View File

@ -461,11 +461,11 @@ public:
bool fulfillsMe(TSubgoal goal) override;
};
class DLL_EXPORT GetObj : public CGoal<GetObj>
class DLL_EXPORT VisitObj : public CGoal<VisitObj> //this goal was previously known as GetObj
{
public:
GetObj() = delete; // empty constructor not allowed
GetObj(int Objid);
VisitObj() = delete; // empty constructor not allowed
VisitObj(int Objid);
TGoalVec getAllPossibleSubgoals() override;
TSubgoal whatToDoToAchieve() override;

View File

@ -268,7 +268,7 @@ void VCAI::heroVisit(const CGHeroInstance * visitor, const CGObjectInstance * vi
{
markObjectVisited(visitedObj);
unreserveObject(visitor, visitedObj);
completeGoal(sptr(Goals::GetObj(visitedObj->id.getNum()).sethero(visitor))); //we don't need to visit it anymore
completeGoal(sptr(Goals::VisitObj(visitedObj->id.getNum()).sethero(visitor))); //we don't need to visit it anymore
//TODO: what if we visited one-time visitable object that was reserved by another hero (shouldn't, but..)
if (visitedObj->ID == Obj::HERO)
{
@ -1013,7 +1013,7 @@ void VCAI::performObjectInteraction(const CGObjectInstance * obj, HeroPtr h)
}
break;
}
completeGoal(sptr(Goals::GetObj(obj->id.getNum()).sethero(h)));
completeGoal(sptr(Goals::VisitObj(obj->id.getNum()).sethero(h)));
}
void VCAI::moveCreaturesToHero(const CGTownInstance * t)
@ -1464,7 +1464,7 @@ void VCAI::wander(HeroPtr h)
Goals::TGoalVec targetObjectGoals;
for(auto destination : dests)
{
targetObjectGoals.push_back(sptr(Goals::GetObj(destination.id.getNum()).sethero(h).setisAbstract(true)));
targetObjectGoals.push_back(sptr(Goals::VisitObj(destination.id.getNum()).sethero(h).setisAbstract(true)));
}
auto bestObjectGoal = fh->chooseSolution(targetObjectGoals);
decomposeGoal(bestObjectGoal)->accept(this);
@ -2002,7 +2002,7 @@ void VCAI::tryRealize(Goals::VisitTile & g)
}
}
void VCAI::tryRealize(Goals::GetObj & g)
void VCAI::tryRealize(Goals::VisitObj & g)
{
auto position = g.tile;
if(!g.hero->movement)
@ -2374,7 +2374,7 @@ Goals::TSubgoal VCAI::questToGoal(const QuestInfo & q)
{
if (q.quest->checkQuest(hero))
{
return sptr(Goals::GetObj(q.obj->id.getNum()).sethero(hero));
return sptr(Goals::VisitObj(q.obj->id.getNum()).sethero(hero));
}
}
for (auto art : q.quest->m5arts)
@ -2390,7 +2390,7 @@ Goals::TSubgoal VCAI::questToGoal(const QuestInfo & q)
{
if (q.quest->checkQuest(hero))
{
return sptr(Goals::GetObj(q.obj->id.getNum()).sethero(hero));
return sptr(Goals::VisitObj(q.obj->id.getNum()).sethero(hero));
}
}
return sptr(Goals::FindObj(Obj::PRISON)); //rule of a thumb - quest heroes usually are locked in prisons
@ -2403,7 +2403,7 @@ Goals::TSubgoal VCAI::questToGoal(const QuestInfo & q)
{
if (q.quest->checkQuest(hero)) //very bad info - stacks can be split between multiple heroes :(
{
return sptr(Goals::GetObj(q.obj->id.getNum()).sethero(hero));
return sptr(Goals::VisitObj(q.obj->id.getNum()).sethero(hero));
}
}
for (auto creature : q.quest->m6creatures)
@ -2420,7 +2420,7 @@ Goals::TSubgoal VCAI::questToGoal(const QuestInfo & q)
{
if (q.quest->checkQuest(heroes.front())) //it doesn't matter which hero it is
{
return sptr(Goals::GetObj(q.obj->id.getNum()));
return sptr(Goals::VisitObj(q.obj->id.getNum()));
}
else
{
@ -2440,9 +2440,9 @@ Goals::TSubgoal VCAI::questToGoal(const QuestInfo & q)
{
auto obj = cb->getObjByQuestIdentifier(q.quest->m13489val);
if (obj)
return sptr(Goals::GetObj(obj->id.getNum()));
return sptr(Goals::VisitObj(obj->id.getNum()));
else
return sptr(Goals::GetObj(q.obj->id.getNum())); //visit seer hut
return sptr(Goals::VisitObj(q.obj->id.getNum())); //visit seer hut
break;
}
case CQuest::MISSION_PRIMARY_STAT:
@ -2452,7 +2452,7 @@ Goals::TSubgoal VCAI::questToGoal(const QuestInfo & q)
{
if (q.quest->checkQuest(hero))
{
return sptr(Goals::GetObj(q.obj->id.getNum()).sethero(hero));
return sptr(Goals::VisitObj(q.obj->id.getNum()).sethero(hero));
}
}
for (int i = 0; i < q.quest->m2stats.size(); ++i)
@ -2468,7 +2468,7 @@ Goals::TSubgoal VCAI::questToGoal(const QuestInfo & q)
{
if (q.quest->checkQuest(hero))
{
return sptr(Goals::GetObj(q.obj->id.getNum()).sethero(hero)); //TODO: causes infinite loop :/
return sptr(Goals::VisitObj(q.obj->id.getNum()).sethero(hero)); //TODO: causes infinite loop :/
}
}
logAi->debug("Don't know how to reach hero level %d", q.quest->m13489val);

View File

@ -121,7 +121,7 @@ public:
void tryRealize(Goals::Explore & g);
void tryRealize(Goals::RecruitHero & g);
void tryRealize(Goals::VisitTile & g);
void tryRealize(Goals::GetObj & g);
void tryRealize(Goals::VisitObj & g);
void tryRealize(Goals::VisitHero & g);
void tryRealize(Goals::BuildThis & g);
void tryRealize(Goals::DigAtTile & g);
@ -285,7 +285,7 @@ public:
h.template registerType<Goals::AbstractGoal, Goals::GatherArmy>();
h.template registerType<Goals::AbstractGoal, Goals::GatherTroops>();
h.template registerType<Goals::AbstractGoal, Goals::GetArtOfType>();
h.template registerType<Goals::AbstractGoal, Goals::GetObj>();
h.template registerType<Goals::AbstractGoal, Goals::VisitObj>();
h.template registerType<Goals::AbstractGoal, Goals::Invalid>();
//h.template registerType<Goals::AbstractGoal, Goals::NotLose>();
h.template registerType<Goals::AbstractGoal, Goals::RecruitHero>();