*Update creature formation code.
--HG-- branch : trunk
This commit is contained in:
+26
-41
@@ -174,24 +174,18 @@ void Creature::AddToWorld()
|
|||||||
{
|
{
|
||||||
ObjectAccessor::Instance().AddObject(this);
|
ObjectAccessor::Instance().AddObject(this);
|
||||||
Unit::AddToWorld();
|
Unit::AddToWorld();
|
||||||
AIM_Initialize();
|
|
||||||
SearchFormation();
|
SearchFormation();
|
||||||
|
AIM_Initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::RemoveFromWorld()
|
void Creature::RemoveFromWorld()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Clear formation info
|
|
||||||
if(m_formation)
|
|
||||||
{
|
|
||||||
formation_mgr.DestroyGroup(m_formation, GetGUID());
|
|
||||||
m_formation = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
///- Remove the creature from the accessor
|
|
||||||
if(IsInWorld())
|
if(IsInWorld())
|
||||||
{
|
{
|
||||||
|
// Clear formation info
|
||||||
|
if(m_formation)
|
||||||
|
formation_mgr.RemoveCreatureFromGroup(m_formation, this);
|
||||||
Unit::RemoveFromWorld();
|
Unit::RemoveFromWorld();
|
||||||
ObjectAccessor::Instance().RemoveObject(this);
|
ObjectAccessor::Instance().RemoveObject(this);
|
||||||
}
|
}
|
||||||
@@ -199,19 +193,16 @@ void Creature::RemoveFromWorld()
|
|||||||
|
|
||||||
void Creature::SearchFormation()
|
void Creature::SearchFormation()
|
||||||
{
|
{
|
||||||
if(isPet())
|
if(isSummon())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32 lowguid = GetDBTableGUIDLow();
|
uint32 lowguid = GetDBTableGUIDLow();
|
||||||
if(!lowguid)
|
if(!lowguid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UNORDERED_MAP<uint32, FormationMember *>::iterator frmdata = CreatureGroupMap.find(lowguid);
|
CreatureGroupInfoType::iterator frmdata = CreatureGroupMap.find(lowguid);
|
||||||
if(frmdata != CreatureGroupMap.end())
|
if(frmdata != CreatureGroupMap.end())
|
||||||
{
|
formation_mgr.AddCreatureToGroup(frmdata->second->leaderGUID, this);
|
||||||
uint32 formationID = frmdata->second->leaderGUID;
|
|
||||||
formation_mgr.UpdateCreatureGroup(formationID, *this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::RemoveCorpse()
|
void Creature::RemoveCorpse()
|
||||||
@@ -620,17 +611,9 @@ bool Creature::AIM_Initialize(CreatureAI* ai)
|
|||||||
}
|
}
|
||||||
|
|
||||||
UnitAI *oldAI = i_AI;
|
UnitAI *oldAI = i_AI;
|
||||||
|
|
||||||
|
Motion_Initialize();
|
||||||
|
|
||||||
if(!m_formation)
|
|
||||||
i_motionMaster.Initialize();
|
|
||||||
else if(m_formation->getLeader() == this)
|
|
||||||
{
|
|
||||||
m_formation->FormDismiss();
|
|
||||||
i_motionMaster.Initialize();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_formation->isFormed() ? i_motionMaster.MoveIdle(MOTION_SLOT_IDLE) : i_motionMaster.Initialize();
|
|
||||||
|
|
||||||
i_AI = ai ? ai : FactorySelector::selectAI(this);
|
i_AI = ai ? ai : FactorySelector::selectAI(this);
|
||||||
if(oldAI) delete oldAI;
|
if(oldAI) delete oldAI;
|
||||||
IsAIEnabled = true;
|
IsAIEnabled = true;
|
||||||
@@ -638,6 +621,21 @@ bool Creature::AIM_Initialize(CreatureAI* ai)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Creature::Motion_Initialize()
|
||||||
|
{
|
||||||
|
if(!m_formation)
|
||||||
|
i_motionMaster.Initialize();
|
||||||
|
else if(m_formation->getLeader() == this)
|
||||||
|
{
|
||||||
|
m_formation->FormationReset(false);
|
||||||
|
i_motionMaster.Initialize();
|
||||||
|
}
|
||||||
|
else if(m_formation->isFormed())
|
||||||
|
i_motionMaster.MoveIdle(MOTION_SLOT_IDLE); //wait the order of leader
|
||||||
|
else
|
||||||
|
i_motionMaster.Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
bool Creature::Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, const CreatureData *data)
|
bool Creature::Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, const CreatureData *data)
|
||||||
{
|
{
|
||||||
SetMapId(map->GetId());
|
SetMapId(map->GetId());
|
||||||
@@ -1676,7 +1674,7 @@ void Creature::setDeathState(DeathState s)
|
|||||||
|
|
||||||
//Dismiss group if is leader
|
//Dismiss group if is leader
|
||||||
if(m_formation && m_formation->getLeader() == this)
|
if(m_formation && m_formation->getLeader() == this)
|
||||||
m_formation->FormDismiss(true);
|
m_formation->FormationReset(true);
|
||||||
}
|
}
|
||||||
if(s == JUST_ALIVED)
|
if(s == JUST_ALIVED)
|
||||||
{
|
{
|
||||||
@@ -1690,22 +1688,9 @@ void Creature::setDeathState(DeathState s)
|
|||||||
AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
|
AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
|
||||||
SetUInt32Value(UNIT_NPC_FLAGS, cinfo->npcflag);
|
SetUInt32Value(UNIT_NPC_FLAGS, cinfo->npcflag);
|
||||||
clearUnitState(UNIT_STAT_ALL_STATE);
|
clearUnitState(UNIT_STAT_ALL_STATE);
|
||||||
//i_motionMaster.Initialize();
|
|
||||||
SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool));
|
SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool));
|
||||||
LoadCreaturesAddon(true);
|
LoadCreaturesAddon(true);
|
||||||
/////////////////////!!!!!!!!!!!!!!!!!!!!
|
Motion_Initialize();
|
||||||
if(!m_formation)
|
|
||||||
i_motionMaster.Initialize();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(m_formation->getLeader() == this)
|
|
||||||
{
|
|
||||||
m_formation->FormDismiss(false);
|
|
||||||
i_motionMaster.Initialize();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_formation->isFormed() ? i_motionMaster.MoveIdle(MOTION_SLOT_IDLE) : i_motionMaster.Initialize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -28,7 +28,6 @@
|
|||||||
#include "LootMgr.h"
|
#include "LootMgr.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "Cell.h"
|
#include "Cell.h"
|
||||||
#include "CreatureGroups.h"
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@@ -38,6 +37,7 @@ class CreatureAI;
|
|||||||
class Quest;
|
class Quest;
|
||||||
class Player;
|
class Player;
|
||||||
class WorldSession;
|
class WorldSession;
|
||||||
|
class CreatureGroup;
|
||||||
|
|
||||||
enum Gossip_Option
|
enum Gossip_Option
|
||||||
{
|
{
|
||||||
@@ -494,6 +494,7 @@ class TRINITY_DLL_SPEC Creature : public Unit
|
|||||||
bool IsInEvadeMode() const;
|
bool IsInEvadeMode() const;
|
||||||
|
|
||||||
bool AIM_Initialize(CreatureAI* ai = NULL);
|
bool AIM_Initialize(CreatureAI* ai = NULL);
|
||||||
|
void Motion_Initialize();
|
||||||
|
|
||||||
void AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type);
|
void AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type);
|
||||||
CreatureAI* AI() { return (CreatureAI*)i_AI; }
|
CreatureAI* AI() { return (CreatureAI*)i_AI; }
|
||||||
|
|||||||
+84
-106
@@ -29,12 +29,13 @@
|
|||||||
INSTANTIATE_SINGLETON_1(CreatureGroupManager);
|
INSTANTIATE_SINGLETON_1(CreatureGroupManager);
|
||||||
|
|
||||||
CreatureGroupHolderType CreatureGroupHolder;
|
CreatureGroupHolderType CreatureGroupHolder;
|
||||||
UNORDERED_MAP<uint32, FormationMember*> CreatureGroupMap;
|
CreatureGroupInfoType CreatureGroupMap;
|
||||||
|
|
||||||
void CreatureGroupManager::UpdateCreatureGroup(uint32 group_id, Creature &member)
|
void CreatureGroupManager::AddCreatureToGroup(uint32 group_id, Creature *member)
|
||||||
{
|
{
|
||||||
std::multimap<uint32, CreatureGroup *>::iterator cgroup_data = CreatureGroupHolder.find(group_id);
|
CreatureGroupHolderType::iterator cgroup_data = CreatureGroupHolder.find(group_id);
|
||||||
|
|
||||||
|
//Add member to an existing group
|
||||||
if(cgroup_data != CreatureGroupHolder.end())
|
if(cgroup_data != CreatureGroupHolder.end())
|
||||||
{
|
{
|
||||||
typedef std::multimap<uint32, CreatureGroup *>::iterator multiplegroup;
|
typedef std::multimap<uint32, CreatureGroup *>::iterator multiplegroup;
|
||||||
@@ -42,28 +43,26 @@ void CreatureGroupManager::UpdateCreatureGroup(uint32 group_id, Creature &member
|
|||||||
|
|
||||||
for(multiplegroup i = range.first; i != range.second; ++i)
|
for(multiplegroup i = range.first; i != range.second; ++i)
|
||||||
{
|
{
|
||||||
if(i->second->getInstanceID() == member.GetInstanceId())
|
if(i->second->getInstanceID() == member->GetInstanceId())
|
||||||
{
|
{
|
||||||
sLog.outDebug("Group found: %u, inserting creature GUID: %u, Group InstanceID %u", group_id, member.GetGUIDLow(), i->second->getInstanceID());
|
sLog.outDebug("Group found: %u, inserting creature GUID: %u, Group InstanceID %u", group_id, member->GetGUIDLow(), i->second->getInstanceID());
|
||||||
i->second->AddMember(member);
|
i->second->AddMember(member);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Create new group
|
||||||
sLog.outDebug("Group not found: %u. Creating new group.", group_id);
|
sLog.outDebug("Group not found: %u. Creating new group.", group_id);
|
||||||
CreatureGroup* cgroup = new CreatureGroup(group_id, member.GetInstanceId());
|
CreatureGroup* cgroup = new CreatureGroup(group_id, member->GetInstanceId());
|
||||||
cgroup->AddMember(member);
|
|
||||||
CreatureGroupHolder.insert(std::make_pair(group_id, cgroup));
|
CreatureGroupHolder.insert(std::make_pair(group_id, cgroup));
|
||||||
|
cgroup->AddMember(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureGroupManager::DestroyGroup(CreatureGroup *&formation, uint64 guid)
|
void CreatureGroupManager::RemoveCreatureFromGroup(CreatureGroup *formation, Creature *member)
|
||||||
{
|
{
|
||||||
if(!formation || !guid)
|
sLog.outDebug("Deleting member pointer to GUID: %u from group %u", formation->GetId(), member->GetDBTableGUIDLow());
|
||||||
return;
|
formation->RemoveMember(member);
|
||||||
|
|
||||||
sLog.outDebug("Deleting member pointer to GUID: %u from group %u", formation->GetId(), guid);
|
|
||||||
formation->RemoveMember(guid);
|
|
||||||
|
|
||||||
if(formation->isEmpty())
|
if(formation->isEmpty())
|
||||||
{
|
{
|
||||||
@@ -111,7 +110,7 @@ void CreatureGroupManager::LoadCreatureFormations()
|
|||||||
barGoLink bar( total_records);
|
barGoLink bar( total_records);
|
||||||
Field *fields;
|
Field *fields;
|
||||||
|
|
||||||
FormationMember *group_member;
|
FormationInfo *group_member;
|
||||||
//Loading data...
|
//Loading data...
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -119,18 +118,18 @@ void CreatureGroupManager::LoadCreatureFormations()
|
|||||||
|
|
||||||
bar.step();
|
bar.step();
|
||||||
//Load group member data
|
//Load group member data
|
||||||
group_member = new FormationMember;
|
group_member = new FormationInfo;
|
||||||
group_member->leaderGUID = fields[0].GetUInt32();
|
group_member->leaderGUID = fields[0].GetUInt32();
|
||||||
group_member->memberGUID = fields[1].GetUInt32();
|
uint32 memberGUID = fields[1].GetUInt32();
|
||||||
group_member->groupAI = fields[4].GetUInt8();
|
group_member->groupAI = fields[4].GetUInt8();
|
||||||
//If creature is group leader we may skip loading of dist/angle
|
//If creature is group leader we may skip loading of dist/angle
|
||||||
if(group_member->leaderGUID != group_member->memberGUID)
|
if(group_member->leaderGUID != memberGUID)
|
||||||
{
|
{
|
||||||
group_member->follow_dist = fields[2].GetUInt32();
|
group_member->follow_dist = fields[2].GetUInt32();
|
||||||
group_member->follow_angle = fields[3].GetUInt32();
|
group_member->follow_angle = fields[3].GetUInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureGroupMap[group_member->memberGUID] = group_member;
|
CreatureGroupMap[memberGUID] = group_member;
|
||||||
|
|
||||||
if(lastLeaderGUID != group_member->leaderGUID)
|
if(lastLeaderGUID != group_member->leaderGUID)
|
||||||
lastLeaderGUID = group_member->leaderGUID;
|
lastLeaderGUID = group_member->leaderGUID;
|
||||||
@@ -144,123 +143,102 @@ void CreatureGroupManager::LoadCreatureFormations()
|
|||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureGroup::AddMember(Creature &member)
|
void CreatureGroup::AddMember(Creature *member)
|
||||||
{
|
{
|
||||||
sLog.outDebug("Adding unit GUID: %u.", member.GetGUIDLow());
|
sLog.outDebug("CreatureGroup::AddMember: Adding unit GUIDLow: %u.", member->GetGUIDLow());
|
||||||
|
|
||||||
uint64 guid = member.GetGUID();
|
//Check if it is a leader
|
||||||
//We first search creature member if exist
|
if(member->GetDBTableGUIDLow() == m_groupID)
|
||||||
if(CreatureGroupMembers.find(guid) != CreatureGroupMembers.end())
|
{
|
||||||
|
sLog.outDebug("Unit GUID: %u is formation leader. Adding group.", member->GetGUIDLow());
|
||||||
|
m_leader = member;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_members[member] = CreatureGroupMap.find(member->GetDBTableGUIDLow())->second;
|
||||||
|
member->SetFormation(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatureGroup::RemoveMember(Creature *member)
|
||||||
|
{
|
||||||
|
if(m_leader == member)
|
||||||
|
m_leader = NULL;
|
||||||
|
|
||||||
|
m_members.erase(member);
|
||||||
|
member->SetFormation(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatureGroup::MemberAttackStart(Creature *member, Unit *target)
|
||||||
|
{
|
||||||
|
uint8 groupAI = CreatureGroupMap[member->GetDBTableGUIDLow()]->groupAI;
|
||||||
|
if(!groupAI)
|
||||||
return;
|
return;
|
||||||
//Check is that shit is a leader
|
|
||||||
if(member.GetDBTableGUIDLow()==m_groupID)
|
|
||||||
{
|
|
||||||
sLog.outDebug("Unit GUID: %u is formation leader. Adding group.", member.GetGUIDLow());
|
|
||||||
m_leader = &member;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sLog.outDebug("Unit GUID: %u is NOT a formation leader. Set IDLE as default movement.", member.GetGUIDLow());
|
|
||||||
member.GetMotionMaster()->MoveIdle(MOTION_SLOT_IDLE);
|
|
||||||
}
|
|
||||||
//Add to the club
|
|
||||||
CreatureGroupMembers[guid] = &member;
|
|
||||||
member.SetFormation(this);
|
|
||||||
sLog.outDebug("Unit GUID: %u added.", member.GetGUID());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreatureGroup::RemoveMember(uint64 guid)
|
if(groupAI == 1 && member != m_leader)
|
||||||
{
|
return;
|
||||||
if(CreatureGroupMembers.find(guid) != CreatureGroupMembers.end())
|
|
||||||
CreatureGroupMembers.erase(guid);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreatureGroup::MemberHasAttacked(Creature &member)
|
for(CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
|
||||||
{
|
|
||||||
uint8 groupAI = CreatureGroupMap[member.GetDBTableGUIDLow()]->groupAI;
|
|
||||||
|
|
||||||
for(UNORDERED_MAP<uint64, Creature*>::iterator itr = CreatureGroupMembers.begin(); itr != CreatureGroupMembers.end(); ++itr)
|
|
||||||
{
|
{
|
||||||
sLog.outDebug("GROUP ATTACK: group instance id %u calls member instid %u", m_leader->GetInstanceId(), member.GetInstanceId());
|
sLog.outDebug("GROUP ATTACK: group instance id %u calls member instid %u", m_leader->GetInstanceId(), member->GetInstanceId());
|
||||||
//sLog.outDebug("AI:%u:Group member found: %u, attacked by %s.", groupAI, itr->second->GetGUIDLow(), member.getVictim()->GetName());
|
//sLog.outDebug("AI:%u:Group member found: %u, attacked by %s.", groupAI, itr->second->GetGUIDLow(), member->getVictim()->GetName());
|
||||||
|
|
||||||
if(itr->second)
|
//Skip one check
|
||||||
{
|
if(itr->first == member)
|
||||||
//Skip one check
|
continue;
|
||||||
if(itr->second == &member)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch(groupAI)
|
if(!itr->first->isAlive())
|
||||||
{
|
continue;
|
||||||
case 0:
|
|
||||||
return;
|
if(itr->first->getVictim())
|
||||||
case 1:
|
continue;
|
||||||
if(&member != m_leader)
|
|
||||||
return;
|
if(itr->first->canAttack(target))
|
||||||
}
|
itr->first->AI()->AttackStart(target);
|
||||||
//Attack if everything is OK
|
|
||||||
if(itr->second->isAlive() && itr->second->AI() && !itr->second->isInCombat() &&
|
|
||||||
!itr->second->getVictim() && member.getVictim() && itr->second->canAttack(member.getVictim()))
|
|
||||||
itr->second->AI()->AttackStart(member.getVictim());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureGroup::LeaderMovedInEvade()
|
void CreatureGroup::FormationReset(bool dismiss)
|
||||||
{
|
{
|
||||||
for(UNORDERED_MAP<uint64, Creature*>::iterator itr = CreatureGroupMembers.begin(); itr != CreatureGroupMembers.end(); ++itr)
|
for(CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
|
||||||
{
|
{
|
||||||
if(itr->second && itr->second != m_leader && itr->second->isAlive() && !itr->second->isInCombat() && !itr->second->getVictim())
|
if(itr->first != m_leader && itr->first->isAlive())
|
||||||
{
|
{
|
||||||
SetMemberDestination(itr->second);
|
if(dismiss)
|
||||||
sLog.outDebug("GROUP MOVE IN EVADE: Set destination for member GUID %u", itr->second->GetGUIDLow());
|
itr->first->GetMotionMaster()->Initialize();
|
||||||
}
|
else
|
||||||
}
|
itr->first->GetMotionMaster()->MoveIdle(MOTION_SLOT_IDLE);
|
||||||
}
|
sLog.outDebug("Set %s movement for member GUID: %u", dismiss ? "default" : "idle", itr->first->GetGUIDLow());
|
||||||
|
|
||||||
void CreatureGroup::FormDismiss(bool dismiss)
|
|
||||||
{
|
|
||||||
for(UNORDERED_MAP<uint64, Creature*>::iterator itr = CreatureGroupMembers.begin(); itr != CreatureGroupMembers.end(); ++itr)
|
|
||||||
{
|
|
||||||
if(itr->second && itr->second != m_leader && itr->second->isAlive())
|
|
||||||
{
|
|
||||||
dismiss ? itr->second->GetMotionMaster()->Initialize() : itr->second->GetMotionMaster()->MoveIdle(MOTION_SLOT_IDLE);
|
|
||||||
sLog.outDebug("Set %s movement for member GUID: %u", dismiss ? "default" : "idle", itr->second->GetGUIDLow());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_Formed = !dismiss;
|
m_Formed = !dismiss;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureGroup::SetMemberDestination(Creature *member)
|
void CreatureGroup::LeaderMoveTo(float x, float y, float z)
|
||||||
{
|
{
|
||||||
if(!member || !m_leader || !member->isAlive() || member->isInCombat() || member->getVictim())
|
if(!m_leader)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sLog.outDebug("GROUP MOVE IN EVADE: leader instid %u set destination of member instid %u", m_leader->GetInstanceId(), member->GetInstanceId());
|
float pathangle = atan2(m_leader->GetPositionY() - y, m_leader->GetPositionX() - x);
|
||||||
|
|
||||||
float x,y,z;
|
for(CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
|
||||||
uint32 lowguid = member->GetDBTableGUIDLow();
|
{
|
||||||
|
Creature *member = itr->first;
|
||||||
|
if(member == m_leader || !member->isAlive() || member->getVictim())
|
||||||
|
continue;
|
||||||
|
|
||||||
UNORDERED_MAP<uint32, FormationMember*>::iterator itr2 = CreatureGroupMap.find(lowguid);
|
float angle = itr->second->follow_angle;
|
||||||
|
float dist = itr->second->follow_dist;
|
||||||
|
|
||||||
if(itr2 != CreatureGroupMap.end() && m_leader->GetMotionMaster()->GetDestination(x,y,z))
|
float dx = x + cos(angle + pathangle) * dist;
|
||||||
{
|
float dy = y + sin(angle + pathangle) * dist;
|
||||||
float dist, angle, pathangle;
|
float dz;
|
||||||
|
member->UpdateGroundPositionZ(dx, dy, dz);
|
||||||
|
|
||||||
angle = itr2->second->follow_angle;
|
if(member->GetDistance(m_leader) < dist + MAX_DESYNC)
|
||||||
dist = itr2->second->follow_dist;
|
|
||||||
pathangle = atan2(m_leader->GetPositionY()-y, m_leader->GetPositionX()-x);
|
|
||||||
|
|
||||||
x = x+cos(angle+pathangle)*dist;
|
|
||||||
y = y+sin(angle+pathangle)*dist;
|
|
||||||
|
|
||||||
if(member->GetDistance(m_leader) < dist+MAX_DESYNC)
|
|
||||||
member->SetUnitMovementFlags(m_leader->GetUnitMovementFlags());
|
member->SetUnitMovementFlags(m_leader->GetUnitMovementFlags());
|
||||||
else
|
else
|
||||||
member->RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
|
member->RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
|
||||||
|
|
||||||
member->GetMotionMaster()->Clear();
|
member->GetMotionMaster()->MovePoint(0, dx, dy, dz);
|
||||||
member->GetMotionMaster()->MovePoint(0, x, y, z);
|
member->SetHomePosition(dx, dy, dz, pathangle);
|
||||||
member->SetHomePosition(x, y, z, pathangle);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-29
@@ -21,60 +21,61 @@
|
|||||||
#ifndef _FORMATIONS_H
|
#ifndef _FORMATIONS_H
|
||||||
#define _FORMATIONS_H
|
#define _FORMATIONS_H
|
||||||
|
|
||||||
//#include <map>
|
|
||||||
//#include "Creature.h"
|
|
||||||
//#include "Policies/Singleton.h"
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
class CreatureGroup;
|
class CreatureGroup;
|
||||||
|
|
||||||
struct FormationMember
|
struct FormationInfo
|
||||||
{
|
{
|
||||||
|
uint32 leaderGUID;
|
||||||
float follow_dist;
|
float follow_dist;
|
||||||
float follow_angle;
|
float follow_angle;
|
||||||
uint32 memberGUID;
|
uint8 groupAI;
|
||||||
uint32 leaderGUID;
|
|
||||||
uint8 groupAI;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CreatureGroupManager
|
class CreatureGroupManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UpdateCreatureGroup(uint32 group_id, Creature &);
|
void AddCreatureToGroup(uint32 group_id, Creature *creature);
|
||||||
void DestroyGroup(CreatureGroup *&, uint64 guid);
|
void RemoveCreatureFromGroup(CreatureGroup *group, Creature *creature);
|
||||||
void LoadCreatureFormations();
|
void LoadCreatureFormations();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::multimap<uint32/*leaderDBGUID*/, CreatureGroup*> CreatureGroupHolderType;
|
||||||
|
typedef UNORDERED_MAP<uint32/*memberDBGUID*/, FormationInfo*> CreatureGroupInfoType;
|
||||||
|
|
||||||
|
extern CreatureGroupHolderType CreatureGroupHolder;
|
||||||
|
extern CreatureGroupInfoType CreatureGroupMap;
|
||||||
|
|
||||||
class CreatureGroup
|
class CreatureGroup
|
||||||
{
|
{
|
||||||
UNORDERED_MAP<uint64, Creature*>CreatureGroupMembers;
|
private:
|
||||||
Creature *m_leader; //Important do not forget sometimes to work with pointers instead synonims :D:D
|
Creature *m_leader; //Important do not forget sometimes to work with pointers instead synonims :D:D
|
||||||
uint32 m_groupID, mInstanceID;
|
typedef std::map<Creature*, FormationInfo*> CreatureGroupMemberType;
|
||||||
bool m_Formed;
|
CreatureGroupMemberType m_members;
|
||||||
|
|
||||||
|
uint32 m_groupID, mInstanceID;
|
||||||
|
bool m_Formed;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//Group cannot be created empty
|
//Group cannot be created empty
|
||||||
explicit CreatureGroup(uint32 id, uint32 InstanceID) : m_groupID(id), m_leader(NULL), mInstanceID(InstanceID), m_Formed(false) {}
|
explicit CreatureGroup(uint32 id, uint32 InstanceID) : m_groupID(id), m_leader(NULL), mInstanceID(InstanceID), m_Formed(false) {}
|
||||||
~CreatureGroup(){sLog.outDebug("Destroying group");}
|
~CreatureGroup(){sLog.outDebug("Destroying group");}
|
||||||
|
|
||||||
Creature* getLeader(){return m_leader;}
|
Creature* getLeader() const { return m_leader; }
|
||||||
uint32 GetId(){return m_groupID;}
|
uint32 GetId() const { return m_groupID; }
|
||||||
uint32 getInstanceID(){return mInstanceID;}
|
uint32 getInstanceID() const { return mInstanceID; }
|
||||||
void AddMember(Creature &);
|
bool isEmpty() const { return m_members.empty(); }
|
||||||
void RemoveMember(uint64 guid);
|
bool isFormed() const { return m_Formed; }
|
||||||
void FormDismiss(bool dismiss=false);
|
|
||||||
void LeaderMovedInEvade();
|
void AddMember(Creature *member);
|
||||||
void MemberHasAttacked(Creature &);
|
void RemoveMember(Creature *member);
|
||||||
void SetMemberDestination(Creature *);
|
void FormationReset(bool dismiss);
|
||||||
bool isEmpty() {return CreatureGroupMembers.empty();}
|
|
||||||
bool isFormed() {return m_Formed;}
|
void LeaderMoveTo(float x, float y, float z);
|
||||||
|
void MemberAttackStart(Creature* member, Unit *target);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::multimap<uint32, CreatureGroup*> CreatureGroupHolderType;
|
|
||||||
|
|
||||||
extern CreatureGroupHolderType CreatureGroupHolder;
|
|
||||||
extern UNORDERED_MAP<uint32, FormationMember*> CreatureGroupMap;
|
|
||||||
|
|
||||||
#define formation_mgr Trinity::Singleton<CreatureGroupManager>::Instance()
|
#define formation_mgr Trinity::Singleton<CreatureGroupManager>::Instance()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+3
-3
@@ -44,6 +44,7 @@
|
|||||||
#include "GlobalEvents.h"
|
#include "GlobalEvents.h"
|
||||||
|
|
||||||
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
|
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
|
||||||
|
#include "CreatureGroups.h"
|
||||||
|
|
||||||
static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK] =
|
static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK] =
|
||||||
{
|
{
|
||||||
@@ -4579,12 +4580,11 @@ bool ChatHandler::HandleNpcAddFormationCommand(const char* args)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
Player *chr = m_session->GetPlayer();
|
Player *chr = m_session->GetPlayer();
|
||||||
FormationMember *group_member;
|
FormationInfo *group_member;
|
||||||
|
|
||||||
group_member = new FormationMember;
|
group_member = new FormationInfo;
|
||||||
group_member->follow_angle = pCreature->GetAngle(chr) - chr->GetOrientation();
|
group_member->follow_angle = pCreature->GetAngle(chr) - chr->GetOrientation();
|
||||||
group_member->follow_dist = sqrtf(pow(chr->GetPositionX() - pCreature->GetPositionX(),int(2))+pow(chr->GetPositionY()-pCreature->GetPositionY(),int(2)));
|
group_member->follow_dist = sqrtf(pow(chr->GetPositionX() - pCreature->GetPositionX(),int(2))+pow(chr->GetPositionY()-pCreature->GetPositionY(),int(2)));
|
||||||
group_member->memberGUID = lowguid;
|
|
||||||
group_member->leaderGUID = leaderGUID;
|
group_member->leaderGUID = leaderGUID;
|
||||||
group_member->groupAI = 0;
|
group_member->groupAI = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ void MotionMaster::DelayedDelete(_Ty curr)
|
|||||||
|
|
||||||
bool MotionMaster::GetDestination(float &x, float &y, float &z)
|
bool MotionMaster::GetDestination(float &x, float &y, float &z)
|
||||||
{
|
{
|
||||||
if(empty() || !Impl[i_top] || isStatic(Impl[i_top]))
|
if(empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return top()->GetDestination(x,y,z);
|
return top()->GetDestination(x,y,z);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "DestinationHolderImp.h"
|
#include "DestinationHolderImp.h"
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "CreatureGroups.h"
|
||||||
|
|
||||||
#define RUNNING_CHANCE_RANDOMMV 20 //will be "1 / RUNNING_CHANCE_RANDOMMV"
|
#define RUNNING_CHANCE_RANDOMMV 20 //will be "1 / RUNNING_CHANCE_RANDOMMV"
|
||||||
|
|
||||||
@@ -114,6 +115,12 @@ RandomMovementGenerator<Creature>::_setRandomLocation(Creature &creature)
|
|||||||
i_nextMoveTime.Reset(urand(500+i_destinationHolder.GetTotalTravelTime(),5000+i_destinationHolder.GetTotalTravelTime()));
|
i_nextMoveTime.Reset(urand(500+i_destinationHolder.GetTotalTravelTime(),5000+i_destinationHolder.GetTotalTravelTime()));
|
||||||
creature.SetUnitMovementFlags(MOVEMENTFLAG_WALK_MODE);
|
creature.SetUnitMovementFlags(MOVEMENTFLAG_WALK_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Call for creature group update
|
||||||
|
if(creature.GetFormation() && creature.GetFormation()->getLeader() == &creature)
|
||||||
|
{
|
||||||
|
creature.GetFormation()->LeaderMoveTo(nx, ny, nz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include "Creature.h"
|
#include "Creature.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "CreatureGroups.h"
|
|
||||||
|
|
||||||
/** Traveller is a wrapper for units (creatures or players) that
|
/** Traveller is a wrapper for units (creatures or players) that
|
||||||
* travel from point A to point B using the destination holder.
|
* travel from point A to point B using the destination holder.
|
||||||
@@ -109,13 +108,6 @@ inline float Traveller<Creature>::GetMoveDestinationTo(float x, float y, float z
|
|||||||
template<>
|
template<>
|
||||||
inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t)
|
inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t)
|
||||||
{
|
{
|
||||||
//Call for creature group update
|
|
||||||
if(i_traveller.GetFormation() && i_traveller.GetFormation()->getLeader() == &i_traveller && !i_traveller.isInCombat())
|
|
||||||
{
|
|
||||||
i_traveller.GetFormation()->LeaderMovedInEvade();
|
|
||||||
sLog.outDebug("Traveller<Creature>::MoveTo(){GUID %u calls LeaderMovedInEvade()}", i_traveller.GetGUIDLow());
|
|
||||||
}
|
|
||||||
|
|
||||||
//i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetUnitMovementFlags(), 0);
|
//i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetUnitMovementFlags(), 0);
|
||||||
i_traveller.SendMonsterMove(x, y, z, t);
|
i_traveller.SendMonsterMove(x, y, z, t);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -9537,7 +9537,14 @@ void Unit::CombatStart(Unit* target)
|
|||||||
|
|
||||||
if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER
|
if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER
|
||||||
&& !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->IsAIEnabled)
|
&& !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->IsAIEnabled)
|
||||||
|
{
|
||||||
((Creature*)target)->AI()->AttackStart(this);
|
((Creature*)target)->AI()->AttackStart(this);
|
||||||
|
if(((Creature*)target)->GetFormation())
|
||||||
|
{
|
||||||
|
((Creature*)target)->GetFormation()->MemberAttackStart((Creature*)target, this);
|
||||||
|
sLog.outDebug("Unit::CombatStart() calls CreatureGroups::MemberHasAttacked(this);");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SetInCombatWith(target);
|
SetInCombatWith(target);
|
||||||
target->SetInCombatWith(this);
|
target->SetInCombatWith(this);
|
||||||
@@ -9554,13 +9561,6 @@ void Unit::CombatStart(Unit* target)
|
|||||||
me->UpdatePvP(true);
|
me->UpdatePvP(true);
|
||||||
me->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
|
me->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Call creature group update
|
|
||||||
if(GetTypeId()==TYPEID_UNIT && ((Creature*)this)->GetFormation())
|
|
||||||
{
|
|
||||||
((Creature*)this)->GetFormation()->MemberHasAttacked(*(Creature*)this);
|
|
||||||
sLog.outDebug("Unit::CombatStart() calls CreatureGroups::MemberHasAttacked(this);");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::SetInCombatState(bool PvP)
|
void Unit::SetInCombatState(bool PvP)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
//Creature-specific headers
|
//Creature-specific headers
|
||||||
#include "Creature.h"
|
#include "Creature.h"
|
||||||
#include "CreatureAI.h"
|
#include "CreatureAI.h"
|
||||||
|
#include "CreatureGroups.h"
|
||||||
//Player-specific
|
//Player-specific
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
|
|
||||||
@@ -109,6 +110,10 @@ WaypointMovementGenerator<Creature>::Initialize(Creature &u)
|
|||||||
InitTraveller(u, *node);
|
InitTraveller(u, *node);
|
||||||
i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z);
|
i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z);
|
||||||
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
||||||
|
|
||||||
|
//Call for creature group update
|
||||||
|
if(u.GetFormation() && u.GetFormation()->getLeader() == &u)
|
||||||
|
u.GetFormation()->LeaderMoveTo(node->x, node->y, node->z);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
node = NULL;
|
node = NULL;
|
||||||
@@ -180,6 +185,10 @@ WaypointMovementGenerator<Creature>::Update(Creature &unit, const uint32 &diff)
|
|||||||
InitTraveller(unit, *node);
|
InitTraveller(unit, *node);
|
||||||
i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z);
|
i_destinationHolder.SetDestination(traveller, node->x, node->y, node->z);
|
||||||
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
||||||
|
|
||||||
|
//Call for creature group update
|
||||||
|
if(unit.GetFormation() && unit.GetFormation()->getLeader() == &unit)
|
||||||
|
unit.GetFormation()->LeaderMoveTo(node->x, node->y, node->z);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user