From 4a70fd09e2ced83d75875013251a28d90cb2a604 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 7 Nov 2013 05:18:21 +0000 Subject: [PATCH] added lua method to be able to allow or disallow speed change toggle void disableSpeedChange(); void enableSpeedChange(); bool getSpeedChangeEnabled(); --- source/glest_game/game/game.cpp | 14 +++++++++ source/glest_game/game/game.h | 4 +++ source/glest_game/game/script_manager.cpp | 38 +++++++++++++++++++++++ source/glest_game/game/script_manager.h | 7 +++++ 4 files changed, 63 insertions(+) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index fe397424..402e951c 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -165,6 +165,7 @@ Game::Game() : ProgramState(NULL) { lastNetworkPlayerConnectionCheck = time(NULL); inJoinGameLoading = false; quitGameCalled = false; + disableSpeedChange = false; for( int i=0;ispeed < Config::getInstance().getInt("FastSpeedLoops")) { @@ -5785,6 +5791,10 @@ void Game::incSpeed() { } void Game::decSpeed() { + if(disableSpeedChange == true) { + return; + } + Lang &lang= Lang::getInstance(); if(this->speed > 0) { this->speed--; @@ -6372,6 +6382,8 @@ string Game::saveGame(string name, string path) { gameNode->addAttribute("timeDisplay",intToStr(timeDisplay), mapTagReplacements); + gameNode->addAttribute("disableSpeedChange",intToStr(disableSpeedChange), mapTagReplacements); + xmlTree.save(saveGameFile); if(masterserverMode == false) { @@ -6642,6 +6654,8 @@ void Game::loadGame(string name,Program *programPtr,bool isMasterserverMode,cons newGame->timeDisplay = gameNode->getAttribute("timeDisplay")->getIntValue() != 0; + newGame->disableSpeedChange = gameNode->getAttribute("disableSpeedChange")->getIntValue() != 0; + //bool gameStarted; //gameNode->addAttribute("gameStarted",intToStr(gameStarted), mapTagReplacements); // newGame->gameStarted = gameNode->getAttribute("gameStarted")->getIntValue(); diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index ff0f6fee..8c4c1b81 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -209,6 +209,7 @@ private: bool initialResumeSpeedLoops; bool quitGameCalled; + bool disableSpeedChange; public: Game(); @@ -332,6 +333,9 @@ public: void DumpCRCWorldLogIfRequired(string fileSuffix=""); + bool getDisableSpeedChange() const { return disableSpeedChange; } + void setDisableSpeedChange(bool value) { disableSpeedChange = value; } + private: //render void render3d(); diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index a7994ada..85b0a5f2 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -377,6 +377,9 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro luaScript.registerFunction(getLastUnitTriggerEventType, "lastUnitTriggerEventType"); luaScript.registerFunction(getUnitProperty, "getUnitProperty"); luaScript.registerFunction(getUnitPropertyName, "getUnitPropertyName"); + luaScript.registerFunction(disableSpeedChange, "disableSpeedChange"); + luaScript.registerFunction(enableSpeedChange, "enableSpeedChange"); + luaScript.registerFunction(getSpeedChangeEnabled, "getSpeedChangeEnabled"); //load code for(int i= 0; igetScriptCount(); ++i){ @@ -1926,6 +1929,26 @@ float ScriptManager::getTimeOfDay() { return tf->getTime(); } +void ScriptManager::disableSpeedChange() { + if(world->getGame() == NULL) { + throw megaglest_runtime_error("world->getGame() == NULL"); + } + world->getGame()->setDisableSpeedChange(true); +} +void ScriptManager::enableSpeedChange() { + if(world->getGame() == NULL) { + throw megaglest_runtime_error("world->getGame() == NULL"); + } + world->getGame()->setDisableSpeedChange(false); +} + +bool ScriptManager::getSpeedChangeEnabled() { + if(world->getGame() == NULL) { + throw megaglest_runtime_error("world->getGame() == NULL"); + } + return world->getGame()->getDisableSpeedChange(); +} + // ========================== lua callbacks =============================================== int ScriptManager::showMessage(LuaHandle* luaHandle){ @@ -3025,6 +3048,21 @@ int ScriptManager::getUnitPropertyName(LuaHandle* luaHandle) { return luaArguments.getReturnCount(); } +int ScriptManager::disableSpeedChange(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + thisScriptManager->disableSpeedChange(); + return luaArguments.getReturnCount(); +} +int ScriptManager::enableSpeedChange(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + thisScriptManager->enableSpeedChange(); + return luaArguments.getReturnCount(); +} +int ScriptManager::getSpeedChangeEnabled(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + luaArguments.returnInt(thisScriptManager->getSpeedChangeEnabled()); + return luaArguments.getReturnCount(); +} void ScriptManager::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index e09bb88f..903b6a37 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -412,6 +412,10 @@ private: int getUnitProperty(int unitId, UnitTriggerEventType type); const string getUnitPropertyName(int unitId, UnitTriggerEventType type); + void disableSpeedChange(); + void enableSpeedChange(); + bool getSpeedChangeEnabled(); + //callbacks, commands static int networkShowMessageForFaction(LuaHandle* luaHandle); static int networkShowMessageForTeam(LuaHandle* luaHandle); @@ -572,6 +576,9 @@ private: static int getUnitProperty(LuaHandle* luaHandle); static int getUnitPropertyName(LuaHandle* luaHandle); + static int disableSpeedChange(LuaHandle* luaHandle); + static int enableSpeedChange(LuaHandle* luaHandle); + static int getSpeedChangeEnabled(LuaHandle* luaHandle); }; }}//end namespace