[9232] Replace list bool fields with exclusive true values by subtype field in Creature.
[getmangos.git] / src / game / GameObject.cpp
blob9ba5cbd7656e1e55485ee74f722d93c62ff994f7
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 "QuestDef.h"
21 #include "GameObject.h"
22 #include "ObjectMgr.h"
23 #include "PoolManager.h"
24 #include "SpellMgr.h"
25 #include "Spell.h"
26 #include "UpdateMask.h"
27 #include "Opcodes.h"
28 #include "WorldPacket.h"
29 #include "World.h"
30 #include "Database/DatabaseEnv.h"
31 #include "LootMgr.h"
32 #include "GridNotifiers.h"
33 #include "GridNotifiersImpl.h"
34 #include "CellImpl.h"
35 #include "InstanceData.h"
36 #include "BattleGround.h"
37 #include "BattleGroundAV.h"
38 #include "Util.h"
39 #include "ScriptCalls.h"
41 GameObject::GameObject() : WorldObject()
43 m_objectType |= TYPEMASK_GAMEOBJECT;
44 m_objectTypeId = TYPEID_GAMEOBJECT;
46 m_updateFlag = (UPDATEFLAG_HIGHGUID | UPDATEFLAG_HAS_POSITION | UPDATEFLAG_POSITION | UPDATEFLAG_ROTATION);
48 m_valuesCount = GAMEOBJECT_END;
49 m_respawnTime = 0;
50 m_respawnDelayTime = 25;
51 m_lootState = GO_NOT_READY;
52 m_spawnedByDefault = true;
53 m_usetimes = 0;
54 m_spellId = 0;
55 m_cooldownTime = 0;
56 m_goInfo = NULL;
58 m_DBTableGuid = 0;
59 m_rotation = 0;
62 GameObject::~GameObject()
66 void GameObject::AddToWorld()
68 ///- Register the gameobject for guid lookup
69 if(!IsInWorld())
70 GetMap()->GetObjectsStore().insert<GameObject>(GetGUID(), (GameObject*)this);
72 Object::AddToWorld();
75 void GameObject::RemoveFromWorld()
77 ///- Remove the gameobject from the accessor
78 if(IsInWorld())
80 // Remove GO from owner
81 if(uint64 owner_guid = GetOwnerGUID())
83 if (Unit* owner = ObjectAccessor::GetUnit(*this,owner_guid))
84 owner->RemoveGameObject(this,false);
85 else
87 const char * ownerType = "creature";
88 if(IS_PLAYER_GUID(owner_guid))
89 ownerType = "player";
90 else if(IS_PET_GUID(owner_guid))
91 ownerType = "pet";
93 sLog.outError("Delete GameObject (GUID: %u Entry: %u SpellId %u LinkedGO %u) that lost references to owner (GUID %u Type '%s') GO list. Crash possible later.",
94 GetGUIDLow(), GetGOInfo()->id, m_spellId, GetGOInfo()->GetLinkedGameObjectEntry(), GUID_LOPART(owner_guid), ownerType);
98 GetMap()->GetObjectsStore().erase<GameObject>(GetGUID(), (GameObject*)NULL);
101 Object::RemoveFromWorld();
104 bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 animprogress, GOState go_state)
106 ASSERT(map);
107 Relocate(x,y,z,ang);
108 SetMap(map);
109 SetPhaseMask(phaseMask,false);
111 if(!IsPositionValid())
113 sLog.outError("Gameobject (GUID: %u Entry: %u ) not created. Suggested coordinates isn't valid (X: %f Y: %f)",guidlow,name_id,x,y);
114 return false;
117 GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(name_id);
118 if (!goinfo)
120 sLog.outErrorDb("Gameobject (GUID: %u Entry: %u) not created: it have not exist entry in `gameobject_template`. Map: %u (X: %f Y: %f Z: %f) ang: %f rotation0: %f rotation1: %f rotation2: %f rotation3: %f",guidlow, name_id, map->GetId(), x, y, z, ang, rotation0, rotation1, rotation2, rotation3);
121 return false;
124 Object::_Create(guidlow, goinfo->id, HIGHGUID_GAMEOBJECT);
126 m_goInfo = goinfo;
128 if (goinfo->type >= MAX_GAMEOBJECT_TYPE)
130 sLog.outErrorDb("Gameobject (GUID: %u Entry: %u) not created: it have not exist GO type '%u' in `gameobject_template`. It's will crash client if created.",guidlow,name_id,goinfo->type);
131 return false;
134 SetFloatValue(GAMEOBJECT_PARENTROTATION+0, rotation0);
135 SetFloatValue(GAMEOBJECT_PARENTROTATION+1, rotation1);
137 UpdateRotationFields(rotation2,rotation3); // GAMEOBJECT_FACING, GAMEOBJECT_ROTATION, GAMEOBJECT_PARENTROTATION+2/3
139 SetFloatValue(OBJECT_FIELD_SCALE_X, goinfo->size);
141 SetUInt32Value(GAMEOBJECT_FACTION, goinfo->faction);
142 SetUInt32Value(GAMEOBJECT_FLAGS, goinfo->flags);
144 SetEntry(goinfo->id);
146 SetUInt32Value(GAMEOBJECT_DISPLAYID, goinfo->displayId);
148 // GAMEOBJECT_BYTES_1, index at 0, 1, 2 and 3
149 SetGoState(go_state);
150 SetGoType(GameobjectTypes(goinfo->type));
151 SetGoArtKit(0); // unknown what this is
152 SetGoAnimProgress(animprogress);
154 //Notify the map's instance data.
155 //Only works if you create the object in it, not if it is moves to that map.
156 //Normally non-players do not teleport to other maps.
157 if(map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData())
159 ((InstanceMap*)map)->GetInstanceData()->OnObjectCreate(this);
162 return true;
165 void GameObject::Update(uint32 /*p_time*/)
167 if (IS_MO_TRANSPORT(GetGUID()))
169 //((Transport*)this)->Update(p_time);
170 return;
173 switch (m_lootState)
175 case GO_NOT_READY:
177 switch(GetGoType())
179 case GAMEOBJECT_TYPE_TRAP:
181 // Arming Time for GAMEOBJECT_TYPE_TRAP (6)
182 Unit* owner = GetOwner();
183 if (owner && ((Player*)owner)->isInCombat())
184 m_cooldownTime = time(NULL) + GetGOInfo()->trap.startDelay;
185 m_lootState = GO_READY;
186 break;
188 case GAMEOBJECT_TYPE_FISHINGNODE:
190 // fishing code (bobber ready)
191 if( time(NULL) > m_respawnTime - FISHING_BOBBER_READY_TIME )
193 // splash bobber (bobber ready now)
194 Unit* caster = GetOwner();
195 if(caster && caster->GetTypeId()==TYPEID_PLAYER)
197 SetGoState(GO_STATE_ACTIVE);
198 SetUInt32Value(GAMEOBJECT_FLAGS, GO_FLAG_NODESPAWN);
200 UpdateData udata;
201 WorldPacket packet;
202 BuildValuesUpdateBlockForPlayer(&udata,((Player*)caster));
203 udata.BuildPacket(&packet);
204 ((Player*)caster)->GetSession()->SendPacket(&packet);
206 SendGameObjectCustomAnim(GetGUID());
209 m_lootState = GO_READY; // can be successfully open with some chance
211 return;
213 default:
214 m_lootState = GO_READY; // for other GOis same switched without delay to GO_READY
215 break;
217 // NO BREAK for switch (m_lootState)
219 case GO_READY:
221 if (m_respawnTime > 0) // timer on
223 if (m_respawnTime <= time(NULL)) // timer expired
225 m_respawnTime = 0;
226 m_SkillupList.clear();
227 m_usetimes = 0;
229 switch (GetGoType())
231 case GAMEOBJECT_TYPE_FISHINGNODE: // can't fish now
233 Unit* caster = GetOwner();
234 if(caster && caster->GetTypeId()==TYPEID_PLAYER)
236 caster->FinishSpell(CURRENT_CHANNELED_SPELL);
238 WorldPacket data(SMSG_FISH_NOT_HOOKED,0);
239 ((Player*)caster)->GetSession()->SendPacket(&data);
241 // can be delete
242 m_lootState = GO_JUST_DEACTIVATED;
243 return;
245 case GAMEOBJECT_TYPE_DOOR:
246 case GAMEOBJECT_TYPE_BUTTON:
247 //we need to open doors if they are closed (add there another condition if this code breaks some usage, but it need to be here for battlegrounds)
248 if (GetGoState() != GO_STATE_READY)
249 ResetDoorOrButton();
250 //flags in AB are type_button and we need to add them here so no break!
251 default:
252 if (!m_spawnedByDefault) // despawn timer
254 // can be despawned or destroyed
255 SetLootState(GO_JUST_DEACTIVATED);
256 return;
258 // respawn timer
259 uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<GameObject>(GetDBTableGUIDLow()) : 0;
260 if (poolid)
261 sPoolMgr.UpdatePool<GameObject>(poolid, GetDBTableGUIDLow());
262 else
263 GetMap()->Add(this);
264 break;
269 if(isSpawned())
271 // traps can have time and can not have
272 GameObjectInfo const* goInfo = GetGOInfo();
273 if(goInfo->type == GAMEOBJECT_TYPE_TRAP)
275 if(m_cooldownTime >= time(NULL))
276 return;
278 // traps
279 Unit* owner = GetOwner();
280 Unit* ok = NULL; // pointer to appropriate target if found any
282 bool IsBattleGroundTrap = false;
283 //FIXME: this is activation radius (in different casting radius that must be selected from spell data)
284 //TODO: move activated state code (cast itself) to GO_ACTIVATED, in this place only check activating and set state
285 float radius = goInfo->trap.radius;
286 if(!radius)
288 if(goInfo->trap.cooldown != 3) // cast in other case (at some triggering/linked go/etc explicit call)
289 return;
290 else
292 if(m_respawnTime > 0)
293 break;
295 radius = goInfo->trap.cooldown; // battlegrounds gameobjects has data2 == 0 && data5 == 3
296 IsBattleGroundTrap = true;
300 CellPair p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY()));
301 Cell cell(p);
302 cell.data.Part.reserved = ALL_DISTRICT;
304 // Note: this hack with search required until GO casting not implemented
305 // search unfriendly creature
306 if(owner && goInfo->trap.charges > 0) // hunter trap
308 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, owner, radius);
309 MaNGOS::UnitSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck> checker(this,ok, u_check);
311 CellLock<GridReadGuard> cell_lock(cell, p);
313 TypeContainerVisitor<MaNGOS::UnitSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck>, GridTypeMapContainer > grid_object_checker(checker);
314 cell_lock->Visit(cell_lock, grid_object_checker, *GetMap(), *this, radius);
316 // or unfriendly player/pet
317 if(!ok)
319 TypeContainerVisitor<MaNGOS::UnitSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker);
320 cell_lock->Visit(cell_lock, world_object_checker, *GetMap(), *this, radius);
323 else // environmental trap
325 // environmental damage spells already have around enemies targeting but this not help in case not existed GO casting support
327 // affect only players
328 Player* p_ok = NULL;
329 MaNGOS::AnyPlayerInObjectRangeCheck p_check(this, radius);
330 MaNGOS::PlayerSearcher<MaNGOS::AnyPlayerInObjectRangeCheck> checker(this,p_ok, p_check);
332 CellLock<GridReadGuard> cell_lock(cell, p);
334 TypeContainerVisitor<MaNGOS::PlayerSearcher<MaNGOS::AnyPlayerInObjectRangeCheck>, WorldTypeMapContainer > world_object_checker(checker);
335 cell_lock->Visit(cell_lock, world_object_checker, *GetMap(), *this, radius);
336 ok = p_ok;
339 if (ok)
341 Unit *caster = owner ? owner : ok;
343 caster->CastSpell(ok, goInfo->trap.spellId, true, NULL, NULL, GetGUID());
344 m_cooldownTime = time(NULL) + 4; // 4 seconds
346 // count charges
347 if(goInfo->trap.charges > 0)
348 AddUse();
350 if(IsBattleGroundTrap && ok->GetTypeId() == TYPEID_PLAYER)
352 //BattleGround gameobjects case
353 if(((Player*)ok)->InBattleGround())
354 if(BattleGround *bg = ((Player*)ok)->GetBattleGround())
355 bg->HandleTriggerBuff(GetGUID());
360 if(uint32 max_charges = goInfo->GetCharges())
362 if (m_usetimes >= max_charges)
364 m_usetimes = 0;
365 SetLootState(GO_JUST_DEACTIVATED); // can be despawned or destroyed
370 break;
372 case GO_ACTIVATED:
374 switch(GetGoType())
376 case GAMEOBJECT_TYPE_DOOR:
377 case GAMEOBJECT_TYPE_BUTTON:
378 if (GetGOInfo()->GetAutoCloseTime() && (m_cooldownTime < time(NULL)))
379 ResetDoorOrButton();
380 break;
381 case GAMEOBJECT_TYPE_GOOBER:
382 if (m_cooldownTime < time(NULL))
384 RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
386 SetLootState(GO_JUST_DEACTIVATED);
387 m_cooldownTime = 0;
389 break;
390 default:
391 break;
393 break;
395 case GO_JUST_DEACTIVATED:
397 //if Gameobject should cast spell, then this, but some GOs (type = 10) should be destroyed
398 if (GetGoType() == GAMEOBJECT_TYPE_GOOBER)
400 uint32 spellId = GetGOInfo()->goober.spellId;
402 if(spellId)
404 std::set<uint32>::const_iterator it = m_unique_users.begin();
405 std::set<uint32>::const_iterator end = m_unique_users.end();
406 for (; it != end; it++)
408 if (Unit* owner = Unit::GetUnit(*this, uint64(*it)))
409 owner->CastSpell(owner, spellId, false, NULL, NULL, GetGUID());
412 m_unique_users.clear();
413 m_usetimes = 0;
416 SetGoState(GO_STATE_READY);
418 //any return here in case battleground traps
421 if(GetOwnerGUID())
423 if(Unit* owner = GetOwner())
424 owner->RemoveGameObject(this, false);
426 SetRespawnTime(0);
427 Delete();
428 return;
431 //burning flags in some battlegrounds, if you find better condition, just add it
432 if (GetGOInfo()->IsDespawnAtAction() || GetGoAnimProgress() > 0)
434 SendObjectDeSpawnAnim(GetGUID());
435 //reset flags
436 SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags);
439 loot.clear();
440 SetLootState(GO_READY);
442 if(!m_respawnDelayTime)
443 return;
445 if(!m_spawnedByDefault)
447 m_respawnTime = 0;
448 return;
451 m_respawnTime = time(NULL) + m_respawnDelayTime;
453 // if option not set then object will be saved at grid unload
454 if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY))
455 SaveRespawnTime();
457 UpdateObjectVisibility();
459 break;
464 void GameObject::Refresh()
466 // not refresh despawned not casted GO (despawned casted GO destroyed in all cases anyway)
467 if(m_respawnTime > 0 && m_spawnedByDefault)
468 return;
470 if(isSpawned())
471 GetMap()->Add(this);
474 void GameObject::AddUniqueUse(Player* player)
476 AddUse();
477 m_unique_users.insert(player->GetGUIDLow());
480 void GameObject::Delete()
482 SendObjectDeSpawnAnim(GetGUID());
484 SetGoState(GO_STATE_READY);
485 SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags);
487 uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<GameObject>(GetDBTableGUIDLow()) : 0;
488 if (poolid)
489 sPoolMgr.UpdatePool<GameObject>(poolid, GetDBTableGUIDLow());
490 else
491 AddObjectToRemoveList();
494 void GameObject::getFishLoot(Loot *fishloot, Player* loot_owner)
496 fishloot->clear();
498 uint32 zone, subzone;
499 GetZoneAndAreaId(zone,subzone);
501 // if subzone loot exist use it
502 if (!fishloot->FillLoot(subzone, LootTemplates_Fishing, loot_owner, true, true))
503 // else use zone loot (must exist in like case)
504 fishloot->FillLoot(zone, LootTemplates_Fishing, loot_owner,true);
507 void GameObject::SaveToDB()
509 // this should only be used when the gameobject has already been loaded
510 // preferably after adding to map, because mapid may not be valid otherwise
511 GameObjectData const *data = sObjectMgr.GetGOData(m_DBTableGuid);
512 if(!data)
514 sLog.outError("GameObject::SaveToDB failed, cannot get gameobject data!");
515 return;
518 SaveToDB(GetMapId(), data->spawnMask, data->phaseMask);
521 void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
523 const GameObjectInfo *goI = GetGOInfo();
525 if (!goI)
526 return;
528 if (!m_DBTableGuid)
529 m_DBTableGuid = GetGUIDLow();
530 // update in loaded data (changing data only in this place)
531 GameObjectData& data = sObjectMgr.NewGOData(m_DBTableGuid);
533 // data->guid = guid don't must be update at save
534 data.id = GetEntry();
535 data.mapid = mapid;
536 data.phaseMask = phaseMask;
537 data.posX = GetPositionX();
538 data.posY = GetPositionY();
539 data.posZ = GetPositionZ();
540 data.orientation = GetOrientation();
541 data.rotation0 = GetFloatValue(GAMEOBJECT_PARENTROTATION+0);
542 data.rotation1 = GetFloatValue(GAMEOBJECT_PARENTROTATION+1);
543 data.rotation2 = GetFloatValue(GAMEOBJECT_PARENTROTATION+2);
544 data.rotation3 = GetFloatValue(GAMEOBJECT_PARENTROTATION+3);
545 data.spawntimesecs = m_spawnedByDefault ? m_respawnDelayTime : -(int32)m_respawnDelayTime;
546 data.animprogress = GetGoAnimProgress();
547 data.go_state = GetGoState();
548 data.spawnMask = spawnMask;
550 // updated in DB
551 std::ostringstream ss;
552 ss << "INSERT INTO gameobject VALUES ( "
553 << m_DBTableGuid << ", "
554 << GetEntry() << ", "
555 << mapid << ", "
556 << uint32(spawnMask) << "," // cast to prevent save as symbol
557 << uint16(GetPhaseMask()) << "," // prevent out of range error
558 << GetPositionX() << ", "
559 << GetPositionY() << ", "
560 << GetPositionZ() << ", "
561 << GetOrientation() << ", "
562 << GetFloatValue(GAMEOBJECT_PARENTROTATION) << ", "
563 << GetFloatValue(GAMEOBJECT_PARENTROTATION+1) << ", "
564 << GetFloatValue(GAMEOBJECT_PARENTROTATION+2) << ", "
565 << GetFloatValue(GAMEOBJECT_PARENTROTATION+3) << ", "
566 << m_respawnDelayTime << ", "
567 << uint32(GetGoAnimProgress()) << ", "
568 << uint32(GetGoState()) << ")";
570 WorldDatabase.BeginTransaction();
571 WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
572 WorldDatabase.PExecuteLog("%s", ss.str().c_str());
573 WorldDatabase.CommitTransaction();
576 bool GameObject::LoadFromDB(uint32 guid, Map *map)
578 GameObjectData const* data = sObjectMgr.GetGOData(guid);
580 if( !data )
582 sLog.outErrorDb("Gameobject (GUID: %u) not found in table `gameobject`, can't load. ",guid);
583 return false;
586 uint32 entry = data->id;
587 //uint32 map_id = data->mapid; // already used before call
588 uint32 phaseMask = data->phaseMask;
589 float x = data->posX;
590 float y = data->posY;
591 float z = data->posZ;
592 float ang = data->orientation;
594 float rotation0 = data->rotation0;
595 float rotation1 = data->rotation1;
596 float rotation2 = data->rotation2;
597 float rotation3 = data->rotation3;
599 uint32 animprogress = data->animprogress;
600 GOState go_state = data->go_state;
602 m_DBTableGuid = guid;
603 if (map->GetInstanceId() != 0) guid = sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);
605 if (!Create(guid,entry, map, phaseMask, x, y, z, ang, rotation0, rotation1, rotation2, rotation3, animprogress, go_state) )
606 return false;
608 if (!GetGOInfo()->GetDespawnPossibility() && !GetGOInfo()->IsDespawnAtAction() && data->spawntimesecs >= 0)
610 SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_NODESPAWN);
611 m_spawnedByDefault = true;
612 m_respawnDelayTime = 0;
613 m_respawnTime = 0;
615 else
617 if(data->spawntimesecs >= 0)
619 m_spawnedByDefault = true;
620 m_respawnDelayTime = data->spawntimesecs;
621 m_respawnTime = sObjectMgr.GetGORespawnTime(m_DBTableGuid, map->GetInstanceId());
623 // ready to respawn
624 if(m_respawnTime && m_respawnTime <= time(NULL))
626 m_respawnTime = 0;
627 sObjectMgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
630 else
632 m_spawnedByDefault = false;
633 m_respawnDelayTime = -data->spawntimesecs;
634 m_respawnTime = 0;
638 return true;
641 void GameObject::DeleteFromDB()
643 sObjectMgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
644 sObjectMgr.DeleteGOData(m_DBTableGuid);
645 WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
646 WorldDatabase.PExecuteLog("DELETE FROM game_event_gameobject WHERE guid = '%u'", m_DBTableGuid);
647 WorldDatabase.PExecuteLog("DELETE FROM gameobject_battleground WHERE guid = '%u'", m_DBTableGuid);
650 GameObjectInfo const *GameObject::GetGOInfo() const
652 return m_goInfo;
655 /*********************************************************/
656 /*** QUEST SYSTEM ***/
657 /*********************************************************/
658 bool GameObject::hasQuest(uint32 quest_id) const
660 QuestRelations const& qr = sObjectMgr.mGOQuestRelations;
661 for(QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr)
663 if(itr->second==quest_id)
664 return true;
666 return false;
669 bool GameObject::hasInvolvedQuest(uint32 quest_id) const
671 QuestRelations const& qr = sObjectMgr.mGOQuestInvolvedRelations;
672 for(QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr)
674 if(itr->second==quest_id)
675 return true;
677 return false;
680 bool GameObject::IsTransport() const
682 // If something is marked as a transport, don't transmit an out of range packet for it.
683 GameObjectInfo const * gInfo = GetGOInfo();
684 if(!gInfo) return false;
685 return gInfo->type == GAMEOBJECT_TYPE_TRANSPORT || gInfo->type == GAMEOBJECT_TYPE_MO_TRANSPORT;
688 Unit* GameObject::GetOwner() const
690 return ObjectAccessor::GetUnit(*this, GetOwnerGUID());
693 void GameObject::SaveRespawnTime()
695 if(m_respawnTime > time(NULL) && m_spawnedByDefault)
696 sObjectMgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),m_respawnTime);
699 bool GameObject::isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const
701 // Not in world
702 if(!IsInWorld() || !u->IsInWorld())
703 return false;
705 // invisible at client always
706 if(!GetGOInfo()->displayId)
707 return false;
709 // Transport always visible at this step implementation
710 if(IsTransport() && IsInMap(u))
711 return true;
713 // quick check visibility false cases for non-GM-mode
714 if(!u->isGameMaster())
716 // despawned and then not visible for non-GM in GM-mode
717 if(!isSpawned())
718 return false;
720 // special invisibility cases
721 /* TODO: implement trap stealth, take look at spell 2836
722 if(GetGOInfo()->type == GAMEOBJECT_TYPE_TRAP && GetGOInfo()->trap.stealthed && u->IsHostileTo(GetOwner()))
724 if(check stuff here)
725 return false;
729 // check distance
730 return IsWithinDistInMap(viewPoint,World::GetMaxVisibleDistanceForObject() +
731 (inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false);
734 void GameObject::Respawn()
736 if(m_spawnedByDefault && m_respawnTime > 0)
738 m_respawnTime = time(NULL);
739 sObjectMgr.SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
743 bool GameObject::ActivateToQuest( Player *pTarget)const
745 if(!sObjectMgr.IsGameObjectForQuests(GetEntry()))
746 return false;
748 switch(GetGoType())
750 // scan GO chest with loot including quest items
751 case GAMEOBJECT_TYPE_CHEST:
753 if(LootTemplates_Gameobject.HaveQuestLootForPlayer(GetGOInfo()->GetLootId(), pTarget))
755 //look for battlegroundAV for some objects which are only activated after mine gots captured by own team
756 if (GetEntry() == BG_AV_OBJECTID_MINE_N || GetEntry() == BG_AV_OBJECTID_MINE_S)
757 if (BattleGround *bg = pTarget->GetBattleGround())
758 if (bg->GetTypeID() == BATTLEGROUND_AV && !(((BattleGroundAV*)bg)->PlayerCanDoMineQuest(GetEntry(),pTarget->GetTeam())))
759 return false;
760 return true;
762 break;
764 case GAMEOBJECT_TYPE_GOOBER:
766 if(pTarget->GetQuestStatus(GetGOInfo()->goober.questId) == QUEST_STATUS_INCOMPLETE)
767 return true;
768 break;
770 default:
771 break;
774 return false;
777 void GameObject::TriggeringLinkedGameObject( uint32 trapEntry, Unit* target)
779 GameObjectInfo const* trapInfo = sGOStorage.LookupEntry<GameObjectInfo>(trapEntry);
780 if(!trapInfo || trapInfo->type!=GAMEOBJECT_TYPE_TRAP)
781 return;
783 SpellEntry const* trapSpell = sSpellStore.LookupEntry(trapInfo->trap.spellId);
784 if(!trapSpell) // checked at load already
785 return;
787 float range = GetSpellMaxRange(sSpellRangeStore.LookupEntry(trapSpell->rangeIndex));
789 // search nearest linked GO
790 GameObject* trapGO = NULL;
792 // using original GO distance
793 CellPair p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
794 Cell cell(p);
795 cell.data.Part.reserved = ALL_DISTRICT;
797 MaNGOS::NearestGameObjectEntryInObjectRangeCheck go_check(*target,trapEntry,range);
798 MaNGOS::GameObjectLastSearcher<MaNGOS::NearestGameObjectEntryInObjectRangeCheck> checker(this, trapGO,go_check);
800 TypeContainerVisitor<MaNGOS::GameObjectLastSearcher<MaNGOS::NearestGameObjectEntryInObjectRangeCheck>, GridTypeMapContainer > object_checker(checker);
801 CellLock<GridReadGuard> cell_lock(cell, p);
802 cell_lock->Visit(cell_lock, object_checker, *GetMap(), *target, range);
805 // found correct GO
806 // FIXME: when GO casting will be implemented trap must cast spell to target
807 if(trapGO)
808 target->CastSpell(target, trapSpell, true, NULL, NULL, GetGUID());
811 GameObject* GameObject::LookupFishingHoleAround(float range)
813 GameObject* ok = NULL;
815 CellPair p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY()));
816 Cell cell(p);
817 cell.data.Part.reserved = ALL_DISTRICT;
818 MaNGOS::NearestGameObjectFishingHole u_check(*this, range);
819 MaNGOS::GameObjectSearcher<MaNGOS::NearestGameObjectFishingHole> checker(this, ok, u_check);
821 CellLock<GridReadGuard> cell_lock(cell, p);
823 TypeContainerVisitor<MaNGOS::GameObjectSearcher<MaNGOS::NearestGameObjectFishingHole>, GridTypeMapContainer > grid_object_checker(checker);
824 cell_lock->Visit(cell_lock, grid_object_checker, *GetMap(), *this, range);
826 return ok;
829 void GameObject::ResetDoorOrButton()
831 if (m_lootState == GO_READY || m_lootState == GO_JUST_DEACTIVATED)
832 return;
834 SwitchDoorOrButton(false);
835 SetLootState(GO_JUST_DEACTIVATED);
836 m_cooldownTime = 0;
839 void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = false */)
841 if(m_lootState != GO_READY)
842 return;
844 if(!time_to_restore)
845 time_to_restore = GetGOInfo()->GetAutoCloseTime();
847 SwitchDoorOrButton(true,alternative);
848 SetLootState(GO_ACTIVATED);
850 m_cooldownTime = time(NULL) + time_to_restore;
853 void GameObject::SwitchDoorOrButton(bool activate, bool alternative /* = false */)
855 if(activate)
856 SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
857 else
858 RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
860 if(GetGoState() == GO_STATE_READY) //if closed -> open
861 SetGoState(alternative ? GO_STATE_ACTIVE_ALTERNATIVE : GO_STATE_ACTIVE);
862 else //if open -> close
863 SetGoState(GO_STATE_READY);
866 void GameObject::Use(Unit* user)
868 // by default spell caster is user
869 Unit* spellCaster = user;
870 uint32 spellId = 0;
871 bool triggered = false;
873 if (user->GetTypeId() == TYPEID_PLAYER && Script->GOHello((Player*)user, this))
874 return;
876 switch(GetGoType())
878 case GAMEOBJECT_TYPE_DOOR: //0
879 case GAMEOBJECT_TYPE_BUTTON: //1
881 //doors/buttons never really despawn, only reset to default state/flags
882 UseDoorOrButton();
884 // activate script
885 GetMap()->ScriptsStart(sGameObjectScripts, GetDBTableGUIDLow(), spellCaster, this);
886 return;
888 case GAMEOBJECT_TYPE_QUESTGIVER: //2
890 if (user->GetTypeId() != TYPEID_PLAYER)
891 return;
893 Player* player = (Player*)user;
895 player->PrepareGossipMenu(this, GetGOInfo()->questgiver.gossipID);
896 player->SendPreparedGossip(this);
897 return;
899 case GAMEOBJECT_TYPE_CHEST:
901 if (user->GetTypeId() != TYPEID_PLAYER)
902 return;
904 // TODO: possible must be moved to loot release (in different from linked triggering)
905 if (GetGOInfo()->chest.eventId)
907 sLog.outDebug("Chest ScriptStart id %u for GO %u", GetGOInfo()->chest.eventId, GetDBTableGUIDLow());
908 GetMap()->ScriptsStart(sEventScripts, GetGOInfo()->chest.eventId, user, this);
911 // triggering linked GO
912 if (uint32 trapEntry = GetGOInfo()->chest.linkedTrapId)
913 TriggeringLinkedGameObject(trapEntry, user);
915 return;
917 case GAMEOBJECT_TYPE_CHAIR: //7 Sitting: Wooden bench, chairs
919 GameObjectInfo const* info = GetGOInfo();
920 if (!info)
921 return;
923 if (user->GetTypeId() != TYPEID_PLAYER)
924 return;
926 Player* player = (Player*)user;
928 // a chair may have n slots. we have to calculate their positions and teleport the player to the nearest one
930 // check if the db is sane
931 if (info->chair.slots > 0)
933 float lowestDist = DEFAULT_VISIBILITY_DISTANCE;
935 float x_lowest = GetPositionX();
936 float y_lowest = GetPositionY();
938 // the object orientation + 1/2 pi
939 // every slot will be on that straight line
940 float orthogonalOrientation = GetOrientation()+M_PI*0.5f;
941 // find nearest slot
942 for(uint32 i=0; i<info->chair.slots; ++i)
944 // the distance between this slot and the center of the go - imagine a 1D space
945 float relativeDistance = (info->size*i)-(info->size*(info->chair.slots-1)/2.0f);
947 float x_i = GetPositionX() + relativeDistance * cos(orthogonalOrientation);
948 float y_i = GetPositionY() + relativeDistance * sin(orthogonalOrientation);
950 // calculate the distance between the player and this slot
951 float thisDistance = player->GetDistance2d(x_i, y_i);
953 /* debug code. It will spawn a npc on each slot to visualize them.
954 Creature* helper = player->SummonCreature(14496, x_i, y_i, GetPositionZ(), GetOrientation(), TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 10000);
955 std::ostringstream output;
956 output << i << ": thisDist: " << thisDistance;
957 helper->MonsterSay(output.str().c_str(), LANG_UNIVERSAL, 0);
960 if (thisDistance <= lowestDist)
962 lowestDist = thisDistance;
963 x_lowest = x_i;
964 y_lowest = y_i;
967 player->TeleportTo(GetMapId(), x_lowest, y_lowest, GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET);
969 else
971 // fallback, will always work
972 player->TeleportTo(GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET);
974 player->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR+info->chair.height);
975 return;
977 case GAMEOBJECT_TYPE_SPELL_FOCUS:
979 // triggering linked GO
980 if (uint32 trapEntry = GetGOInfo()->spellFocus.linkedTrapId)
981 TriggeringLinkedGameObject(trapEntry, user);
983 // some may be activated in addition? Conditions for this? (ex: entry 181616)
984 break;
986 case GAMEOBJECT_TYPE_GOOBER: //10
988 GameObjectInfo const* info = GetGOInfo();
990 if(user->GetTypeId()==TYPEID_PLAYER)
992 Player* player = (Player*)user;
994 if (info->goober.pageId) // show page...
996 WorldPacket data(SMSG_GAMEOBJECT_PAGETEXT, 8);
997 data << GetGUID();
998 player->GetSession()->SendPacket(&data);
1000 else if (info->goober.gossipID) // ...or gossip, if page does not exist
1002 player->PrepareGossipMenu(this, info->goober.gossipID);
1003 player->SendPreparedGossip(this);
1006 if (info->goober.eventId)
1008 sLog.outDebug("Goober ScriptStart id %u for GO entry %u (GUID %u).", info->goober.eventId, GetEntry(), GetDBTableGUIDLow());
1009 GetMap()->ScriptsStart(sEventScripts, info->goober.eventId, player, this);
1012 // possible quest objective for active quests
1013 if (info->goober.questId && sObjectMgr.GetQuestTemplate(info->goober.questId))
1015 //Quest require to be active for GO using
1016 if (player->GetQuestStatus(info->goober.questId) != QUEST_STATUS_INCOMPLETE)
1017 break;
1020 player->CastedCreatureOrGO(info->id, GetGUID(), 0);
1023 if (uint32 trapEntry = info->goober.linkedTrapId)
1024 TriggeringLinkedGameObject(trapEntry, user);
1026 SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
1027 SetLootState(GO_ACTIVATED);
1029 uint32 time_to_restore = info->GetAutoCloseTime();
1031 // this appear to be ok, however others exist in addition to this that should have custom (ex: 190510, 188692, 187389)
1032 if (time_to_restore && info->goober.customAnim)
1033 SendGameObjectCustomAnim(GetGUID());
1034 else
1035 SetGoState(GO_STATE_ACTIVE);
1037 m_cooldownTime = time(NULL) + time_to_restore;
1039 // cast this spell later if provided
1040 spellId = info->goober.spellId;
1042 break;
1044 case GAMEOBJECT_TYPE_CAMERA: //13
1046 GameObjectInfo const* info = GetGOInfo();
1047 if(!info)
1048 return;
1050 if (user->GetTypeId() != TYPEID_PLAYER)
1051 return;
1053 Player* player = (Player*)user;
1055 if (info->camera.cinematicId)
1056 player->SendCinematicStart(info->camera.cinematicId);
1058 if (info->camera.eventID)
1059 GetMap()->ScriptsStart(sEventScripts, info->camera.eventID, player, this);
1061 return;
1063 case GAMEOBJECT_TYPE_FISHINGNODE: //17 fishing bobber
1065 if (user->GetTypeId() != TYPEID_PLAYER)
1066 return;
1068 Player* player = (Player*)user;
1070 if (player->GetGUID() != GetOwnerGUID())
1071 return;
1073 switch(getLootState())
1075 case GO_READY: // ready for loot
1077 // 1) skill must be >= base_zone_skill
1078 // 2) if skill == base_zone_skill => 5% chance
1079 // 3) chance is linear dependence from (base_zone_skill-skill)
1081 uint32 zone, subzone;
1082 GetZoneAndAreaId(zone,subzone);
1084 int32 zone_skill = sObjectMgr.GetFishingBaseSkillLevel(subzone);
1085 if (!zone_skill)
1086 zone_skill = sObjectMgr.GetFishingBaseSkillLevel(zone);
1088 //provide error, no fishable zone or area should be 0
1089 if (!zone_skill)
1090 sLog.outErrorDb("Fishable areaId %u are not properly defined in `skill_fishing_base_level`.",subzone);
1092 int32 skill = player->GetSkillValue(SKILL_FISHING);
1093 int32 chance = skill - zone_skill + 5;
1094 int32 roll = irand(1,100);
1096 DEBUG_LOG("Fishing check (skill: %i zone min skill: %i chance %i roll: %i",skill,zone_skill,chance,roll);
1098 if (skill >= zone_skill && chance >= roll)
1100 // prevent removing GO at spell cancel
1101 player->RemoveGameObject(this,false);
1102 SetOwnerGUID(player->GetGUID());
1104 //fish catched
1105 player->UpdateFishingSkill();
1107 //TODO: find reasonable value for fishing hole search
1108 GameObject* ok = LookupFishingHoleAround(20.0f + CONTACT_DISTANCE);
1109 if (ok)
1111 player->SendLoot(ok->GetGUID(),LOOT_FISHINGHOLE);
1112 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT, ok->GetGOInfo()->id);
1113 SetLootState(GO_JUST_DEACTIVATED);
1115 else
1116 player->SendLoot(GetGUID(),LOOT_FISHING);
1118 else
1120 // fish escaped, can be deleted now
1121 SetLootState(GO_JUST_DEACTIVATED);
1123 WorldPacket data(SMSG_FISH_ESCAPED, 0);
1124 player->GetSession()->SendPacket(&data);
1126 break;
1128 case GO_JUST_DEACTIVATED: // nothing to do, will be deleted at next update
1129 break;
1130 default:
1132 SetLootState(GO_JUST_DEACTIVATED);
1134 WorldPacket data(SMSG_FISH_NOT_HOOKED, 0);
1135 player->GetSession()->SendPacket(&data);
1136 break;
1140 player->FinishSpell(CURRENT_CHANNELED_SPELL);
1141 return;
1143 case GAMEOBJECT_TYPE_SUMMONING_RITUAL: //18
1145 if (user->GetTypeId() != TYPEID_PLAYER)
1146 return;
1148 Player* player = (Player*)user;
1150 Unit* caster = GetOwner();
1152 GameObjectInfo const* info = GetGOInfo();
1154 if (!caster || caster->GetTypeId()!=TYPEID_PLAYER)
1155 return;
1157 // accept only use by player from same group for caster except caster itself
1158 if (((Player*)caster) == player || !((Player*)caster)->IsInSameRaidWith(player))
1159 return;
1161 AddUniqueUse(player);
1163 // full amount unique participants including original summoner
1164 if (GetUniqueUseCount() < info->summoningRitual.reqParticipants)
1165 return;
1167 // in case summoning ritual caster is GO creator
1168 spellCaster = caster;
1170 if (!caster->GetCurrentSpell(CURRENT_CHANNELED_SPELL))
1171 return;
1173 spellId = info->summoningRitual.spellId;
1174 if (spellId == 62330) // GO store not existed spell, replace by expected
1176 // spell have reagent and mana cost but it not expected use its
1177 // it triggered spell in fact casted at currently channeled GO
1178 spellId = 61993;
1179 triggered = true;
1182 // finish spell
1183 player->FinishSpell(CURRENT_CHANNELED_SPELL);
1185 // can be deleted now
1186 SetLootState(GO_JUST_DEACTIVATED);
1188 // go to end function to spell casting
1189 break;
1191 case GAMEOBJECT_TYPE_SPELLCASTER: //22
1193 SetUInt32Value(GAMEOBJECT_FLAGS,2);
1195 GameObjectInfo const* info = GetGOInfo();
1196 if (!info)
1197 return;
1199 if (info->spellcaster.partyOnly)
1201 Unit* caster = GetOwner();
1202 if (!caster || caster->GetTypeId() != TYPEID_PLAYER)
1203 return;
1205 if (user->GetTypeId() != TYPEID_PLAYER || !((Player*)user)->IsInSameRaidWith((Player*)caster))
1206 return;
1209 spellId = info->spellcaster.spellId;
1211 AddUse();
1212 break;
1214 case GAMEOBJECT_TYPE_MEETINGSTONE: //23
1216 GameObjectInfo const* info = GetGOInfo();
1218 if (user->GetTypeId() != TYPEID_PLAYER)
1219 return;
1221 Player* player = (Player*)user;
1223 Player* targetPlayer = ObjectAccessor::FindPlayer(player->GetSelection());
1225 // accept only use by player from same group for caster except caster itself
1226 if (!targetPlayer || targetPlayer == player || !targetPlayer->IsInSameGroupWith(player))
1227 return;
1229 //required lvl checks!
1230 uint8 level = player->getLevel();
1231 if (level < info->meetingstone.minLevel || level > info->meetingstone.maxLevel)
1232 return;
1234 level = targetPlayer->getLevel();
1235 if (level < info->meetingstone.minLevel || level > info->meetingstone.maxLevel)
1236 return;
1238 if (info->id == 194097)
1239 spellId = 61994; // Ritual of Summoning
1240 else
1241 spellId = 59782; // Summoning Stone Effect
1243 break;
1245 case GAMEOBJECT_TYPE_FLAGSTAND: // 24
1247 if (user->GetTypeId() != TYPEID_PLAYER)
1248 return;
1250 Player* player = (Player*)user;
1252 if (player->CanUseBattleGroundObject())
1254 // in battleground check
1255 BattleGround *bg = player->GetBattleGround();
1256 if (!bg)
1257 return;
1258 // BG flag click
1259 // AB:
1260 // 15001
1261 // 15002
1262 // 15003
1263 // 15004
1264 // 15005
1265 bg->EventPlayerClickedOnFlag(player, this);
1266 return; //we don;t need to delete flag ... it is despawned!
1268 break;
1270 case GAMEOBJECT_TYPE_FLAGDROP: // 26
1272 if (user->GetTypeId() != TYPEID_PLAYER)
1273 return;
1275 Player* player = (Player*)user;
1277 if (player->CanUseBattleGroundObject())
1279 // in battleground check
1280 BattleGround *bg = player->GetBattleGround();
1281 if (!bg)
1282 return;
1283 // BG flag dropped
1284 // WS:
1285 // 179785 - Silverwing Flag
1286 // 179786 - Warsong Flag
1287 // EotS:
1288 // 184142 - Netherstorm Flag
1289 GameObjectInfo const* info = GetGOInfo();
1290 if (info)
1292 switch(info->id)
1294 case 179785: // Silverwing Flag
1295 // check if it's correct bg
1296 if(bg->GetTypeID() == BATTLEGROUND_WS)
1297 bg->EventPlayerClickedOnFlag(player, this);
1298 break;
1299 case 179786: // Warsong Flag
1300 if(bg->GetTypeID() == BATTLEGROUND_WS)
1301 bg->EventPlayerClickedOnFlag(player, this);
1302 break;
1303 case 184142: // Netherstorm Flag
1304 if(bg->GetTypeID() == BATTLEGROUND_EY)
1305 bg->EventPlayerClickedOnFlag(player, this);
1306 break;
1309 //this cause to call return, all flags must be deleted here!!
1310 spellId = 0;
1311 Delete();
1313 break;
1315 case GAMEOBJECT_TYPE_BARBER_CHAIR: //32
1317 GameObjectInfo const* info = GetGOInfo();
1318 if (!info)
1319 return;
1321 if (user->GetTypeId() != TYPEID_PLAYER)
1322 return;
1324 Player* player = (Player*)user;
1326 // fallback, will always work
1327 player->TeleportTo(GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET);
1329 WorldPacket data(SMSG_ENABLE_BARBER_SHOP, 0);
1330 player->GetSession()->SendPacket(&data);
1332 player->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR+info->barberChair.chairheight);
1333 return;
1335 default:
1336 sLog.outError("GameObject::Use unhandled GameObject type %u (entry %u).", GetGoType(), GetEntry());
1337 break;
1340 if (!spellId)
1341 return;
1343 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellId );
1344 if (!spellInfo)
1346 sLog.outError("WORLD: unknown spell id %u at use action for gameobject (Entry: %u GoType: %u )", spellId,GetEntry(),GetGoType());
1347 return;
1350 Spell *spell = new Spell(spellCaster, spellInfo, triggered,GetGUID());
1352 // spell target is user of GO
1353 SpellCastTargets targets;
1354 targets.setUnitTarget( user );
1356 spell->prepare(&targets);
1359 // overwrite WorldObject function for proper name localization
1360 const char* GameObject::GetNameForLocaleIdx(int32 loc_idx) const
1362 if (loc_idx >= 0)
1364 GameObjectLocale const *cl = sObjectMgr.GetGameObjectLocale(GetEntry());
1365 if (cl)
1367 if (cl->Name.size() > (size_t)loc_idx && !cl->Name[loc_idx].empty())
1368 return cl->Name[loc_idx].c_str();
1372 return GetName();
1375 void GameObject::UpdateRotationFields(float rotation2 /*=0.0f*/, float rotation3 /*=0.0f*/)
1377 static double const atan_pow = atan(pow(2.0f, -20.0f));
1379 double f_rot1 = sin(GetOrientation() / 2.0f);
1380 double f_rot2 = cos(GetOrientation() / 2.0f);
1382 int64 i_rot1 = int64(f_rot1 / atan_pow *(f_rot2 >= 0 ? 1.0f : -1.0f));
1383 int64 rotation = (i_rot1 << 43 >> 43) & 0x00000000001FFFFF;
1385 //float f_rot2 = sin(0.0f / 2.0f);
1386 //int64 i_rot2 = f_rot2 / atan(pow(2.0f, -20.0f));
1387 //rotation |= (((i_rot2 << 22) >> 32) >> 11) & 0x000003FFFFE00000;
1389 //float f_rot3 = sin(0.0f / 2.0f);
1390 //int64 i_rot3 = f_rot3 / atan(pow(2.0f, -21.0f));
1391 //rotation |= (i_rot3 >> 42) & 0x7FFFFC0000000000;
1393 m_rotation = rotation;
1395 if(rotation2==0.0f && rotation3==0.0f)
1397 rotation2 = f_rot1;
1398 rotation3 = f_rot2;
1401 SetFloatValue(GAMEOBJECT_PARENTROTATION+2, rotation2);
1402 SetFloatValue(GAMEOBJECT_PARENTROTATION+3, rotation3);