2012-01-14 15:34:41 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef TRINITYSERVER_MOVESPLINEINIT_H
|
|
|
|
|
#define TRINITYSERVER_MOVESPLINEINIT_H
|
|
|
|
|
|
|
|
|
|
#include "MoveSplineInitArgs.h"
|
2012-08-25 21:55:03 -05:00
|
|
|
#include "PathGenerator.h"
|
2012-01-14 15:34:41 +01:00
|
|
|
|
|
|
|
|
class Unit;
|
|
|
|
|
|
|
|
|
|
namespace Movement
|
|
|
|
|
{
|
|
|
|
|
enum AnimType
|
|
|
|
|
{
|
|
|
|
|
ToGround = 0, // 460 = ToGround, index of AnimationData.dbc
|
|
|
|
|
FlyToFly = 1, // 461 = FlyToFly?
|
|
|
|
|
ToFly = 2, // 458 = ToFly
|
2012-09-10 13:03:38 +02:00
|
|
|
FlyToGround = 3 // 463 = FlyToGround
|
2012-01-14 15:34:41 +01:00
|
|
|
};
|
|
|
|
|
|
2012-05-31 19:45:11 +02:00
|
|
|
// Transforms coordinates from global to transport offsets
|
|
|
|
|
class TransportPathTransform
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-08-25 22:57:55 -05:00
|
|
|
TransportPathTransform(Unit* owner, bool transformForTransport)
|
2012-06-06 20:36:34 +02:00
|
|
|
: _owner(owner), _transformForTransport(transformForTransport) { }
|
2012-05-31 19:45:11 +02:00
|
|
|
Vector3 operator()(Vector3 input);
|
|
|
|
|
|
|
|
|
|
private:
|
2012-08-25 22:57:55 -05:00
|
|
|
Unit* _owner;
|
2012-06-06 20:36:34 +02:00
|
|
|
bool _transformForTransport;
|
2012-05-31 19:45:11 +02:00
|
|
|
};
|
|
|
|
|
|
2012-01-14 15:34:41 +01:00
|
|
|
/* Initializes and launches spline movement
|
|
|
|
|
*/
|
|
|
|
|
class MoveSplineInit
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2012-08-25 22:57:55 -05:00
|
|
|
explicit MoveSplineInit(Unit* m);
|
2012-01-14 15:34:41 +01:00
|
|
|
|
|
|
|
|
/* Final pass of initialization that launches spline movement.
|
|
|
|
|
*/
|
2012-04-09 16:38:05 +02:00
|
|
|
int32 Launch();
|
2012-01-14 15:34:41 +01:00
|
|
|
|
|
|
|
|
/* Adds movement by parabolic trajectory
|
|
|
|
|
* @param amplitude - the maximum height of parabola, value could be negative and positive
|
|
|
|
|
* @param start_time - delay between movement starting time and beginning to move by parabolic trajectory
|
|
|
|
|
* can't be combined with final animation
|
|
|
|
|
*/
|
|
|
|
|
void SetParabolic(float amplitude, float start_time);
|
|
|
|
|
/* Plays animation after movement done
|
|
|
|
|
* can't be combined with parabolic movement
|
|
|
|
|
*/
|
|
|
|
|
void SetAnimation(AnimType anim);
|
|
|
|
|
|
|
|
|
|
/* Adds final facing animation
|
|
|
|
|
* sets unit's facing to specified point/angle after all path done
|
|
|
|
|
* you can have only one final facing: previous will be overriden
|
|
|
|
|
*/
|
|
|
|
|
void SetFacing(float angle);
|
|
|
|
|
void SetFacing(Vector3 const& point);
|
2012-08-25 22:57:55 -05:00
|
|
|
void SetFacing(const Unit* target);
|
2012-01-14 15:34:41 +01:00
|
|
|
|
|
|
|
|
/* Initializes movement by path
|
|
|
|
|
* @param path - array of points, shouldn't be empty
|
|
|
|
|
* @param pointId - Id of fisrt point of the path. Example: when third path point will be done it will notify that pointId + 3 done
|
|
|
|
|
*/
|
|
|
|
|
void MovebyPath(const PointsArray& path, int32 pointId = 0);
|
|
|
|
|
|
2012-08-22 17:47:58 -05:00
|
|
|
/* Initializes simple A to B motion, A is current unit's position, B is destination
|
2012-01-14 15:34:41 +01:00
|
|
|
*/
|
2012-08-22 17:47:58 -05:00
|
|
|
void MoveTo(const Vector3& destination, bool generatePath = true, bool forceDestination = false);
|
|
|
|
|
void MoveTo(float x, float y, float z, bool generatePath = true, bool forceDestination = false);
|
2012-01-14 15:34:41 +01:00
|
|
|
|
|
|
|
|
/* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done
|
|
|
|
|
* Needed for waypoint movement where path splitten into parts
|
|
|
|
|
*/
|
|
|
|
|
void SetFirstPointId(int32 pointId) { args.path_Idx_offset = pointId; }
|
|
|
|
|
|
|
|
|
|
/* Enables CatmullRom spline interpolation mode(makes path smooth)
|
|
|
|
|
* if not enabled linear spline mode will be choosen. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetSmooth();
|
|
|
|
|
/* Enables CatmullRom spline interpolation mode, enables flying animation. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetFly();
|
|
|
|
|
/* Enables walk mode. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetWalk(bool enable);
|
|
|
|
|
/* Makes movement cyclic. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetCyclic();
|
|
|
|
|
/* Enables falling mode. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetFall();
|
2012-06-06 20:36:34 +02:00
|
|
|
/* Enters transport. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetTransportEnter();
|
|
|
|
|
/* Exits transport. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetTransportExit();
|
2012-01-14 15:34:41 +01:00
|
|
|
/* Inverses unit model orientation. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetOrientationInversed();
|
|
|
|
|
/* Fixes unit's model rotation. Disabled by default
|
|
|
|
|
*/
|
|
|
|
|
void SetOrientationFixed(bool enable);
|
|
|
|
|
|
|
|
|
|
/* Sets the velocity (in case you want to have custom movement velocity)
|
|
|
|
|
* if no set, speed will be selected based on unit's speeds and current movement mode
|
|
|
|
|
* Has no effect if falling mode enabled
|
|
|
|
|
* velocity shouldn't be negative
|
|
|
|
|
*/
|
|
|
|
|
void SetVelocity(float velocity);
|
|
|
|
|
|
|
|
|
|
PointsArray& Path() { return args.path; }
|
|
|
|
|
|
2012-06-06 20:36:34 +02:00
|
|
|
/* Disables transport coordinate transformations for cases where raw offsets are available
|
|
|
|
|
*/
|
|
|
|
|
void DisableTransportPathTransformations();
|
2012-01-14 15:34:41 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
MoveSplineInitArgs args;
|
2012-08-25 22:57:55 -05:00
|
|
|
Unit* unit;
|
2012-01-14 15:34:41 +01:00
|
|
|
};
|
|
|
|
|
|
2012-06-06 20:36:34 +02:00
|
|
|
inline void MoveSplineInit::SetFly() { args.flags.EnableFlying(); }
|
2012-01-14 15:34:41 +01:00
|
|
|
inline void MoveSplineInit::SetWalk(bool enable) { args.flags.walkmode = enable;}
|
|
|
|
|
inline void MoveSplineInit::SetSmooth() { args.flags.EnableCatmullRom();}
|
|
|
|
|
inline void MoveSplineInit::SetCyclic() { args.flags.cyclic = true;}
|
|
|
|
|
inline void MoveSplineInit::SetFall() { args.flags.EnableFalling();}
|
2012-05-31 19:45:11 +02:00
|
|
|
inline void MoveSplineInit::SetVelocity(float vel) { args.velocity = vel; args.HasVelocity = true; }
|
2012-01-14 15:34:41 +01:00
|
|
|
inline void MoveSplineInit::SetOrientationInversed() { args.flags.orientationInversed = true;}
|
2012-06-06 20:36:34 +02:00
|
|
|
inline void MoveSplineInit::SetTransportEnter() { args.flags.EnableTransportEnter(); }
|
|
|
|
|
inline void MoveSplineInit::SetTransportExit() { args.flags.EnableTransportExit(); }
|
2012-01-14 15:34:41 +01:00
|
|
|
inline void MoveSplineInit::SetOrientationFixed(bool enable) { args.flags.orientationFixed = enable;}
|
|
|
|
|
|
|
|
|
|
inline void MoveSplineInit::MovebyPath(const PointsArray& controls, int32 path_offset)
|
|
|
|
|
{
|
|
|
|
|
args.path_Idx_offset = path_offset;
|
2012-05-31 19:45:11 +02:00
|
|
|
args.path.resize(controls.size());
|
2012-06-06 20:36:34 +02:00
|
|
|
std::transform(controls.begin(), controls.end(), args.path.begin(), TransportPathTransform(unit, args.TransformForTransport));
|
2012-01-14 15:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-09 16:38:05 +02:00
|
|
|
inline void MoveSplineInit::MoveTo(float x, float y, float z, bool generatePath, bool forceDestination)
|
2012-01-14 15:34:41 +01:00
|
|
|
{
|
2012-08-24 11:38:39 -05:00
|
|
|
Vector3 v(x, y, z);
|
2012-04-09 16:38:05 +02:00
|
|
|
MoveTo(v, generatePath, forceDestination);
|
2012-01-14 15:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void MoveSplineInit::SetParabolic(float amplitude, float time_shift)
|
|
|
|
|
{
|
|
|
|
|
args.time_perc = time_shift;
|
|
|
|
|
args.parabolic_amplitude = amplitude;
|
|
|
|
|
args.flags.EnableParabolic();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void MoveSplineInit::SetAnimation(AnimType anim)
|
|
|
|
|
{
|
|
|
|
|
args.time_perc = 0.f;
|
|
|
|
|
args.flags.EnableAnimation((uint8)anim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void MoveSplineInit::SetFacing(Vector3 const& spot)
|
|
|
|
|
{
|
2012-06-06 20:36:34 +02:00
|
|
|
TransportPathTransform transform(unit, args.TransformForTransport);
|
2012-06-03 15:31:37 +02:00
|
|
|
Vector3 finalSpot = transform(spot);
|
|
|
|
|
args.facing.f.x = finalSpot.x;
|
|
|
|
|
args.facing.f.y = finalSpot.y;
|
|
|
|
|
args.facing.f.z = finalSpot.z;
|
2012-01-14 15:34:41 +01:00
|
|
|
args.flags.EnableFacingPoint();
|
|
|
|
|
}
|
2012-06-06 20:36:34 +02:00
|
|
|
|
|
|
|
|
inline void MoveSplineInit::DisableTransportPathTransformations() { args.TransformForTransport = false; }
|
2012-01-14 15:34:41 +01:00
|
|
|
}
|
|
|
|
|
#endif // TRINITYSERVER_MOVESPLINEINIT_H
|