diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index be42d340..38fed4f4 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1317,7 +1317,6 @@ void Game::render2d(){ if(mainMessageBox.getEnabled()){ renderer.renderMessageBox(&mainMessageBox); } - if(errorMessageBox.getEnabled()){ renderer.renderMessageBox(&errorMessageBox); } @@ -1325,7 +1324,7 @@ void Game::render2d(){ //script message box if( mainMessageBox.getEnabled() == false && errorMessageBox.getEnabled() == false && - scriptManager.getMessageBoxEnabled()){ + scriptManager.getMessageBoxEnabled()) { renderer.renderMessageBox(scriptManager.getMessageBox()); } @@ -1510,6 +1509,9 @@ void Game::checkWinnerStandard(){ // but don't let him cheat via teamchat chatManager.setDisableTeamMode(true); } + + scriptManager.onGameOver(!lose); + showLoseMessageBox(); } @@ -1544,6 +1546,8 @@ void Game::checkWinnerStandard(){ // END } + scriptManager.onGameOver(win); + showWinMessageBox(); } } @@ -1557,6 +1561,9 @@ void Game::checkWinnerScripted(){ world.getStats()->setVictorious(i); } } + + scriptManager.onGameOver(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()); + if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){ showWinMessageBox(); } diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index e3fdf2e3..05822356 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -105,6 +105,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){ luaScript.registerFunction(getUnitCount, "unitCount"); luaScript.registerFunction(getUnitCountOfType, "unitCountOfType"); + luaScript.registerFunction(getLastCreatedUnitName, "gameWon"); + //load code for(int i= 0; igetScriptCount(); ++i){ const Script* script= scenario->getScript(i); @@ -119,6 +121,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){ lastCreatedUnitId= -1; lastDeadUnitId= -1; gameOver= false; + gameWon = false; //call startup function luaScript.beginCall("startup"); @@ -160,6 +163,12 @@ void ScriptManager::onUnitDied(const Unit* unit){ luaScript.endCall(); } +void ScriptManager::onGameOver(bool won){ + gameWon = won; + luaScript.beginCall("gameOver"); + luaScript.endCall(); +} + // ========================== lua wrappers =============================================== string ScriptManager::wrapString(const string &str, int wrapCount){ @@ -361,6 +370,11 @@ const string &ScriptManager::getLastCreatedUnitName(){ return lastCreatedUnitName; } +bool ScriptManager::getGameWon() { + ScriptManager_STREFLOP_Wrapper streflopWrapper; + return gameWon; +} + int ScriptManager::getLastCreatedUnitId(){ ScriptManager_STREFLOP_Wrapper streflopWrapper; return lastCreatedUnitId; @@ -703,4 +717,11 @@ int ScriptManager::DisplayFormattedText(LuaHandle* luaHandle) { */ } +int ScriptManager::getGameWon(LuaHandle* luaHandle){ + LuaArguments luaArguments(luaHandle); + luaArguments.returnInt(thisScriptManager->getGameWon()); + return luaArguments.getReturnCount(); +} + + }}//end namespace diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 060b5269..b1ce9912 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -103,6 +103,7 @@ private: // end game state bool gameOver; + bool gameWon; PlayerModifiers playerModifiers[GameConstants::maxPlayers]; private: @@ -120,6 +121,7 @@ public: GraphicMessageBox* getMessageBox() {return &messageBox;} string getDisplayText() const {return displayText;} bool getGameOver() const {return gameOver;} + bool getGameWon() const {return gameWon;} const PlayerModifiers *getPlayerModifiers(int factionIndex) const {return &playerModifiers[factionIndex];} //events @@ -127,6 +129,7 @@ public: void onResourceHarvested(); void onUnitCreated(const Unit* unit); void onUnitDied(const Unit* unit); + void onGameOver(bool won); private: string wrapString(const string &str, int wrapCount); @@ -170,6 +173,8 @@ private: int getUnitCount(int factionIndex); int getUnitCountOfType(int factionIndex, const string &typeName); + bool getGameWon(); + //callbacks, commands static int showMessage(LuaHandle* luaHandle); static int setDisplayText(LuaHandle* luaHandle); @@ -208,6 +213,8 @@ private: static int getLastDeadUnitId(LuaHandle* luaHandle); static int getUnitCount(LuaHandle* luaHandle); static int getUnitCountOfType(LuaHandle* luaHandle); + + static int getGameWon(LuaHandle* luaHandle); }; }}//end namespace