aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
authorVincent_Michael <Vincent_Michael@gmx.de>2013-12-18 23:48:20 +0100
committerVincent_Michael <Vincent_Michael@gmx.de>2013-12-18 23:48:20 +0100
commit2ded11354de44d6dd7ce6bd222ac188f8fbc3c9c (patch)
treed6de9a5c1a548c8c19582470e278a82e40063622 /src/server/game
parentf7aedaef3303b38d2e54faaad6ff80b66aaea074 (diff)
parent18cc0758395896f705a5dfd6e363b06367d617e9 (diff)
Merge branch 'master' of github.com:TrinityCore/TrinityCore into 4.3.4
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp48
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.h1
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp62
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp4
-rw-r--r--src/server/game/Entities/Player/Player.cpp4
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp4
-rw-r--r--src/server/game/Handlers/AuctionHouseHandler.cpp1
-rw-r--r--src/server/game/Maps/Map.cpp8
-rw-r--r--src/server/game/Maps/MapManager.cpp36
-rw-r--r--src/server/game/Maps/MapManager.h5
-rwxr-xr-xsrc/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp12
-rw-r--r--src/server/game/Movement/Spline/MoveSpline.h2
12 files changed, 97 insertions, 90 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index 1c78b97866f..1ced9e79672 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -339,27 +339,10 @@ void SmartAI::UpdateAI(uint32 diff)
{
if (me->FindNearestCreature(mFollowArrivedEntry, INTERACTION_DISTANCE, true))
{
- if (Player* player = ObjectAccessor::GetPlayer(*me, mFollowGuid))
- {
- if (!mFollowCreditType)
- player->RewardPlayerAndGroupAtEvent(mFollowCredit, me);
- else
- player->GroupEventHappens(mFollowCredit, me);
- }
- mFollowGuid = 0;
- mFollowDist = 0;
- mFollowAngle = 0;
- mFollowCredit = 0;
- mFollowArrivedTimer = 1000;
- mFollowArrivedEntry = 0;
- mFollowCreditType = 0;
- SetDespawnTime(5000);
- me->StopMoving();
- me->GetMotionMaster()->MoveIdle();
- StartDespawn();
- GetScript()->ProcessEventsFor(SMART_EVENT_FOLLOW_COMPLETED);
+ StopFollow();
return;
}
+
mFollowArrivedTimer = 1000;
}
else
@@ -803,7 +786,11 @@ void SmartAI::SetCombatMove(bool on)
void SmartAI::SetFollow(Unit* target, float dist, float angle, uint32 credit, uint32 end, uint32 creditType)
{
if (!target)
+ {
+ StopFollow();
return;
+ }
+
SetRun(mRun);
mFollowGuid = target->GetGUID();
mFollowDist = dist >= 0.0f ? dist : PET_FOLLOW_DIST;
@@ -815,6 +802,29 @@ void SmartAI::SetFollow(Unit* target, float dist, float angle, uint32 credit, ui
mFollowCreditType = creditType;
}
+void SmartAI::StopFollow()
+{
+ if (Player* player = ObjectAccessor::GetPlayer(*me, mFollowGuid))
+ {
+ if (!mFollowCreditType)
+ player->RewardPlayerAndGroupAtEvent(mFollowCredit, me);
+ else
+ player->GroupEventHappens(mFollowCredit, me);
+ }
+
+ mFollowGuid = 0;
+ mFollowDist = 0;
+ mFollowAngle = 0;
+ mFollowCredit = 0;
+ mFollowArrivedTimer = 1000;
+ mFollowArrivedEntry = 0;
+ mFollowCreditType = 0;
+ SetDespawnTime(5000);
+ me->StopMoving();
+ me->GetMotionMaster()->MoveIdle();
+ StartDespawn();
+ GetScript()->ProcessEventsFor(SMART_EVENT_FOLLOW_COMPLETED);
+}
void SmartAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
{
if (invoker)
diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h
index 085859a6d85..5c56736a673 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.h
+++ b/src/server/game/AI/SmartScripts/SmartAI.h
@@ -63,6 +63,7 @@ class SmartAI : public CreatureAI
void SetCombatMove(bool on);
bool CanCombatMove() { return mCanCombatMove; }
void SetFollow(Unit* target, float dist = 0.0f, float angle = 0.0f, uint32 credit = 0, uint32 end = 0, uint32 creditType = 0);
+ void StopFollow();
void SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker);
SmartScript* GetScript() { return &mScript; }
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 138c610ac46..6af09f3bb2b 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -367,12 +367,14 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsPlayer(*itr))
+ {
if (Quest const* q = sObjectMgr->GetQuestTemplate(e.action.quest.quest))
{
(*itr)->ToPlayer()->AddQuestAndCheckCompletion(q, NULL);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_ADD_QUEST: Player guidLow %u add quest %u",
(*itr)->GetGUIDLow(), e.action.quest.quest);
}
+ }
}
delete targets;
@@ -380,12 +382,18 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_SET_REACT_STATE:
{
- if (!me)
+ ObjectList* targets = GetTargets(e, unit);
+ if (!targets)
break;
- me->SetReactState(ReactStates(e.action.react.state));
- TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_SET_REACT_STATE: Creature guidLow %u set reactstate %u",
- me->GetGUIDLow(), e.action.react.state);
+ for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
+ {
+ if (!IsCreature(*itr))
+ continue;
+
+ (*itr)->ToCreature()->SetReactState(ReactStates(e.action.react.state));
+ }
+
break;
}
case SMART_ACTION_RANDOM_EMOTE:
@@ -825,7 +833,10 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
ObjectList* targets = GetTargets(e, unit);
if (!targets)
+ {
+ CAST_AI(SmartAI, me->AI())->StopFollow();
break;
+ }
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
@@ -1029,25 +1040,41 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_FORCE_DESPAWN:
{
- if (!IsSmart())
+ ObjectList* targets = GetTargets(e, unit);
+
+ if (!targets)
break;
- // The AI is only updated if the creature is alive
- if (me->IsAlive())
+ for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
- CAST_AI(SmartAI, me->AI())->SetDespawnTime(e.action.forceDespawn.delay + 1); // Next tick
- CAST_AI(SmartAI, me->AI())->StartDespawn();
+ if (!IsCreature(*itr))
+ continue;
+
+ if ((*itr)->ToUnit()->IsAlive() && IsSmart((*itr)->ToCreature()))
+ {
+ CAST_AI(SmartAI, (*itr)->ToCreature()->AI())->SetDespawnTime(e.action.forceDespawn.delay + 1); // Next tick
+ CAST_AI(SmartAI, (*itr)->ToCreature()->AI())->StartDespawn();
+ }
+ else
+ (*itr)->ToCreature()->DespawnOrUnsummon(e.action.forceDespawn.delay);
}
- // Otherwise we call the despawn directly
- else
- me->DespawnOrUnsummon(e.action.forceDespawn.delay);
break;
}
case SMART_ACTION_SET_INGAME_PHASE_MASK:
{
- if (WorldObject* baseObj = GetBaseObject())
- baseObj->SetPhaseMask(e.action.ingamePhaseMask.mask, true);
+ ObjectList* targets = GetTargets(e, unit);
+
+ if (!targets)
+ break;
+
+ for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
+ {
+ if (IsUnit(*itr))
+ (*itr)->ToUnit()->SetPhaseMask(e.action.ingamePhaseMask.mask, true);
+ else if (IsGameObject(*itr))
+ (*itr)->ToGameObject()->SetPhaseMask(e.action.ingamePhaseMask.mask, true);
+ }
break;
}
@@ -1132,6 +1159,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (WorldObject* baseObj = GetBaseObject())
baseObj->setActive(e.action.active.state);
+
break;
}
case SMART_ACTION_ATTACK_START:
@@ -1647,7 +1675,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
- if (IsUnit(*itr))
+ if (IsCreature(*itr))
(*itr)->ToUnit()->SetUInt32Value(UNIT_NPC_FLAGS, e.action.unitFlag.flag);
delete targets;
@@ -1660,7 +1688,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
- if (IsUnit(*itr))
+ if (IsCreature(*itr))
(*itr)->ToUnit()->SetFlag(UNIT_NPC_FLAGS, e.action.unitFlag.flag);
delete targets;
@@ -1673,7 +1701,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
- if (IsUnit(*itr))
+ if (IsCreature(*itr))
(*itr)->ToUnit()->RemoveFlag(UNIT_NPC_FLAGS, e.action.unitFlag.flag);
delete targets;
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index b14d22e77b2..e416500f77f 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -1540,7 +1540,11 @@ void Creature::Respawn(bool force)
//Call AI respawn virtual function
if (IsAIEnabled)
+ {
+ //reset the AI to be sure no dirty or uninitialized values will be used till next tick
+ AI()->Reset();
TriggerJustRespawned = true;//delay event to next tick so all creatures are created on the map before processing
+ }
uint32 poolid = GetDBTableGUIDLow() ? sPoolMgr->IsPartOfAPool<Creature>(GetDBTableGUIDLow()) : 0;
if (poolid)
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 9f8fb0a1064..ec087de0a06 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -15468,7 +15468,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
if (quest->GetRewSpellCast() > 0)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(quest->GetRewSpellCast());
- if (questGiver->isType(TYPEMASK_UNIT) && (!spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) || !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM)))
+ if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM))
{
if (Creature* creature = GetMap()->GetCreature(questGiver->GetGUID()))
creature->CastSpell(this, quest->GetRewSpellCast(), true);
@@ -15479,7 +15479,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
else if (quest->GetRewSpell() > 0)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(quest->GetRewSpell());
- if (questGiver->isType(TYPEMASK_UNIT) && (!spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) || !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM)))
+ if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM))
{
if (Creature* creature = GetMap()->GetCreature(questGiver->GetGUID()))
creature->CastSpell(this, quest->GetRewSpell(), true);
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 9fd9e1f3606..02bdc5f3a8c 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -11898,6 +11898,9 @@ void CharmInfo::InitPossessCreateSpells()
switch (_unit->GetEntry())
{
case 23575: // Mindless Abomination
+ case 24783: // Trained Rock Falcon
+ case 27664: // Crashin' Thrashin' Racer
+ case 40281: // Crashin' Thrashin' Racer
break;
default:
InitEmptyActionBar();
@@ -14165,7 +14168,6 @@ void Unit::RemoveCharmedBy(Unit* charmer)
}
}
break;
- default:
case CHARM_TYPE_CONVERT:
break;
}
diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp
index 50e21edb1fd..053746654b7 100644
--- a/src/server/game/Handlers/AuctionHouseHandler.cpp
+++ b/src/server/game/Handlers/AuctionHouseHandler.cpp
@@ -362,6 +362,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
item2->DeleteFromInventoryDB(trans);
item2->DeleteFromDB(trans);
CharacterDatabase.CommitTransaction(trans);
+ delete item2;
}
else // Item stack count is bigger than required count, update item stack count and save to database - cloned item will be used for auction
{
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 3c0837676c2..4f3640fe73b 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -68,12 +68,8 @@ Map::~Map()
Transport* transport = *itr;
++itr;
- // Destroy local transports
- if (transport->GetTransportTemplate()->inInstance)
- {
- transport->RemoveFromWorld();
- delete transport;
- }
+ transport->RemoveFromWorld();
+ delete transport;
}
if (!m_scriptSchedule.empty())
diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp
index 1837546d375..e9b12f2db58 100644
--- a/src/server/game/Maps/MapManager.cpp
+++ b/src/server/game/Maps/MapManager.cpp
@@ -37,14 +37,10 @@
#include "WorldSession.h"
#include "Opcodes.h"
-extern GridState* si_GridStates[]; // debugging code, should be deleted some day
-
MapManager::MapManager()
{
i_gridCleanUpDelay = sWorld->getIntConfig(CONFIG_INTERVAL_GRIDCLEAN);
i_timer.SetInterval(sWorld->getIntConfig(CONFIG_INTERVAL_MAPUPDATE));
- memset(i_GridStates, 0, sizeof(i_GridStates));
- i_GridStateErrorCount = 0;
_nextInstanceId = 0;
}
@@ -54,13 +50,6 @@ void MapManager::Initialize()
{
Map::InitStateMachine();
- // debugging code, should be deleted some day
- {
- for (uint8 i = 0; i < MAX_GRID_STATE; ++i)
- i_GridStates[i] = si_GridStates[i];
-
- i_GridStateErrorCount = 0;
- }
int num_threads(sWorld->getIntConfig(CONFIG_NUMTHREADS));
// Start mtmaps if needed.
if (num_threads > 0 && m_updater.activate(num_threads) == -1)
@@ -73,31 +62,6 @@ void MapManager::InitializeVisibilityDistanceInfo()
(*iter).second->InitVisibilityDistance();
}
-// debugging code, should be deleted some day
-void MapManager::checkAndCorrectGridStatesArray()
-{
- bool ok = true;
- for (int i=0; i<MAX_GRID_STATE; i++)
- {
- if (i_GridStates[i] != si_GridStates[i])
- {
- TC_LOG_ERROR("maps", "MapManager::checkGridStates(), GridState: si_GridStates is currupt !!!");
- ok = false;
- si_GridStates[i] = i_GridStates[i];
- }
- #ifdef TRINITY_DEBUG
- // inner class checking only when compiled with debug
- if (!si_GridStates[i]->checkMagic())
- {
- ok = false;
- si_GridStates[i]->setMagic();
- }
- #endif
- }
- if (!ok)
- ++i_GridStateErrorCount;
-}
-
Map* MapManager::CreateBaseMap(uint32 id)
{
Map* map = FindBaseMap(id);
diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h
index 230b4648f4a..48537558057 100644
--- a/src/server/game/Maps/MapManager.h
+++ b/src/server/game/Maps/MapManager.h
@@ -129,11 +129,6 @@ class MapManager
typedef UNORDERED_MAP<uint32, Map*> MapMapType;
typedef std::vector<bool> InstanceIds;
- // debugging code, should be deleted some day
- void checkAndCorrectGridStatesArray(); // just for debugging to find some memory overwrites
- GridState* i_GridStates[MAX_GRID_STATE]; // shadow entries to the global array in Map.cpp
- int i_GridStateErrorCount;
-
MapManager();
~MapManager();
diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
index 6787144e2e5..a20a8a30de5 100755
--- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
@@ -74,19 +74,24 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
if (m_isArrivalDone)
return;
- creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
m_isArrivalDone = true;
if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance)
{
TC_LOG_DEBUG("maps.script", "Creature movement start script %u at point %u for " UI64FMTD ".", i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID());
+ creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, NULL);
}
// Inform script
MovementInform(creature);
creature->UpdateWaypointID(i_currentNode);
- Stop(i_path->at(i_currentNode)->delay);
+
+ if (i_path->at(i_currentNode)->delay)
+ {
+ creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
+ Stop(i_path->at(i_currentNode)->delay);
+ }
}
bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
@@ -188,7 +193,8 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
{
if (creature->IsStopped())
Stop(STOP_TIME_FOR_PLAYER);
- else if (creature->movespline->Finalized())
+ // Checking just before reaching waypoint gives smother movement than using FinalDestination
+ else if (creature->movespline->timeElapsed() < 150)
{
OnArrived(creature);
return StartMove(creature);
diff --git a/src/server/game/Movement/Spline/MoveSpline.h b/src/server/game/Movement/Spline/MoveSpline.h
index 209f978d658..5a788201e7f 100644
--- a/src/server/game/Movement/Spline/MoveSpline.h
+++ b/src/server/game/Movement/Spline/MoveSpline.h
@@ -79,10 +79,10 @@ namespace Movement
UpdateResult _updateState(int32& ms_time_diff);
int32 next_timestamp() const { return spline.length(point_Idx + 1); }
int32 segment_time_elapsed() const { return next_timestamp() - time_passed; }
- int32 timeElapsed() const { return Duration() - time_passed; }
int32 timePassed() const { return time_passed; }
public:
+ int32 timeElapsed() const { return Duration() - time_passed; }
int32 Duration() const { return spline.length(); }
MySpline const& _Spline() const { return spline; }
int32 _currentSplineIdx() const { return point_Idx; }