Scripts/SmartAI: Some clean-up work:

- NULL -> nullptr
- Rename "AssistPlayerInCombat(who)" to "AssistPlayerInCombatAgainst(who)" to reflect what the method actually does
- Code style

No functionality was changed.

(cherry picked from commit 152b3ad5b997f4be06c5bb55ddb15c57a8e28c3b)

# Conflicts:
#	src/server/game/AI/SmartScripts/SmartAI.cpp
#	src/server/game/AI/SmartScripts/SmartScript.cpp
This commit is contained in:
treeston
2017-02-11 22:34:59 +01:00
committed by joschiwald
parent 5515ff683f
commit 8d7ab10efa
8 changed files with 84 additions and 112 deletions
+35 -33
View File
@@ -30,12 +30,12 @@ SmartAI::SmartAI(Creature* c) : CreatureAI(c)
{
// copy script to local (protection for table reload)
mWayPoints = NULL;
mWayPoints = nullptr;
mEscortState = SMART_ESCORT_NONE;
mCurrentWPID = 0;//first wp id is 1 !!
mWPReached = false;
mWPPauseTimer = 0;
mLastWP = NULL;
mLastWP = nullptr;
mCanRepeatPath = false;
@@ -90,7 +90,7 @@ void SmartAI::UpdateDespawn(const uint32 diff)
WayPoint* SmartAI::GetNextWayPoint()
{
if (!mWayPoints || mWayPoints->empty())
return NULL;
return nullptr;
mCurrentWPID++;
WPPath::const_iterator itr = mWayPoints->find(mCurrentWPID);
@@ -103,7 +103,7 @@ WayPoint* SmartAI::GetNextWayPoint()
}
return (*itr).second;
}
return NULL;
return nullptr;
}
void SmartAI::StartPath(bool run, uint32 path, bool repeat, Unit* /*invoker*/)
@@ -130,7 +130,7 @@ void SmartAI::StartPath(bool run, uint32 path, bool repeat, Unit* /*invoker*/)
{
mLastOOCPos = me->GetPosition();
me->GetMotionMaster()->MovePoint(wp->id, wp->x, wp->y, wp->z);
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, NULL, wp->id, GetScript()->GetPathId());
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, wp->id, GetScript()->GetPathId());
}
}
@@ -167,7 +167,7 @@ void SmartAI::PausePath(uint32 delay, bool forced)
me->StopMoving();//force stop
me->GetMotionMaster()->MoveIdle();//force stop
}
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_PAUSED, NULL, mLastWP->id, GetScript()->GetPathId());
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_PAUSED, nullptr, mLastWP->id, GetScript()->GetPathId());
}
void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
@@ -183,19 +183,19 @@ void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
mLastOOCPos = me->GetPosition();
me->StopMoving();//force stop
me->GetMotionMaster()->MoveIdle();
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_STOPPED, NULL, mLastWP->id, GetScript()->GetPathId());
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_STOPPED, nullptr, mLastWP->id, GetScript()->GetPathId());
EndPath(fail);
}
void SmartAI::EndPath(bool fail)
{
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, NULL, mLastWP->id, GetScript()->GetPathId());
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, mLastWP->id, GetScript()->GetPathId());
RemoveEscortState(SMART_ESCORT_ESCORTING | SMART_ESCORT_PAUSED | SMART_ESCORT_RETURNING);
mWayPoints = NULL;
mWayPoints = nullptr;
mCurrentWPID = 0;
mWPPauseTimer = 0;
mLastWP = NULL;
mLastWP = nullptr;
if (mCanRepeatPath)
StartPath(mRun, GetScript()->GetPathId(), true);
@@ -216,7 +216,7 @@ void SmartAI::EndPath(bool fail)
if (Group* group = player->GetGroup())
{
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != NULL; groupRef = groupRef->next())
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
{
Player* groupGuy = groupRef->GetSource();
@@ -226,7 +226,8 @@ void SmartAI::EndPath(bool fail)
groupGuy->FailQuest(mEscortQuestID);
}
}
}else
}
else
{
for (ObjectList::iterator iter = targets->begin(); iter != targets->end(); ++iter)
{
@@ -278,7 +279,7 @@ void SmartAI::UpdatePath(const uint32 diff)
{
if (!me->IsInCombat() && !HasEscortState(SMART_ESCORT_RETURNING) && (mWPReached || mLastWPIDReached == SMART_ESCORT_LAST_OOC_POINT || mForcedPaused))
{
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_RESUMED, NULL, mLastWP->id, GetScript()->GetPathId());
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_RESUMED, nullptr, mLastWP->id, GetScript()->GetPathId());
RemoveEscortState(SMART_ESCORT_PAUSED);
if (mForcedPaused)// if paused between 2 wps resend movement
{
@@ -365,7 +366,7 @@ bool SmartAI::IsEscortInvokerInRange()
if (Group* group = player->GetGroup())
{
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != NULL; groupRef = groupRef->next())
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
{
Player* groupGuy = groupRef->GetSource();
@@ -373,7 +374,8 @@ bool SmartAI::IsEscortInvokerInRange()
return true;
}
}
}else
}
else
{
for (ObjectList::iterator iter = targets->begin(); iter != targets->end(); ++iter)
{
@@ -391,7 +393,7 @@ bool SmartAI::IsEscortInvokerInRange()
void SmartAI::MovepointReached(uint32 id)
{
if (id != SMART_ESCORT_LAST_OOC_POINT && mLastWPIDReached != id)
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, NULL, id);
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, id);
mLastWPIDReached = id;
mWPReached = true;
@@ -402,7 +404,7 @@ void SmartAI::MovementInform(uint32 MovementType, uint32 Data)
if ((MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT) || MovementType == FOLLOW_MOTION_TYPE)
me->ClearUnitState(UNIT_STATE_EVADE);
GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, NULL, MovementType, Data);
GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
if (MovementType != POINT_MOTION_TYPE || !HasEscortState(SMART_ESCORT_ESCORTING))
return;
MovepointReached(Data);
@@ -448,7 +450,7 @@ void SmartAI::MoveInLineOfSight(Unit* who)
GetScript()->OnMoveInLineOfSight(who);
if (AssistPlayerInCombat(who))
if (AssistPlayerInCombatAgainst(who))
return;
CreatureAI::MoveInLineOfSight(who);
@@ -459,7 +461,7 @@ bool SmartAI::CanAIAttack(const Unit* /*who*/) const
return !(me->HasReactState(REACT_PASSIVE));
}
bool SmartAI::AssistPlayerInCombat(Unit* who)
bool SmartAI::AssistPlayerInCombatAgainst(Unit* who)
{
if (me->HasReactState(REACT_PASSIVE))
return false;
@@ -627,7 +629,7 @@ void SmartAI::UpdateAIWhileCharmed(const uint32 /*diff*/) { }
void SmartAI::CorpseRemoved(uint32& respawnDelay)
{
GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, NULL, respawnDelay);
GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
}
void SmartAI::PassengerBoarded(Unit* who, int8 seatId, bool apply)
@@ -646,7 +648,7 @@ void SmartAI::InitializeAI()
void SmartAI::OnCharmed(bool apply)
{
GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, NULL, 0, 0, apply);
GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, apply);
if (!apply && !me->IsInEvadeMode())
if (Unit* charmer = me->GetCharmer())
@@ -655,7 +657,7 @@ void SmartAI::OnCharmed(bool apply)
void SmartAI::DoAction(int32 param)
{
GetScript()->ProcessEventsFor(SMART_EVENT_ACTION_DONE, NULL, param);
GetScript()->ProcessEventsFor(SMART_EVENT_ACTION_DONE, nullptr, param);
}
uint32 SmartAI::GetData(uint32 /*id*/) const
@@ -665,7 +667,7 @@ uint32 SmartAI::GetData(uint32 /*id*/) const
void SmartAI::SetData(uint32 id, uint32 value)
{
GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, NULL, id, value);
GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, nullptr, id, value);
}
void SmartAI::SetGUID(ObjectGuid /*guid*/, int32 /*id*/) { }
@@ -799,7 +801,7 @@ void SmartAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
void SmartAI::sOnGameEvent(bool start, uint16 eventId)
{
GetScript()->ProcessEventsFor(start ? SMART_EVENT_GAME_EVENT_START : SMART_EVENT_GAME_EVENT_END, NULL, eventId);
GetScript()->ProcessEventsFor(start ? SMART_EVENT_GAME_EVENT_START : SMART_EVENT_GAME_EVENT_END, nullptr, eventId);
}
void SmartAI::OnSpellClick(Unit* clicker, bool& result)
@@ -838,14 +840,14 @@ void SmartGameObjectAI::Reset()
bool SmartGameObjectAI::GossipHello(Player* player, bool /*isUse*/)
{
TC_LOG_DEBUG("scripts.ai", "SmartGameObjectAI::GossipHello");
GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_HELLO, player, 0, 0, false, NULL, go);
GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_HELLO, player, 0, 0, false, nullptr, go);
return false;
}
// Called when a player selects a gossip item in the gameobject's gossip menu.
bool SmartGameObjectAI::GossipSelect(Player* player, uint32 sender, uint32 action)
{
GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action, false, NULL, go);
GetScript()->ProcessEventsFor(SMART_EVENT_GOSSIP_SELECT, player, sender, action, false, nullptr, go);
return false;
}
@@ -858,26 +860,26 @@ bool SmartGameObjectAI::GossipSelectCode(Player* /*player*/, uint32 /*sender*/,
// Called when a player accepts a quest from the gameobject.
bool SmartGameObjectAI::QuestAccept(Player* player, Quest const* quest)
{
GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId(), 0, false, NULL, go);
GetScript()->ProcessEventsFor(SMART_EVENT_ACCEPTED_QUEST, player, quest->GetQuestId(), 0, false, nullptr, go);
return false;
}
// Called when a player selects a quest reward.
bool SmartGameObjectAI::QuestReward(Player* player, Quest const* quest, uint32 opt)
{
GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt, false, NULL, go);
GetScript()->ProcessEventsFor(SMART_EVENT_REWARD_QUEST, player, quest->GetQuestId(), opt, false, nullptr, go);
return false;
}
// Called when the gameobject is destroyed (destructible buildings only).
void SmartGameObjectAI::Destroyed(Player* player, uint32 eventId)
{
GetScript()->ProcessEventsFor(SMART_EVENT_DEATH, player, eventId, 0, false, NULL, go);
GetScript()->ProcessEventsFor(SMART_EVENT_DEATH, player, eventId, 0, false, nullptr, go);
}
void SmartGameObjectAI::SetData(uint32 id, uint32 value)
{
GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, NULL, id, value);
GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, nullptr, id, value);
}
void SmartGameObjectAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
@@ -889,7 +891,7 @@ void SmartGameObjectAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* inv
void SmartGameObjectAI::OnGameEvent(bool start, uint16 eventId)
{
GetScript()->ProcessEventsFor(start ? SMART_EVENT_GAME_EVENT_START : SMART_EVENT_GAME_EVENT_END, NULL, eventId);
GetScript()->ProcessEventsFor(start ? SMART_EVENT_GAME_EVENT_START : SMART_EVENT_GAME_EVENT_END, nullptr, eventId);
}
void SmartGameObjectAI::OnStateChanged(uint32 state, Unit* unit)
@@ -899,7 +901,7 @@ void SmartGameObjectAI::OnStateChanged(uint32 state, Unit* unit)
void SmartGameObjectAI::EventInform(uint32 eventId)
{
GetScript()->ProcessEventsFor(SMART_EVENT_GO_EVENT_INFORM, NULL, eventId);
GetScript()->ProcessEventsFor(SMART_EVENT_GO_EVENT_INFORM, nullptr, eventId);
}
class SmartTrigger : public AreaTriggerScript
@@ -915,7 +917,7 @@ class SmartTrigger : public AreaTriggerScript
TC_LOG_DEBUG("scripts.ai", "AreaTrigger %u is using SmartTrigger script", trigger->ID);
SmartScript script;
script.OnInitialize(NULL, trigger);
script.OnInitialize(nullptr, trigger);
script.ProcessEventsFor(SMART_EVENT_AREATRIGGER_ONTRIGGER, player, trigger->ID);
return true;
}