2008-10-11 14:16:25 -05:00
/*
2009-02-04 12:42:26 +01:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-11 14:16:25 -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-11 14:16:25 -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-11 14:16:25 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
#include "PointMovementGenerator.h"
#include "Errors.h"
#include "Creature.h"
#include "CreatureAI.h"
#include "DestinationHolderImp.h"
2009-05-21 10:48:00 -05:00
#include "World.h"
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//----- Point Movement Generator
template < class T >
void PointMovementGenerator < T >:: Initialize ( T & unit )
{
2009-05-03 16:29:33 -05:00
unit . StopMoving ();
2008-10-11 14:16:25 -05:00
Traveller < T > traveller ( unit );
2009-07-06 19:04:44 +02:00
// knockback effect has UNIT_STAT_JUMPING set,so if here we disable sentmonstermove there will be creature position sync problem between client and server
i_destinationHolder . SetDestination ( traveller , i_x , i_y , i_z , true /* !unit.hasUnitState(UNIT_STAT_JUMPING)*/ );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
template < class T >
bool PointMovementGenerator < T >:: Update ( T & unit , const uint32 & diff )
{
2010-04-07 19:14:10 +02:00
if ( !& unit )
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( unit . hasUnitState ( UNIT_STAT_ROOT | UNIT_STAT_STUNNED ))
2009-01-17 17:46:28 -06:00
{
2010-04-07 19:14:10 +02:00
if ( unit . hasUnitState ( UNIT_STAT_CHARGING ))
2009-01-17 17:46:28 -06:00
return false ;
else
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
Traveller < T > traveller ( unit );
2009-10-17 15:51:44 -07:00
2009-05-01 21:04:02 -05:00
i_destinationHolder . UpdateTraveller ( traveller , diff );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( i_destinationHolder . HasArrived ())
2008-10-11 14:16:25 -05:00
{
2009-05-01 21:04:02 -05:00
unit . clearUnitState ( UNIT_STAT_MOVE );
2009-03-17 10:40:28 -06:00
arrived = true ;
2008-10-11 14:16:25 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2009-03-17 10:40:28 -06:00
template < class T >
void PointMovementGenerator < T >:: Finalize ( T & unit )
{
2010-04-07 19:14:10 +02:00
if ( unit . hasUnitState ( UNIT_STAT_CHARGING ))
2009-03-23 15:26:13 -06:00
unit . clearUnitState ( UNIT_STAT_CHARGING | UNIT_STAT_JUMPING );
2010-04-07 19:14:10 +02:00
if ( arrived ) // without this crash!
2009-08-30 18:32:55 -05:00
MovementInform ( unit );
2009-03-17 10:40:28 -06:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
template < class T >
2010-04-19 09:26:37 +02:00
void PointMovementGenerator < T >:: MovementInform ( T & /*unit*/ )
2008-10-11 14:16:25 -05:00
{
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
template <> void PointMovementGenerator < Creature >:: MovementInform ( Creature & unit )
{
2010-04-07 19:14:10 +02:00
if ( id == EVENT_FALL_GROUND )
2009-08-28 11:26:20 -05:00
{
2009-08-26 19:28:21 -05:00
unit . setDeathState ( JUST_DIED );
2009-08-28 11:26:20 -05:00
unit . SetFlying ( true );
}
2008-10-11 14:16:25 -05:00
unit . AI () -> MovementInform ( POINT_MOTION_TYPE , id );
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
template void PointMovementGenerator < Player >:: Initialize ( Player & );
template bool PointMovementGenerator < Player >:: Update ( Player & , const uint32 & diff );
template void PointMovementGenerator < Player >:: MovementInform ( Player & );
2009-03-17 10:40:28 -06:00
template void PointMovementGenerator < Player >:: Finalize ( Player & );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
template void PointMovementGenerator < Creature >:: Initialize ( Creature & );
template bool PointMovementGenerator < Creature >:: Update ( Creature & , const uint32 & diff );
2009-03-17 10:40:28 -06:00
template void PointMovementGenerator < Creature >:: Finalize ( Creature & );
2009-10-17 15:51:44 -07:00
2009-05-21 10:48:00 -05:00
void AssistanceMovementGenerator :: Finalize ( Unit & unit )
{
2010-03-07 18:30:53 +01:00
unit . ToCreature () -> SetNoCallAssistance ( false );
unit . ToCreature () -> CallAssistance ();
2009-05-21 10:48:00 -05:00
if ( unit . isAlive ())
unit . GetMotionMaster () -> MoveSeekAssistanceDistract ( sWorld . getConfig ( CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY ));
}
2010-04-01 12:56:26 -06:00