[11323] Avoid explicit use HIGHGUID_UNIT as creature high guid in guids or creature creating.

This helper change for allow have in future static spawned vehicles as `creature` table data.

Added CreatureInfo::GetHighGuid() high guid selector, and wrapper CreatureData::GetHighGuid()
for most real cases of usage. Also easy get expected guid form by CreatureData::GetObjectGuid(lowguid).

Also fixed some memory lost cases at creature spawn fail.
This commit is contained in:
VladimirMangos 2011-04-07 19:22:30 +04:00
parent 0dfcbf8051
commit ba77d85a30
16 changed files with 156 additions and 81 deletions

View file

@ -1558,6 +1558,15 @@ bool ChatHandler::HandleNpcAddCommand(char* args)
if (!ExtractUint32KeyFromLink(&args, "Hcreature_entry", id))
return false;
CreatureInfo const *cinfo = ObjectMgr::GetCreatureTemplate(id);
//FIXME: need vehicle support like GenerateStaticCreatureLowGuid when its will allowed static spawns
if (!cinfo || cinfo->GetHighGuid() != HIGHGUID_UNIT)
{
PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, id);
SetSentErrorMessage(true);
return false;
}
Player *chr = m_session->GetPlayer();
CreatureCreatePos pos(chr, chr->GetOrientation());
Map *map = chr->GetMap();
@ -1573,7 +1582,7 @@ bool ChatHandler::HandleNpcAddCommand(char* args)
return false;
}
if (!pCreature->Create(lowguid, pos, id))
if (!pCreature->Create(lowguid, pos, cinfo))
{
delete pCreature;
return false;
@ -1695,7 +1704,7 @@ bool ChatHandler::HandleNpcAddMoveCommand(char* args)
return false;
}
Creature* pCreature = player->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
Creature* pCreature = player->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
sWaypointMgr.AddLastNode(lowguid, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), wait, 0);
@ -1796,7 +1805,7 @@ bool ChatHandler::HandleNpcDeleteCommand(char* args)
return false;
if (CreatureData const* data = sObjectMgr.GetCreatureData(lowguid))
unit = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
unit = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
}
else
unit = getSelectedCreature();
@ -1848,7 +1857,7 @@ bool ChatHandler::HandleNpcMoveCommand(char* args)
return false;
}
pCreature = player->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
pCreature = player->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
}
else
lowguid = pCreature->GetGUIDLow();
@ -1931,7 +1940,7 @@ bool ChatHandler::HandleNpcSetMoveTypeCommand(char* args)
return false;
}
pCreature = player->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
pCreature = player->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
}
MovementGeneratorType move_type;
@ -2867,7 +2876,7 @@ bool ChatHandler::HandleWpAddCommand(char* args)
return false;
}
target = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
target = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
if (!target)
{
PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, lowguid);
@ -2901,7 +2910,7 @@ bool ChatHandler::HandleWpAddCommand(char* args)
return false;
}
target = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
target = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
if (!target || target->IsPet())
{
PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid);
@ -2965,6 +2974,10 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
if (!*args)
return false;
CreatureInfo const* waypointInfo = ObjectMgr::GetCreatureTemplate(VISUAL_WAYPOINT);
if (!waypointInfo || waypointInfo->GetHighGuid() != HIGHGUID_UNIT)
return false; // must exist as normal creature in mangos.sql 'creature_template'
// first arg: add del text emote spell waittime move
char* show_str = strtok(args, " ");
if (!show_str)
@ -3116,7 +3129,7 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
return false;
}
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
if (!npcCreature)
{
@ -3152,7 +3165,7 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
CreatureCreatePos pos(chr, chr->GetOrientation());
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, VISUAL_WAYPOINT))
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature;
@ -3187,7 +3200,7 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
return false;
}
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
// wpCreature
Creature* wpCreature = NULL;
@ -3247,7 +3260,7 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
return false;
}
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
// wpCreature
Creature* wpCreature = NULL;
@ -3264,7 +3277,7 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
CreatureCreatePos pos(chr, chr->GetOrientation());
if (!wpCreature2->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, VISUAL_WAYPOINT))
if (!wpCreature2->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature2;
@ -3312,7 +3325,7 @@ bool ChatHandler::HandleWpModifyCommand(char* args)
sWaypointMgr.SetNodeText(lowguid, point, show_str, arg_str);
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
if (npcCreature)
{
npcCreature->SetDefaultMovementType(WAYPOINT_MOTION_TYPE);
@ -3360,6 +3373,10 @@ bool ChatHandler::HandleWpShowCommand(char* args)
if (!*args)
return false;
CreatureInfo const* waypointInfo = ObjectMgr::GetCreatureTemplate(VISUAL_WAYPOINT);
if (!waypointInfo || waypointInfo->GetHighGuid() != HIGHGUID_UNIT)
return false; // must exist as normal creature in mangos.sql 'creature_template'
// first arg: on, off, first, last
char* show_str = strtok(args, " ");
if (!show_str)
@ -3412,7 +3429,7 @@ bool ChatHandler::HandleWpShowCommand(char* args)
return false;
}
target = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, data->id, lowguid));
target = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid));
if (!target)
{
@ -3555,7 +3572,7 @@ bool ChatHandler::HandleWpShowCommand(char* args)
Creature* wpCreature = new Creature;
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, VISUAL_WAYPOINT))
if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete wpCreature;
@ -3600,7 +3617,7 @@ bool ChatHandler::HandleWpShowCommand(char* args)
Creature* pCreature = new Creature;
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, VISUAL_WAYPOINT))
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo))
{
PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
delete pCreature;
@ -3648,7 +3665,7 @@ bool ChatHandler::HandleWpShowCommand(char* args)
Creature* pCreature = new Creature;
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, VISUAL_WAYPOINT))
if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo))
{
PSendSysMessage(LANG_WAYPOINT_NOTCREATED, VISUAL_WAYPOINT);
delete pCreature;