forked from 0ad/0ad
# Housekeeping and pathfinder enhancements / optimization when dealing with ranged actions.
- Modified Xeromyces to no longer automatically convert element and attribute names to lowercase, so that we can have camelCase names. We should now be able to convert all the multi-word entity properties, like pass_through_allies, to camelCase, like passThroughAllies, which is more consistent with the rest of our JavaScript naming conventions. To support the existing code that assumes lowercase element names, I made the getElementID and getAttributeID methods (used in the EL and AT macros) ignore case, and I changed any code that directly accessed element names to use the right case. CEntityTemplate now converts Names_LikeThis to names_likeThis (changing each separate "word" in the name to camelCase). Changed the version letter in XMB filenames from A to B to support this without requiring people to delete old XMBs. - Enhanced the pathfinder's handling of contact paths, resulting in a very large speedup for actions like attacking, construction, etc. The problem was that the pathfinder used to not count a given state as the goal unless it was exactly coincident with the target location. This is fine when you order a unit to go exactly to a certain spot, but if you're ordering a unit to build, gather or attack something, then the target tile is impassable (because your target is there) and therefore the pathfinder never declares a state final. As a result, the pathfinder tries hundreds of extra tiles in case there is a long path that gets to the goal, and after failing to find any path that reaches the goal, it gives you one to the closest point it got to. To fix it, I made the pathfinder take into account a radius around the goal in which it's OK to be, which depends on the size of the target unit and the range of your action. This was SVN commit r4186.
This commit is contained in:
parent
f76d0ffdc6
commit
44fe226dd2
@ -313,7 +313,7 @@ void CXMLReader::Init(const CStr& xml_filename)
|
||||
#undef EL
|
||||
|
||||
XMBElement root = xmb_file.getRoot();
|
||||
debug_assert(xmb_file.getElementString(root.getNodeName()) == "scenario");
|
||||
debug_assert(xmb_file.getElementString(root.getNodeName()) == "Scenario");
|
||||
nodes = root.getChildNodes();
|
||||
|
||||
// find out total number of entities+nonentities
|
||||
@ -643,21 +643,21 @@ int CXMLReader::ProgressiveRead()
|
||||
{
|
||||
XMBElement node = nodes.item(node_idx);
|
||||
CStr name = xmb_file.getElementString(node.getNodeName());
|
||||
if (name == "environment")
|
||||
if (name == "Environment")
|
||||
{
|
||||
ReadEnvironment(node);
|
||||
}
|
||||
else if (name == "camera")
|
||||
else if (name == "Camera")
|
||||
{
|
||||
ReadCamera(node);
|
||||
}
|
||||
else if (name == "entities")
|
||||
else if (name == "Entities")
|
||||
{
|
||||
ret = ReadEntities(node, end_time);
|
||||
if (ret != 0) // error or timed out
|
||||
return ret;
|
||||
}
|
||||
else if (name == "nonentities")
|
||||
else if (name == "Nonentities")
|
||||
{
|
||||
ret = ReadNonEntities(node, end_time);
|
||||
if (ret != 0) // error or timed out
|
||||
|
@ -34,7 +34,7 @@ CTerrainPropertiesPtr CTerrainProperties::FromXML(CTerrainPropertiesPtr parent,
|
||||
CStr rootName = XeroFile.getElementString(root.getNodeName());
|
||||
|
||||
// Check that we've got the right kind of xml document
|
||||
if (rootName != "terrains")
|
||||
if (rootName != "Terrains")
|
||||
{
|
||||
LOG(ERROR,
|
||||
LOG_CATEGORY,
|
||||
|
@ -89,7 +89,7 @@ int XMBFile::getElementID(const char* Name) const
|
||||
{
|
||||
// See if this could be the right string, checking its
|
||||
// length and then its contents
|
||||
if (*(int*)Pos == len && memcmp(Pos+4, Name, len) == 0)
|
||||
if (*(int*)Pos == len && strnicmp(Pos+4, Name, len) == 0)
|
||||
return i;
|
||||
// If not, jump to the next string
|
||||
Pos += 4 + *(int*)Pos;
|
||||
@ -109,7 +109,7 @@ int XMBFile::getAttributeID(const char* Name) const
|
||||
{
|
||||
// See if this could be the right string, checking its
|
||||
// length and then its contents
|
||||
if (*(int*)Pos == len && memcmp(Pos+4, Name, len) == 0)
|
||||
if (*(int*)Pos == len && strnicmp(Pos+4, Name, len) == 0)
|
||||
return i;
|
||||
// If not, jump to the next string
|
||||
Pos += 4 + *(int*)Pos;
|
||||
|
@ -142,7 +142,7 @@ private:
|
||||
|
||||
|
||||
CXeromyces::CXeromyces()
|
||||
: XMBFileHandle(0), XMBBuffer(NULL)
|
||||
: XMBFileHandle(0), XMBBuffer(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -248,7 +248,7 @@ PSRETURN CXeromyces::Load(const char* filename)
|
||||
|
||||
const int bufLen = 22;
|
||||
char buf[bufLen+1];
|
||||
if (sprintf(buf, "_%08x%08xA.xmb", (int)xmlStat.st_mtime & ~1, (int)xmlStat.st_size) != bufLen)
|
||||
if (sprintf(buf, "_%08x%08xB.xmb", (int)xmlStat.st_mtime & ~1, (int)xmlStat.st_size) != bufLen)
|
||||
{
|
||||
debug_warn("Failed to create filename (?!)");
|
||||
return PSRETURN_Xeromyces_XMLOpenFailed;
|
||||
@ -373,6 +373,7 @@ void XeroHandler::endDocument()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
// Silently clobbers non-ASCII characters
|
||||
std::string lowercase_ascii(const XMLCh *a)
|
||||
{
|
||||
@ -383,10 +384,31 @@ std::string lowercase_ascii(const XMLCh *a)
|
||||
b[i] = (char)towlower(a[i]);
|
||||
return b;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return an ASCII version of the given 16-bit string, ignoring
|
||||
* any non-ASCII characters.
|
||||
*
|
||||
* @param const XMLCh * a Input string.
|
||||
* @return std::string 8-bit ASCII version of <code>a</code>.
|
||||
**/
|
||||
std::string toAscii( const XMLCh* a )
|
||||
{
|
||||
std::string b;
|
||||
uint len=XMLString::stringLen(a);
|
||||
b.reserve(len);
|
||||
for (uint i = 0; i < len; ++i)
|
||||
{
|
||||
if(iswascii(a[i]))
|
||||
b += (char) a[i];
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
void XeroHandler::startElement(const XMLCh* const UNUSED(uri), const XMLCh* const localname, const XMLCh* const UNUSED(qname), const Attributes& attrs)
|
||||
{
|
||||
std::string elementName = lowercase_ascii(localname);
|
||||
std::string elementName = toAscii(localname);
|
||||
ElementNames.insert(elementName);
|
||||
|
||||
// Create a new element
|
||||
@ -397,7 +419,7 @@ void XeroHandler::startElement(const XMLCh* const UNUSED(uri), const XMLCh* cons
|
||||
// Store all the attributes in the new element
|
||||
for (unsigned int i = 0; i < attrs.getLength(); ++i)
|
||||
{
|
||||
std::string attrName = lowercase_ascii(attrs.getLocalName(i));
|
||||
std::string attrName = toAscii(attrs.getLocalName(i));
|
||||
AttributeNames.insert(attrName);
|
||||
XMLAttribute* a = new XMLAttribute;
|
||||
a->name = attrName;
|
||||
|
@ -63,12 +63,13 @@ CAStarEngine::~CAStarEngine()
|
||||
|
||||
|
||||
bool CAStarEngine::findPath(
|
||||
const CVector2D &src, const CVector2D &dest, CPlayer* player )
|
||||
const CVector2D &src, const CVector2D &dest, CPlayer* player, float radius )
|
||||
{
|
||||
mSolved = false;
|
||||
int iterations = 0;
|
||||
|
||||
mGoal->setDestination(dest);
|
||||
mGoal->setRadius(radius);
|
||||
|
||||
AStarNode *start = getFreeASNode();
|
||||
start->coord = mGoal->getTile(src);
|
||||
@ -327,19 +328,32 @@ void AStarGoalLowLevel::setDestination( const CVector2D &dest )
|
||||
coord = WorldspaceToTilespace(dest);
|
||||
}
|
||||
|
||||
|
||||
void AStarGoalLowLevel::setRadius( float r )
|
||||
{
|
||||
radius = r;
|
||||
}
|
||||
|
||||
float AStarGoalLowLevel::getRadius()
|
||||
{
|
||||
return radius;
|
||||
}
|
||||
|
||||
float AStarGoalLowLevel::distanceToGoal( const CVector2D &loc )
|
||||
{
|
||||
return 3*((coord-loc).length());
|
||||
return ((coord-loc).length());
|
||||
}
|
||||
|
||||
bool AStarGoalLowLevel::atGoal( const CVector2D &loc )
|
||||
{
|
||||
return (coord.x == loc.x) && (coord.y == loc.y);
|
||||
float dx = coord.x - loc.x;
|
||||
float dy = coord.y - loc.y;
|
||||
return dx*dx + dy*dy <= radius*radius;
|
||||
}
|
||||
|
||||
float AStarGoalLowLevel::getTileCost( const CVector2D& loc1, const CVector2D& loc2 )
|
||||
{
|
||||
return (loc2-loc1).length();
|
||||
return (loc2-loc1).length() - radius;
|
||||
}
|
||||
|
||||
bool AStarGoalLowLevel::isPassable( const CVector2D &loc, CPlayer* player )
|
||||
|
@ -64,7 +64,7 @@ public:
|
||||
|
||||
void setGoal(AStarGoalBase* goal) { mGoal = goal; }
|
||||
|
||||
bool findPath( const CVector2D& src, const CVector2D& dest, CPlayer* player=0 );
|
||||
bool findPath( const CVector2D& src, const CVector2D& dest, CPlayer* player=0, float radius=0.0f );
|
||||
std::vector<CVector2D> getLastPath();
|
||||
|
||||
// The maximum number of nodes that will be expanded before failure is declared
|
||||
@ -116,12 +116,19 @@ private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* An A* goal consists of a destination tile and a radius within which a
|
||||
* unit must get to the destination. The radius is necessary because for
|
||||
* actions on a target unit, like attacking or building, the destination
|
||||
* tile is obstructed by that unit and what we really want is not to get
|
||||
* to that tile but to get close enough to perform our action.
|
||||
**/
|
||||
class AStarGoalBase
|
||||
{
|
||||
public:
|
||||
AStarGoalBase() {}
|
||||
virtual void setDestination( const CVector2D& ) = 0;
|
||||
virtual void setRadius( float r ) = 0;
|
||||
virtual float distanceToGoal( const CVector2D& ) = 0;
|
||||
virtual bool atGoal( const CVector2D& ) = 0;
|
||||
virtual float getTileCost( const CVector2D&, const CVector2D& ) = 0;
|
||||
@ -129,13 +136,15 @@ public:
|
||||
virtual std::vector<CVector2D> getNeighbors( const CVector2D&, CPlayer* player=0 ) = 0;
|
||||
virtual CVector2D getCoord( const CVector2D& ) = 0;
|
||||
virtual CVector2D getTile( const CVector2D& ) = 0;
|
||||
virtual float getRadius() = 0;
|
||||
};
|
||||
|
||||
class AStarGoalLowLevel : public AStarGoalBase
|
||||
{
|
||||
public:
|
||||
AStarGoalLowLevel() {}
|
||||
AStarGoalLowLevel(): radius(0.0f) {}
|
||||
void setDestination( const CVector2D& dest );
|
||||
void setRadius( float r );
|
||||
float distanceToGoal( const CVector2D& loc );
|
||||
bool atGoal( const CVector2D& loc );
|
||||
float getTileCost( const CVector2D& loc1, const CVector2D& loc2 );
|
||||
@ -143,8 +152,10 @@ public:
|
||||
std::vector<CVector2D> getNeighbors( const CVector2D& loc, CPlayer* player=0 );
|
||||
CVector2D getCoord( const CVector2D& loc);
|
||||
CVector2D getTile( const CVector2D& loc);
|
||||
float getRadius();
|
||||
private:
|
||||
CVector2D coord;
|
||||
float radius;
|
||||
};
|
||||
|
||||
class CAStarEngineLowLevel : public CAStarEngine
|
||||
|
@ -49,6 +49,7 @@ CEntity* GetCollisionObject( float x, float y )
|
||||
CBoundingObject* getCollisionObject( CBoundingObject* bounds, CPlayer* player, const CStrW* ignoreClass )
|
||||
{
|
||||
std::vector<CEntity*> entities;
|
||||
entities.reserve(8);
|
||||
g_EntityManager.GetInRange( bounds->m_pos.x, bounds->m_pos.y, COLLISION_RANGE, entities );
|
||||
std::vector<CEntity*>::iterator it;
|
||||
|
||||
@ -76,6 +77,7 @@ CBoundingObject* getCollisionObject( CBoundingObject* bounds, CPlayer* player, c
|
||||
CEntity* getCollisionEntity( CBoundingObject* bounds, CPlayer* player, const CStrW* ignoreClass )
|
||||
{
|
||||
std::vector<CEntity*> entities;
|
||||
entities.reserve(8);
|
||||
g_EntityManager.GetInRange( bounds->m_pos.x, bounds->m_pos.y, COLLISION_RANGE, entities );
|
||||
std::vector<CEntity*>::iterator it;
|
||||
|
||||
@ -108,6 +110,7 @@ HEntity getCollisionObject( CEntity* entity )
|
||||
#endif
|
||||
|
||||
std::vector<CEntity*> entities;
|
||||
entities.reserve(8);
|
||||
g_EntityManager.GetInRange( entity->m_position.X, entity->m_position.Z, COLLISION_RANGE, entities );
|
||||
std::vector<CEntity*>::iterator it;
|
||||
|
||||
|
@ -31,7 +31,7 @@ struct rayIntersectionResults
|
||||
};
|
||||
|
||||
// maximum radius at which we check for entities (if some entity is much bigger than this, that's bad)
|
||||
#define COLLISION_RANGE 30
|
||||
#define COLLISION_RANGE 20
|
||||
|
||||
typedef std::vector<CEntity*> RayIntersects;
|
||||
|
||||
|
@ -1455,7 +1455,7 @@ void CEntity::ScriptingInit()
|
||||
AddClassProperty( L"traits.id.classes", (GetFn)&CEntity::getClassSet, (SetFn)&CEntity::setClassSet );
|
||||
AddClassProperty( L"template", (CEntityTemplate* CEntity::*)&CEntity::m_base, false, (NotifyFn)&CEntity::loadBase );
|
||||
|
||||
/* Anything inherited property MUST be added to EntityTemplate.cpp as well */
|
||||
/* Any inherited property MUST be added to EntityTemplate.cpp as well */
|
||||
|
||||
AddClassProperty( L"actions.move.speed_curr", &CEntity::m_speed );
|
||||
AddClassProperty( L"actions.move.run.speed", &CEntity::m_runSpeed );
|
||||
@ -1467,44 +1467,21 @@ void CEntity::ScriptingInit()
|
||||
AddClassProperty( L"selected", &CEntity::m_selected, false, (NotifyFn)&CEntity::checkSelection );
|
||||
AddClassProperty( L"group", &CEntity::m_grouped, false, (NotifyFn)&CEntity::checkGroup );
|
||||
AddClassProperty( L"traits.extant", &CEntity::m_extant );
|
||||
AddClassProperty( L"actions.move.turningradius", &CEntity::m_turningRadius );
|
||||
AddClassProperty( L"actions.move.turningRadius", &CEntity::m_turningRadius );
|
||||
AddClassProperty( L"position", &CEntity::m_graphics_position, false, (NotifyFn)&CEntity::teleport );
|
||||
AddClassProperty( L"orientation", &CEntity::m_orientation, false, (NotifyFn)&CEntity::reorient );
|
||||
AddClassProperty( L"player", (GetFn)&CEntity::JSI_GetPlayer, (SetFn)&CEntity::JSI_SetPlayer );
|
||||
AddClassProperty( L"traits.health.curr", &CEntity::m_healthCurr );
|
||||
AddClassProperty( L"traits.health.max", &CEntity::m_healthMax );
|
||||
//AddClassProperty( L"traits.health.bar_height", &CEntity::m_base->m_healthBarHeight );
|
||||
//AddClassProperty( L"traits.health.bar_size", &CEntity::m_base->m_healthBarSize );
|
||||
//AddClassProperty( L"traits.health.bar_width", &CEntity::m_base->m_healthBarWidth );
|
||||
//AddClassProperty( L"traits.health.border_height", &CEntity::m_base->m_healthBorderHeight);
|
||||
//AddClassProperty( L"traits.health.border_width", &CEntity::m_base->m_healthBorderWidth );
|
||||
//AddClassProperty( L"traits.health.border_name", &CEntity::m_base->m_healthBorderName );
|
||||
AddClassProperty( L"traits.health.regen_rate", &CEntity::m_healthRegenRate );
|
||||
AddClassProperty( L"traits.health.regen_start", &CEntity::m_healthRegenStart );
|
||||
AddClassProperty( L"traits.health.decay_rate", &CEntity::m_healthDecayRate );
|
||||
AddClassProperty( L"traits.stamina.curr", &CEntity::m_staminaCurr );
|
||||
AddClassProperty( L"traits.stamina.max", &CEntity::m_staminaMax );
|
||||
//AddClassProperty( L"traits.stamina.bar_height", &CEntity::m_base->m_staminaBarHeight );
|
||||
//AddClassProperty( L"traits.stamina.bar_size", &CEntity::m_base->m_staminaBarSize );
|
||||
//AddClassProperty( L"traits.stamina.bar_width", &CEntity::m_base->m_staminaBarWidth );
|
||||
//AddClassProperty( L"traits.stamina.border_height", &CEntity::m_base->m_staminaBorderHeight);
|
||||
//AddClassProperty( L"traits.stamina.border_width", &CEntity::m_base->m_staminaBorderWidth );
|
||||
//AddClassProperty( L"traits.stamina.border_name", &CEntity::m_base->m_staminaBorderName );
|
||||
AddClassProperty( L"traits.rally.name", &CEntity::m_rallyTexture );
|
||||
AddClassProperty( L"traits.rally.width", &CEntity::m_rallyWidth );
|
||||
AddClassProperty( L"traits.rally.height", &CEntity::m_rallyHeight );
|
||||
//AddClassProperty( L"traits.flank_penalty.sectors", &CEntity::m_base->m_sectorDivs);
|
||||
//AddClassProperty( L"traits.pitch.sectors", &CEntity::m_base->m_pitchDivs );
|
||||
//AddClassProperty( L"traits.rank.width", &CEntity::m_base->m_rankWidth );
|
||||
//AddClassProperty( L"traits.rank.height", &CEntity::m_base->m_rankHeight );
|
||||
AddClassProperty( L"traits.rank.name", &CEntity::m_rankName );
|
||||
//AddClassProperty( L"traits.minimap.type", &CEntity::m_base->m_minimapType );
|
||||
//AddClassProperty( L"traits.minimap.red", &CEntity::m_base->m_minimapR );
|
||||
//AddClassProperty( L"traits.minimap.green", &CEntity::m_base->m_minimapG );
|
||||
//AddClassProperty( L"traits.minimap.blue", &CEntity::m_base->m_minimapB );
|
||||
//AddClassProperty( L"traits.anchor.type", &CEntity::m_base->m_anchorType );
|
||||
//AddClassProperty( L"traits.anchor.conformx", &CEntity::m_base->m_anchorConformX );
|
||||
//AddClassProperty( L"traits.anchor.conformz", &CEntity::m_base->m_anchorConformZ );
|
||||
AddClassProperty( L"traits.vision.los", &CEntity::m_los );
|
||||
AddClassProperty( L"traits.vision.permanent", &CEntity::m_permanent );
|
||||
AddClassProperty( L"traits.is_territory_centre", &CEntity::m_isTerritoryCentre );
|
||||
|
@ -167,6 +167,8 @@ void CEntityManager::GetInRange( float x, float z, float radius, std::vector<CEn
|
||||
{
|
||||
results.clear();
|
||||
|
||||
float radiusSq = radius * radius;
|
||||
|
||||
int cx = (int) ( x / COLLISION_PATCH_SIZE );
|
||||
int cz = (int) ( z / COLLISION_PATCH_SIZE );
|
||||
|
||||
@ -182,12 +184,12 @@ void CEntityManager::GetInRange( float x, float z, float radius, std::vector<CEn
|
||||
for( int pz = minZ; pz <= maxZ; pz++ )
|
||||
{
|
||||
std::vector<CEntity*>& vec = m_collisionPatches[ px * m_collisionPatchesPerSide + pz ];
|
||||
for( std::vector<CEntity*>::iterator it = vec.begin(); it != vec.end(); it++ )
|
||||
for( size_t i=0; i<vec.size(); i++ )
|
||||
{
|
||||
CEntity* e = *it;
|
||||
CEntity* e = vec[i];
|
||||
float dx = x - e->m_position.X;
|
||||
float dz = z - e->m_position.Z;
|
||||
if(dx*dx + dz*dz <= radius*radius)
|
||||
if(dx*dx + dz*dz <= radiusSq)
|
||||
{
|
||||
results.push_back( e );
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ bool CEntity::processContactAction( CEntityOrder* current, size_t UNUSED(timeste
|
||||
// The pathfinder will push its result back into this unit's queue and
|
||||
// add back the current order at the end with the transition type.
|
||||
(int&)current->m_type = transition;
|
||||
g_Pathfinder.requestContactPath( me, current );
|
||||
g_Pathfinder.requestContactPath( me, current, action->m_MaxRange );
|
||||
|
||||
return( true );
|
||||
}
|
||||
@ -633,7 +633,8 @@ bool CEntity::processGotoWaypoint( CEntityOrder* current, size_t UNUSED(timestep
|
||||
|
||||
processChooseMovement( Distance );
|
||||
|
||||
g_Pathfinder.requestLowLevelPath( me, path_to, contact );
|
||||
float radius = *((float*)¤t->m_data[0].data);
|
||||
g_Pathfinder.requestLowLevelPath( me, path_to, contact, radius );
|
||||
|
||||
return( true );
|
||||
}
|
||||
|
@ -117,25 +117,25 @@ bool CEntityTemplate::loadXML( const CStr& filename )
|
||||
#define EL(x) int el_##x = XeroFile.getElementID(#x)
|
||||
#define AT(x) int at_##x = XeroFile.getAttributeID(#x)
|
||||
// Only the ones we can't load using normal methods.
|
||||
EL(entity);
|
||||
EL(script);
|
||||
EL(event);
|
||||
EL(traits);
|
||||
EL(footprint);
|
||||
EL(depth);
|
||||
EL(height);
|
||||
EL(radius);
|
||||
EL(width);
|
||||
AT(parent);
|
||||
AT(on);
|
||||
AT(file);
|
||||
AT(function);
|
||||
EL(Entity);
|
||||
EL(Script);
|
||||
EL(Event);
|
||||
EL(Traits);
|
||||
EL(Footprint);
|
||||
EL(Depth);
|
||||
EL(Height);
|
||||
EL(Radius);
|
||||
EL(Width);
|
||||
AT(Parent);
|
||||
AT(On);
|
||||
AT(File);
|
||||
AT(Function);
|
||||
#undef AT
|
||||
#undef EL
|
||||
|
||||
XMBElement Root = XeroFile.getRoot();
|
||||
|
||||
if( Root.getNodeName() != el_entity )
|
||||
if( Root.getNodeName() != el_Entity )
|
||||
{
|
||||
LOG( ERROR, LOG_CATEGORY, "CEntityTemplate::LoadXML: XML root was not \"Entity\" in file %s. Load failed.", filename.c_str() );
|
||||
return( false );
|
||||
@ -145,7 +145,7 @@ bool CEntityTemplate::loadXML( const CStr& filename )
|
||||
|
||||
m_Tag = CStr(filename).AfterLast("/").BeforeLast(".xml");
|
||||
|
||||
m_Base_Name = Root.getAttributes().getNamedItem( at_parent );
|
||||
m_Base_Name = Root.getAttributes().getNamedItem( at_Parent );
|
||||
|
||||
// Load our parent, if we have one
|
||||
if( m_Base_Name.Length() )
|
||||
@ -169,9 +169,9 @@ bool CEntityTemplate::loadXML( const CStr& filename )
|
||||
XMBElement Child = RootChildren.item(i);
|
||||
|
||||
int ChildName = Child.getNodeName();
|
||||
if( ChildName == el_script )
|
||||
if( ChildName == el_Script )
|
||||
{
|
||||
CStr Include = Child.getAttributes().getNamedItem( at_file );
|
||||
CStr Include = Child.getAttributes().getNamedItem( at_File );
|
||||
|
||||
if( Include.Length() && scriptsLoaded.find( Include ) == scriptsLoaded.end() )
|
||||
{
|
||||
@ -185,14 +185,14 @@ bool CEntityTemplate::loadXML( const CStr& filename )
|
||||
g_ScriptingHost.RunMemScript( Inline.c_str(), Inline.Length(), filename.c_str(), Child.getLineNumber() );
|
||||
}
|
||||
}
|
||||
else if (ChildName == el_traits)
|
||||
else if (ChildName == el_Traits)
|
||||
{
|
||||
XMBElementList TraitChildren = Child.getChildNodes();
|
||||
for(int j = 0; j < TraitChildren.Count; ++j)
|
||||
{
|
||||
XMBElement TraitChild = TraitChildren.item(j);
|
||||
int TraitChildName = TraitChild.getNodeName();
|
||||
if( TraitChildName == el_footprint )
|
||||
if( TraitChildName == el_Footprint )
|
||||
{
|
||||
XMBElementList FootprintChildren = TraitChild.getChildNodes();
|
||||
float radius=0, height=0, width=0, depth=0;
|
||||
@ -201,20 +201,20 @@ bool CEntityTemplate::loadXML( const CStr& filename )
|
||||
{
|
||||
XMBElement FootprintChild = FootprintChildren.item(k);
|
||||
int FootprintChildName = FootprintChild.getNodeName();
|
||||
if( FootprintChildName == el_radius )
|
||||
if( FootprintChildName == el_Radius )
|
||||
{
|
||||
hadRadius = true;
|
||||
radius = CStrW( FootprintChild.getText() ).ToFloat();
|
||||
}
|
||||
else if( FootprintChildName == el_width )
|
||||
else if( FootprintChildName == el_Width )
|
||||
{
|
||||
width = CStrW( FootprintChild.getText() ).ToFloat();
|
||||
}
|
||||
else if( FootprintChildName == el_height )
|
||||
else if( FootprintChildName == el_Height )
|
||||
{
|
||||
height = CStrW( FootprintChild.getText() ).ToFloat();
|
||||
}
|
||||
else if( FootprintChildName == el_depth )
|
||||
else if( FootprintChildName == el_Depth )
|
||||
{
|
||||
hadDepth = true;
|
||||
depth = CStrW( FootprintChild.getText() ).ToFloat();
|
||||
@ -244,13 +244,13 @@ bool CEntityTemplate::loadXML( const CStr& filename )
|
||||
// important so that scripts can see traits
|
||||
XMLLoadProperty( XeroFile, Child, CStrW() );
|
||||
}
|
||||
else if( ChildName == el_event )
|
||||
else if( ChildName == el_Event )
|
||||
{
|
||||
// Action...On for consistency with the GUI.
|
||||
CStrW EventName = L"on" + (CStrW)Child.getAttributes().getNamedItem( at_on );
|
||||
CStrW EventName = L"on" + (CStrW)Child.getAttributes().getNamedItem( at_On );
|
||||
|
||||
CStrW Code (Child.getText());
|
||||
utf16string ExternalFunction = Child.getAttributes().getNamedItem( at_function );
|
||||
utf16string ExternalFunction = Child.getAttributes().getNamedItem( at_Function );
|
||||
|
||||
// Does a property with this name already exist?
|
||||
|
||||
@ -297,10 +297,35 @@ bool CEntityTemplate::loadXML( const CStr& filename )
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given string, consisting of underscores and letters,
|
||||
* to camelCase: the first letter of each underscore-separated "word"
|
||||
* is changed to lowercase. For example, the string MiniMap_Colour
|
||||
* is converted to miniMap_colour. This is consistent with the
|
||||
* previous casing of entity attributes (all lowercase, with words
|
||||
* separated by underscores), while allowing us to switch over to
|
||||
* camelCase identifiers.
|
||||
*
|
||||
* @param const std::string & str The string to convert.
|
||||
* @return std::string The given string in camelCase.
|
||||
**/
|
||||
std::string toCamelCase( const std::string& str )
|
||||
{
|
||||
std::string ret = str;
|
||||
for( size_t i=0; i<ret.size(); i++ )
|
||||
{
|
||||
if( i==0 || ret[i-1] == '_' )
|
||||
{
|
||||
ret[i] = tolower( ret[i] );
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CEntityTemplate::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, const CStrW& BasePropertyName )
|
||||
{
|
||||
// Add a property, put the node text into it.
|
||||
CStrW PropertyName = BasePropertyName + CStrW( XeroFile.getElementString( Source.getNodeName() ) );
|
||||
CStrW PropertyName = BasePropertyName + CStrW( toCamelCase( XeroFile.getElementString( Source.getNodeName() ) ) );
|
||||
|
||||
IJSComplexProperty* Existing = HasProperty( PropertyName );
|
||||
if( Existing )
|
||||
@ -332,7 +357,7 @@ void CEntityTemplate::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElem
|
||||
for( unsigned int AttributeID = 0; AttributeID < (unsigned int)AttributeSet.Count; AttributeID++ )
|
||||
{
|
||||
XMBAttribute Attribute = AttributeSet.item( AttributeID );
|
||||
CStrW AttributeName = PropertyName + CStr8( XeroFile.getAttributeString( Attribute.Name ) );
|
||||
CStrW AttributeName = PropertyName + CStr8( toCamelCase( XeroFile.getAttributeString( Attribute.Name ) ) );
|
||||
Existing = HasProperty( AttributeName );
|
||||
|
||||
if( Existing )
|
||||
@ -367,9 +392,9 @@ void CEntityTemplate::ScriptingInit()
|
||||
AddClassProperty( L"traits.id.classes", (GetFn)&CEntityTemplate::getClassSet, (SetFn)&CEntityTemplate::setClassSet );
|
||||
|
||||
AddClassProperty( L"actions.move.speed_curr", &CEntityTemplate::m_speed );
|
||||
AddClassProperty( L"actions.move.turningradius", &CEntityTemplate::m_turningRadius );
|
||||
AddClassProperty( L"actions.move.turningRadius", &CEntityTemplate::m_turningRadius );
|
||||
AddClassProperty( L"actions.move.run.speed", &CEntityTemplate::m_runSpeed );
|
||||
AddClassProperty( L"actions.move.run.rangemin", &CEntityTemplate::m_runMinRange );
|
||||
AddClassProperty( L"actions.move.run.rangeMin", &CEntityTemplate::m_runMinRange );
|
||||
AddClassProperty( L"actions.move.run.range", &CEntityTemplate::m_runMaxRange );
|
||||
AddClassProperty( L"actions.move.run.regen_rate", &CEntityTemplate::m_runRegenRate );
|
||||
AddClassProperty( L"actions.move.run.decay_rate", &CEntityTemplate::m_runDecayRate );
|
||||
@ -400,13 +425,13 @@ void CEntityTemplate::ScriptingInit()
|
||||
AddClassProperty( L"traits.rank.width", &CEntityTemplate::m_rankWidth );
|
||||
AddClassProperty( L"traits.rank.height", &CEntityTemplate::m_rankHeight );
|
||||
AddClassProperty( L"traits.rank.name", &CEntityTemplate::m_rankName );
|
||||
AddClassProperty( L"traits.minimap.type", &CEntityTemplate::m_minimapType );
|
||||
AddClassProperty( L"traits.minimap.red", &CEntityTemplate::m_minimapR );
|
||||
AddClassProperty( L"traits.minimap.green", &CEntityTemplate::m_minimapG );
|
||||
AddClassProperty( L"traits.minimap.blue", &CEntityTemplate::m_minimapB );
|
||||
AddClassProperty( L"traits.miniMap.type", &CEntityTemplate::m_minimapType );
|
||||
AddClassProperty( L"traits.miniMap.red", &CEntityTemplate::m_minimapR );
|
||||
AddClassProperty( L"traits.miniMap.green", &CEntityTemplate::m_minimapG );
|
||||
AddClassProperty( L"traits.miniMap.blue", &CEntityTemplate::m_minimapB );
|
||||
AddClassProperty( L"traits.anchor.type", &CEntityTemplate::m_anchorType );
|
||||
AddClassProperty( L"traits.anchor.conformx", &CEntityTemplate::m_anchorConformX );
|
||||
AddClassProperty( L"traits.anchor.conformz", &CEntityTemplate::m_anchorConformZ );
|
||||
AddClassProperty( L"traits.anchor.conformX", &CEntityTemplate::m_anchorConformX );
|
||||
AddClassProperty( L"traits.anchor.conformZ", &CEntityTemplate::m_anchorConformZ );
|
||||
AddClassProperty( L"traits.vision.los", &CEntityTemplate::m_los );
|
||||
AddClassProperty( L"traits.vision.permanent", &CEntityTemplate::m_permanent );
|
||||
AddClassProperty( L"traits.display.bars.enabled", &CEntityTemplate::m_barsEnabled );
|
||||
|
@ -20,16 +20,17 @@ void CPathfindEngine::requestPath( HEntity entity, const CVector2D& destination
|
||||
CEntityOrder waypoint;
|
||||
waypoint.m_type = CEntityOrder::ORDER_GOTO_WAYPOINT;
|
||||
waypoint.m_data[0].location = destination;
|
||||
*((float*)&waypoint.m_data[0].data) = 0.0f;
|
||||
entity->m_orderQueue.push_front( waypoint );
|
||||
}
|
||||
|
||||
void CPathfindEngine::requestLowLevelPath( HEntity entity, const CVector2D& destination, bool contact )
|
||||
void CPathfindEngine::requestLowLevelPath( HEntity entity, const CVector2D& destination, bool contact, float radius )
|
||||
{
|
||||
PROFILE_START("Pathfinding");
|
||||
|
||||
CVector2D source( entity->m_position.X, entity->m_position.Z );
|
||||
|
||||
if ( mLowPathfinder.findPath(source, destination, entity->m_player) )
|
||||
if ( mLowPathfinder.findPath(source, destination, entity->m_player, radius) )
|
||||
{
|
||||
std::vector<CVector2D> path = mLowPathfinder.getLastPath();
|
||||
if( path.size() > 0 )
|
||||
@ -64,12 +65,13 @@ void CPathfindEngine::requestLowLevelPath( HEntity entity, const CVector2D& dest
|
||||
PROFILE_END("Pathfinding");
|
||||
}
|
||||
|
||||
void CPathfindEngine::requestContactPath( HEntity entity, CEntityOrder* current )
|
||||
void CPathfindEngine::requestContactPath( HEntity entity, CEntityOrder* current, float range )
|
||||
{
|
||||
/* TODO: Same as non-contact: need high-level planner */
|
||||
CEntityOrder waypoint;
|
||||
waypoint.m_type = CEntityOrder::ORDER_GOTO_WAYPOINT_CONTACT;
|
||||
waypoint.m_data[0].location = current->m_data[0].entity->m_position;
|
||||
*((float*)&waypoint.m_data[0].data) = std::max( current->m_data[0].entity->m_bounds->m_radius, range );
|
||||
entity->m_orderQueue.push_front( waypoint );
|
||||
|
||||
//pathSparse( entity, current->m_data[0].entity->m_position );
|
||||
|
@ -32,8 +32,8 @@ class CPathfindEngine : public Singleton<CPathfindEngine>
|
||||
public:
|
||||
CPathfindEngine();
|
||||
void requestPath( HEntity entity, const CVector2D& destination );
|
||||
void requestLowLevelPath( HEntity entity, const CVector2D& destination, bool contact );
|
||||
void requestContactPath( HEntity entity, CEntityOrder* current );
|
||||
void requestLowLevelPath( HEntity entity, const CVector2D& destination, bool contact, float radius );
|
||||
void requestContactPath( HEntity entity, CEntityOrder* current, float range );
|
||||
private:
|
||||
CAStarEngineLowLevel mLowPathfinder;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user