[9529] Make Player::IsValidPos const
[getmangos.git] / src / game / HomeMovementGenerator.cpp
blob055951e19ca6f4d2bba4885991359c9d9d787991
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "HomeMovementGenerator.h"
20 #include "Creature.h"
21 #include "CreatureAI.h"
22 #include "Traveller.h"
23 #include "DestinationHolderImp.h"
24 #include "ObjectMgr.h"
25 #include "WorldPacket.h"
27 void
28 HomeMovementGenerator<Creature>::Initialize(Creature & owner)
30 owner.RemoveSplineFlag(SPLINEFLAG_WALKMODE);
31 _setTargetLocation(owner);
34 void
35 HomeMovementGenerator<Creature>::Reset(Creature &)
39 void
40 HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
42 if (owner.hasUnitState(UNIT_STAT_NOT_MOVE))
43 return;
45 float x, y, z;
47 // at apply we can select more nice return points base at current movegen
48 if (owner.GetMotionMaster()->empty() || !owner.GetMotionMaster()->top()->GetResetPosition(owner,x,y,z))
49 owner.GetRespawnCoord(x, y, z);
51 CreatureTraveller traveller(owner);
53 uint32 travel_time = i_destinationHolder.SetDestination(traveller, x, y, z);
54 modifyTravelTime(travel_time);
55 owner.clearUnitState(UNIT_STAT_ALL_STATE);
58 bool
59 HomeMovementGenerator<Creature>::Update(Creature &owner, const uint32& time_diff)
61 CreatureTraveller traveller( owner);
62 if (i_destinationHolder.UpdateTraveller(traveller, time_diff, false))
64 if (!IsActive(owner)) // force stop processing (movement can move out active zone with cleanup movegens list)
65 return true; // not expire now, but already lost
68 if (time_diff > i_travel_timer)
70 owner.AddSplineFlag(SPLINEFLAG_WALKMODE);
72 // restore orientation of not moving creature at returning to home
73 if(owner.GetDefaultMovementType()==IDLE_MOTION_TYPE)
75 if(CreatureData const* data = sObjectMgr.GetCreatureData(owner.GetDBTableGUIDLow()))
77 owner.SetOrientation(data->orientation);
78 WorldPacket packet;
79 owner.BuildHeartBeatMsg(&packet);
80 owner.SendMessageToSet(&packet, false);
84 owner.AI()->JustReachedHome();
85 return false;
88 i_travel_timer -= time_diff;
90 return true;