forked from 0ad/0ad
3408b078b7
-Added functionality for "casting" and creating net messages (without JS) -Rank textures-specified in XML -Formations-currently don't attack correctly (i.e. travel like mobs) and don't switch to their movement formations when tasked to go somewhere (the pathfinder doesn't give any heads up about destination reached, so there's no way to change back to the original). Also, base switching is untested so no garuntees for next and prior formation things. This was SVN commit r3710.
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
#include "precompiled.h"
|
|
|
|
#include "BaseFormationCollection.h"
|
|
#include "ObjectManager.h"
|
|
#include "Model.h"
|
|
#include "CLogger.h"
|
|
#include "VFSUtil.h"
|
|
|
|
#define LOG_CATEGORY "formation"
|
|
|
|
|
|
void CBaseFormationCollection::LoadFile( const char* path )
|
|
{
|
|
// Build the formation name -> filename mapping. This is done so that
|
|
// the formation 'x' can be in units/x.xml, structures/x.xml, etc, and
|
|
// we don't have to search every directory for x.xml.
|
|
|
|
// Extract the filename out of the path+name+extension.
|
|
// Equivalent to /.*\/(.*)\.xml/, but not as pretty.
|
|
CStrW tag = CStr(path).AfterLast("/").BeforeLast(".xml");
|
|
m_templateFilenames[tag] = path;
|
|
}
|
|
|
|
static void LoadFormationThunk( const char* path, const DirEnt* UNUSED(ent), void* context )
|
|
{
|
|
CBaseFormationCollection* this_ = (CBaseFormationCollection*)context;
|
|
this_->LoadFile(path);
|
|
}
|
|
|
|
int CBaseFormationCollection::loadTemplates()
|
|
{
|
|
// Load all files in entities/formations and subdirectories.
|
|
THROW_ERR( VFSUtil::EnumDirEnts( "entities/formations", VFSUtil::RECURSIVE, "*.xml",
|
|
LoadFormationThunk, this ) );
|
|
return 0;
|
|
}
|
|
|
|
CBaseFormation* CBaseFormationCollection::getTemplate( CStrW name )
|
|
{
|
|
// Check whether this template has already been loaded
|
|
templateMap::iterator it = m_templates.find( name );
|
|
if( it != m_templates.end() )
|
|
return( it->second );
|
|
|
|
// Find the filename corresponding to this template
|
|
templateFilenameMap::iterator filename_it = m_templateFilenames.find( name );
|
|
if( filename_it == m_templateFilenames.end() )
|
|
return( NULL );
|
|
|
|
CStr path( filename_it->second );
|
|
|
|
//Try to load to the formation
|
|
CBaseFormation* newTemplate = new CBaseFormation();
|
|
if( !newTemplate->loadXML( path ) )
|
|
{
|
|
LOG(ERROR, LOG_CATEGORY, "CBaseFormationCollection::loadTemplates(): Couldn't load template \"%s\"", path.c_str());
|
|
return( NULL );
|
|
}
|
|
|
|
LOG(NORMAL, LOG_CATEGORY, "CBaseFormationCollection::loadTemplates(): Loaded template \"%s\"", path.c_str());
|
|
m_templates[name] = newTemplate;
|
|
|
|
return newTemplate;
|
|
}
|
|
|
|
void CBaseFormationCollection::getBaseFormationNames( std::vector<CStrW>& names )
|
|
{
|
|
for( templateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it )
|
|
if( ! (it->first.Length() > 8 && it->first.Left(8) == L"template"))
|
|
names.push_back( it->first );
|
|
}
|
|
|
|
CBaseFormationCollection::~CBaseFormationCollection()
|
|
{
|
|
for( templateMap::iterator it = m_templates.begin(); it != m_templates.end(); ++it )
|
|
delete( it->second );
|
|
}
|