Files
TCPlayerbotCore/src/game/Traveller.h
T

117 lines
4.0 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
2008-10-14 11:57:03 -05:00
*
* Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* 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
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2008-10-14 11:57:03 -05:00
#ifndef TRINITY_TRAVELLER_H
#define TRINITY_TRAVELLER_H
2008-10-02 16:23:55 -05:00
#include "MapManager.h"
#include "Creature.h"
#include "Player.h"
#include <cassert>
2008-12-15 00:07:21 +02:00
#include "CreatureGroups.h"
2008-10-02 16:23:55 -05:00
/** Traveller is a wrapper for units (creatures or players) that
* travel from point A to point B using the destination holder.
*/
#define PLAYER_FLIGHT_SPEED 32.0f
template<class T>
2008-10-14 11:57:03 -05:00
struct TRINITY_DLL_DECL Traveller
2008-10-02 16:23:55 -05:00
{
T &i_traveller;
Traveller(T &t) : i_traveller(t) {}
Traveller(const Traveller &obj) : i_traveller(obj) {}
Traveller& operator=(const Traveller &obj)
{
this->~Traveller();
new (this) Traveller(obj);
return *this;
}
operator T&(void) { return i_traveller; }
operator const T&(void) { return i_traveller; }
inline float GetPositionX() const { return i_traveller.GetPositionX(); }
inline float GetPositionY() const { return i_traveller.GetPositionY(); }
inline float GetPositionZ() const { return i_traveller.GetPositionZ(); }
inline T& GetTraveller(void) { return i_traveller; }
float Speed(void) { assert(false); return 0.0f; }
void Relocation(float x, float y, float z, float orientation) {}
void Relocation(float x, float y, float z) { Relocation(x, y, z, i_traveller.GetOrientation()); }
void MoveTo(float x, float y, float z, uint32 t) {}
};
// specialization for creatures
template<>
inline float Traveller<Creature>::Speed()
{
2008-12-08 16:34:03 -06:00
if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE))
return i_traveller.GetSpeed(MOVE_WALK);
else if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_FLYING2))
2008-12-12 11:21:28 -06:00
return i_traveller.GetSpeed(MOVE_FLIGHT);
2008-12-08 16:34:03 -06:00
else
return i_traveller.GetSpeed(MOVE_RUN);
2008-10-02 16:23:55 -05:00
}
template<>
inline void Traveller<Creature>::Relocation(float x, float y, float z, float orientation)
{
MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->CreatureRelocation(&i_traveller, x, y, z, orientation);
}
template<>
inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t)
{
2008-12-15 00:07:21 +02:00
//Call for creature group update
2009-02-09 08:16:34 -05:00
if(i_traveller.IsFormationLeader() && !i_traveller.isInCombat() &&
CreatureGroupHolder.find(i_traveller.GetFormationID()) != CreatureGroupHolder.end())
CreatureGroupHolder[i_traveller.GetFormationID()]->LeaderMovedInEvade();
2009-02-09 08:16:34 -05:00
i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetUnitMovementFlags(), 0);
2008-10-02 16:23:55 -05:00
}
// specialization for players
template<>
inline float Traveller<Player>::Speed()
{
if (i_traveller.isInFlight())
return PLAYER_FLIGHT_SPEED;
else
return i_traveller.GetSpeed(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
}
template<>
inline void Traveller<Player>::Relocation(float x, float y, float z, float orientation)
{
MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->PlayerRelocation(&i_traveller, x, y, z, orientation);
}
template<>
inline void Traveller<Player>::MoveTo(float x, float y, float z, uint32 t)
{
//Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
i_traveller.SendMonsterMove(x, y, z, 0, MOVEMENTFLAG_WALK_MODE, t);
}
typedef Traveller<Creature> CreatureTraveller;
typedef Traveller<Player> PlayerTraveller;
#endif
2009-02-17 20:07:49 -06:00