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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "MoveSplineInit.h"
|
|
|
|
|
#include "MoveSpline.h"
|
|
|
|
|
#include "MovementPacketBuilder.h"
|
|
|
|
|
#include "Unit.h"
|
2012-05-31 19:45:11 +02:00
|
|
|
#include "Transport.h"
|
|
|
|
|
#include "Vehicle.h"
|
2012-11-20 14:54:33 +01:00
|
|
|
#include "WorldPacket.h"
|
|
|
|
|
#include "Opcodes.h"
|
2012-01-14 15:34:41 +01:00
|
|
|
|
|
|
|
|
namespace Movement
|
|
|
|
|
{
|
|
|
|
|
UnitMoveType SelectSpeedType(uint32 moveFlags)
|
|
|
|
|
{
|
2013-06-01 17:47:02 +02:00
|
|
|
if (moveFlags & MOVEMENTFLAG_FLYING)
|
2012-01-14 15:34:41 +01:00
|
|
|
{
|
2012-03-15 13:14:42 +01:00
|
|
|
if (moveFlags & MOVEMENTFLAG_BACKWARD /*&& speed_obj.flight >= speed_obj.flight_back*/)
|
2012-01-14 15:34:41 +01:00
|
|
|
return MOVE_FLIGHT_BACK;
|
|
|
|
|
else
|
|
|
|
|
return MOVE_FLIGHT;
|
|
|
|
|
}
|
|
|
|
|
else if (moveFlags & MOVEMENTFLAG_SWIMMING)
|
|
|
|
|
{
|
|
|
|
|
if (moveFlags & MOVEMENTFLAG_BACKWARD /*&& speed_obj.swim >= speed_obj.swim_back*/)
|
|
|
|
|
return MOVE_SWIM_BACK;
|
|
|
|
|
else
|
|
|
|
|
return MOVE_SWIM;
|
|
|
|
|
}
|
|
|
|
|
else if (moveFlags & MOVEMENTFLAG_WALKING)
|
|
|
|
|
{
|
2012-03-15 13:14:42 +01:00
|
|
|
//if (speed_obj.run > speed_obj.walk)
|
2012-01-14 15:34:41 +01:00
|
|
|
return MOVE_WALK;
|
|
|
|
|
}
|
|
|
|
|
else if (moveFlags & MOVEMENTFLAG_BACKWARD /*&& speed_obj.run >= speed_obj.run_back*/)
|
|
|
|
|
return MOVE_RUN_BACK;
|
|
|
|
|
|
2013-06-01 17:47:02 +02:00
|
|
|
// Flying creatures use MOVEMENTFLAG_CAN_FLY or MOVEMENTFLAG_DISABLE_GRAVITY
|
|
|
|
|
// Run speed is their default flight speed.
|
2012-01-14 15:34:41 +01:00
|
|
|
return MOVE_RUN;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-09 16:38:05 +02:00
|
|
|
int32 MoveSplineInit::Launch()
|
2012-01-14 15:34:41 +01:00
|
|
|
{
|
2012-08-25 22:57:55 -05:00
|
|
|
MoveSpline& move_spline = *unit->movespline;
|
2012-01-14 15:34:41 +01:00
|
|
|
|
2012-05-31 19:45:11 +02:00
|
|
|
bool transport = false;
|
2012-08-25 22:57:55 -05:00
|
|
|
Location real_position(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZMinusOffset(), unit->GetOrientation());
|
2012-06-06 20:36:34 +02:00
|
|
|
// Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
|
2012-08-25 22:57:55 -05:00
|
|
|
if (unit->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit->GetTransGUID())
|
2012-05-31 19:45:11 +02:00
|
|
|
{
|
|
|
|
|
transport = true;
|
2012-08-25 22:57:55 -05:00
|
|
|
real_position.x = unit->GetTransOffsetX();
|
|
|
|
|
real_position.y = unit->GetTransOffsetY();
|
|
|
|
|
real_position.z = unit->GetTransOffsetZ();
|
|
|
|
|
real_position.orientation = unit->GetTransOffsetO();
|
2012-05-31 19:45:11 +02:00
|
|
|
}
|
2012-09-07 14:00:05 +02:00
|
|
|
|
2012-05-31 19:45:11 +02:00
|
|
|
// there is a big chance that current position is unknown if current state is not finalized, need compute it
|
2012-08-24 20:03:57 -05:00
|
|
|
// this also allows CalculatePath spline position and update map position in much greater intervals
|
2012-09-07 14:00:05 +02:00
|
|
|
// Don't compute for transport movement if the unit is in a motion between two transports
|
|
|
|
|
if (!move_spline.Finalized() && move_spline.onTransport == transport)
|
2012-01-14 15:34:41 +01:00
|
|
|
real_position = move_spline.ComputePosition();
|
|
|
|
|
|
2012-05-31 19:45:11 +02:00
|
|
|
// should i do the things that user should do? - no.
|
2012-01-14 15:34:41 +01:00
|
|
|
if (args.path.empty())
|
2012-08-24 11:38:39 -05:00
|
|
|
return 0;
|
2012-01-14 15:34:41 +01:00
|
|
|
|
|
|
|
|
// corrent first vertex
|
|
|
|
|
args.path[0] = real_position;
|
|
|
|
|
args.initialOrientation = real_position.orientation;
|
2012-09-07 14:00:05 +02:00
|
|
|
move_spline.onTransport = transport;
|
2012-01-14 15:34:41 +01:00
|
|
|
|
2012-08-25 22:57:55 -05:00
|
|
|
uint32 moveFlags = unit->m_movementInfo.GetMovementFlags();
|
2012-01-14 15:34:41 +01:00
|
|
|
moveFlags |= (MOVEMENTFLAG_SPLINE_ENABLED|MOVEMENTFLAG_FORWARD);
|
|
|
|
|
|
2013-06-01 17:47:02 +02:00
|
|
|
if (moveFlags & MOVEMENTFLAG_ROOT)
|
|
|
|
|
moveFlags &= ~MOVEMENTFLAG_MASK_MOVING;
|
|
|
|
|
|
2012-05-31 19:45:11 +02:00
|
|
|
if (!args.HasVelocity)
|
2013-06-01 17:47:02 +02:00
|
|
|
{
|
|
|
|
|
// If spline is initialized with SetWalk method it only means we need to select
|
|
|
|
|
// walk move speed for it but not add walk flag to unit
|
|
|
|
|
uint32 moveFlagsForSpeed = moveFlags;
|
|
|
|
|
if (args.flags.walkmode)
|
|
|
|
|
moveFlagsForSpeed |= MOVEMENTFLAG_WALKING;
|
2013-06-18 16:47:12 +02:00
|
|
|
else
|
|
|
|
|
moveFlagsForSpeed &= ~MOVEMENTFLAG_WALKING;
|
2013-06-01 17:47:02 +02:00
|
|
|
|
|
|
|
|
args.velocity = unit->GetSpeed(SelectSpeedType(moveFlagsForSpeed));
|
|
|
|
|
}
|
2012-01-14 15:34:41 +01:00
|
|
|
|
2012-11-07 16:42:22 +01:00
|
|
|
if (!args.Validate(unit))
|
2012-04-09 16:38:05 +02:00
|
|
|
return 0;
|
2012-01-14 15:34:41 +01:00
|
|
|
|
2012-08-25 22:57:55 -05:00
|
|
|
unit->m_movementInfo.SetMovementFlags((MovementFlags)moveFlags);
|
2012-01-14 15:34:41 +01:00
|
|
|
move_spline.Initialize(args);
|
|
|
|
|
|
2012-05-31 19:45:11 +02:00
|
|
|
WorldPacket data(!transport ? SMSG_MONSTER_MOVE : SMSG_MONSTER_MOVE_TRANSPORT, 64);
|
2012-08-25 22:57:55 -05:00
|
|
|
data.append(unit->GetPackGUID());
|
2012-05-31 19:45:11 +02:00
|
|
|
if (transport)
|
|
|
|
|
{
|
2012-08-25 22:57:55 -05:00
|
|
|
data.appendPackGUID(unit->GetTransGUID());
|
|
|
|
|
data << int8(unit->GetTransSeat());
|
2012-05-31 19:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-14 15:34:41 +01:00
|
|
|
PacketBuilder::WriteMonsterMove(move_spline, data);
|
2013-05-21 08:37:28 +02:00
|
|
|
unit->SendMessageToSet(&data, true);
|
2012-04-09 16:38:05 +02:00
|
|
|
|
|
|
|
|
return move_spline.Duration();
|
2012-01-14 15:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-25 22:57:55 -05:00
|
|
|
MoveSplineInit::MoveSplineInit(Unit* m) : unit(m)
|
2012-01-14 15:34:41 +01:00
|
|
|
{
|
2013-04-07 16:02:27 +02:00
|
|
|
args.splineId = splineIdGen.NewId();
|
2012-06-06 20:36:34 +02:00
|
|
|
// Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
|
2012-08-25 22:57:55 -05:00
|
|
|
args.TransformForTransport = unit->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit->GetTransGUID();
|
2012-01-14 15:34:41 +01:00
|
|
|
// mix existing state into new
|
2012-08-25 22:57:55 -05:00
|
|
|
args.flags.walkmode = unit->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING);
|
|
|
|
|
args.flags.flying = unit->m_movementInfo.HasMovementFlag((MovementFlags)(MOVEMENTFLAG_CAN_FLY | MOVEMENTFLAG_DISABLE_GRAVITY));
|
2012-01-14 15:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-25 22:57:55 -05:00
|
|
|
void MoveSplineInit::SetFacing(const Unit* target)
|
2012-01-14 15:34:41 +01:00
|
|
|
{
|
|
|
|
|
args.flags.EnableFacingTarget();
|
2012-06-07 23:20:57 +02:00
|
|
|
args.facing.target = target->GetGUID();
|
2012-01-14 15:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MoveSplineInit::SetFacing(float angle)
|
|
|
|
|
{
|
2012-06-06 20:36:34 +02:00
|
|
|
if (args.TransformForTransport)
|
2012-06-03 15:31:37 +02:00
|
|
|
{
|
2012-08-25 22:57:55 -05:00
|
|
|
if (Unit* vehicle = unit->GetVehicleBase())
|
2012-06-03 15:31:37 +02:00
|
|
|
angle -= vehicle->GetOrientation();
|
2012-08-25 22:57:55 -05:00
|
|
|
else if (Transport* transport = unit->GetTransport())
|
2012-06-03 15:31:37 +02:00
|
|
|
angle -= transport->GetOrientation();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 15:34:41 +01:00
|
|
|
args.facing.angle = G3D::wrap(angle, 0.f, (float)G3D::twoPi());
|
|
|
|
|
args.flags.EnableFacingAngle();
|
|
|
|
|
}
|
2012-05-31 19:45:11 +02:00
|
|
|
|
2012-08-24 11:38:39 -05:00
|
|
|
void MoveSplineInit::MoveTo(const Vector3& dest, bool generatePath, bool forceDestination)
|
2012-05-31 19:45:11 +02:00
|
|
|
{
|
2012-08-24 11:38:39 -05:00
|
|
|
if (generatePath)
|
|
|
|
|
{
|
2012-08-25 22:57:55 -05:00
|
|
|
PathGenerator path(unit);
|
2012-09-07 04:21:11 +02:00
|
|
|
bool result = path.CalculatePath(dest.x, dest.y, dest.z, forceDestination);
|
2013-02-13 20:21:26 +01:00
|
|
|
if (result && !(path.GetPathType() & PATHFIND_NOPATH))
|
2012-09-07 04:21:11 +02:00
|
|
|
{
|
|
|
|
|
MovebyPath(path.GetPath());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-08-24 11:38:39 -05:00
|
|
|
}
|
2012-09-07 04:21:11 +02:00
|
|
|
|
|
|
|
|
args.path_Idx_offset = 0;
|
|
|
|
|
args.path.resize(2);
|
|
|
|
|
TransportPathTransform transform(unit, args.TransformForTransport);
|
|
|
|
|
args.path[1] = transform(dest);
|
2012-05-31 19:45:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3 TransportPathTransform::operator()(Vector3 input)
|
|
|
|
|
{
|
2012-06-06 20:36:34 +02:00
|
|
|
if (_transformForTransport)
|
2012-09-10 13:24:01 +02:00
|
|
|
if (TransportBase* transport = _owner->GetDirectTransport())
|
2013-05-30 20:32:33 +02:00
|
|
|
transport->CalculatePassengerOffset(input.x, input.y, input.z);
|
2012-05-31 19:45:11 +02:00
|
|
|
|
|
|
|
|
return input;
|
|
|
|
|
}
|
2012-01-14 15:34:41 +01:00
|
|
|
}
|