From c8c4c5b6829ea5d1e101b6c916f9608282a3af8b Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Tue, 13 Mar 2012 20:33:00 +0000 Subject: [PATCH] AI heroes won't trash for objects when exploring area together. String logging for goal types. Fixes. --- AI/VCAI/VCAI.cpp | 42 +++++++++++++++++++++++++++++++------- server/VCMI_server.vcxproj | 26 ++++++++++++++--------- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 6c8878262..f633f0808 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -52,6 +52,29 @@ const int ALLOWED_ROAMING_HEROES = 8; const int GOLD_MINE_PRODUCTION = 1000, WOOD_ORE_MINE_PRODUCTION = 2, RESOURCE_MINE_PRODUCTION = 1; +std::string goalName(EGoals goalType) +{ + switch (goalType) + { + case INVALID: + return "INVALID"; + case WIN: + return "WIN"; + case CONQUER: + return "CONQUER"; + case EXPLORE: + return "EXPLORE"; + case GATHER_ARMY: + return "GATHER ARMY"; + case VISIT_TILE: + return "VISIT TILE"; + case CLEAR_WAY_TO: + return "CLEAR WAY TO"; + default: + return boost::lexical_cast(goalType); + } +} + bool compareHeroStrength(const CGHeroInstance *h1, const CGHeroInstance *h2) { return h1->getTotalStrength() < h2->getTotalStrength(); @@ -866,6 +889,7 @@ void VCAI::makeTurn() } } } + break; case 7: //reconsider strategy { const CGHeroInstance * h = primaryHero(); @@ -889,6 +913,7 @@ void VCAI::makeTurn() } } } + break; } if(cb->getSelectedHero()) cb->recalculatePaths(); @@ -912,8 +937,7 @@ void VCAI::makeTurnInternal() striveToGoal(CGoal(WIN)); for (auto hg = lockedHeroes.begin(); hg != lockedHeroes.end(); hg++) //continue our goals { - if (!hg->second.invalid()) - striveToGoal (hg->second); + striveToGoal (hg->second); } striveToGoal(CGoal(BUILD)); //TODO: smarter building management } @@ -1100,16 +1124,18 @@ void VCAI::wander(const CGHeroInstance * h) while(1) { auto dests = getPossibleDestinations(h); - if(!dests.size()) //TODO: merge with GATHER_ARMY goal + if(!dests.size()) { PNLOG("Nowhere more to go...\n"); setGoal (h, INVALID); break; } - - if(!goVisitObj(dests.front(), h)) + const CGObjectInstance * obj = dests.front(); + if(!goVisitObj(obj, h)) { BNLOG("Hero %s apparently used all MPs (%d left)\n", h->name % h->movement); + alreadyVisited.push_back(obj); //reserve that object - we predict it will be reached soon + setGoal(h, CGoal(VISIT_TILE).sethero(h).settile(obj->visitablePos())); break; } @@ -1545,6 +1571,8 @@ void VCAI::endTurn() void VCAI::striveToGoal(const CGoal &ultimateGoal) { + if (ultimateGoal.invalid()) + return; while(1) { CGoal goal = ultimateGoal; @@ -1553,7 +1581,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal) while(!goal.isElementar && maxGoals) { INDENT; - BNLOG("Considering goal %d.", goal.goalType); + BNLOG("Considering goal %s", goalName(goal.goalType)); try { boost::this_thread::interruption_point(); @@ -1562,7 +1590,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal) } catch(std::exception &e) { - BNLOG("Goal %d decomposition failed: %s", goal.goalType % e.what()); + BNLOG("Goal %s decomposition failed: %s", goalName(goal.goalType) % e.what()); return; } } diff --git a/server/VCMI_server.vcxproj b/server/VCMI_server.vcxproj index c87f13e49..962c61767 100644 --- a/server/VCMI_server.vcxproj +++ b/server/VCMI_server.vcxproj @@ -62,12 +62,17 @@ - <_ProjectFileVersion>10.0.30128.1 - $(SolutionDir) + <_ProjectFileVersion>10.0.30319.1 + ..\.. + $(Configuration)_VC9\ $(SolutionDir) $(Configuration)\ + $(SolutionDir)$(Configuration)\ + $(Configuration)_VC9\ + ..\..\RD + $(Configuration)_VC9\ $(Configuration)\ - $(SolutionDir)$(Configuration)\bin\ + G:\Programowanie\VCMI\RD $(SolutionDir)$(Configuration)\bin\ $(Configuration)\ $(Configuration)\ @@ -107,8 +112,8 @@ StdInc.h - VCMI_lib.lib;zlib.lib;%(AdditionalDependencies) - $(OutDir);%(AdditionalLibraryDirectories) + VCMI_lib.lib;zdll.lib;%(AdditionalDependencies) + ../..;../../libs;../;%(AdditionalLibraryDirectories) true MachineX86 @@ -155,13 +160,14 @@ VCMI_lib.lib;zlib.lib;%(AdditionalDependencies) - $(OutDir);%(AdditionalLibraryDirectories) + G:\Programowanie\VCMI\libs;$(OutDir);G:\Programowanie\VCMI\RD;%(AdditionalLibraryDirectories) true true true true MachineX86 true + $(OutDir)$(TargetName)$(TargetExt) @@ -172,7 +178,7 @@ Speed false true - %(AdditionalIncludeDirectories) + F:\Programowanie\VCMI\include;%(AdditionalIncludeDirectories) true MultiThreadedDLL false @@ -185,13 +191,12 @@ StdInc.h - VCMI_lib.lib;zlib.lib;%(AdditionalDependencies) - $(OutDir);%(AdditionalLibraryDirectories) + VCMI_lib.lib;zdll.lib;%(AdditionalDependencies) + F:\Programowanie\VCMI\libs;F:\Programowanie\VCMI\RD;%(AdditionalLibraryDirectories) true true true true - true @@ -215,6 +220,7 @@ {b952ffc5-3039-4de1-9f08-90acda483d8f} + false