Added setPlayerType function

This commit is contained in:
mathusummut
2019-03-12 22:49:29 +01:00
parent 9476e6b11f
commit dba4af26c8
3 changed files with 39 additions and 1 deletions

View File

@@ -7705,7 +7705,14 @@ namespace Game {
case ctCpuGlest:
factionInfo += " CPU Glest" + multiplier;
break;
case ctNetwork:
factionInfo += " (Network)";
break;
case ctHuman:
factionInfo += " (Human)";
break;
default:
factionInfo += " (Closed)";
break;
}

View File

@@ -556,6 +556,7 @@ namespace Game {
luaScript.registerFunction(loadSaveGameData, "loadSaveGameData");
luaScript.registerFunction(getPlayerType, "getPlayerType");
luaScript.registerFunction(setPlayerType, "setPlayerType");
map<string, pair<Script, vector<string>>> scripts;
map<string, pair<Script, vector<string>>>::iterator iter;
@@ -3406,6 +3407,23 @@ namespace Game {
}
return ctClosed;
}
void
ScriptManager::setPlayerType(int factionIndex, ControlType playerType) {
if (factionIndex < 0 || factionIndex >= world->getFactionCount() || playerType < ctClosed || playerType > ctHuman)
return;
Faction *
faction = world->getFaction(factionIndex);
if (faction != NULL) {
faction->setControlType(playerType);
GameSettings* settings = world->getGameSettingsPtr();
if (settings != NULL)
settings->setFactionControl(factionIndex, playerType);
Stats* stats = world->getStats();
if (stats != NULL)
stats->setControl(factionIndex, playerType);
}
}
// ========================== lua callbacks ===============================================
int
@@ -6115,9 +6133,19 @@ namespace Game {
} catch (const game_runtime_error & ex) {
error(luaHandle, &ex, __FILE__, __FUNCTION__, __LINE__);
}
return luaArguments.getReturnCount();
}
int
ScriptManager::setPlayerType(LuaHandle * luaHandle) {
LuaArguments
luaArguments(luaHandle);
try {
thisScriptManager->setPlayerType(luaArguments.getInt(-2), static_cast<ControlType>(luaArguments.getInt(-1)));
} catch (const game_runtime_error & ex) {
error(luaHandle, &ex, __FILE__, __FUNCTION__, __LINE__);
}
return luaArguments.getReturnCount();
}
void

View File

@@ -769,6 +769,8 @@ namespace Game {
loadSaveGameData(string name);
ControlType getPlayerType(int factionIndex);
void setPlayerType(int factionIndex, ControlType playerType);
// -----------------------------------------------------------------------
static void
@@ -1091,6 +1093,7 @@ namespace Game {
loadSaveGameData(LuaHandle * luaHandle);
static int getPlayerType(LuaHandle * luaHandle);
static int setPlayerType(LuaHandle * luaHandle);
};
} //end namespace