From 2300a810705d4141acf6bbe6b6b47cbd1c5c1e4d Mon Sep 17 00:00:00 2001 From: Matei Date: Thu, 15 Dec 2005 21:59:48 +0000 Subject: [PATCH] C++ code changes for new entities (mostly referring to the right new properties or XML attributes in CEntity.cpp and CBaseEntity.cpp). This was SVN commit r3249. --- source/ps/Interact.cpp | 6 +++ source/scripting/ScriptGlue.cpp | 2 +- source/simulation/BaseEntity.cpp | 89 +++++++++++++++++++++----------- source/simulation/Collision.cpp | 1 + source/simulation/Entity.cpp | 8 ++- source/simulation/Entity.h | 1 + 6 files changed, 76 insertions(+), 31 deletions(-) diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index 40ff309fe7..ddd563bb39 100755 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -1074,6 +1074,12 @@ bool CBuildingPlacer::activate(CStrW& templateName) CBaseEntity* base = g_EntityTemplateCollection.getTemplate( m_templateName ); + if( !base ) + { + deactivate(); + return false; + } + // m_actor CStr actorName ( base->m_actorName ); // convert CStrW->CStr8 m_actor = g_UnitMan.CreateUnit( actorName, 0 ); diff --git a/source/scripting/ScriptGlue.cpp b/source/scripting/ScriptGlue.cpp index 89bdf6d173..61aa038988 100755 --- a/source/scripting/ScriptGlue.cpp +++ b/source/scripting/ScriptGlue.cpp @@ -752,7 +752,7 @@ JSBool startPlacing( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, j name = L"hele_ho"; // save some typing during testing } else { - if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], name )) + if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], name )) { JS_ReportError( cx, "Invalid template name argument" ); *rval = JSVAL_NULL; diff --git a/source/simulation/BaseEntity.cpp b/source/simulation/BaseEntity.cpp index 5a93d18423..8591a42f78 100755 --- a/source/simulation/BaseEntity.cpp +++ b/source/simulation/BaseEntity.cpp @@ -28,7 +28,7 @@ CBaseEntity::CBaseEntity() AddProperty( L"actions.heal.speed", &( m_heal.m_Speed ) ); AddProperty( L"actor", &m_actorName ); AddProperty( L"traits.extant", &m_extant ); - AddProperty( L"traits.corpse", &m_corpse ); + AddProperty( L"traits.corpse", &m_corpse ); AddProperty( L"traits.health.curr", &m_healthCurr ); AddProperty( L"traits.health.max", &m_healthMax ); AddProperty( L"traits.health.bar_height", &m_healthBarHeight ); @@ -167,13 +167,14 @@ bool CBaseEntity::loadXML( CStr filename ) // Only the ones we can't load using normal methods. EL(entity); EL(script); - EL(footprint); EL(event); + EL(traits); + EL(footprint); + EL(depth); + EL(height); + EL(radius); + EL(width); AT(parent); - AT(radius); - AT(width); - AT(depth); - AT(height); AT(on); AT(file); AT(function); @@ -212,32 +213,62 @@ bool CBaseEntity::loadXML( CStr filename ) if( Inline.Length() ) g_ScriptingHost.RunMemScript(Inline.c_str(), Inline.Length(), filename.c_str(), Child.getLineNumber()); } - else if (ChildName == el_footprint) + else if (ChildName == el_traits) { - if( Child.getAttributes().getNamedItem( at_radius ).length() ) + XMBElementList TraitChildren = Child.getChildNodes(); + for(int j = 0; j < TraitChildren.Count; ++j) { - // Specifying a circular footprint - if( !m_bound_circle ) - m_bound_circle = new CBoundingCircle(); - CStrW radius (Child.getAttributes().getNamedItem(at_radius)); - CStrW height (Child.getAttributes().getNamedItem(at_height)); - - m_bound_circle->setRadius( radius.ToFloat() ); - m_bound_circle->setHeight( height.ToFloat() ); - m_bound_type = CBoundingObject::BOUND_CIRCLE; - } - else - { - if( !m_bound_box ) - m_bound_box = new CBoundingBox(); - CStrW width (Child.getAttributes().getNamedItem(at_width)); - CStrW depth (Child.getAttributes().getNamedItem(at_depth)); - CStrW height (Child.getAttributes().getNamedItem(at_height)); - - m_bound_box->setDimensions( width.ToFloat(), depth.ToFloat() ); - m_bound_box->setHeight( height.ToFloat() ); - m_bound_type = CBoundingObject::BOUND_OABB; + XMBElement TraitChild = TraitChildren.item(j); + int TraitChildName = TraitChild.getNodeName(); + if( TraitChildName == el_footprint ) + { + XMBElementList FootprintChildren = TraitChild.getChildNodes(); + float radius=0, height=0, width=0, depth=0; + bool hadRadius = false, hadDepth = false; + for(int k = 0; k < FootprintChildren.Count; ++k) + { + XMBElement FootprintChild = FootprintChildren.item(k); + int FootprintChildName = FootprintChild.getNodeName(); + if( FootprintChildName == el_radius ) + { + hadRadius = true; + radius = CStrW( FootprintChild.getText() ).ToFloat(); + } + else if( FootprintChildName == el_width ) + { + width = CStrW( FootprintChild.getText() ).ToFloat(); + } + else if( FootprintChildName == el_height ) + { + height = CStrW( FootprintChild.getText() ).ToFloat(); + } + else if( FootprintChildName == el_depth ) + { + hadDepth = true; + depth = CStrW( FootprintChild.getText() ).ToFloat(); + } + } + if( hadRadius ) + { + // Specifying a circular footprint + if( !m_bound_circle ) + m_bound_circle = new CBoundingCircle(); + m_bound_circle->setRadius( radius ); + m_bound_circle->setHeight( height ); + m_bound_type = CBoundingObject::BOUND_CIRCLE; + } + else if( hadDepth ) + { + if( !m_bound_box ) + m_bound_box = new CBoundingBox(); + m_bound_box->setDimensions( width, depth ); + m_bound_box->setHeight( height ); + m_bound_type = CBoundingObject::BOUND_OABB; + } + } } + // important so that scripts can see traits + XMLLoadProperty( XeroFile, Child, CStrW() ); } else if( ChildName == el_event ) { diff --git a/source/simulation/Collision.cpp b/source/simulation/Collision.cpp index a71b16d326..ecd268bf22 100755 --- a/source/simulation/Collision.cpp +++ b/source/simulation/Collision.cpp @@ -162,6 +162,7 @@ void GetProjectileIntersection( const CVector2D& position, const CVector2D& axis for( it = entities.begin(); it != entities.end(); it++ ) { CBoundingObject* obj = (*it)->m_bounds; + if( !obj ) continue; delta = obj->m_pos - position; closestApproach = delta.betadot( axis ); if( fabs( closestApproach ) > obj->m_radius ) diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 3404908f6c..db07284d33 100755 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -50,7 +50,7 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation ) AddProperty( L"actions.heal.speed", &( m_heal.m_Speed ) ); AddProperty( L"position", &m_graphics_position, false, (NotifyFn)&CEntity::teleport ); AddProperty( L"orientation", &m_graphics_orientation, false, (NotifyFn)&CEntity::reorient ); - AddProperty( L"player", &m_player ); + AddProperty( L"player", &m_player, false, (NotifyFn)&CEntity::playerChanged ); AddProperty( L"traits.health.curr", &m_healthCurr ); AddProperty( L"traits.health.max", &m_healthMax ); AddProperty( L"traits.health.bar_height", &m_healthBarHeight ); @@ -586,6 +586,12 @@ void CEntity::teleport() repath(); } +void CEntity::playerChanged() +{ + if( m_actor ) + m_actor->GetModel()->SetPlayerID( m_player->GetPlayerID() ); +} + void CEntity::checkSelection() { if( m_selected ) diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index 9c4cddfd9b..7a83682d1e 100755 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -222,6 +222,7 @@ public: // Reset properties after the entity-template we use changes. void loadBase(); + void playerChanged(); // Fixes player colour if player is changed by script void reorient(); // Orientation void teleport(); // Fixes things if the position is changed by something externally. void checkSelection(); // In case anyone tries to select/deselect this through JavaScript.