1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-17 20:58:07 +02:00

Reduce excessive NKAI logging

This commit is contained in:
Ivan Savenko 2025-01-10 22:39:20 +00:00
parent d935a19504
commit 1c6fbe4200
3 changed files with 30 additions and 8 deletions

View File

@ -20,7 +20,9 @@ void BuildAnalyzer::updateTownDwellings(TownDevelopmentInfo & developmentInfo)
{
for(int level = 0; level < developmentInfo.town->getTown()->creatures.size(); level++)
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Checking dwelling level %d", level);
#endif
std::vector<BuildingID> dwellingsInTown;
for(BuildingID buildID = BuildingID::getDwellingFromLevel(level, 0); buildID.hasValue(); BuildingID::advanceDwelling(buildID))
@ -143,9 +145,9 @@ void BuildAnalyzer::update()
{
if(town->built >= cb->getSettings().getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP))
continue; // Not much point in trying anything - can't built in this town anymore today
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Checking town %s", town->getNameTranslated());
#endif
developmentInfos.push_back(TownDevelopmentInfo(town));
TownDevelopmentInfo & developmentInfo = developmentInfos.back();
@ -161,10 +163,10 @@ void BuildAnalyzer::update()
}
armyCost += developmentInfo.armyCost;
#if NKAI_TRACE_LEVEL >= 1
for(auto bi : developmentInfo.toBuild)
{
logAi->trace("Building preferences %s", bi.toString());
}
#endif
}
std::sort(developmentInfos.begin(), developmentInfos.end(), [](const TownDevelopmentInfo & t1, const TownDevelopmentInfo & t2) -> bool
@ -179,7 +181,9 @@ void BuildAnalyzer::update()
goldPressure = (ai->getLockedResources()[EGameResID::GOLD] + (float)armyCost[EGameResID::GOLD] + economyDevelopmentCost) / (1 + 2 * ai->getFreeGold() + (float)dailyIncome[EGameResID::GOLD] * 7.0f);
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Gold pressure: %f", goldPressure);
#endif
}
void BuildAnalyzer::reset()
@ -268,12 +272,15 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
if(vstd::contains_if(missingBuildings, otherDwelling))
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("cant build %d. Need other dwelling %d", toBuild.getNum(), missingBuildings.front().getNum());
#endif
}
else if(missingBuildings[0] != toBuild)
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("cant build %d. Need %d", toBuild.getNum(), missingBuildings[0].num);
#endif
BuildingInfo prerequisite = getBuildingOrPrerequisite(town, missingBuildings[0], excludeDwellingDependencies);
prerequisite.buildCostWithPrerequisites += info.buildCost;
@ -298,19 +305,24 @@ BuildingInfo BuildAnalyzer::getBuildingOrPrerequisite(
}
else
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Cant build. The building requires itself as prerequisite");
#endif
return info;
}
}
else
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Cant build. Reason: %d", static_cast<int>(canBuild));
#endif
}
}
else
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Dwelling %d exists", toBuild.getNum());
#endif
info.exists = true;
}

View File

@ -151,7 +151,9 @@ bool handleGarrisonHeroFromPreviousTurn(const CGTownInstance * town, Goals::TGoa
void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInstance * town, const Nullkiller * ai) const
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Evaluating defence for %s", town->getNameTranslated());
#endif
auto threatNode = ai->dangerHitMap->getObjectThreat(town);
std::vector<HitMapInfo> threats = ai->dangerHitMap->getTownThreats(town);
@ -164,8 +166,9 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
}
if(!threatNode.fastestDanger.hero)
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("No threat found for town %s", town->getNameTranslated());
#endif
return;
}
@ -173,7 +176,9 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
if(reinforcement)
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Town %s can buy defence army %lld", town->getNameTranslated(), reinforcement);
#endif
tasks.push_back(Goals::sptr(Goals::BuyArmy(town, reinforcement).setpriority(0.5f)));
}
@ -181,13 +186,14 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
for(auto & threat : threats)
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace(
"Town %s has threat %lld in %s turns, hero: %s",
town->getNameTranslated(),
threat.danger,
std::to_string(threat.turn),
threat.hero ? threat.hero->getNameTranslated() : std::string("<no hero>"));
#endif
handleCounterAttack(town, threat, threatNode.maximumDanger, ai, tasks);
if(isThreatUnderControl(town, threat, ai, paths))
@ -199,7 +205,9 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
if(paths.empty())
{
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("No ways to defend town %s", town->getNameTranslated());
#endif
continue;
}

View File

@ -1201,7 +1201,9 @@ public:
if (bi.id == BuildingID::MARKETPLACE || bi.dailyIncome[EGameResID::WOOD] > 0)
evaluationContext.isTradeBuilding = true;
#if NKAI_TRACE_LEVEL >= 1
logAi->trace("Building costs for %s : %s MarketValue: %d",bi.toString(), evaluationContext.buildingCost.toString(), evaluationContext.buildingCost.marketValue());
#endif
if(bi.creatureID != CreatureID::NONE)
{