Skip to content

Instantly share code, notes, and snippets.

@nzatsepilov
Last active December 30, 2015 03:49
Show Gist options
  • Save nzatsepilov/7771897 to your computer and use it in GitHub Desktop.
Save nzatsepilov/7771897 to your computer and use it in GitHub Desktop.
diff --git a/src/game/FleeingMovementGenerator.cpp b/src/game/FleeingMovementGenerator.cpp
index b3d8627..43cf9a9 100644
--- a/src/game/FleeingMovementGenerator.cpp
+++ b/src/game/FleeingMovementGenerator.cpp
@@ -25,7 +25,7 @@
#include "movement/MoveSpline.h"
#include "PathFinder.h"
-#define MIN_QUIET_DISTANCE 28.0f
+#define MIN_QUIET_DISTANCE 20.0f
#define MAX_QUIET_DISTANCE 43.0f
template<class T>
@@ -45,11 +45,13 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T& owner)
owner.addUnitState(UNIT_STAT_FLEEING_MOVE);
PathFinder path(&owner);
- path.setPathLengthLimit(30.0f);
+ path.setPathLengthLimit(15.0f);
+ path.setUseStrightPath(true);
path.calculate(x, y, z);
+
if (path.getPathType() & PATHFIND_NOPATH)
{
- i_nextCheckTime.Reset(urand(1000, 1500));
+ i_nextCheckTime.Reset(urand(800, 1200));
return;
}
@@ -57,7 +59,7 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T& owner)
init.MovebyPath(path.getPath());
init.SetWalk(false);
int32 traveltime = init.Launch();
- i_nextCheckTime.Reset(traveltime + urand(800, 1500));
+ i_nextCheckTime.Reset(traveltime + urand(800, 1200));
}
template<class T>
@@ -71,42 +73,39 @@ bool FleeingMovementGenerator<T>::_getPoint(T& owner, float& x, float& y, float&
{
dist_from_caster = fright->GetDistance(&owner);
if (dist_from_caster > 0.2f)
- angle_to_caster = fright->GetAngle(&owner);
+ angle_to_caster = fright->GetOrientation();
else
- angle_to_caster = frand(0, 2 * M_PI_F);
+ angle_to_caster = owner.GetOrientation();
}
else
{
dist_from_caster = 0.0f;
- angle_to_caster = frand(0, 2 * M_PI_F);
+ angle_to_caster = owner.GetOrientation();
}
- float dist, angle;
- if (dist_from_caster < MIN_QUIET_DISTANCE)
- {
- dist = frand(0.4f, 1.3f) * (MIN_QUIET_DISTANCE - dist_from_caster);
- angle = angle_to_caster + frand(-M_PI_F / 8, M_PI_F / 8);
- }
- else if (dist_from_caster > MAX_QUIET_DISTANCE)
- {
- dist = frand(0.4f, 1.0f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
- angle = -angle_to_caster + frand(-M_PI_F / 4, M_PI_F / 4);
- }
- else // we are inside quiet range
- {
- dist = frand(0.6f, 1.2f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
- angle = frand(0, 2 * M_PI_F);
- }
+ if (dist_from_caster > MIN_QUIET_DISTANCE)
+ angle_to_caster = urand(1, 8) * M_PI / 4.0f;
+
+ float dist = frand(8.0f, 10.0f);
+ float angle = angle_to_caster;
+
+ // Get current position
+ Position curr;
+ owner.GetPosition(curr.x, curr.y, curr.z);
- float curr_x, curr_y, curr_z;
- owner.GetPosition(curr_x, curr_y, curr_z);
+ // Get destination position
+ Position dest;
+ dest.x = curr.x + dist * cos(angle);
+ dest.y = curr.y + dist * sin(angle);
+ dest.z = curr.z;
- x = curr_x + dist * cos(angle);
- y = curr_y + dist * sin(angle);
- z = curr_z;
+ // Set destination position
+ x = dest.x;
+ y = dest.y;
+ z = dest.z;
- if (owner.GetTypeId() == TYPEID_PLAYER)
- owner.GetMap()->GetHitPosition(curr_x, curr_y, curr_z, x, y, z, -0.1f);
+// if (owner.GetTypeId() == TYPEID_PLAYER)
+// owner.GetMap()->GetHitPosition(curr.x, curr.y, curr.z, x, y, z, -0.1f);
owner.UpdateAllowedPositionZ(x, y, z);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment