#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; if (XeroFile.Load(filename) != PSRETURN_OK) // Fail 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(graphicsoffset); 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_graphicsoffset) { CStr x (Child.getAttributes().getNamedItem(at_x)); CStr y (Child.getAttributes().getNamedItem(at_y)); m_graphicsOffset.x = x.ToFloat(); m_graphicsOffset.y = y.ToFloat(); } } return true; }