1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Some improvements for AI logging.

This commit is contained in:
DjWarmonger
2012-11-15 10:40:40 +00:00
parent 100dad889a
commit c54b983663
4 changed files with 33 additions and 23 deletions

View File

@@ -76,7 +76,7 @@
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RD|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\bin\AI\</OutDir>
<OutDir>G:\Programowanie\VCMI\RD\AI\</OutDir>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
@@ -122,7 +122,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\include\fuzzyLite;..\..\..\include\fuzzyLite\fuzzylite</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdInc.h</PrecompiledHeaderFile>
</ClCompile>
@@ -131,7 +131,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)..;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>G:\Programowanie\VCMI\libs;G:\Programowanie\VCMI\RD;../;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(OutDir)BattleAI.dll</OutputFile>
</Link>
</ItemDefinitionGroup>

View File

@@ -3,6 +3,7 @@
#include "../../lib/UnlockGuard.h"
#include "../../lib/CObjectHandler.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHerohandler.h"
#define I_AM_ELEMENTAR return CGoal(*this).setisElementar(true)
CLogger &aiLogger = tlog6;
@@ -73,7 +74,7 @@ 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)
std::string CGoal::name() const
{
switch (goalType)
{
@@ -93,26 +94,30 @@ std::string goalName(EGoals goalType)
return "GATHER ARMY";
case BOOST_HERO:
return "BOOST_HERO (unsupported)";
case RECRUIT_HERO:
return "RECRUIT HERO";
case BUILD_STRUCTURE:
return "BUILD STRUCTURE";
case COLLECT_RES:
return "COLLECT RESOURCE";
case GATHER_TROOPS:
return "GATHER TROOPS";
case GET_OBJ:
return "GET OBJECT";
return "GET OBJECT " + objid;
case FIND_OBJ:
return "FIND OBJECT";
return "FIND OBJECT " + objid;
case VISIT_HERO:
return "VISIT HERO";
return "VISIT HERO " + VLC->heroh->heroes[objid]->name;
case GET_ART_TYPE:
return "GET ARTIFACT OF TYPE";
return "GET ARTIFACT OF TYPE " + VLC->arth->artifacts[aid]->Name();
case ISSUE_COMMAND:
return "ISSUE COMMAND (unsupported)";
case VISIT_TILE:
return "VISIT TILE";
return "VISIT TILE " + tile();
case CLEAR_WAY_TO:
return "CLEAR WAY TO";
return "CLEAR WAY TO " + tile();
case DIG_AT_TILE:
return "DIG AT TILE";
return "DIG AT TILE " + tile();
default:
return boost::lexical_cast<std::string>(goalType);
}
@@ -1858,7 +1863,7 @@ void getVisibleNeighbours(const std::vector<int3> &tiles, std::vector<int3> &out
void VCAI::tryRealize(CGoal g)
{
BNLOG("Attempting realizing goal with code %s", goalName(g.goalType));
BNLOG("Attempting realizing goal with code %s", g.name());
switch(g.goalType)
{
case EXPLORE:
@@ -2079,12 +2084,12 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
while(1)
{
CGoal goal = ultimateGoal;
BNLOG("Striving to goal of type %s", goalName(ultimateGoal.goalType));
BNLOG("Striving to goal of type %s", ultimateGoal.name());
int maxGoals = 100; //preventing deadlock for mutually dependent goals
while(!goal.isElementar && !goal.isAbstract && maxGoals)
{
INDENT;
BNLOG("Considering goal %s", goalName(goal.goalType));
BNLOG("Considering goal %s", goal.name());
try
{
boost::this_thread::interruption_point();
@@ -2093,7 +2098,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
}
catch(std::exception &e)
{
BNLOG("Goal %s decomposition failed: %s", goalName(goal.goalType) % e.what());
BNLOG("Goal %s decomposition failed: %s", goal.name() % e.what());
//setGoal (goal.hero, INVALID); //test: if we don't know how to realize goal, we should abandon it for now
return;
}
@@ -2118,7 +2123,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
if (goal.isAbstract)
{
abstractGoal = goal; //allow only one abstract goal per call
BNLOG("Choosing abstract goal %s", goalName(goal.goalType));
BNLOG("Choosing abstract goal %s", goal.name());
break;
}
else
@@ -2139,7 +2144,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
}
catch(std::exception &e)
{
BNLOG("Failed to realize subgoal of type %s (greater goal type was %s), I will stop.", goalName(goal.goalType) % goalName(ultimateGoal.goalType));
BNLOG("Failed to realize subgoal of type %s (greater goal type was %s), I will stop.", goal.name() % ultimateGoal.name());
BNLOG("The error message was: %s", e.what());
break;
}
@@ -2162,7 +2167,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
}
catch(std::exception &e)
{
BNLOG("Goal %s decomposition failed: %s", goalName(goal.goalType) % e.what());
BNLOG("Goal %s decomposition failed: %s", goal.name() % e.what());
//setGoal (goal.hero, INVALID);
return;
}
@@ -2186,7 +2191,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
}
catch(std::exception &e)
{
BNLOG("Failed to realize subgoal of type %s (greater goal type was %s), I will stop.", goalName(goal.goalType) % goalName(ultimateGoal.goalType));
BNLOG("Failed to realize subgoal of type %s (greater goal type was %s), I will stop.", goal.name() % ultimateGoal.name());
BNLOG("The error message was: %s", e.what());
break;
}
@@ -2733,7 +2738,7 @@ int3 whereToExplore(HeroPtr h)
TSubgoal CGoal::whatToDoToAchieve()
{
BNLOG("Decomposing goal of type %s", goalName(goalType));
BNLOG("Decomposing goal of type %s", name());
INDENT;
switch(goalType)
{

View File

@@ -128,6 +128,7 @@ struct CGoal
bool isElementar; SETTER(bool, isElementar)
bool isAbstract; SETTER(bool, isAbstract) //allows to remember abstract goals
int priority; SETTER(bool, priority)
std::string name() const;
virtual TSubgoal whatToDoToAchieve();
@@ -403,8 +404,6 @@ public:
void requestActionASAP(boost::function<void()> whatToDo);
};
std::string goalName(EGoals goalType); //TODO: move to CGoal class?
class cannotFulfillGoalException : public std::exception
{
std::string msg;
@@ -437,7 +436,7 @@ public:
const char *what() const throw () OVERRIDE
{
return goalName(goal.goalType).c_str();
return goal.name().c_str();
}
};

View File

@@ -78,6 +78,12 @@ public:
return false;
return false;
}
inline std::string operator ()() const
{
return "(" + boost::lexical_cast<std::string>(x) +
" " + boost::lexical_cast<std::string>(y) +
" " + boost::lexical_cast<std::string>(z) + ")";
}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & x & y & z;