1
1
forked from 0ad/0ad

# Units will now back away from enemies when below minimum range.

Also a small water specular strength tweak.

This was SVN commit r4481.
This commit is contained in:
Matei 2006-10-04 04:47:58 +00:00
parent 1735502032
commit 1036799546
4 changed files with 58 additions and 7 deletions

View File

@ -52,7 +52,7 @@ WaterManager::WaterManager()
m_RefractionTexture = 0;
m_WaterTexTimer = 0.0;
m_Shininess = 150.0f;
m_SpecularStrength = 0.45f;
m_SpecularStrength = 0.4f;
m_Waviness = 8.0f;
m_ReflectionTint = CColor(1.0f, 1.0f, 1.0f, 1.0f);
m_ReflectionTintStrength = 0.0f;

View File

@ -475,10 +475,26 @@ bool CEntity::processContactActionNoPathing( CEntityOrder* current, size_t times
float adjMinRange = action->m_MinRange + m_bounds->m_radius + target->m_bounds->m_radius;
if( delta.within( adjMinRange ) )
{
// Too close... do nothing.
entf_clear(ENTF_IS_RUNNING);
entf_clear(ENTF_SHOULD_RUN);
return( false );
// Too close... avoid it if allowed by the current stance.
if( current->m_source == CEntityOrder::SOURCE_UNIT_AI && !m_stance->allowsMovement() )
{
popOrder();
m_actor->SetRandomAnimation( "idle" );
return false; // We're not allowed to move at all by the current stance
}
entf_set(ENTF_SHOULD_RUN);
chooseMovementSpeed( action->m_MinRange );
// The pathfinder will push its result in front of the current order
if( !g_Pathfinder.requestAvoidPath( me, current, action->m_MinRange + 2.0f ) )
{
popOrder(); // Nothing we can do.. maybe we'll find a better target
m_actor->SetRandomAnimation( "idle" );
return false;
}
return true;
}
}

View File

@ -6,6 +6,8 @@
#include "Entity.h"
#include "EntityTemplate.h"
#include "PathfindEngine.h"
#include "graphics/Terrain.h"
#include "ps/World.h"
CPathfindEngine::CPathfindEngine()
@ -94,8 +96,9 @@ void CPathfindEngine::requestContactPath( HEntity entity, CEntityOrder* current,
CEntityOrder waypoint;
waypoint.m_type = CEntityOrder::ORDER_GOTO_WAYPOINT_CONTACT;
waypoint.m_source = current->m_source;
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 );
HEntity target = current->m_data[0].entity;
waypoint.m_data[0].location = target->m_position;
*((float*)&waypoint.m_data[0].data) = std::max( target->m_bounds->m_radius, range );
entity->m_orderQueue.push_front( waypoint );
//pathSparse( entity, current->m_data[0].entity->m_position );
@ -112,3 +115,34 @@ void CPathfindEngine::requestContactPath( HEntity entity, CEntityOrder* current,
// }
//}
}
bool CPathfindEngine::requestAvoidPath( HEntity entity, CEntityOrder* current, float avoidRange )
{
/* TODO: Same as non-contact: need high-level planner */
// TODO: Replace this with a new type of goal which is to avoid some point or line segment
// (requires changes to pathfinder to support this type of goal)
CEntityOrder waypoint;
waypoint.m_type = CEntityOrder::ORDER_GOTO_WAYPOINT_CONTACT;
waypoint.m_source = current->m_source;
// Figure out a direction to move
HEntity target = current->m_data[0].entity;
CVector3D dir = entity->m_position - target->m_position;
if(dir.LengthSquared() == 0) // shouldn't happen, but just in case
dir = CVector3D(1, 0, 0);
float dist = dir.GetLength();
dir.Normalize();
waypoint.m_data[0].location = entity->m_position + dir * (avoidRange - dist);
if( !g_Game->GetWorld()->GetTerrain()->isOnMap( waypoint.m_data[0].location ) )
{
return false;
}
*((float*)&waypoint.m_data[0].data) = 0.0f;
entity->m_orderQueue.push_front( waypoint );
return true;
}

View File

@ -39,6 +39,7 @@ public:
float radius, CEntityOrder::EOrderSource orderSource );
void requestContactPath( HEntity entity, CEntityOrder* current, float range );
bool requestAvoidPath( HEntity entity, CEntityOrder* current, float avoidRange );
private:
CAStarEngineLowLevel mLowPathfinder;
};