Skip to content

Instantly share code, notes, and snippets.

@nzatsepilov
Created January 23, 2014 20:42
Show Gist options
  • Save nzatsepilov/8586353 to your computer and use it in GitHub Desktop.
Save nzatsepilov/8586353 to your computer and use it in GitHub Desktop.
diff --git a/src/game/ConfusedMovementGenerator.cpp b/src/game/ConfusedMovementGenerator.cpp
--- a/src/game/ConfusedMovementGenerator.cpp
+++ b/src/game/ConfusedMovementGenerator.cpp
@@ -30,16 +30,19 @@ template<class UNIT>
void ConfusedMovementGenerator<UNIT>::Initialize(UNIT &unit)
{
_generateMovement(unit);
unit.InterruptNonMeleeSpells(false);
unit.StopMoving();
unit.addUnitState(UNIT_STAT_CONFUSED);
+
+ unit.GetPosition(_startPosition);
+ _goToStartPosition = false;
}
template<class UNIT>
void ConfusedMovementGenerator<UNIT>::Reset(UNIT &u)
{
Initialize(u);
}
@@ -65,29 +68,54 @@ bool ConfusedMovementGenerator<UNIT>::Up
_nextMoveTime.Update(diff);
if (_nextMoveTime.Passed() || static_cast<MovementGenerator*>(this)->_recalculateTravel)
{
uint32 nextMove = urand(0, MAX_RANDOM_POINTS-1);
Movement::MoveSplineInit init(unit);
- PathFinder path(&unit);
- path.setPathLengthLimit(30.0f);
- bool result = path.calculate(_randomPosition[nextMove].x, _randomPosition[nextMove].y, _randomPosition[nextMove].z);
- if (!result || path.getPathType() & PATHFIND_NOPATH)
- init.MoveTo(_randomPosition[nextMove].x, _randomPosition[nextMove].y, _randomPosition[nextMove].z);
+ if (_goToStartPosition && !unit.IsPolymorphed())
+ {
+ // Path to start position
+ PathFinder path(&unit);
+ path.setPathLengthLimit(30.0f);
+ path.calculate(_startPosition.x, _startPosition.y, _startPosition.z);
+ init.MoveTo(_startPosition.x, _startPosition.y, _startPosition.z);
+
+ init.SetWalk(true);
+ init.Launch();
+
+ _goToStartPosition = false;
+ static_cast<MovementGenerator*>(this)->_recalculateTravel = false;
+ _nextMoveTime.Reset(urand(600, 800));
+ }
else
- init.MovebyPath(path.getPath());
+ {
+ // Path to random position
+ PathFinder path(&unit);
+ path.setPathLengthLimit(30.0f);
+ bool result = path.calculate(_randomPosition[nextMove].x, _randomPosition[nextMove].y, _randomPosition[nextMove].z);
+ if (!result || path.getPathType() & PATHFIND_NOPATH)
+ init.MoveTo(_randomPosition[nextMove].x, _randomPosition[nextMove].y, _randomPosition[nextMove].z);
+ else
+ init.MovebyPath(path.getPath());
- init.SetWalk(true);
- init.Launch();
+ init.SetWalk(true);
+ init.Launch();
- static_cast<MovementGenerator*>(this)->_recalculateTravel = false;
- _nextMoveTime.Reset(urand(0, 2000));
+ static_cast<MovementGenerator*>(this)->_recalculateTravel = false;
+ if (unit.IsPolymorphed())
+ _nextMoveTime.Reset(urand(1500, 2000));
+ else
+ {
+ _goToStartPosition = true;
+ _nextMoveTime.Reset(urand(600, 800));
+ }
+ }
}
return true;
}
template<class UNIT>
void ConfusedMovementGenerator<UNIT>::Finalize(UNIT &unit)
{
unit.StopMoving();
diff --git a/src/game/ConfusedMovementGenerator.h b/src/game/ConfusedMovementGenerator.h
--- a/src/game/ConfusedMovementGenerator.h
+++ b/src/game/ConfusedMovementGenerator.h
@@ -45,11 +45,13 @@ class HELLGROUND_DLL_SPEC ConfusedMoveme
MovementGeneratorType GetMovementGeneratorType() const { return CONFUSED_MOTION_TYPE; }
private:
void _generateMovement(UNIT &unit);
TimeTrackerSmall _nextMoveTime;
Position _randomPosition[MAX_RANDOM_POINTS+1];
+ Position _startPosition;
+ bool _goToStartPosition;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment