This commit is contained in:
romkazvo
2023-08-07 19:29:24 +08:00
commit 34d6c5d489
4832 changed files with 1389451 additions and 0 deletions

130
Editor/AI/AIManager.cpp Normal file
View File

@@ -0,0 +1,130 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2002.
// -------------------------------------------------------------------------
// File name: aimanager.cpp
// Version: v1.00
// Created: 11/9/2002 by Timur.
// Compilers: Visual Studio.NET
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "AIManager.h"
#include "AIGoalLibrary.h"
#include "AiGoal.h"
#include "AiBehaviorLibrary.h"
#include "IAISystem.h"
#include <IScriptSystem.h>
//////////////////////////////////////////////////////////////////////////
// CAI Manager.
//////////////////////////////////////////////////////////////////////////
CAIManager::CAIManager()
{
m_goalLibrary = new CAIGoalLibrary;
m_behaviorLibrary = new CAIBehaviorLibrary;
}
CAIManager::~CAIManager()
{
delete m_behaviorLibrary;
m_behaviorLibrary = 0;
delete m_goalLibrary;
m_goalLibrary = 0;
}
void CAIManager::Init( ISystem *system )
{
m_aiSystem = system->GetAISystem();
if (!m_aiSystem)
return;
//m_goalLibrary->InitAtomicGoals();
m_behaviorLibrary->LoadBehaviors( "Scripts\\AI\\Behaviors\\" );
//enumerate Anchor actions.
EnumAnchorActions();
}
IAISystem* CAIManager::GetAISystem()
{
return GetIEditor()->GetSystem()->GetAISystem();
}
//////////////////////////////////////////////////////////////////////////
void CAIManager::ReloadScripts()
{
GetBehaviorLibrary()->ReloadScripts();
EnumAnchorActions();
}
//////////////////////////////////////////////////////////////////////////
void CAIManager::GetAnchorActions( std::vector<CString> &actions ) const
{
actions.clear();
for (AnchorActions::const_iterator it = m_anchorActions.begin(); it != m_anchorActions.end(); it++)
{
actions.push_back( it->first );
}
}
//////////////////////////////////////////////////////////////////////////
int CAIManager::AnchorActionToId( const char *sAction ) const
{
AnchorActions::const_iterator it = m_anchorActions.find(sAction);
if (it != m_anchorActions.end())
return it->second;
return -1;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
struct CAIAnchorDump : public IScriptObjectDumpSink
{
CAIManager::AnchorActions actions;
CAIAnchorDump( IScriptObject *obj )
{
m_pScriptObject = obj;
}
virtual void OnElementFound(int nIdx,ScriptVarType type) {}
virtual void OnElementFound(const char *sName,ScriptVarType type)
{
if (type == svtNumber)
{
// New behavior.
int val;
if (m_pScriptObject->GetValue(sName,val))
{
actions[sName] = val;
}
}
}
private:
IScriptObject *m_pScriptObject;
};
//////////////////////////////////////////////////////////////////////////
void CAIManager::EnumAnchorActions()
{
IScriptSystem *pScriptSystem = GetIEditor()->GetSystem()->GetIScriptSystem();
_SmartScriptObject pAIAnchorTable( pScriptSystem,true );
if (pScriptSystem->GetGlobalValue( "AIAnchor",pAIAnchorTable ))
{
CAIAnchorDump anchorDump(pAIAnchorTable);
pAIAnchorTable->Dump( &anchorDump );
m_anchorActions = anchorDump.actions;
}
}

63
Editor/AI/AIManager.h Normal file
View File

@@ -0,0 +1,63 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2002.
// -------------------------------------------------------------------------
// File name: aimanager.h
// Version: v1.00
// Created: 11/9/2002 by Timur.
// Compilers: Visual Studio.NET
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#ifndef __aimanager_h__
#define __aimanager_h__
#if _MSC_VER > 1000
#pragma once
#endif
// forward declarations.
class CAIGoalLibrary;
class CAIBehaviorLibrary;
//////////////////////////////////////////////////////////////////////////
class CAIManager
{
public:
CAIManager();
~CAIManager();
void Init( ISystem *system );
IAISystem* GetAISystem();
CAIGoalLibrary* GetGoalLibrary() { return m_goalLibrary; };
CAIBehaviorLibrary* GetBehaviorLibrary() { return m_behaviorLibrary; };
//////////////////////////////////////////////////////////////////////////
//! AI Anchor Actions enumeration.
void GetAnchorActions( std::vector<CString> &actions ) const;
int AnchorActionToId( const char *sAction ) const;
// Enumerate all AI characters.
//////////////////////////////////////////////////////////////////////////
void ReloadScripts();
private:
void EnumAnchorActions();
CAIGoalLibrary* m_goalLibrary;
CAIBehaviorLibrary* m_behaviorLibrary;
IAISystem* m_aiSystem;
//! AI Anchor Actions.
friend struct CAIAnchorDump;
typedef std::map<CString,int> AnchorActions;
AnchorActions m_anchorActions;
};
#endif // __aimanager_h__

64
Editor/AI/AiBehavior.cpp Normal file
View File

@@ -0,0 +1,64 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: aibehavior.cpp
// Version: v1.00
// Created: 9/4/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "aibehavior.h"
#include "..\Util\FileUtil.h"
#include "IScriptSystem.h"
#include "..\Objects\ObjectManager.h"
//////////////////////////////////////////////////////////////////////////
void CAIBehavior::ReloadScript()
{
// Execute script file in script system.
if (m_script.IsEmpty())
return;
if (CFileUtil::CompileLuaFile( GetScript() ))
{
IScriptSystem *scriptSystem = GetIEditor()->GetSystem()->GetIScriptSystem();
// Script compiled succesfully.
scriptSystem->ReloadScript( m_script );
}
}
//////////////////////////////////////////////////////////////////////////
void CAIBehavior::Edit()
{
CFileUtil::EditTextFile( GetScript() );
}
//////////////////////////////////////////////////////////////////////////
void CAICharacter::ReloadScript()
{
// Execute script file in script system.
if (m_script.IsEmpty())
return;
if (CFileUtil::CompileLuaFile( GetScript() ))
{
IScriptSystem *scriptSystem = GetIEditor()->GetSystem()->GetIScriptSystem();
// Script compiled succesfully.
scriptSystem->ReloadScript( m_script );
}
}
//////////////////////////////////////////////////////////////////////////
void CAICharacter::Edit()
{
CFileUtil::EditTextFile( GetScript() );
}

90
Editor/AI/AiBehavior.h Normal file
View File

@@ -0,0 +1,90 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: aibehavior.h
// Version: v1.00
// Created: 21/3/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#ifndef __aibehavior_h__
#define __aibehavior_h__
#if _MSC_VER > 1000
#pragma once
#endif
/** AI Behavior definition.
*/
class CAIBehavior : public CRefCountBase
{
public:
CAIBehavior() {};
virtual ~CAIBehavior() {};
void SetName( const CString& name ) { m_name = name; }
const CString& GetName() { return m_name; }
//! Set name of script that implements this behavior.
void SetScript( const CString &script ) { m_script = script; };
const CString& GetScript() const { return m_script; };
//! Get human readable description of this goal.
const CString& GetDescription() { return m_description; }
//! Set human readable description of this goal.
void SetDescription( const CString& desc ) { m_description = desc; }
//! Force reload of script file.
void ReloadScript();
//! Start editing script file in Text editor.
void Edit();
private:
CString m_name;
CString m_description;
CString m_script;
};
/** AICharacter behaviour definition.
*/
class CAICharacter : public CRefCountBase
{
public:
CAICharacter() {};
virtual ~CAICharacter() {};
void SetName( const CString& name ) { m_name = name; }
const CString& GetName() { return m_name; }
//! Set name of script that implements this behavior.
void SetScript( const CString &script ) { m_script = script; };
const CString& GetScript() const { return m_script; };
//! Get human readable description of this goal.
const CString& GetDescription() { return m_description; }
//! Set human readable description of this goal.
void SetDescription( const CString& desc ) { m_description = desc; }
//! Force reload of script file.
void ReloadScript();
//! Start editing script file in Text editor.
void Edit();
private:
CString m_name;
CString m_description;
CString m_script;
};
typedef TSmartPtr<CAIBehavior> CAIBehaviorPtr;
typedef TSmartPtr<CAICharacter> CAICharacterPtr;
#endif // __aibehavior_h__

View File

@@ -0,0 +1,278 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: AiBehaviorLibrary.h
// Version: v1.00
// Created: 21/3/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "AiBehaviorLibrary.h"
#include "AiBehavior.h"
#include "IScriptSystem.h"
#define AI_CONFIG_FILE "Scripts\\AI\\aiconfig.lua"
//////////////////////////////////////////////////////////////////////////
struct CAIBehaviorsDump : public IScriptObjectDumpSink
{
CAIBehaviorsDump( CAIBehaviorLibrary* lib,IScriptObject *obj )
{
m_pLibrary = lib;
m_pScriptObject = obj;
}
virtual void OnElementFound(int nIdx,ScriptVarType type) {}
virtual void OnElementFound(const char *sName,ScriptVarType type)
{
if (type == svtString)
{
// New behavior.
const char *scriptFile;
if (m_pScriptObject->GetValue(sName,scriptFile))
{
CAIBehavior *behavior = new CAIBehavior;
behavior->SetName(sName);
CString file = scriptFile;
file.Replace( '/','\\' );
behavior->SetScript(file);
behavior->SetDescription( "" );
m_pLibrary->AddBehavior( behavior );
}
}
}
private:
CAIBehaviorLibrary *m_pLibrary;
IScriptObject *m_pScriptObject;
};
//////////////////////////////////////////////////////////////////////////
struct CAICharactersDump : public IScriptObjectDumpSink
{
CAICharactersDump( CAIBehaviorLibrary* lib,IScriptObject *obj )
{
m_pLibrary = lib;
m_pScriptObject = obj;
}
virtual void OnElementFound(int nIdx,ScriptVarType type) {}
virtual void OnElementFound(const char *sName,ScriptVarType type)
{
if (type == svtString)
{
// New behavior.
const char *scriptFile;
if (m_pScriptObject->GetValue(sName,scriptFile))
{
CAICharacter* c = new CAICharacter;
c->SetName(sName);
CString file = scriptFile;
file.Replace( '/','\\' );
c->SetScript(file);
c->SetDescription( "" );
m_pLibrary->AddCharacter( c );
}
}
}
private:
CAIBehaviorLibrary *m_pLibrary;
IScriptObject *m_pScriptObject;
};
//////////////////////////////////////////////////////////////////////////
// CAIBehaviorLibrary implementation.
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
CAIBehaviorLibrary::CAIBehaviorLibrary()
{
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::AddBehavior( CAIBehavior* behavior )
{
CAIBehaviorPtr g;
if (m_behaviors.Find(behavior->GetName(),g))
{
// Behavior with this name already exist in the library.
}
m_behaviors[behavior->GetName()] = behavior;
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::RemoveBehavior( CAIBehavior* behavior )
{
m_behaviors.Erase( behavior->GetName() );
}
//////////////////////////////////////////////////////////////////////////
CAIBehavior* CAIBehaviorLibrary::FindBehavior( const CString &name ) const
{
CAIBehaviorPtr behavior=0;
m_behaviors.Find( name,behavior );
return behavior;
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::ClearBehaviors()
{
m_behaviors.Clear();
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::LoadBehaviors( const CString &path )
{
m_scriptsPath = path;
ClearBehaviors();
IScriptSystem *pScriptSystem = GetIEditor()->GetSystem()->GetIScriptSystem();
_SmartScriptObject pAIBehaviorTable( pScriptSystem,true );
if (pScriptSystem->GetGlobalValue( "AIBehaviour",pAIBehaviorTable ))
{
_SmartScriptObject pAvailableTable( pScriptSystem,true );
if (pAIBehaviorTable->GetValue( "AVAILABLE",pAvailableTable ))
{
// Enumerate all behaviours.
CAIBehaviorsDump bdump( this,pAvailableTable );
pAvailableTable->Dump( &bdump );
}
}
/*
int i;
XmlParser xmlParser;
// Scan all behavior files.
std::vector<CString> files;
CFileEnum::ScanDirectory( path,"*.ai",files,true );
for (i = 0; i < files.size(); i++)
{
// Load behavior scripts.
CString file = path + files[i];
XmlNodeRef behaviorsNode = xmlParser.parse(file);
if (!behaviorsNode)
continue;
for (int j = 0; j < behaviorsNode->getChildCount(); j++)
{
XmlNodeRef bhNode = behaviorsNode->getChild(j);
CString name,script,desc;
bhNode->getAttr( "Name",name );
bhNode->getAttr( "Script",script );
bhNode->getAttr( "Description",desc );
char fdir[_MAX_PATH];
_splitpath(files[i],0,fdir,0,0 );
CString scriptFile = path + fdir + script;
// New behavior.
CAIBehavior *behavior = new CAIBehavior;
behavior->SetName(name);
behavior->SetScript(scriptFile);
behavior->SetDescription( desc );
AddBehavior( behavior );
}
}
*/
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::GetBehaviors( std::vector<CAIBehaviorPtr> &behaviors )
{
// Load behaviours again.
LoadBehaviors( m_scriptsPath );
m_behaviors.GetAsVector(behaviors);
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::ReloadScripts()
{
LoadBehaviors( m_scriptsPath );
int i;
// Generate uniq set of script files used by behaviors.
std::set<CString> scriptFiles;
std::vector<CAIBehaviorPtr> behaviors;
GetBehaviors( behaviors );
for (i = 0; i < behaviors.size(); i++)
{
scriptFiles.insert( behaviors[i]->GetScript() );
}
IScriptSystem *scriptSystem = GetIEditor()->GetSystem()->GetIScriptSystem();
// Load script files to script system.
for (std::set<CString>::iterator it = scriptFiles.begin(); it != scriptFiles.end(); it++)
{
CString file = *it;
CLogFile::FormatLine( "Loading AI Behavior Script: %s",(const char*)file );
scriptSystem->ExecuteFile( file );
}
// Reload main AI script.
// IScriptSystem *scriptSystem = GetIEditor()->GetSystem()->GetIScriptSystem();
scriptSystem->ExecuteFile( AI_CONFIG_FILE,true,true );
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::LoadCharacters()
{
m_characters.Clear();
IScriptSystem *pScriptSystem = GetIEditor()->GetSystem()->GetIScriptSystem();
_SmartScriptObject pAIBehaviorTable( pScriptSystem,true );
if (pScriptSystem->GetGlobalValue( "AICharacter",pAIBehaviorTable ))
{
_SmartScriptObject pAvailableTable( pScriptSystem,true );
if (pAIBehaviorTable->GetValue( "AVAILABLE",pAvailableTable ))
{
// Enumerate all characters.
CAICharactersDump bdump( this,pAvailableTable );
pAvailableTable->Dump( &bdump );
}
}
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::GetCharacters( std::vector<CAICharacterPtr> &characters )
{
LoadCharacters();
m_characters.GetAsVector(characters);
}
//////////////////////////////////////////////////////////////////////////
CAICharacter* CAIBehaviorLibrary::FindCharacter( const CString &name ) const
{
CAICharacterPtr chr=0;
m_characters.Find( name,chr );
return chr;
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::AddCharacter( CAICharacter* chr )
{
CAICharacterPtr g;
if (m_characters.Find(chr->GetName(),g))
{
// Behavior with this name already exist in the library.
}
m_characters[chr->GetName()] = chr;
}
//////////////////////////////////////////////////////////////////////////
void CAIBehaviorLibrary::RemoveCharacter( CAICharacter* chr )
{
m_characters.Erase( chr->GetName() );
}

View File

@@ -0,0 +1,72 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: aiBehaviorLibrary.h
// Version: v1.00
// Created: 21/3/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#ifndef __aibehaviorlibrary_h__
#define __aibehaviorlibrary_h__
#if _MSC_VER > 1000
#pragma once
#endif
#include "AiBehavior.h"
/*!
* CAIBehaviorLibrary is collection of global AI behaviors.
*/
class CAIBehaviorLibrary
{
public:
CAIBehaviorLibrary();
~CAIBehaviorLibrary() {};
//! Add new behavior to the library.
void AddBehavior( CAIBehavior* behavior );
//! Remove behavior from the library.
void RemoveBehavior( CAIBehavior* behavior );
CAIBehavior* FindBehavior( const CString &name ) const;
//! Clear all behaviors from library.
void ClearBehaviors();
//! Get all stored behaviors as a vector.
void GetBehaviors( std::vector<CAIBehaviorPtr> &behaviors );
//! Load all behaviors from givven path and add them to library.
void LoadBehaviors( const CString &path );
//! Reload behavior scripts.
void ReloadScripts();
//! Get all available characters in system.
void GetCharacters( std::vector<CAICharacterPtr> &characters );
//! Add new behavior to the library.
void AddCharacter( CAICharacter* chr );
//! Remove behavior from the library.
void RemoveCharacter( CAICharacter* chr );
// Finds specified character.
CAICharacter* FindCharacter( const CString &name ) const;
private:
void LoadCharacters();
StdMap<CString,TSmartPtr<CAIBehavior> > m_behaviors;
StdMap<CString,TSmartPtr<CAICharacter> > m_characters;
CString m_scriptsPath;
};
#endif // __aibehaviorlibrary_h__

71
Editor/AI/AiGoal.cpp Normal file
View File

@@ -0,0 +1,71 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: aigoal.h
// Version: v1.00
// Created: 21/3/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "AiGoal.h"
//////////////////////////////////////////////////////////////////////////
// CAIgoal implementation.
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
CAIGoal::CAIGoal()
{
m_atomic = false;
m_modified = false;
}
//////////////////////////////////////////////////////////////////////////
CAIGoal::~CAIGoal()
{
m_atomic = false;
}
//////////////////////////////////////////////////////////////////////////
void CAIGoal::Serialize( XmlNodeRef &node,bool bLoading )
{
if (bLoading)
{
m_stages.clear();
// Loading.
node->getAttr( "Name",m_name );
m_stages.resize( node->getChildCount() );
for (int i = 0; i < node->getChildCount(); i++)
{
// Write goals stages to xml.
CAIGoalStage &stage = m_stages[i];
XmlNodeRef stageNode = node->getChild(i);
stageNode->getAttr( "Blocking",stage.blocking );
stage.params->copyAttributes( stageNode );
stage.params->delAttr( "Blocking" );
}
}
else
{
// Saving.
node->setAttr( "Name",m_name );
for (int i = 0; i < m_stages.size(); i++)
{
// Write goals stages to xml.
CAIGoalStage &stage = m_stages[i];
XmlNodeRef stageNode = node->newChild( stage.name );
stageNode->copyAttributes( stage.params );
stageNode->setAttr( "Blocking",stage.blocking );
}
}
}

95
Editor/AI/AiGoal.h Normal file
View File

@@ -0,0 +1,95 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: aigoal.h
// Version: v1.00
// Created: 21/3/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#ifndef __aigoal_h__
#define __aigoal_h__
#if _MSC_VER > 1000
#pragma once
#endif
/*
* CAIGoalStage is single stage of AI goal.
*/
class CAIGoalStage
{
public:
//! Name of goal used by this stage.
CString name;
//! True if this stage will block goal pipeline execution.
bool blocking;
//! Goal parameters.
XmlNodeRef params;
};
/*!
* CAIGoal contain definition of AI goal pipe.
*/
class CAIGoal : public CRefCountBase
{
public:
CAIGoal();
~CAIGoal();
const CString& GetName() { return m_name; }
void SetName( const CString& name ) { m_name = name; }
//! Get human readable description of this goal.
const CString& GetDescription() { return m_description; }
//! Set human readable description of this goal.
void SetDescription( const CString& desc ) { m_description = desc; }
//////////////////////////////////////////////////////////////////////////
//! Return true if this goal is Atomic goal, (atomic goals defined by system)
bool IsAtomic() const { return m_atomic; };
//! Set this goal as atomic.
void SetAtomic( bool atomic ) { m_atomic = atomic; };
//! Return true if goal was modified by user and should be stored in goal database.
bool IsModified() const { return m_modified; };
// Mark this goal as modified.
void SetModified( bool modified ) { m_modified = modified; }
//! Get number of stages in goal.
int GetStageCount() const { return m_stages.size(); };
//! Get goal stage at specified index.
CAIGoalStage& GetStage( int index ) { return m_stages[index]; }
const CAIGoalStage& GetStage( int index ) const { return m_stages[index]; }
void AddStage( const CAIGoalStage &stage ) { m_stages.push_back(stage); }
//! Template for parameters used in goal.
XmlNodeRef& GetParamsTemplate() { return m_paramsTemplate; };
//! Serialize Goal to/from xml.
void Serialize( XmlNodeRef &node,bool bLoading );
private:
CString m_name;
CString m_description;
std::vector<CAIGoalStage> m_stages;
XmlNodeRef m_attributes;
//! True if its atomic goal.
bool m_atomic;
bool m_modified;
//! Parameters template for this goal.
XmlNodeRef m_paramsTemplate;
};
// Define smart pointer to AIGoal
typedef TSmartPtr<CAIGoal> CAIGoalPtr;
#endif // __aigoal_h__

134
Editor/AI/AiGoalLibrary.cpp Normal file
View File

@@ -0,0 +1,134 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: aigoal.h
// Version: v1.00
// Created: 21/3/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "AiGoalLibrary.h"
#include "AiGoal.h"
#include "AiBehaviorLibrary.h"
#include "IAISystem.h"
#include "AIManager.h"
//////////////////////////////////////////////////////////////////////////
// CAIGoalLibrary implementation.
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
CAIGoalLibrary::CAIGoalLibrary()
{
}
//////////////////////////////////////////////////////////////////////////
void CAIGoalLibrary::InitAtomicGoals()
{
// Create Atomic goals.
IAISystem *ai = GetIEditor()->GetAI()->GetAISystem();
char xmlBuf[32768];
strcpy( xmlBuf,"" );
int num = 0;//ai->EnumAtomicGoals( xmlBuf,sizeof(xmlBuf) );
XmlParser parser;
XmlNodeRef node = parser.parseBuffer( xmlBuf );
//FILE *file = fopen( "c:\\test.xml","wt" );
//fprintf( file,"%s",xmlBuf );
//fclose(file);
if (!node)
return;
for (int i = 0; i < node->getChildCount(); i++)
{
// Create new atomic goal.
XmlNodeRef goalNode = node->getChild(i);
CString goalName = goalNode->getTag();
CString goalDesc;
goalNode->getAttr( "Description",goalDesc );
CAIGoalPtr goal = new CAIGoal;
goal->SetName( goalName );
goal->SetDescription( goalDesc );
goal->SetAtomic(true);
XmlNodeRef params = new CXmlNode("Params");
for (int j = 0; j < goalNode->getChildCount(); j++)
{
params->addChild(goalNode->getChild(j));
}
goal->GetParamsTemplate() = params;
AddGoal( goal );
}
CAIGoalPtr goal = new CAIGoal;
goal->SetName( "Attack" );
goal->SetDescription( "Attacks enemy" );
CAIGoalStage stage;
stage.name = "locate";
stage.blocking = true;
goal->AddStage( stage );
stage.name = "approach";
stage.blocking = true;
goal->AddStage( stage );
stage.name = "pathfind";
stage.blocking = true;
goal->AddStage( stage );
//goal->AddStage(
AddGoal( goal );
}
//////////////////////////////////////////////////////////////////////////
void CAIGoalLibrary::AddGoal( CAIGoal* goal )
{
CAIGoalPtr g;
if (m_goals.Find(goal->GetName(),g))
{
// Goal with this name already exist in the library.
}
m_goals[goal->GetName()] = goal;
}
//////////////////////////////////////////////////////////////////////////
void CAIGoalLibrary::RemoveGoal( CAIGoal* goal )
{
m_goals.Erase( goal->GetName() );
}
//////////////////////////////////////////////////////////////////////////
CAIGoal* CAIGoalLibrary::FindGoal( const CString &name ) const
{
CAIGoalPtr goal=0;
m_goals.Find( name,goal );
return goal;
}
//////////////////////////////////////////////////////////////////////////
void CAIGoalLibrary::ClearGoals()
{
m_goals.Clear();
}
//////////////////////////////////////////////////////////////////////////
void CAIGoalLibrary::LoadGoals( const CString &path )
{
// Scan all goal files.
}
//////////////////////////////////////////////////////////////////////////
void CAIGoalLibrary::GetGoals( std::vector<CAIGoalPtr> &goals ) const
{
m_goals.GetAsVector(goals);
}

58
Editor/AI/AiGoalLibrary.h Normal file
View File

@@ -0,0 +1,58 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: aigoallibrary.h
// Version: v1.00
// Created: 21/3/2002 by Timur.
// Compilers: Visual C++ 7.0
// Description:
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#ifndef __aigoallibrary_h__
#define __aigoallibrary_h__
#if _MSC_VER > 1000
#pragma once
#endif
#include "AiGoal.h"
class CAIBehaviorLibrary;
/*!
* CAIGoalLibrary is collection of global AI goals.
*/
class CAIGoalLibrary
{
public:
CAIGoalLibrary();
~CAIGoalLibrary() {};
//! Add new goal to the library.
void AddGoal( CAIGoal* goal );
//! Remove goal from the library.
void RemoveGoal( CAIGoal* goal );
CAIGoal* FindGoal( const CString &name ) const;
//! Clear all goals from library.
void ClearGoals();
//! Get all stored goals as a vector.
void GetGoals( std::vector<CAIGoalPtr> &goals ) const;
//! Load all goals from givven path and add them to library.
void LoadGoals( const CString &path );
//! Initialize atomic goals from AI system.
void InitAtomicGoals();
private:
StdMap<CString,CAIGoalPtr> m_goals;
};
#endif // __aigoallibrary_h__