added lua method to be able to allow or disallow speed change toggle

void disableSpeedChange();
	void enableSpeedChange();
	bool getSpeedChangeEnabled();
This commit is contained in:
Mark Vejvoda 2013-11-07 05:18:21 +00:00
parent f7002a36ef
commit 4a70fd09e2
4 changed files with 63 additions and 0 deletions

View File

@ -165,6 +165,7 @@ Game::Game() : ProgramState(NULL) {
lastNetworkPlayerConnectionCheck = time(NULL);
inJoinGameLoading = false;
quitGameCalled = false;
disableSpeedChange = false;
for( int i=0;i<GameConstants::networkSmoothInterval;i++){
receivedTooEarlyInFrames[i]=-1;
@ -277,6 +278,7 @@ void Game::resetMembers() {
inJoinGameLoading = false;
quitGameCalled = false;
disableSpeedChange = false;
for( int i=0;i<GameConstants::networkSmoothInterval;i++){
receivedTooEarlyInFrames[i]=-1;
@ -5771,6 +5773,10 @@ bool Game::hasBuilding(const Faction *faction) {
}
void Game::incSpeed() {
if(disableSpeedChange == true) {
return;
}
Lang &lang= Lang::getInstance();
if(this->speed < 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();

View File

@ -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();

View File

@ -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; i<scenario->getScriptCount(); ++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<string,string> mapTagReplacements;

View File

@ -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