Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
world and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp.dallig committed Nov 18, 2011
1 parent be7fef1 commit 51a2b0d
Show file tree
Hide file tree
Showing 18 changed files with 1,058 additions and 343 deletions.
6 changes: 1 addition & 5 deletions base/escort_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,11 @@ bool npc_escortAI::IsPlayerOrGroupInRange()
{
if (Group* pGroup = pPlayer->GetGroup())
{
for(GroupReference* pRef = pGroup->GetFirstMember(); pRef != NULL; pRef = pRef->next())
for (GroupReference* pRef = pGroup->GetFirstMember(); pRef != NULL; pRef = pRef->next())
{
Player* pMember = pRef->getSource();

if (pMember && m_creature->IsWithinDistInMap(pMember, MAX_PLAYER_DISTANCE))
{
return true;
break;
}
}
}
else
Expand Down
46 changes: 34 additions & 12 deletions include/sc_creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ struct TSpellSummary

ScriptedAI::ScriptedAI(Creature* pCreature) : CreatureAI(pCreature),
m_bCombatMovement(true),
m_uiEvadeCheckCooldown(2500)
m_uiEvadeCheckCooldown(2500),
m_events(NULL)
{}

ScriptedAI::~ScriptedAI()
{
if (m_events)
delete m_events;
}

/// This function shows if combat movement is enabled, overwrite for more info
void ScriptedAI::GetAIInformation(ChatHandler& reader)
{
Expand Down Expand Up @@ -124,7 +131,6 @@ void ScriptedAI::EnterEvadeMode()
m_creature->RemoveAllAuras();
m_creature->DeleteThreatList();
m_creature->CombatStop(true);
m_creature->LoadCreatureAddon();

if (m_creature->isAlive())
m_creature->GetMotionMaster()->MoveTargetedHome();
Expand Down Expand Up @@ -196,7 +202,7 @@ Creature* ScriptedAI::DoSpawnCreature(uint32 uiId, float fX, float fY, float fZ,
return m_creature->SummonCreature(uiId,m_creature->GetPositionX()+fX, m_creature->GetPositionY()+fY, m_creature->GetPositionZ()+fZ, fAngle, (TempSummonType)uiType, uiDespawntime);
}

SpellEntry const* ScriptedAI::SelectSpell(Unit* pTarget, int32 uiSchool, int32 uiMechanic, SelectTarget selectTargets, uint32 uiPowerCostMin, uint32 uiPowerCostMax, float fRangeMin, float fRangeMax, SelectEffect selectEffects)
SpellEntry const* ScriptedAI::SelectSpell(Unit* pTarget, int32 uiSchool, int32 iMechanic, SelectTarget selectTargets, uint32 uiPowerCostMin, uint32 uiPowerCostMax, float fRangeMin, float fRangeMax, SelectEffect selectEffects)
{
//No target so we can't cast
if (!pTarget)
Expand Down Expand Up @@ -238,7 +244,7 @@ SpellEntry const* ScriptedAI::SelectSpell(Unit* pTarget, int32 uiSchool, int32 u
continue;

//Check for spell mechanic if specified
if (uiMechanic >= 0 && pTempSpell->Mechanic != uiMechanic)
if (iMechanic >= 0 && pTempSpell->Mechanic != (uint32)iMechanic)
continue;

//Make sure that the spell uses the requested amount of power
Expand Down Expand Up @@ -474,22 +480,22 @@ Player* ScriptedAI::GetPlayerAtMinimumRange(float fMinimumRange)
return pPlayer;
}

void ScriptedAI::SetEquipmentSlots(bool bLoadDefault, int32 uiMainHand, int32 uiOffHand, int32 uiRanged)
void ScriptedAI::SetEquipmentSlots(bool bLoadDefault, int32 iMainHand, int32 iOffHand, int32 iRanged)
{
if (bLoadDefault)
{
m_creature->LoadEquipment(m_creature->GetCreatureInfo()->equipmentId,true);
m_creature->LoadEquipment(m_creature->GetCreatureInfo()->equipmentId, true);
return;
}

if (uiMainHand >= 0)
m_creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0, uint32(uiMainHand));
if (iMainHand >= 0)
m_creature->SetVirtualItem(VIRTUAL_ITEM_SLOT_0, iMainHand);

if (uiOffHand >= 0)
m_creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, uint32(uiOffHand));
if (iOffHand >= 0)
m_creature->SetVirtualItem(VIRTUAL_ITEM_SLOT_1, iOffHand);

if (uiRanged >= 0)
m_creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 2, uint32(uiRanged));
if (iRanged >= 0)
m_creature->SetVirtualItem(VIRTUAL_ITEM_SLOT_2, iRanged);
}

void ScriptedAI::SetCombatMovement(bool bCombatMove)
Expand All @@ -506,6 +512,7 @@ enum
NPC_JAN_ALAI = 23578,
NPC_SARTHARION = 28860,
NPC_TALON_KING_IKISS = 18473,
NPC_KARGATH_BLADEFIST = 16808,
};

bool ScriptedAI::EnterEvadeIfOutOfCombatArea(const uint32 uiDiff)
Expand Down Expand Up @@ -544,11 +551,17 @@ bool ScriptedAI::EnterEvadeIfOutOfCombatArea(const uint32 uiDiff)
return false;
break;
case NPC_TALON_KING_IKISS:
{
float fX, fY, fZ;
m_creature->GetRespawnCoord(fX, fY, fZ);
if (m_creature->GetDistance2d(fX, fY) < 70.0f)
return false;
break;
}
case NPC_KARGATH_BLADEFIST:
if (fX < 255.0f && fX > 205.0f)
return false;
break;
default:
error_log("SD2: EnterEvadeIfOutOfCombatArea used for creature entry %u, but does not have any definition.", m_creature->GetEntry());
return false;
Expand All @@ -558,6 +571,15 @@ bool ScriptedAI::EnterEvadeIfOutOfCombatArea(const uint32 uiDiff)
return true;
}

EventManager& ScriptedAI::Events()
{
// use lazy initialization to save memory
if (!m_events)
m_events = new EventManager();

return *m_events;
}

void Scripted_NoMovementAI::GetAIInformation(ChatHandler& reader)
{
reader.PSendSysMessage("Subclass of Scripted_NoMovementAI");
Expand Down
11 changes: 8 additions & 3 deletions include/sc_creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "Creature.h"
#include "Chat.h"

class EventManager;

//Spell targets used by SelectSpell
enum SelectTarget
{
Expand Down Expand Up @@ -46,7 +48,7 @@ struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI
{
public:
explicit ScriptedAI(Creature* pCreature);
~ScriptedAI() {}
~ScriptedAI();

// *************
// CreatureAI Functions
Expand Down Expand Up @@ -206,22 +208,25 @@ struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI
Creature* DoSpawnCreature(uint32 uiId, float fX, float fY, float fZ, float fAngle, uint32 uiType, uint32 uiDespawntime);

// Returns spells that meet the specified criteria from the creatures spell list
SpellEntry const* SelectSpell(Unit* pTarget, int32 uiSchool, int32 uiMechanic, SelectTarget selectTargets, uint32 uiPowerCostMin, uint32 uiPowerCostMax, float fRangeMin, float fRangeMax, SelectEffect selectEffect);
SpellEntry const* SelectSpell(Unit* pTarget, int32 uiSchool, int32 iMechanic, SelectTarget selectTargets, uint32 uiPowerCostMin, uint32 uiPowerCostMax, float fRangeMin, float fRangeMax, SelectEffect selectEffect);

// Checks if you can cast the specified spell
bool CanCast(Unit* pTarget, SpellEntry const* pSpell, bool bTriggered = false);

void SetEquipmentSlots(bool bLoadDefault, int32 uiMainHand = EQUIP_NO_CHANGE, int32 uiOffHand = EQUIP_NO_CHANGE, int32 uiRanged = EQUIP_NO_CHANGE);
void SetEquipmentSlots(bool bLoadDefault, int32 iMainHand = EQUIP_NO_CHANGE, int32 iOffHand = EQUIP_NO_CHANGE, int32 iRanged = EQUIP_NO_CHANGE);

// Generally used to control if MoveChase() is to be used or not in AttackStart(). Some creatures do not chase victims
void SetCombatMovement(bool bCombatMove);
bool IsCombatMovement() { return m_bCombatMovement; }

bool EnterEvadeIfOutOfCombatArea(const uint32 uiDiff);

EventManager& Events();

private:
bool m_bCombatMovement;
uint32 m_uiEvadeCheckCooldown;
EventManager* m_events;
};

struct MANGOS_DLL_DECL Scripted_NoMovementAI : public ScriptedAI
Expand Down
22 changes: 0 additions & 22 deletions include/sc_gossip.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,6 @@ extern uint32 GetSkillLevel(Player* pPlayer, uint32 uiSkill);
// guid - npc guid (ObjectGuid)
#define SEND_GOSSIP_MENU(uiTextId, guid) PlayerTalkClass->SendGossipMenu(uiTextId, guid)

// This fuction shows POI(point of interest) to client.
// a - position X
// b - position Y
// c - Icon Id
// d - Flags
// e - Data
// f - Location Name
#define SEND_POI(a, b, c, d, e, f) PlayerTalkClass->SendPointOfInterest(a, b, c, d, e, f)

// Closes the Menu
#define CLOSE_GOSSIP_MENU() PlayerTalkClass->CloseGossip()

Expand All @@ -165,17 +156,4 @@ extern uint32 GetSkillLevel(Player* pPlayer, uint32 uiSkill);
#define SEND_TABARDLIST(a) GetSession()->SendTabardVendorActivate(a)
#define SEND_TAXILIST(a) GetSession()->SendTaxiStatus(a)

// Function to send the Auction List
// a - pointer to unit (Unit*)
#define SEND_AUCTIONLIST(a) GetSession()->SendAuctionHello(a)

// Ressurect's the player if is dead.
#define SEND_SPRESURRECT() GetSession()->SendSpiritResurrect()

// Function to send the Quest Dialogue Status
// a - pointer to player (Player*)
// b - pointer to questgiver (Object*)
// c - defstatus (uint32)
#define QUEST_DIALOG_STATUS(a, b, c) GetSession()->getDialogStatus(a, b, c)

#endif
19 changes: 11 additions & 8 deletions include/sc_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,19 @@ void DialogueHelper::DoNextDialogueStep()
}

// Simulate Case
if (m_bCanSimulate && m_pInstance && uiSpeakerEntry && iTextEntry < 0)
m_pInstance->DoOrSimulateScriptTextForThisInstance(iTextEntry, uiSpeakerEntry);
else
if (uiSpeakerEntry && iTextEntry < 0)
{
// Get Speaker
Creature* pSpeaker = NULL;
if (m_pInstance && uiSpeakerEntry)
pSpeaker = m_pInstance->GetSingleCreatureFromStorage(uiSpeakerEntry);
// Use Speaker if directly provided
Creature* pSpeaker = GetSpeakerByEntry(uiSpeakerEntry);
if (m_pInstance && !pSpeaker) // Get Speaker from instance
{
if (m_bCanSimulate) // Simulate case
m_pInstance->DoOrSimulateScriptTextForThisInstance(iTextEntry, uiSpeakerEntry);
else
pSpeaker = m_pInstance->GetSingleCreatureFromStorage(uiSpeakerEntry);
}

if (pSpeaker && iTextEntry < 0)
if (pSpeaker)
DoScriptText(iTextEntry, pSpeaker);
}

Expand Down
16 changes: 13 additions & 3 deletions include/sc_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ enum EncounterState
#define OUT_SAVE_INST_DATA debug_log("SD2: Saving Instance Data for Instance %s (Map %d, Instance Id %d)", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_SAVE_INST_DATA_COMPLETE debug_log("SD2: Saving Instance Data for Instance %s (Map %d, Instance Id %d) completed.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA(a) debug_log("SD2: Loading Instance Data for Instance %s (Map %d, Instance Id %d). Input is '%s'", instance->GetMapName(), instance->GetId(), instance->GetInstanceId(), a)
#define OUT_LOAD_INST_DATA_COMPLETE debug_log("SD2: Instance Data Load for Instance %s (Map %d, Instance Id: %d) is complete.",instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA_FAIL error_log("SD2: Unable to load Instance Data for Instance %s (Map %d, Instance Id: %d).",instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA_COMPLETE debug_log("SD2: Instance Data Load for Instance %s (Map %d, Instance Id: %d) is complete.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA_FAIL error_log("SD2: Unable to load Instance Data for Instance %s (Map %d, Instance Id: %d).", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())

class MANGOS_DLL_DECL ScriptedInstance : public InstanceData
{
Expand Down Expand Up @@ -69,6 +69,13 @@ class MANGOS_DLL_DECL ScriptedInstance : public InstanceData
EntryGuidMap m_mNpcEntryGuidStore; ///< Store unique NPC-Guids by entry
};

// Class for world maps (May need additional zone-wide functions later on)
class MANGOS_DLL_DECL ScriptedMap : public ScriptedInstance
{
public:
ScriptedMap(Map* pMap) : ScriptedInstance(pMap) {}
};

/// A static const array of this structure must be handled to DialogueHelper
struct DialogueEntry
{
Expand Down Expand Up @@ -96,7 +103,7 @@ class DialogueHelper
// The array MUST be terminated by {0,0,0,0,0}
DialogueHelper(DialogueEntryTwoSide const* aDialogueTwoSide);

/// Function that MUST be called
/// Function to initialize the dialogue helper for instances. If not used with instances, GetSpeakerByEntry MUST be overwritten to obtain the speakers
void InitializeDialogueHelper(ScriptedInstance* pInstance, bool bCanSimulateText = false) { m_pInstance = pInstance; m_bCanSimulate = bCanSimulateText; }
/// Set if take first entries or second entries
void SetDialogueSide(bool bIsFirstSide) { m_bIsFirstSide = bIsFirstSide; }
Expand All @@ -106,7 +113,10 @@ class DialogueHelper
void DialogueUpdate(uint32 uiDiff);

protected:
/// Will be called when a dialogue step was done
virtual void JustDidDialogueStep(int32 iEntry) {}
/// Will be called to get a speaker, MUST be implemented if not used in instances
virtual Creature* GetSpeakerByEntry(uint32 uiEntry) { return NULL; }

private:
void DoNextDialogueStep();
Expand Down
Loading

0 comments on commit 51a2b0d

Please sign in to comment.