mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
Forgot to commit the source changes in the last commit. Sorry. So, here they are.
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5999 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,221 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="ModularizedTacticalAI"
|
||||
ProjectGUID="{FF0A809E-A370-4640-A301-17B76D7A5B4E}"
|
||||
RootNamespace="ModularizedTacticalAI"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="..\ja2.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
GenerateDebugInformation="true"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories=""C:\Documents and Settings\jcd\Desktop\ja2_v1.13\Build\ext\VFS\include""
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\LegacyAIPlan.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\LegacyAIPlanFactory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\NullPlan.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\NullPlanFactory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\PlanFactoryLibrary.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\AbstractPlanFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\LegacyAIPlan.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\LegacyAIPlanFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\NullPlan.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\NullPlanFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Plan.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\PlanFactoryLibrary.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#ifndef ABSTRACT_PLAN_FACTORY_H_
|
||||
#define ABSTRACT_PLAN_FACTORY_H_
|
||||
|
||||
class SOLDIERTYPE;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
/**@class AIInputData
|
||||
* @brief Wrapper class around the environmental data required to build an AI plan
|
||||
*
|
||||
* At the moment, simply a wrapper around SOLDIERTYPE. Future versions might require more data; without the
|
||||
* wrapper, *every* Concrete Factory ever created would need to be changed in this event. With the wrapper, no
|
||||
* change is required at all.
|
||||
*/
|
||||
struct AIInputData
|
||||
{
|
||||
SOLDIERTYPE* npc_to_plan_for_;
|
||||
};
|
||||
class Plan;
|
||||
/**@class AbstractPlanFactory
|
||||
* @brief Abstract Factory. Base class for all plan factories.
|
||||
*
|
||||
* The Abstract Factory design pattern is used to create instances of Plan object hierarchies. The concrete
|
||||
* factories differ not necessarily in the concrete product they produce (as is otherwise the case when using
|
||||
* this design pattern), but in the structure of the compositions (plans are Composites) instead. Public
|
||||
* inheritance is required for two reasons: (a) several sub-class instances are packed in a container, and this
|
||||
* abstract class serves as the container's data type. And (b) implementation of create_plan() and update_plan()
|
||||
* is forced for concrete subclasses.
|
||||
*/
|
||||
class AbstractPlanFactory
|
||||
{
|
||||
private:
|
||||
bool initialize_called_;
|
||||
public:
|
||||
AbstractPlanFactory() : initialize_called_(false) { }
|
||||
bool initialize_called() const { return initialize_called_; }
|
||||
/**@brief Used for delayed initialization of ressource-intensive initialization tasks
|
||||
*
|
||||
* Due to the design of the modularized AI, each factory's constructor must be called, even if the
|
||||
* factory is not used. Therefore, memory- and cpu intensive tasks should not be performed in the
|
||||
* constructor, but in this function instead. It will only be called if the factory is actually
|
||||
* referenced in the AI.ini file.
|
||||
*/
|
||||
virtual void initialize() { };
|
||||
/**@brief Abstract Plan object hierarchy creation function
|
||||
*
|
||||
* The subclasses (i.e., Concrete Factories) implpmenting this routine contain
|
||||
* the decision-making AI core.
|
||||
*
|
||||
* @param input A pointer to a structure containing all required input data in order for the AI
|
||||
* algorithms to perform their task. At the moment, simply a wrapper around SOLDIERTYPE. Future versions
|
||||
* might require other datatypes; without the wrapper, *every* Concrete Factory ever created would need
|
||||
* to be changed in this event.
|
||||
* @return A Plan object tree representing the produced strategy
|
||||
*/
|
||||
virtual Plan* create_plan(const AIInputData& input) = 0;
|
||||
/**@brief Abstract Plan object hierarchy update function, called in order to update an already created
|
||||
* plan
|
||||
*
|
||||
* @param input A pointer to a structure containing all required input data in order for the AI
|
||||
* algorithms to perform their task
|
||||
* @param plan_to_change The Plan object hierarchy that is to be updated
|
||||
*/
|
||||
virtual void update_plan(const AIInputData& input, Plan* plan_to_change) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#ifndef LEGACY_AI_PLAN_H_
|
||||
#define LEGACY_AI_PLAN_H_
|
||||
|
||||
#include "Plan.h"
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
/**@class LegacyAIPlan
|
||||
* @brief Component/Concrete Product. Generates a Plan that executes the AI as it was before modularization.
|
||||
*
|
||||
* A simple encapsulation of the functions TurnBasedHandleNPCAI() and RTHandleAI(), defined in
|
||||
* TacticalAI/AIMain.cpp and TacticalAI/Realtime.cpp, respectively. The AI handles decisions for all kinds of
|
||||
* NPCs (enemies, zombies, civilians, ...)
|
||||
*/
|
||||
class LegacyAIPlan: public Plan
|
||||
{
|
||||
private:
|
||||
public:
|
||||
virtual void execute(bool turn_based, PlanInputData& manipulated_object);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#ifndef LEGACY_AI_PLAN_FACTORY_H_
|
||||
#define LEGACY_AI_PLAN_FACTORY_H_
|
||||
|
||||
#include "AbstractPlanFactory.h"
|
||||
#include <string>
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
/**@class LegacyAIPlanFactory
|
||||
* @brief Concrete Factory. Generates the LegacyAIPlan, making NPCs do exactly what it did before this AI
|
||||
* modularization/re-write.
|
||||
*/
|
||||
class LegacyAIPlanFactory : public AbstractPlanFactory
|
||||
{
|
||||
private:
|
||||
public:
|
||||
static std::string get_name() {return "LegacyAIPlanFactory";}
|
||||
virtual Plan* create_plan(const AIInputData& input);
|
||||
virtual void update_plan(const AIInputData& input, Plan* plan_to_change);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#ifndef NULL_PLAN_H_
|
||||
#define NULL_PLAN_H_
|
||||
|
||||
#include "Plan.h"
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
/**@class NullPlan
|
||||
* @brief Component/Concrete Product. The NullPlan lets makes the NPC executing it do absolutely nothing.
|
||||
*
|
||||
* The purpose of this plan is two-fold. Firstly, it is a good starting point for new plans; to use it
|
||||
* as such, perform a
|
||||
|
||||
* - \c svn copy include/NullPlan.h include/YourPlan.h
|
||||
* - \c svn copy src/NullPlan.cpp src/YourPlan.cpp
|
||||
*
|
||||
* Remember to
|
||||
*
|
||||
* - Adjust the include guards
|
||||
* - A concrete factory using this plan is required in order for it to be used
|
||||
*
|
||||
* And secondly, it is a debugging tool (cf. NullPlanFactory)
|
||||
*/
|
||||
class NullPlan: public Plan
|
||||
{
|
||||
private:
|
||||
public:
|
||||
virtual void execute(bool turn_based, PlanInputData& manipulated_object);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#ifndef NULL_PLAN_FACTORY_H_
|
||||
#define NULL_PLAN_FACTORY_H_
|
||||
|
||||
#include "AbstractPlanFactory.h"
|
||||
#include <string>
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
/**@class NullPlanFactory
|
||||
* @brief Concrete Factory. Generates the NullPlan, making a NPC do absolutely nothing.
|
||||
*
|
||||
* The purpose of this factory is two-fold. Firstly, it is a good starting point for new plan factories; to use
|
||||
* it as such, perform a
|
||||
|
||||
* \c svn copy include/NullPlanFactory.h include/YourPlanFactory.h\n
|
||||
* \c svn copy src/NullPlanFactory.cpp src/YourPlanFactory.cpp
|
||||
*
|
||||
* Remember to
|
||||
* - Adjust the include guards
|
||||
* - Adjust the string returned by get_name()
|
||||
* - Add a line in PlanFactoryLibrary.cpp to create an instance of the new factory in the library's
|
||||
* constructor; otherwise, it won't be accessible via the configuration file.
|
||||
*
|
||||
* And secondly, it is a debugging tool. Change the configuration file to use this AI factory for a certain
|
||||
* AI_INDEX to have said group do... nothing (e.g. to measure performance differences).
|
||||
*/
|
||||
class NullPlanFactory : public AbstractPlanFactory
|
||||
{
|
||||
private:
|
||||
public:
|
||||
static std::string get_name() {return "NullPlanFactory";}
|
||||
virtual Plan* create_plan(const AIInputData& input);
|
||||
virtual void update_plan(const AIInputData& input, Plan* plan_to_change);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#ifndef PLAN_H_
|
||||
#define PLAN_H_
|
||||
|
||||
class SOLDIERTYPE;
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
/**@class PlanInputData
|
||||
* @brief Wrapper class around the entity manipulated through plan execution
|
||||
*
|
||||
* At the moment, simply a wrapper around SOLDIERTYPE. Future versions might require other datatypes; without
|
||||
* the wrapper, *every* Plan subclass ever created would need to be changed in this event. With the wrapper, no
|
||||
* change is required at all.
|
||||
*/
|
||||
struct PlanInputData
|
||||
{
|
||||
SOLDIERTYPE* controlled_npc_;
|
||||
};
|
||||
/**@class Plan
|
||||
* @brief Composite/Abstract Product. Base class for all plan compositions and components.
|
||||
*
|
||||
* The Plan class provides a common interface for both plan compositions and plan components.
|
||||
*/
|
||||
class Plan
|
||||
{
|
||||
private:
|
||||
public:
|
||||
/** @brief Plan execution is the encapsulation of an action sequence, making up higher-level building blocks
|
||||
*
|
||||
* Each plan objects represents a high-level action, implemented by means of lower-level actions. These
|
||||
* lower level actions can be other Plans subtypes; at some point, a Plan object has no further
|
||||
* sub-plans, i.e., the objet is no composition, but a component, forming a leaf in the Plan hierarchy.
|
||||
* The components' lower level actions are formed by the fundamental npc actions made available outside
|
||||
* the AI framework.
|
||||
*
|
||||
* @param turn_based true if turn-based mode is active, false for real-time mode
|
||||
* @param manipulated_object Encapsulation of around object(s) a plan may manipulate.
|
||||
*/
|
||||
virtual void execute(bool turn_based, PlanInputData& manipulated_object) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#ifndef PLAN_FACTORY_LIBRARY_H_
|
||||
#define PLAN_FACTORY_LIBRARY_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
// forward declarations
|
||||
class AbstractPlanFactory;
|
||||
class Plan;
|
||||
struct AIInputData;
|
||||
|
||||
/**@class PlanFactoryLibrary
|
||||
* @brief Singleton. A "library" containing all available PlanFactories, accessible via the strings returned by
|
||||
* their get_name() function.
|
||||
*
|
||||
*/
|
||||
class PlanFactoryLibrary
|
||||
{
|
||||
private:
|
||||
static PlanFactoryLibrary* instance_;
|
||||
std::map<std::string, AbstractPlanFactory*> registred_factories_;
|
||||
std::deque<AbstractPlanFactory*> ai_index_to_factory_mapping_;
|
||||
PlanFactoryLibrary();
|
||||
public:
|
||||
static PlanFactoryLibrary* instance();
|
||||
Plan* create_plan(size_t index, AIInputData& input) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
API Documentation
|
||||
=================
|
||||
The API documentation is available in the source code repository under
|
||||
./Developer_Docs/ModularizedAI/html/index.html
|
||||
|
||||
|
||||
Coding style guidelines
|
||||
=======================
|
||||
When modifying or adding to the code in ModularizedTacticalAI, plese adhere to
|
||||
the following rules in order to keep the place tidy.
|
||||
|
||||
- Do indent code blocks by 4 spaces
|
||||
- Do not use tabs; they are interpreted differently on each platform, messing up the indention
|
||||
- Do not #include compilation units (cpp files). Doing so will lead to you facing the firing squad.
|
||||
- Do try to limit the number of include files to what is really needed. If a lot is needed, consider using the Pimpl
|
||||
idiom.
|
||||
- Do not use leading underscores or double underscores. They are reserved for compiler implementation.
|
||||
- Do document your code using Doxygen-style comments, and update the doxygen documentation by running doxygen in the
|
||||
ModularizedTacticalAI directory.
|
||||
- Do use identifier names that reflect what you are doing.
|
||||
- Do use CamelCase for classes, and all_lowercase_characters() for function names and attributes
|
||||
- Do use one trailing underscore for class_members_
|
||||
- Do not event think about adding a global variable, goto, macros (unless absolutely needed) or other BS.
|
||||
- Do follow the C++ specifications, as in ISO 14882
|
||||
- Do, if you feel that these guidelines are an impediment for your work, discuss alternatives at bears-pit.com
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#include "../include/LegacyAIPlan.h"
|
||||
|
||||
#include "../../TacticalAI/ai.h" // for EndAIGuysTurn
|
||||
|
||||
|
||||
// Forward declarations for the two legacy functions called here
|
||||
void RTHandleAI( SOLDIERTYPE * pSoldier ); // defined in TacticalAI/Realtime.cpp
|
||||
void TurnBasedHandleNPCAI(SOLDIERTYPE *pSoldier); // defined in TacticalAI/AIMain.cpp
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
void LegacyAIPlan::execute(bool turn_based, PlanInputData& manipulated_object)
|
||||
{
|
||||
if(turn_based)
|
||||
TurnBasedHandleNPCAI(manipulated_object.controlled_npc_);
|
||||
else
|
||||
RTHandleAI(manipulated_object.controlled_npc_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
#include "../include/LegacyAIPlanFactory.h"
|
||||
#include "../include/LegacyAIPlan.h"
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
Plan* LegacyAIPlanFactory::create_plan(const AIInputData& input)
|
||||
{
|
||||
return new LegacyAIPlan();
|
||||
}
|
||||
|
||||
void LegacyAIPlanFactory::update_plan(const AIInputData& input, Plan* plan_to_change)
|
||||
{
|
||||
// TODO: currently, everything is handled in the LegacyAIPlan. The goal is to modularize the AI, so that in
|
||||
// the end, the LegacyAIPlan is split into so many "new" AI Plan subclasses, that every case is covered.
|
||||
// Then the behavior of the old AI would be implemented here.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#include "../include/NullPlan.h"
|
||||
|
||||
#include "../../TacticalAI/ai.h" // for EndAIGuysTurn
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
/// Simply end the turn for the npc passed in the manipulated_object wrapper, then return.
|
||||
void NullPlan::execute(bool turn_based, PlanInputData& manipulated_object)
|
||||
{
|
||||
EndAIGuysTurn(manipulated_object.controlled_npc_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#include "../include/NullPlanFactory.h"
|
||||
#include "../include/NullPlan.h"
|
||||
#include "../Tactical/Soldier Control.h"
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
Plan* NullPlanFactory::create_plan(const AIInputData& input)
|
||||
{
|
||||
return new NullPlan();
|
||||
}
|
||||
|
||||
void NullPlanFactory::update_plan(const AIInputData& input, Plan* plan_to_change)
|
||||
{
|
||||
// the idea is to do nothing, so let's do it...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @file
|
||||
* @author feynman (bears-pit.com)
|
||||
*/
|
||||
|
||||
#include "../include/PlanFactoryLibrary.h"
|
||||
#include "../include/NullPlanFactory.h"
|
||||
#include "../include/LegacyAIPlanFactory.h"
|
||||
// XXX Add includes for new factories here XXX
|
||||
|
||||
|
||||
#include "../../Utils/INIReader.h"
|
||||
|
||||
#undef max // Who the fuck writes MACROS not using CAPITAL LETTERS??? You, sir, have lost your coding license. Please hand over your compiler and leave. Now.
|
||||
|
||||
#include <stdexcept>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace AI
|
||||
{
|
||||
namespace tactical
|
||||
{
|
||||
PlanFactoryLibrary* PlanFactoryLibrary::instance_ = 0;
|
||||
|
||||
/*@brief Initialize all PlanFactories and map them to the slots defined by the configuration file
|
||||
*
|
||||
* This is the place where new factories need to be "registred" in order for them to be available using the
|
||||
* settings in AI.ini
|
||||
*/
|
||||
PlanFactoryLibrary::PlanFactoryLibrary()
|
||||
{
|
||||
|
||||
// ================================================================================
|
||||
// XXX vv Add new factory registrations here vv XXX
|
||||
|
||||
registred_factories_[NullPlanFactory::get_name()] = new NullPlanFactory();
|
||||
registred_factories_[LegacyAIPlanFactory::get_name()] = new LegacyAIPlanFactory();
|
||||
|
||||
// XXX ^^ Add new factory registrations here ^^ XXX
|
||||
// ================================================================================
|
||||
|
||||
CIniReader ini_reader("AI.ini", true);
|
||||
size_t num_slots = ini_reader.ReadInteger("Modularized Tactical AI", "NumFactories", 0, 0, std::numeric_limits<int>::max());
|
||||
for(size_t i(0); i<num_slots; ++i)
|
||||
{
|
||||
std::stringstream slot_index;
|
||||
slot_index<<"Factory_"<<i;
|
||||
std::string factory_name = ini_reader.ReadString("Modularized Tactical AI", const_cast<char*>(slot_index.str().c_str()), "LegacyAIFactory");
|
||||
ai_index_to_factory_mapping_.push_back(registred_factories_[factory_name]);
|
||||
if(!ai_index_to_factory_mapping_.back()->initialize_called())
|
||||
ai_index_to_factory_mapping_.back()->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief If no instance exists yet, create it. Return a pointer to the only existing instance of this library.
|
||||
* @return Pointer to the only instance of the PlanFactoryLibrary
|
||||
*/
|
||||
PlanFactoryLibrary* PlanFactoryLibrary::instance()
|
||||
{
|
||||
if(instance_ == 0)
|
||||
instance_ = new PlanFactoryLibrary();
|
||||
return instance_;
|
||||
}
|
||||
|
||||
/**@brief Create a plan for the given input using the factory at the given index
|
||||
* @param index Index of the concrete plan factory to use, set in the constructor via ini settings
|
||||
* @param input The environmental data required for a factory to plan
|
||||
* @throws std::out_of_range for invalid index
|
||||
* @throws std::logic_error for valid index, but undefined factory (most likely due to typo in AI.ini)
|
||||
* @return Pointer to the only instance of the PlanFactoryLibrary
|
||||
*/
|
||||
Plan* PlanFactoryLibrary::create_plan(size_t index, AIInputData& input) const
|
||||
{
|
||||
if(index >= ai_index_to_factory_mapping_.size())
|
||||
throw std::out_of_range("PlanFactoryLibrary detected invalid factory index");
|
||||
if(!ai_index_to_factory_mapping_[index])
|
||||
throw std::logic_error("PlanFactoryLibrary encountered a nullptr for a valid index (typo in AI.ini?)");
|
||||
return ai_index_to_factory_mapping_[index]->create_plan(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user