1
1
forked from 0ad/0ad
0ad/source/simulation/BaseEntity.cpp
Ykkrosh 0eecb81bac wchar_t/etc fixes
This was SVN commit r692.
2004-07-10 20:56:15 +00:00

126 lines
2.7 KiB
C++
Executable File

#include "precompiled.h"
#include "BaseEntity.h"
#include "ObjectManager.h"
#include "CStr.h"
#include "ps/Xeromyces.h"
CBaseEntity::CBaseEntity()
{
m_base = NULL;
m_base.associate( this, "super" );
m_name.associate( this, "name" );
m_speed.associate( this, "speed" );
m_turningRadius.associate( this, "turningRadius" );
m_bound_circle = NULL;
m_bound_box = NULL;
}
CBaseEntity::~CBaseEntity()
{
if( m_bound_box )
delete( m_bound_box );
if( m_bound_circle )
delete( m_bound_circle );
}
bool CBaseEntity::loadXML( CStr filename )
{
CXeromyces XeroFile;
try
{
XeroFile.Load(filename);
}
catch (...)
{
return false;
}
// Define all the elements and attributes used in the XML file
#define EL(x) int el_##x = XeroFile.getElementID(#x)
#define AT(x) int at_##x = XeroFile.getAttributeID(#x)
EL(entity);
EL(name);
EL(actor);
EL(speed);
EL(turningradius);
EL(size);
EL(footprint);
EL(boundsoffset);
AT(radius);
AT(width);
AT(height);
AT(x);
AT(y);
#undef AT
#undef EL
XMBElement Root = XeroFile.getRoot();
assert(Root.getNodeName() == el_entity);
XMBElementList RootChildren = Root.getChildNodes();
for (int i = 0; i < RootChildren.Count; ++i)
{
XMBElement Child = RootChildren.item(i);
int ChildName = Child.getNodeName();
if (ChildName == el_name)
{
m_name = (CStr)Child.getText();
}
else if (ChildName == el_actor)
{
m_actorObject = g_ObjMan.FindObject( (CStr)Child.getText() );
}
else if (ChildName == el_speed)
{
m_speed = CStr(Child.getText()).ToFloat();
}
else if (ChildName == el_turningradius)
{
m_turningRadius = CStr(Child.getText()).ToFloat();
}
else if (ChildName == el_size)
{
if( !m_bound_circle )
m_bound_circle = new CBoundingCircle();
CStr radius (Child.getAttributes().getNamedItem(at_radius));
m_bound_circle->setRadius( radius.ToFloat() );
m_bound_type = CBoundingObject::BOUND_CIRCLE;
}
else if (ChildName == el_footprint)
{
if( !m_bound_box )
m_bound_box = new CBoundingBox();
CStr width (Child.getAttributes().getNamedItem(at_width));
CStr height (Child.getAttributes().getNamedItem(at_height));
m_bound_box->setDimensions( width.ToFloat(), height.ToFloat() );
m_bound_type = CBoundingObject::BOUND_OABB;
}
else if (ChildName == el_boundsoffset)
{
CStr x (Child.getAttributes().getNamedItem(at_x));
CStr y (Child.getAttributes().getNamedItem(at_y));
if( !m_bound_circle )
m_bound_circle = new CBoundingCircle();
if( !m_bound_box )
m_bound_box = new CBoundingBox();
m_bound_circle->m_offset.x = x.ToFloat();
m_bound_circle->m_offset.y = y.ToFloat();
m_bound_box->m_offset.x = x.ToFloat();
m_bound_box->m_offset.y = y.ToFloat();
}
}
return true;
}