From: <Kha...@us...> - 2009-05-10 01:14:14
|
Revision: 3646 http://planeshift.svn.sourceforge.net/planeshift/?rev=3646&view=rev Author: Khakilord Date: 2009-05-10 01:14:06 +0000 (Sun, 10 May 2009) Log Message: ----------- Fixed npc chasing behaviour so they don't do wild goose chases. Modified Paths: -------------- trunk/src/npcclient/npcoperations.cpp trunk/src/npcclient/npcoperations.h Modified: trunk/src/npcclient/npcoperations.cpp =================================================================== --- trunk/src/npcclient/npcoperations.cpp 2009-05-10 00:58:58 UTC (rev 3645) +++ trunk/src/npcclient/npcoperations.cpp 2009-05-10 01:14:06 UTC (rev 3646) @@ -1950,26 +1950,11 @@ chaseRange = -1.0f; // Disable max chase range } - if ( node->GetAttributeValue("offset_x") ) + if ( node->GetAttributeValue("offset") ) { - offset.x = node->GetAttributeValueAsFloat("offset_x"); + offset = node->GetAttributeValueAsFloat("offset"); } - else - { - offset.x = 0.5F; - } - - if ( node->GetAttributeValue( "offset_z" ) ) - { - offset.z = node->GetAttributeValueAsFloat("offset_z"); - } - else - { - offset.z = 0.5F; - } - offset.y = 0.0f; - LoadVelocity(node); LoadCheckMoveOk(node); ang_vel = node->GetAttributeValueAsFloat("ang_vel"); @@ -2069,7 +2054,7 @@ npc->Printf("ChaseOperation: target's sector is not connected to ours!"); return true; // This operation is complete } - if ( Calc2DDistance( myPos, targetPos ) < sqrt((offset.x * offset.x)+(offset.z * offset.z)) ) + if ( Calc2DDistance( myPos, targetPos ) < offset ) { return true; // This operation is complete } @@ -2077,7 +2062,7 @@ // This prevents NPCs from wanting to occupy the same physical space as something else csVector3 displacement = targetPos - myPos; displacement.y = 0; - float factor = sqrt((offset.x * offset.x)+(offset.z * offset.z)) / displacement.Norm(); + float factor = offset / displacement.Norm(); csVector3 destPos = myPos + (1 - factor) * displacement; destPos.y = targetPos.y; @@ -2140,6 +2125,7 @@ if (!targetActor || !target_entity) // no entity close to us { npc->Printf(5, "ChaseOp has no target now!"); + npc->ResumeScript(npc->GetBrain()->GetCurrentBehavior() ); return; } @@ -2155,6 +2141,7 @@ if (!npcclient->GetWorld()->WarpSpace(targetSector, mySector, targetPos)) { npc->Printf("ChaseOperation: target's sector is not connected to ours!"); + npc->ResumeScript(npc->GetBrain()->GetCurrentBehavior() ); return; } @@ -2177,7 +2164,7 @@ } - float factor = sqrt((offset.x * offset.x)+(offset.z * offset.z)) / distance; + float factor = offset / distance; targetPos = myPos + (1 - factor) * displacement; targetPos.y = myPos.y; Modified: trunk/src/npcclient/npcoperations.h =================================================================== --- trunk/src/npcclient/npcoperations.h 2009-05-10 00:58:58 UTC (rev 3645) +++ trunk/src/npcclient/npcoperations.h 2009-05-10 01:14:06 UTC (rev 3646) @@ -350,7 +350,7 @@ int type; float searchRange; float chaseRange; - csVector3 offset; + float offset; EID target_id; psAPath path; csVector3 localDest; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |