OregonCore  revision be9e804-git
Your Favourite TBC server
MoveSplineInit.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 #include "MoveSplineInit.h"
19 #include "MoveSpline.h"
20 #include "packet_builder.h"
21 #include "Unit.h"
22 
23 namespace Movement
24 {
26  {
27  if (moveFlags & MOVEMENTFLAG_FLYING)
28  {
29  if (moveFlags & MOVEMENTFLAG_BACKWARD /*&& speed_obj.flight >= speed_obj.flight_back*/)
30  return MOVE_FLIGHT_BACK;
31  else
32  return MOVE_FLIGHT;
33  }
34  else if (moveFlags & MOVEMENTFLAG_SWIMMING)
35  {
36  if (moveFlags & MOVEMENTFLAG_BACKWARD /*&& speed_obj.swim >= speed_obj.swim_back*/)
37  return MOVE_SWIM_BACK;
38  else
39  return MOVE_SWIM;
40  }
41  else if (moveFlags & MOVEMENTFLAG_WALK_MODE)
42  {
43  // if ( speed_obj.run > speed_obj.walk )
44  return MOVE_WALK;
45  }
46  else if (moveFlags & MOVEMENTFLAG_BACKWARD /*&& speed_obj.run >= speed_obj.run_back*/)
47  return MOVE_RUN_BACK;
48 
49  return MOVE_RUN;
50  }
51 
53  {
54  MoveSpline& move_spline = *unit.movespline;
55 
57 
58 
59  // there is a big chane that current position is unknown if current state is not finalized, need compute it
60  // this also allows calculate spline position and update map position in much greater intervals
61  if (!move_spline.Finalized())
62  real_position = move_spline.ComputePosition();
63 
64  if (args.path.empty())
65  {
66  // should i do the things that user should do?
67  MoveTo(real_position);
68  }
69 
70  // corrent first vertex
71  args.path[0] = real_position;
73  if (args.flags.runmode)
74  moveFlags &= ~MOVEMENTFLAG_WALK_MODE;
75  else
76  moveFlags |= MOVEMENTFLAG_WALK_MODE;
77 
79 
80  if (args.velocity == 0.f)
82 
83  if (!args.Validate(&unit))
84  return 0;
85 
87  move_spline.Initialize(args);
88 
90  data << unit.GetPackGUID();
91 
92  PacketBuilder::WriteMonsterMove(move_spline, data);
93  unit.SendMessageToSet(&data, true);
94 
95  return move_spline.Duration();
96  }
97 
99  {
100  MoveSpline& move_spline = *unit.movespline;
101 
102  // No need to stop if we are not moving
103  if (move_spline.Finalized())
104  return;
105 
107 
108 
109  // there is a big chance that current position is unknown if current state is not finalized, need compute it
110  // this also allows calculate spline position and update map position in much greater intervals
111  if (!move_spline.Finalized())
112  real_position = move_spline.ComputePosition();
113 
114  if (args.path.empty())
115  {
116  // should i do the things that user should do?
117  MoveTo(real_position);
118  }
119 
120  // current first vertex
121  args.path[0] = real_position;
122 
125  move_spline.Initialize(args);
126 
127  WorldPacket data(SMSG_MONSTER_MOVE, 64);
128  data << unit.GetPackGUID();
129 
130  data << real_position.x << real_position.y << real_position.z;
131  data << move_spline.GetId();
132  data << uint8(MonsterMoveStop);
133  unit.SendMessageToSet(&data, true);
134  }
135 
137  {
138  // mix existing state into new
141  }
142 
143  void MoveSplineInit::SetFacing(const Unit* target)
144  {
147  }
148 
149  void MoveSplineInit::SetFacing(float angle)
150  {
151  args.facing.angle = G3D::wrap(angle, 0.f, (float)G3D::twoPi());
153  }
154 }
UnitMoveType
Definition: Unit.h:482
UnitMoveType SelectSpeedType(uint32 moveFlags)
ObjectGuid const & GetObjectGUID() const
Definition: Object.h:182
float GetSpeed(UnitMoveType mtype) const
Definition: Unit.cpp:10044
MovementInfo m_movementInfo
Definition: Object.h:890
Movement::MoveSpline * movespline
Definition: Unit.h:1910
void Initialize(const MoveSplineInitArgs &)
Definition: MoveSpline.cpp:139
ACE_INT32 int32
Definition: Define.h:67
void RemoveMovementFlag(MovementFlags f)
Definition: Object.h:463
MoveSplineInitArgs args
void MoveTo(const Vector3 &destination, bool generatePath=false, bool forceDestination=false)
virtual void SendMessageToSet(WorldPacket *data, bool self)
Definition: Object.h:765
bool Validate(Unit *unit) const
============================================================================================ ...
Definition: MoveSpline.cpp:164
MovementFlags
Definition: Object.h:67
void SetMovementFlags(MovementFlags f)
Definition: Object.h:475
ACE_UINT8 uint8
Definition: Define.h:73
float GetOrientation() const
Definition: Position.h:100
uint64 const & GetRawValue() const
Definition: ObjectGuid.h:154
bool HasMovementFlag(MovementFlags f) const
Definition: Object.h:467
float GetPositionY() const
Definition: Position.h:98
float GetPositionZ() const
Definition: Position.h:99
bool Finalized() const
Definition: MoveSpline.h:117
PackedGuid const & GetPackGUID() const
Definition: Object.h:181
static void WriteMonsterMove(const MoveSpline &mov, WorldPacket &data)
int32 Duration() const
Definition: MoveSpline.h:124
Definition: Unit.h:485
MovementFlags GetMovementFlags() const
Definition: Object.h:471
uint32 GetId() const
Definition: MoveSpline.h:116
Location ComputePosition() const
Definition: MoveSpline.cpp:29
ACE_UINT32 uint32
Definition: Define.h:71
float GetPositionX() const
Definition: Position.h:97
Definition: Unit.h:908
void SetFacing(float angle)