Index: Bindings.cpp =================================================================== --- Bindings.cpp (revision 1481) +++ Bindings.cpp (working copy) @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 05/12/13 17:56:56. +** Generated automatically by tolua++-1.0.92 on 05/14/13 21:22:46. */ #ifndef __cplusplus @@ -24927,6 +24927,7 @@ tolua_constant(tolua_S,"HOOK_UPDATING_SIGN",cPluginManager::HOOK_UPDATING_SIGN); tolua_constant(tolua_S,"HOOK_WEATHER_CHANGED",cPluginManager::HOOK_WEATHER_CHANGED); tolua_constant(tolua_S,"HOOK_WEATHER_CHANGING",cPluginManager::HOOK_WEATHER_CHANGING); + tolua_constant(tolua_S,"HOOK_EXPLOSION",cPluginManager::HOOK_EXPLOSION); tolua_function(tolua_S,"Get",tolua_AllToLua_cPluginManager_Get00); tolua_function(tolua_S,"GetPlugin",tolua_AllToLua_cPluginManager_GetPlugin00); tolua_function(tolua_S,"FindPlugins",tolua_AllToLua_cPluginManager_FindPlugins00); Index: Bindings.h =================================================================== --- Bindings.h (revision 1481) +++ Bindings.h (working copy) @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 05/12/13 17:56:56. +** Generated automatically by tolua++-1.0.92 on 05/14/13 21:22:47. */ /* Exported function */ Index: Plugin.cpp =================================================================== --- Plugin.cpp (revision 1481) +++ Plugin.cpp (working copy) @@ -524,6 +524,7 @@ + bool cPlugin::OnWeatherChanging(cWorld & a_World, eWeather & a_Weather) { UNUSED(a_World); @@ -535,6 +536,19 @@ +bool cPlugin::OnExplosion(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + UNUSED(a_World); + UNUSED(a_BlockX); + UNUSED(a_BlockY); + UNUSED(a_BlockZ); + return false; +} + + + + + bool cPlugin::HandleCommand(const AStringVector & a_Split, cPlayer * a_Player) { UNUSED(a_Split); Index: Plugin.h =================================================================== --- Plugin.h (revision 1481) +++ Plugin.h (working copy) @@ -85,6 +85,7 @@ virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player); virtual bool OnWeatherChanged (cWorld & a_World); virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather); + virtual bool OnExplosion (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ); /** Handles the command split into a_Split, issued by player a_Player. Command permissions have already been checked. Index: Plugin_NewLua.cpp =================================================================== --- Plugin_NewLua.cpp (revision 1481) +++ Plugin_NewLua.cpp (working copy) @@ -1324,6 +1324,35 @@ +bool cPlugin_NewLua::OnExplosion(cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + cCSLock Lock(m_CriticalSection); + const char * FnName = GetHookFnName(cPluginManager::HOOK_EXPLOSION); + ASSERT(FnName != NULL); + if (!PushFunction(FnName)) + { + return false; + } + + tolua_pushusertype(m_LuaState, &a_World, "cWorld"); + tolua_pushnumber (m_LuaState, a_BlockX); + tolua_pushnumber (m_LuaState, a_BlockY); + tolua_pushnumber (m_LuaState, a_BlockZ); + + if (!CallFunction(2, 1, FnName)) + { + return false; + } + + bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) != 0); + lua_pop(m_LuaState, 1); + return bRetVal; +} + + + + + bool cPlugin_NewLua::HandleCommand(const AStringVector & a_Split, cPlayer * a_Player) { ASSERT(!a_Split.empty()); @@ -1546,6 +1575,7 @@ case cPluginManager::HOOK_UPDATING_SIGN: return "OnUpdatingSign"; case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged"; case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging"; + case cPluginManager::HOOK_EXPLOSION: return "OnExplosion"; default: return NULL; } // switch (a_Hook) } Index: Plugin_NewLua.h =================================================================== --- Plugin_NewLua.h (revision 1481) +++ Plugin_NewLua.h (working copy) @@ -70,6 +70,7 @@ virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) override; virtual bool OnWeatherChanged (cWorld & a_World) override; virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather) override; + virtual bool OnExplosion (cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual bool HandleCommand(const AStringVector & a_Split, cPlayer * a_Player) override; Index: PluginManager.cpp =================================================================== --- PluginManager.cpp (revision 1481) +++ PluginManager.cpp (working copy) @@ -970,7 +970,26 @@ +bool cPluginManager::CallHookOnExplosion(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + HookMap::iterator Plugins = m_Hooks.find(HOOK_EXPLOSION); + if (Plugins == m_Hooks.end()) + { + return false; + } + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnExplosion(a_World, a_BlockX, a_BlockY, a_BlockZ)) + { + return true; + } + } + return false; +} + + + bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions) { ASSERT(a_Player != NULL); Index: PluginManager.h =================================================================== --- PluginManager.h (revision 1481) +++ PluginManager.h (working copy) @@ -77,6 +77,7 @@ HOOK_UPDATING_SIGN, HOOK_WEATHER_CHANGED, HOOK_WEATHER_CHANGING, + HOOK_EXPLOSION, // Note that if a hook type is added, it may need processing in cPlugin::CanAddHook() descendants, // and it definitely needs adding in cPlugin_NewLua::GetHookFnName() ! @@ -144,6 +145,7 @@ bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player); bool CallHookWeatherChanged (cWorld & a_World); bool CallHookWeatherChanging (cWorld & a_World, eWeather & a_NewWeather); + bool CallHookOnExplosion (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ); bool DisablePlugin(const AString & a_PluginName); // tolua_export bool LoadPlugin (const AString & a_PluginName); // tolua_export Index: World.cpp =================================================================== --- World.cpp (revision 1481) +++ World.cpp (working copy) @@ -705,6 +705,10 @@ void cWorld::DoExplosiontAt(float a_ExplosionSize, int a_BlockX, int a_BlockY, int a_BlockZ) { + if(cRoot::Get()->GetPluginManager()->CallHookOnExplosion(this , a_BlockX, a_BlockY, a_BlockZ)) + { + return; + } // TODO: Add damage to entities, add support for pickups, and implement block hardiness Vector3d explosion_pos = Vector3d(a_BlockX,a_BlockY,a_BlockZ); cVector3iArray * BlocksAffected = m_ChunkMap->DoExplosiontAt(a_ExplosionSize,a_BlockX,a_BlockY,a_BlockZ);