* This should help with the Linux build; thanks to Machiavelli/click.
* VehicleScript is now bound to the database (`creature_template`.`ScriptName`) and only works for creature vehicles. --HG-- branch : trunk
This commit is contained in:
@@ -109,7 +109,8 @@ void Vehicle::Install()
|
||||
|
||||
Reset();
|
||||
|
||||
sScriptMgr.OnInstall(this);
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
sScriptMgr.OnInstall(this);
|
||||
}
|
||||
|
||||
void Vehicle::InstallAllAccessories()
|
||||
@@ -132,7 +133,8 @@ void Vehicle::Uninstall()
|
||||
|
||||
RemoveAllPassengers();
|
||||
|
||||
sScriptMgr.OnUninstall(this);
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
sScriptMgr.OnUninstall(this);
|
||||
}
|
||||
|
||||
void Vehicle::Die()
|
||||
@@ -145,7 +147,8 @@ void Vehicle::Die()
|
||||
|
||||
RemoveAllPassengers();
|
||||
|
||||
sScriptMgr.OnDie(this);
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
sScriptMgr.OnDie(this);
|
||||
}
|
||||
|
||||
void Vehicle::Reset()
|
||||
@@ -163,7 +166,8 @@ void Vehicle::Reset()
|
||||
me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
|
||||
}
|
||||
|
||||
sScriptMgr.OnReset(this);
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
sScriptMgr.OnReset(this);
|
||||
}
|
||||
|
||||
void Vehicle::RemoveAllPassengers()
|
||||
@@ -248,7 +252,8 @@ void Vehicle::InstallAccessory(uint32 entry, int8 seatId, bool minion)
|
||||
// This is not good, we have to send update twice
|
||||
accessory->SendMovementFlagUpdate();
|
||||
|
||||
sScriptMgr.OnInstallAccessory(this, accessory);
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
sScriptMgr.OnInstallAccessory(this, accessory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +334,8 @@ bool Vehicle::AddPassenger(Unit *unit, int8 seatId)
|
||||
}
|
||||
}
|
||||
|
||||
sScriptMgr.OnAddPassenger(this, unit, seatId);
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
sScriptMgr.OnAddPassenger(this, unit, seatId);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -377,7 +383,8 @@ void Vehicle::RemovePassenger(Unit *unit)
|
||||
if (unit->HasUnitMovementFlag(MOVEMENTFLAG_FLYING))
|
||||
me->CastSpell(unit, 45472, true); // Parachute
|
||||
|
||||
sScriptMgr.OnRemovePassenger(this, unit);
|
||||
if (GetBase()->GetTypeId() == TYPEID_UNIT)
|
||||
sScriptMgr.OnRemovePassenger(this, unit);
|
||||
}
|
||||
|
||||
void Vehicle::RelocatePassengers(float x, float y, float z, float ang)
|
||||
|
||||
@@ -13,18 +13,19 @@
|
||||
|
||||
// Utility macros to refer to the script registry.
|
||||
#define SCR_REG_MAP(T) ScriptRegistry<T>::ScriptMap
|
||||
#define SCR_REG_ITR(T) ScriptRegistry<T>::ScriptMapIterator
|
||||
#define SCR_REG_LST(T) ScriptRegistry<T>::ScriptPointerList
|
||||
|
||||
// Utility macros for looping over scripts.
|
||||
#define FOR_SCRIPTS(T,C,E) \
|
||||
if (SCR_REG_LST(T).empty()) \
|
||||
return; \
|
||||
for (SCR_REG_MAP(T)::iterator C = SCR_REG_LST(T).begin(); \
|
||||
for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \
|
||||
C != SCR_REG_LST(T).end(); ++C)
|
||||
#define FOR_SCRIPTS_RET(T,C,E,R) \
|
||||
if (SCR_REG_LST(T).empty()) \
|
||||
return R; \
|
||||
for (SCR_REG_MAP(T)::iterator C = SCR_REG_LST(T).begin(); \
|
||||
for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \
|
||||
C != SCR_REG_LST(T).end(); ++C)
|
||||
#define FOREACH_SCRIPT(T) \
|
||||
FOR_SCRIPTS(T, itr, end) \
|
||||
@@ -586,7 +587,7 @@ bool ScriptMgr::OnDummyEffect(Unit* caster, uint32 spellId, SpellEffIndex effInd
|
||||
ASSERT(caster);
|
||||
ASSERT(target);
|
||||
|
||||
GET_SCRIPT_RET(ItemScript, target->GetProto()->ScriptId, tmpscript, false);
|
||||
GET_SCRIPT_RET(ItemScript, target->GetScriptId(), tmpscript, false);
|
||||
return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
|
||||
}
|
||||
|
||||
@@ -596,7 +597,7 @@ bool ScriptMgr::OnQuestAccept(Player* player, Item* item, Quest const* quest)
|
||||
ASSERT(item);
|
||||
ASSERT(quest);
|
||||
|
||||
GET_SCRIPT_RET(ItemScript, item->GetProto()->ScriptId, tmpscript, false);
|
||||
GET_SCRIPT_RET(ItemScript, item->GetScriptId(), tmpscript, false);
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
return tmpscript->OnQuestAccept(player, item, quest);
|
||||
}
|
||||
@@ -606,7 +607,7 @@ bool ScriptMgr::OnItemUse(Player* player, Item* item, SpellCastTargets const& ta
|
||||
ASSERT(player);
|
||||
ASSERT(item);
|
||||
|
||||
GET_SCRIPT_RET(ItemScript, item->GetProto()->ScriptId, tmpscript, false);
|
||||
GET_SCRIPT_RET(ItemScript, item->GetScriptId(), tmpscript, false);
|
||||
return tmpscript->OnUse(player, item, targets);
|
||||
}
|
||||
|
||||
@@ -914,53 +915,67 @@ bool ScriptMgr::OnConditionCheck(Condition* condition, Player* player, Unit* tar
|
||||
void ScriptMgr::OnInstall(Vehicle* veh)
|
||||
{
|
||||
ASSERT(veh);
|
||||
ASSERT(veh->GetBase()->GetTypeId() == TYPEID_UNIT);
|
||||
|
||||
FOREACH_SCRIPT(VehicleScript)->OnInstall(veh);
|
||||
GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
|
||||
tmpscript->OnInstall(veh);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnUninstall(Vehicle* veh)
|
||||
{
|
||||
ASSERT(veh);
|
||||
ASSERT(veh->GetBase()->GetTypeId() == TYPEID_UNIT);
|
||||
|
||||
FOREACH_SCRIPT(VehicleScript)->OnUninstall(veh);
|
||||
GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
|
||||
tmpscript->OnUninstall(veh);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnDie(Vehicle* veh)
|
||||
{
|
||||
ASSERT(veh);
|
||||
ASSERT(veh->GetBase()->GetTypeId() == TYPEID_UNIT);
|
||||
|
||||
FOREACH_SCRIPT(VehicleScript)->OnDie(veh);
|
||||
GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
|
||||
tmpscript->OnDie(veh);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnReset(Vehicle* veh)
|
||||
{
|
||||
ASSERT(veh);
|
||||
ASSERT(veh->GetBase()->GetTypeId() == TYPEID_UNIT);
|
||||
|
||||
FOREACH_SCRIPT(VehicleScript)->OnReset(veh);
|
||||
GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
|
||||
tmpscript->OnReset(veh);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnInstallAccessory(Vehicle* veh, Creature* accessory)
|
||||
{
|
||||
ASSERT(veh);
|
||||
ASSERT(veh->GetBase()->GetTypeId() == TYPEID_UNIT);
|
||||
ASSERT(accessory);
|
||||
|
||||
FOREACH_SCRIPT(VehicleScript)->OnInstallAccessory(veh, accessory);
|
||||
GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
|
||||
tmpscript->OnInstallAccessory(veh, accessory);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnAddPassenger(Vehicle* veh, Unit* passenger, int8 seatId)
|
||||
{
|
||||
ASSERT(veh);
|
||||
ASSERT(veh->GetBase()->GetTypeId() == TYPEID_UNIT);
|
||||
ASSERT(passenger);
|
||||
|
||||
FOREACH_SCRIPT(VehicleScript)->OnAddPassenger(veh, passenger, seatId);
|
||||
GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
|
||||
tmpscript->OnAddPassenger(veh, passenger, seatId);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnRemovePassenger(Vehicle* veh, Unit* passenger)
|
||||
{
|
||||
ASSERT(veh);
|
||||
ASSERT(veh->GetBase()->GetTypeId() == TYPEID_UNIT);
|
||||
ASSERT(passenger);
|
||||
|
||||
FOREACH_SCRIPT(VehicleScript)->OnRemovePassenger(veh, passenger);
|
||||
GET_SCRIPT(VehicleScript, veh->GetBase()->ToCreature()->GetScriptId(), tmpscript);
|
||||
tmpscript->OnRemovePassenger(veh, passenger);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnDynamicObjectUpdate(DynamicObject* dynobj, uint32 diff)
|
||||
@@ -1145,48 +1160,51 @@ void ScriptMgr::ScriptRegistry<TScript>::AddScript(TScript* const script)
|
||||
}
|
||||
}
|
||||
|
||||
// Get an ID for the script. An ID only exists if it's a script that is assigned in the database
|
||||
// through a script name (or similar).
|
||||
uint32 id = GetScriptId(script->ToString());
|
||||
if (id)
|
||||
if (script->IsDatabaseBound())
|
||||
{
|
||||
// Try to find an existing script.
|
||||
bool existing = false;
|
||||
for (ScriptMap::iterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
|
||||
// Get an ID for the script. An ID only exists if it's a script that is assigned in the database
|
||||
// through a script name (or similar).
|
||||
uint32 id = GetScriptId(script->ToString());
|
||||
if (id)
|
||||
{
|
||||
// If the script names match...
|
||||
if (it->second->GetName() == script->GetName())
|
||||
// Try to find an existing script.
|
||||
bool existing = false;
|
||||
for (ScriptMap::iterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
|
||||
{
|
||||
// ... It exists.
|
||||
existing = true;
|
||||
break;
|
||||
// If the script names match...
|
||||
if (it->second->GetName() == script->GetName())
|
||||
{
|
||||
// ... It exists.
|
||||
existing = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the script isn't assigned -> assign it!
|
||||
if (!existing)
|
||||
{
|
||||
ScriptPointerList[id] = script;
|
||||
sScriptMgr.IncrementScriptCount();
|
||||
// If the script isn't assigned -> assign it!
|
||||
if (!existing)
|
||||
{
|
||||
ScriptPointerList[id] = script;
|
||||
sScriptMgr.IncrementScriptCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the script is already assigned -> delete it!
|
||||
sLog.outError("Script '%s' already assigned with the same script name, so the script can't work.",
|
||||
script->ToString());
|
||||
|
||||
delete script;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the script is already assigned -> delete it!
|
||||
sLog.outError("Script '%s' already assigned with the same script name, so the script can't work.",
|
||||
script->ToString());
|
||||
// The script uses a script name from database, but isn't assigned to anything.
|
||||
if (script->GetName().find("example") == std::string::npos)
|
||||
sLog.outErrorDb("Script named '%s' does not have a script name assigned in database.",
|
||||
script->ToString());
|
||||
|
||||
delete script;
|
||||
}
|
||||
}
|
||||
else if (script->IsDatabaseBound())
|
||||
{
|
||||
// The script uses a script name from database, but isn't assigned to anything.
|
||||
if (script->GetName().find("example") == std::string::npos)
|
||||
sLog.outErrorDb("Script named '%s' does not have a script name assigned in database.",
|
||||
script->ToString());
|
||||
|
||||
delete script;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're dealing with a code-only script; just add it.
|
||||
@@ -1229,4 +1247,5 @@ template class ScriptMgr::ScriptRegistry<TransportScript>;
|
||||
#undef FOR_SCRIPTS_RET
|
||||
#undef FOR_SCRIPTS
|
||||
#undef SCR_REG_LST
|
||||
#undef SCR_REG_ITR
|
||||
#undef SCR_REG_MAP
|
||||
|
||||
@@ -920,6 +920,7 @@ class ScriptMgr
|
||||
public:
|
||||
|
||||
typedef std::map<uint32, TScript*> ScriptMap;
|
||||
typedef typename ScriptMap::iterator ScriptMapIterator;
|
||||
|
||||
// The actual list of scripts. This will be accessed concurrently, so it must not be modified
|
||||
// after server startup.
|
||||
@@ -928,7 +929,7 @@ class ScriptMgr
|
||||
// Gets a script by its ID (assigned by ObjectMgr).
|
||||
static TScript* GetScriptById(uint32 id)
|
||||
{
|
||||
ScriptMap it = ScriptPointerList.find(id);
|
||||
ScriptMapIterator it = ScriptPointerList.find(id);
|
||||
if (it != ScriptPointerList.end())
|
||||
return it->second;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user