[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / Vehicle.cpp
blob3de27b2b9f14484cfbdc39362fd6797cb56041a4
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 "Common.h"
20 #include "Log.h"
21 #include "ObjectMgr.h"
22 #include "Vehicle.h"
23 #include "Unit.h"
24 #include "Util.h"
26 Vehicle::Vehicle() : Creature(CREATURE_SUBTYPE_VEHICLE), m_vehicleId(0)
28 m_updateFlag = (UPDATEFLAG_LIVING | UPDATEFLAG_HAS_POSITION | UPDATEFLAG_VEHICLE);
31 Vehicle::~Vehicle()
35 void Vehicle::AddToWorld()
37 ///- Register the vehicle for guid lookup
38 if(!IsInWorld())
39 GetMap()->GetObjectsStore().insert<Vehicle>(GetGUID(), (Vehicle*)this);
41 Unit::AddToWorld();
44 void Vehicle::RemoveFromWorld()
46 ///- Remove the vehicle from the accessor
47 if(IsInWorld())
48 GetMap()->GetObjectsStore().erase<Vehicle>(GetGUID(), (Vehicle*)NULL);
50 ///- Don't call the function for Creature, normal mobs + totems go in a different storage
51 Unit::RemoveFromWorld();
54 void Vehicle::setDeathState(DeathState s) // overwrite virtual Creature::setDeathState and Unit::setDeathState
56 Creature::setDeathState(s);
59 void Vehicle::Update(uint32 diff)
61 Creature::Update(diff);
64 bool Vehicle::Create(uint32 guidlow, Map *map, uint32 Entry, uint32 vehicleId, uint32 team)
66 SetMap(map);
68 Object::_Create(guidlow, Entry, HIGHGUID_VEHICLE);
70 if(!InitEntry(Entry, team))
71 return false;
73 m_defaultMovementType = IDLE_MOTION_TYPE;
75 AIM_Initialize();
77 SetVehicleId(vehicleId);
79 SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
80 SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f);
82 CreatureInfo const *ci = GetCreatureInfo();
83 setFaction(team == ALLIANCE ? ci->faction_A : ci->faction_H);
84 SetMaxHealth(ci->maxhealth);
85 SelectLevel(ci);
86 SetHealth(GetMaxHealth());
88 return true;
91 void Vehicle::Dismiss()
93 SendObjectDeSpawnAnim(GetGUID());
94 CombatStop();
95 AddObjectToRemoveList();