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.
This commit is contained in:
Matei 2005-12-15 21:59:48 +00:00
parent b14dc940ef
commit 2300a81070
6 changed files with 76 additions and 31 deletions

View File

@ -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 );

View File

@ -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<CStrW>( g_ScriptingHost.GetContext(), argv[0], name ))
{
JS_ReportError( cx, "Invalid template name argument" );
*rval = JSVAL_NULL;

View File

@ -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 )
{

View File

@ -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 )

View File

@ -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 )

View File

@ -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.