void CreatureGroupManager::AddCreatureToGroup(uint32 groupId, Creature *member) { Map *map = member->FindMap(); if (!map) return; CreatureGroupHolderType::iterator itr = map->CreatureGroupHolder.find( groupId); //Add member to an existing group if (itr != map->CreatureGroupHolder.end()) { sLog->outDebug( LOG_FILTER_UNITS, "Group found: %u, inserting creature GUID: %u, Group InstanceID %u", groupId, member->GetGUIDLow(), member->GetInstanceId()); itr->second->AddMember(member); } //Create new group else { sLog->outDebug(LOG_FILTER_UNITS, "Group not found: %u. Creating new group.", groupId); CreatureGroup* group = new CreatureGroup(groupId); map->CreatureGroupHolder[groupId] = group; group->AddMember(member); } }
void CreatureGroupsManager::Load() { uint32 oldMSTime = WorldTimer::getMSTime(); // Memory leak, but we cannot delete the loaded groups, since pointer may be present at loaded creatures _groups.clear(); QueryResult* result = WorldDatabase.Query("SELECT leaderGUID, memberGUID, dist, angle, flags FROM creature_groups ORDER BY leaderGUID"); if (!result) { sLog.outErrorDb(">> Loaded 0 creature groups. DB table `creature_groups` is empty!"); sLog.outString(); return; } uint32 count = 0; Field *fields; CreatureGroup *currentGroup = NULL; do { fields = result->Fetch(); //Load group member data ObjectGuid leaderGuid = ConvertDBGuid(fields[0].GetUInt32()); ObjectGuid memberGuid = ConvertDBGuid(fields[1].GetUInt32()); if (leaderGuid.IsEmpty()) sLog.outErrorDb("CREATURE GROUPS: Bad leader guid %u", fields[0].GetUInt32()); else if (memberGuid.IsEmpty()) sLog.outErrorDb("CREATURE GROUPS: Bad member guid %u", fields[1].GetUInt32()); else { if (!currentGroup || leaderGuid != currentGroup->GetLeaderGuid()) { currentGroup = new CreatureGroup(leaderGuid); RegisterNewGroup(currentGroup); } currentGroup->AddMember(memberGuid, fields[2].GetFloat(), fields[3].GetFloat(), fields[4].GetUInt8()); ++count; } } while (result->NextRow()); delete result; sLog.outString(">> Loaded %u creature groups in %u ms", count, WorldTimer::getMSTime() - oldMSTime); sLog.outString(); }
void FormationMgr::AddCreatureToGroup(ObjectGuid::LowType leaderGuid, Creature* creature) { Map* map = creature->FindMap(); if (!map) return; CreatureGroupHolderType::iterator itr = map->CreatureGroupHolder.find(leaderGuid); //Add member to an existing group if (itr != map->CreatureGroupHolder.end()) { TC_LOG_DEBUG("entities.unit", "Group found: " UI64FMTD ", inserting %s, Group InstanceID %u", leaderGuid, creature->GetGUID().ToString().c_str(), creature->GetInstanceId()); itr->second->AddMember(creature); } //Create new group else { TC_LOG_DEBUG("entities.unit", "Group not found: " UI64FMTD ". Creating new group.", leaderGuid); CreatureGroup* group = new CreatureGroup(leaderGuid); map->CreatureGroupHolder[leaderGuid] = group; group->AddMember(creature); } }
void FormationMgr::AddCreatureToGroup(uint32 groupId, Creature* member) { Map* map = member->FindMap(); if (!map) return; CreatureGroupHolderType::iterator itr = map->CreatureGroupHolder.find(groupId); //Add member to an existing group if (itr != map->CreatureGroupHolder.end()) { TC_LOG_DEBUG("entities.unit", "Group found: %u, inserting creature GUID: %u, Group InstanceID %u", groupId, member->GetGUIDLow(), member->GetInstanceId()); itr->second->AddMember(member); } //Create new group else { TC_LOG_DEBUG("entities.unit", "Group not found: %u. Creating new group.", groupId); CreatureGroup* group = new CreatureGroup(groupId); map->CreatureGroupHolder[groupId] = group; group->AddMember(member); } }