From 70e01d5e0bc9efa9097a37f6280da1ec4bded88b Mon Sep 17 00:00:00 2001 From: titiger Date: Tue, 4 Feb 2014 21:21:06 +0100 Subject: [PATCH] lua commands to shake the cam -- camera-distance-affected=false shakeCamera(int shakeIntensity, int shakeDuration) -- camera-distance-affected=true shakeCameraOnUnit(int shakeIntensity, int shakeDuration , int UnitId) --- source/glest_game/game/script_manager.cpp | 55 +++++++++++++++++++++++ source/glest_game/game/script_manager.h | 3 ++ 2 files changed, 58 insertions(+) diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 6e9290424..31bec54e1 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -248,6 +248,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro luaScript.registerFunction(DisplayFormattedLangText, "displayFormattedLangText"); luaScript.registerFunction(clearDisplayText, "clearDisplayText"); luaScript.registerFunction(setCameraPosition, "setCameraPosition"); + luaScript.registerFunction(shakeCamera, "shakeCamera"); + luaScript.registerFunction(shakeCameraOnUnit, "shakeCameraOnUnit"); luaScript.registerFunction(createUnit, "createUnit"); luaScript.registerFunction(createUnitNoSpacing, "createUnitNoSpacing"); luaScript.registerFunction(destroyUnit, "destroyUnit"); @@ -1025,6 +1027,17 @@ void ScriptManager::setCameraPosition(const Vec2i &pos){ gameCamera->centerXZ(pos.x, pos.y); } +void ScriptManager::shakeCamera(int shakeIntensity, int shakeDuration, bool cameraDistanceAffected, int unitId){ + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + + if (cameraDistanceAffected) { + Unit *unit = world->findUnitById(unitId); + gameCamera->shake(shakeDuration, shakeIntensity,cameraDistanceAffected, unit->getCurrVector()); + } else { + gameCamera->shake(shakeDuration, shakeIntensity,cameraDistanceAffected, Vec3f(0.f,0.f,0.f)); + } +} + void ScriptManager::createUnit(const string &unitName, int factionIndex, Vec2i pos){ if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitName.c_str(),factionIndex); world->createUnit(unitName, factionIndex, pos); @@ -2185,6 +2198,48 @@ int ScriptManager::setCameraPosition(LuaHandle* luaHandle){ return luaArguments.getReturnCount(); } +int ScriptManager::shakeCamera(LuaHandle* luaHandle){ + LuaArguments luaArguments(luaHandle); + + try { + thisScriptManager->shakeCamera(luaArguments.getInt(-2),luaArguments.getInt(-1),false,0); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nThe game may no longer be stable!\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error",-1,-1,true)); + thisScriptManager->onMessageBoxOk(false); + } + + return luaArguments.getReturnCount(); +} + +int ScriptManager::shakeCameraOnUnit(LuaHandle* luaHandle){ + LuaArguments luaArguments(luaHandle); + + try { + thisScriptManager->shakeCamera(luaArguments.getInt(-3),luaArguments.getInt(-2),true,luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nThe game may no longer be stable!\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error",-1,-1,true)); + thisScriptManager->onMessageBoxOk(false); + } + + return luaArguments.getReturnCount(); +} + int ScriptManager::createUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index c5b42fa35..f8e8659ab 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -278,6 +278,7 @@ private: void DisplayFormattedText(const char *fmt,...); void DisplayFormattedLangText(const char *fmt,...); void setCameraPosition(const Vec2i &pos); + void shakeCamera(int shakeIntensity, int shakeDuration, bool cameraDistanceAffected, int unitId); void createUnit(const string &unitName, int factionIndex, Vec2i pos); void createUnitNoSpacing(const string &unitName, int factionIndex, Vec2i pos); @@ -441,6 +442,8 @@ private: static int DisplayFormattedLangText(LuaHandle* luaHandle); static int clearDisplayText(LuaHandle* luaHandle); static int setCameraPosition(LuaHandle* luaHandle); + static int shakeCamera(LuaHandle* luaHandle); + static int shakeCameraOnUnit(LuaHandle* luaHandle); static int createUnit(LuaHandle* luaHandle); static int createUnitNoSpacing(LuaHandle* luaHandle);