- added more LUA features.
new event: gameOver new method: getGameWon()
This commit is contained in:
parent
4d372c12bc
commit
03848fc84f
|
@ -1317,7 +1317,6 @@ void Game::render2d(){
|
||||||
if(mainMessageBox.getEnabled()){
|
if(mainMessageBox.getEnabled()){
|
||||||
renderer.renderMessageBox(&mainMessageBox);
|
renderer.renderMessageBox(&mainMessageBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(errorMessageBox.getEnabled()){
|
if(errorMessageBox.getEnabled()){
|
||||||
renderer.renderMessageBox(&errorMessageBox);
|
renderer.renderMessageBox(&errorMessageBox);
|
||||||
}
|
}
|
||||||
|
@ -1510,6 +1509,9 @@ void Game::checkWinnerStandard(){
|
||||||
// but don't let him cheat via teamchat
|
// but don't let him cheat via teamchat
|
||||||
chatManager.setDisableTeamMode(true);
|
chatManager.setDisableTeamMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scriptManager.onGameOver(!lose);
|
||||||
|
|
||||||
showLoseMessageBox();
|
showLoseMessageBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1544,6 +1546,8 @@ void Game::checkWinnerStandard(){
|
||||||
// END
|
// END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scriptManager.onGameOver(win);
|
||||||
|
|
||||||
showWinMessageBox();
|
showWinMessageBox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1557,6 +1561,9 @@ void Game::checkWinnerScripted(){
|
||||||
world.getStats()->setVictorious(i);
|
world.getStats()->setVictorious(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scriptManager.onGameOver(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner());
|
||||||
|
|
||||||
if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){
|
if(scriptManager.getPlayerModifiers(world.getThisFactionIndex())->getWinner()){
|
||||||
showWinMessageBox();
|
showWinMessageBox();
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||||
luaScript.registerFunction(getUnitCount, "unitCount");
|
luaScript.registerFunction(getUnitCount, "unitCount");
|
||||||
luaScript.registerFunction(getUnitCountOfType, "unitCountOfType");
|
luaScript.registerFunction(getUnitCountOfType, "unitCountOfType");
|
||||||
|
|
||||||
|
luaScript.registerFunction(getLastCreatedUnitName, "gameWon");
|
||||||
|
|
||||||
//load code
|
//load code
|
||||||
for(int i= 0; i<scenario->getScriptCount(); ++i){
|
for(int i= 0; i<scenario->getScriptCount(); ++i){
|
||||||
const Script* script= scenario->getScript(i);
|
const Script* script= scenario->getScript(i);
|
||||||
|
@ -119,6 +121,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||||
lastCreatedUnitId= -1;
|
lastCreatedUnitId= -1;
|
||||||
lastDeadUnitId= -1;
|
lastDeadUnitId= -1;
|
||||||
gameOver= false;
|
gameOver= false;
|
||||||
|
gameWon = false;
|
||||||
|
|
||||||
//call startup function
|
//call startup function
|
||||||
luaScript.beginCall("startup");
|
luaScript.beginCall("startup");
|
||||||
|
@ -160,6 +163,12 @@ void ScriptManager::onUnitDied(const Unit* unit){
|
||||||
luaScript.endCall();
|
luaScript.endCall();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptManager::onGameOver(bool won){
|
||||||
|
gameWon = won;
|
||||||
|
luaScript.beginCall("gameOver");
|
||||||
|
luaScript.endCall();
|
||||||
|
}
|
||||||
|
|
||||||
// ========================== lua wrappers ===============================================
|
// ========================== lua wrappers ===============================================
|
||||||
|
|
||||||
string ScriptManager::wrapString(const string &str, int wrapCount){
|
string ScriptManager::wrapString(const string &str, int wrapCount){
|
||||||
|
@ -361,6 +370,11 @@ const string &ScriptManager::getLastCreatedUnitName(){
|
||||||
return lastCreatedUnitName;
|
return lastCreatedUnitName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptManager::getGameWon() {
|
||||||
|
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
return gameWon;
|
||||||
|
}
|
||||||
|
|
||||||
int ScriptManager::getLastCreatedUnitId(){
|
int ScriptManager::getLastCreatedUnitId(){
|
||||||
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||||
return lastCreatedUnitId;
|
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
|
}}//end namespace
|
||||||
|
|
|
@ -103,6 +103,7 @@ private:
|
||||||
|
|
||||||
// end game state
|
// end game state
|
||||||
bool gameOver;
|
bool gameOver;
|
||||||
|
bool gameWon;
|
||||||
PlayerModifiers playerModifiers[GameConstants::maxPlayers];
|
PlayerModifiers playerModifiers[GameConstants::maxPlayers];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -120,6 +121,7 @@ public:
|
||||||
GraphicMessageBox* getMessageBox() {return &messageBox;}
|
GraphicMessageBox* getMessageBox() {return &messageBox;}
|
||||||
string getDisplayText() const {return displayText;}
|
string getDisplayText() const {return displayText;}
|
||||||
bool getGameOver() const {return gameOver;}
|
bool getGameOver() const {return gameOver;}
|
||||||
|
bool getGameWon() const {return gameWon;}
|
||||||
const PlayerModifiers *getPlayerModifiers(int factionIndex) const {return &playerModifiers[factionIndex];}
|
const PlayerModifiers *getPlayerModifiers(int factionIndex) const {return &playerModifiers[factionIndex];}
|
||||||
|
|
||||||
//events
|
//events
|
||||||
|
@ -127,6 +129,7 @@ public:
|
||||||
void onResourceHarvested();
|
void onResourceHarvested();
|
||||||
void onUnitCreated(const Unit* unit);
|
void onUnitCreated(const Unit* unit);
|
||||||
void onUnitDied(const Unit* unit);
|
void onUnitDied(const Unit* unit);
|
||||||
|
void onGameOver(bool won);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string wrapString(const string &str, int wrapCount);
|
string wrapString(const string &str, int wrapCount);
|
||||||
|
@ -170,6 +173,8 @@ private:
|
||||||
int getUnitCount(int factionIndex);
|
int getUnitCount(int factionIndex);
|
||||||
int getUnitCountOfType(int factionIndex, const string &typeName);
|
int getUnitCountOfType(int factionIndex, const string &typeName);
|
||||||
|
|
||||||
|
bool getGameWon();
|
||||||
|
|
||||||
//callbacks, commands
|
//callbacks, commands
|
||||||
static int showMessage(LuaHandle* luaHandle);
|
static int showMessage(LuaHandle* luaHandle);
|
||||||
static int setDisplayText(LuaHandle* luaHandle);
|
static int setDisplayText(LuaHandle* luaHandle);
|
||||||
|
@ -208,6 +213,8 @@ private:
|
||||||
static int getLastDeadUnitId(LuaHandle* luaHandle);
|
static int getLastDeadUnitId(LuaHandle* luaHandle);
|
||||||
static int getUnitCount(LuaHandle* luaHandle);
|
static int getUnitCount(LuaHandle* luaHandle);
|
||||||
static int getUnitCountOfType(LuaHandle* luaHandle);
|
static int getUnitCountOfType(LuaHandle* luaHandle);
|
||||||
|
|
||||||
|
static int getGameWon(LuaHandle* luaHandle);
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
Loading…
Reference in New Issue
Block a user