diff options
author | ccrs <ccrs@users.noreply.github.com> | 2019-05-15 19:23:28 +0200 |
---|---|---|
committer | ccrs <ccrs@users.noreply.github.com> | 2019-05-15 19:23:28 +0200 |
commit | fdb71ce19e02b44323fbb9dfa5f07dae2a35f8ba (patch) | |
tree | 85aa29babf837cab61f38eab120d75ed7781438b /src/server/game/AI/CreatureAI.cpp | |
parent | 0eb5d240fa82592ff7a4b2df81206ac49df628e2 (diff) |
Core/AI: logs, codestyle & cosmetics standarization
Diffstat (limited to 'src/server/game/AI/CreatureAI.cpp')
-rw-r--r-- | src/server/game/AI/CreatureAI.cpp | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index d0388d5b253..1a468a4e8a1 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -33,19 +33,6 @@ #include "Vehicle.h" #include "World.h" -//Disable CreatureAI when charmed -void CreatureAI::OnCharmed(bool isNew) -{ - if (isNew && !me->IsCharmed() && me->LastCharmerGUID) - { - if (!me->HasReactState(REACT_PASSIVE)) - if (Unit* lastCharmer = ObjectAccessor::GetUnit(*me, me->LastCharmerGUID)) - me->EngageWithTarget(lastCharmer); - me->LastCharmerGUID.Clear(); - } - UnitAI::OnCharmed(isNew); -} - AISpellInfoType* UnitAI::AISpellInfo; AISpellInfoType* GetAISpellInfo(uint32 i) { return &UnitAI::AISpellInfo[i]; } @@ -62,15 +49,32 @@ void CreatureAI::Talk(uint8 id, WorldObject const* whisperTarget /*= nullptr*/) sCreatureTextMgr->SendChat(me, id, whisperTarget); } +// Disable CreatureAI when charmed +void CreatureAI::OnCharmed(bool isNew) +{ + if (isNew && !me->IsCharmed() && me->LastCharmerGUID) + { + if (!me->HasReactState(REACT_PASSIVE)) + { + if (Unit* lastCharmer = ObjectAccessor::GetUnit(*me, me->LastCharmerGUID)) + me->EngageWithTarget(lastCharmer); + } + + me->LastCharmerGUID.Clear(); + } + + UnitAI::OnCharmed(isNew); +} + void CreatureAI::DoZoneInCombat(Creature* creature /*= nullptr*/) { if (!creature) creature = me; Map* map = creature->GetMap(); - if (!map->IsDungeon()) //use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated + if (!map->IsDungeon()) // use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated { - TC_LOG_ERROR("misc", "DoZoneInCombat call for map that isn't an instance (creature entry = %d)", creature->GetTypeId() == TYPEID_UNIT ? creature->ToCreature()->GetEntry() : 0); + TC_LOG_ERROR("scripts.ai", "CreatureAI::DoZoneInCombat: call for map that isn't an instance (%s)", creature->GetGUID().ToString().c_str()); return; } @@ -79,17 +83,21 @@ void CreatureAI::DoZoneInCombat(Creature* creature /*= nullptr*/) return; for (auto const& ref : playerList) + { if (Player* player = ref.GetSource()) { if (!player->IsAlive() || !CombatManager::CanBeginCombat(creature, player)) continue; creature->EngageWithTarget(player); + for (Unit* pet : player->m_Controlled) creature->EngageWithTarget(pet); + if (Unit* vehicle = player->GetVehicleBase()) creature->EngageWithTarget(vehicle); } + } } // scripts does not take care about MoveInLineOfSight loops @@ -148,7 +156,7 @@ void CreatureAI::EnterEvadeMode(EvadeReason why) if (!_EnterEvadeMode(why)) return; - TC_LOG_DEBUG("entities.unit", "Creature %u enters evade mode.", me->GetEntry()); + TC_LOG_DEBUG("scripts.ai", "CreatureAI::EnterEvadeMode: entering evade mode (why: %u) (%s)", why, me->GetGUID().ToString().c_str()); if (!me->GetVehicle()) // otherwise me will be in evade mode forever { @@ -236,11 +244,11 @@ int32 CreatureAI::VisualizeBoundary(uint32 duration, Unit* owner, bool fill) con std::unordered_set<coordinate> outOfBounds; Position startPosition = owner->GetPosition(); - if (!IsInBoundary(&startPosition)) - { // fall back to creature position + if (!IsInBoundary(&startPosition)) // fall back to creature position + { startPosition = me->GetPosition(); - if (!IsInBoundary(&startPosition)) - { // fall back to creature home position + if (!IsInBoundary(&startPosition)) // fall back to creature home position + { startPosition = me->GetHomePosition(); if (!IsInBoundary(&startPosition)) return LANG_CREATURE_NO_INTERIOR_POINT_FOUND; @@ -254,7 +262,7 @@ int32 CreatureAI::VisualizeBoundary(uint32 duration, Unit* owner, bool fill) con { coordinate front = Q.front(); bool hasOutOfBoundsNeighbor = false; - for (coordinate off : std::initializer_list<coordinate>{{1,0}, {0,1}, {-1,0}, {0,-1}}) + for (coordinate const& off : std::list<coordinate>{ {1, 0}, {0, 1}, {-1, 0}, {0, -1} }) { coordinate next(front.first + off.first, front.second + off.second); if (next.first > BOUNDARY_VISUALIZE_FAILSAFE_LIMIT || next.first < -BOUNDARY_VISUALIZE_FAILSAFE_LIMIT || next.second > BOUNDARY_VISUALIZE_FAILSAFE_LIMIT || next.second < -BOUNDARY_VISUALIZE_FAILSAFE_LIMIT) @@ -274,12 +282,12 @@ int32 CreatureAI::VisualizeBoundary(uint32 duration, Unit* owner, bool fill) con } alreadyChecked.insert(next); } - else - if (outOfBounds.find(next) != outOfBounds.end()) - hasOutOfBoundsNeighbor = true; + else if (outOfBounds.find(next) != outOfBounds.end()) + hasOutOfBoundsNeighbor = true; } if (fill || hasOutOfBoundsNeighbor) - if (TempSummon* point = owner->SummonCreature(BOUNDARY_VISUALIZE_CREATURE, Position(startPosition.GetPositionX() + front.first*BOUNDARY_VISUALIZE_STEP_SIZE, startPosition.GetPositionY() + front.second*BOUNDARY_VISUALIZE_STEP_SIZE, spawnZ), TEMPSUMMON_TIMED_DESPAWN, duration * IN_MILLISECONDS)) + { + if (TempSummon* point = owner->SummonCreature(BOUNDARY_VISUALIZE_CREATURE, Position(startPosition.GetPositionX() + front.first * BOUNDARY_VISUALIZE_STEP_SIZE, startPosition.GetPositionY() + front.second * BOUNDARY_VISUALIZE_STEP_SIZE, spawnZ), TEMPSUMMON_TIMED_DESPAWN, duration * IN_MILLISECONDS)) { point->SetObjectScale(BOUNDARY_VISUALIZE_CREATURE_SCALE); point->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); @@ -287,6 +295,8 @@ int32 CreatureAI::VisualizeBoundary(uint32 duration, Unit* owner, bool fill) con if (!hasOutOfBoundsNeighbor) point->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); } + } + Q.pop(); } return boundsWarning ? LANG_CREATURE_MOVEMENT_MAYBE_UNBOUNDED : 0; @@ -300,7 +310,7 @@ bool CreatureAI::IsInBoundary(Position const* who) const if (!who) who = me; - return (CreatureAI::IsInBounds(*_boundary, who) != _negateBoundary); + return CreatureAI::IsInBounds(*_boundary, who) != _negateBoundary; } bool CreatureAI::IsInBounds(CreatureBoundary const& boundary, Position const* pos) |