mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- Improved AI logging messages
- Cut wandering time of AI
This commit is contained in:
parent
8eafb9f951
commit
c708a631c1
@ -108,7 +108,7 @@ struct TimeCheck
|
||||
|
||||
~TimeCheck()
|
||||
{
|
||||
logAi->debugStream() << boost::format("Time of %s was %d ms.") % txt % time.getDiff();
|
||||
logAi->traceStream() << boost::format("Time of %s was %d ms.") % txt % time.getDiff();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -650,7 +650,7 @@ void VCAI::makeTurn()
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
||||
setThreadName("VCAI::makeTurn");
|
||||
|
||||
logAi->debugStream() << boost::format("Player %d starting turn") % static_cast<int>(playerID.getNum());
|
||||
logGlobal->infoStream() << boost::format("Player %d starting turn") % static_cast<int>(playerID.getNum());
|
||||
|
||||
switch(cb->getDate(Date::DAY_OF_WEEK))
|
||||
{
|
||||
@ -1239,7 +1239,8 @@ bool VCAI::canRecruitAnyHero (const CGTownInstance * t) const
|
||||
void VCAI::wander(HeroPtr h)
|
||||
{
|
||||
TimeCheck tc("looking for wander destination");
|
||||
while(1)
|
||||
|
||||
while (h->movement)
|
||||
{
|
||||
validateVisitableObjs();
|
||||
std::vector <ObjectIdRef> dests, tmp;
|
||||
@ -1319,6 +1320,11 @@ void VCAI::wander(HeroPtr h)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//end of objs empty
|
||||
|
||||
while (dests.size()) //performance improvement
|
||||
{
|
||||
//wander should not cause heroes to be reserved - they are always considered free
|
||||
const ObjectIdRef&dest = dests.front();
|
||||
logAi->debugStream() << boost::format("Of all %d destinations, object oid=%d seems nice") % dests.size() % dest.id.getNum();
|
||||
if(!goVisitObj(dest, h))
|
||||
@ -1330,15 +1336,36 @@ void VCAI::wander(HeroPtr h)
|
||||
else
|
||||
{
|
||||
logAi->debugStream() << boost::format("Hero %s apparently used all MPs (%d left)") % h->name % h->movement;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (dest)
|
||||
erase_if_present(dests, dest);
|
||||
|
||||
if(h->visitedTown)
|
||||
////TODO: refactor removing deleted objects from the list
|
||||
//std::vector<const CGObjectInstance *> hlp;
|
||||
//retreiveVisitableObjs(hlp, true);
|
||||
|
||||
//auto shouldBeErased = [&](const CGObjectInstance *obj) -> bool
|
||||
//{
|
||||
// if(!vstd::contains(hlp, obj))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
//};
|
||||
//erase_if(dests, shouldBeErased);
|
||||
|
||||
boost::sort(dests, isCloser); //find next closest one
|
||||
}
|
||||
}
|
||||
|
||||
if (h->visitedTown)
|
||||
{
|
||||
townVisitsThisWeek[h].insert(h->visitedTown);
|
||||
buildArmyIn(h->visitedTown);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1356,7 +1383,7 @@ void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal)
|
||||
|
||||
void VCAI::completeGoal (Goals::TSubgoal goal)
|
||||
{
|
||||
logAi->debugStream() << boost::format("Completing goal: %s") % goal->name();
|
||||
logAi->traceStream() << boost::format("Completing goal: %s") % goal->name();
|
||||
if (const CGHeroInstance * h = goal->hero.get(true))
|
||||
{
|
||||
auto it = lockedHeroes.find(h);
|
||||
@ -1844,18 +1871,19 @@ HeroPtr VCAI::primaryHero() const
|
||||
|
||||
void VCAI::endTurn()
|
||||
{
|
||||
logAi->debugStream() << "Player " << static_cast<int>(playerID.getNum()) << " ends turn";
|
||||
logAi->infoStream() << "Player " << static_cast<int>(playerID.getNum()) << " ends turn";
|
||||
if(!status.haveTurn())
|
||||
{
|
||||
logAi->errorStream() << "Not having turn at the end of turn???";
|
||||
}
|
||||
logAi->debugStream() << "Resources at the end of turn: " << cb->getResourceAmount();
|
||||
|
||||
do
|
||||
{
|
||||
cb->endTurn();
|
||||
} while(status.haveTurn()); //for some reasons, our request may fail -> stop requesting end of turn only after we've received a confirmation that it's over
|
||||
|
||||
logAi->debugStream() << "Player " << static_cast<int>(playerID.getNum()) << " ended turn";
|
||||
logGlobal->infoStream() << "Player " << static_cast<int>(playerID.getNum()) << " ended turn";
|
||||
}
|
||||
|
||||
void VCAI::striveToGoal(Goals::TSubgoal ultimateGoal)
|
||||
@ -1931,7 +1959,10 @@ Goals::TSubgoal VCAI::striveToGoalInternal(Goals::TSubgoal ultimateGoal, bool on
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
logAi->debugStream() << boost::format("Trying to realize %s (value %2.3f)") % goal->name() % goal->priority;
|
||||
goal->accept(this);
|
||||
}
|
||||
|
||||
boost::this_thread::interruption_point();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user