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:
feynman
2013-04-14 15:54:56 +00:00
parent 25de719d79
commit 8f3bff764b
26 changed files with 11543 additions and 9871 deletions
@@ -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.
}
}
}
+21
View File
@@ -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);
}
}
}