- added new lua function to display playername:
getPlayerName(i)
This commit is contained in:
parent
6f924b310d
commit
e351def1cb
|
@ -176,6 +176,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||||
luaScript.registerFunction(getGameWon, "gameWon");
|
luaScript.registerFunction(getGameWon, "gameWon");
|
||||||
|
|
||||||
luaScript.registerFunction(getSystemMacroValue, "getSystemMacroValue");
|
luaScript.registerFunction(getSystemMacroValue, "getSystemMacroValue");
|
||||||
|
luaScript.registerFunction(getPlayerName, "getPlayerName");
|
||||||
|
|
||||||
luaScript.registerFunction(loadScenario, "loadScenario");
|
luaScript.registerFunction(loadScenario, "loadScenario");
|
||||||
|
|
||||||
|
@ -1032,6 +1033,12 @@ const string ScriptManager::getSystemMacroValue(const string &key) {
|
||||||
return world->getSystemMacroValue(key);
|
return world->getSystemMacroValue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string ScriptManager::getPlayerName(int factionIndex) {
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
return world->getPlayerName(factionIndex);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptManager::loadScenario(const string &name, bool keepFactions) {
|
void ScriptManager::loadScenario(const string &name, bool keepFactions) {
|
||||||
//printf("[%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
//printf("[%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -1484,6 +1491,12 @@ int ScriptManager::getSystemMacroValue(LuaHandle* luaHandle) {
|
||||||
return luaArguments.getReturnCount();
|
return luaArguments.getReturnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ScriptManager::getPlayerName(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
luaArguments.returnString(thisScriptManager->getPlayerName(luaArguments.getInt(-1)));
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
|
||||||
int ScriptManager::getUnitCount(LuaHandle* luaHandle){
|
int ScriptManager::getUnitCount(LuaHandle* luaHandle){
|
||||||
LuaArguments luaArguments(luaHandle);
|
LuaArguments luaArguments(luaHandle);
|
||||||
luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1)));
|
luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1)));
|
||||||
|
|
|
@ -272,6 +272,7 @@ private:
|
||||||
bool getGameWon();
|
bool getGameWon();
|
||||||
|
|
||||||
const string getSystemMacroValue(const string &key);
|
const string getSystemMacroValue(const string &key);
|
||||||
|
const string getPlayerName(int factionIndex);
|
||||||
|
|
||||||
void loadScenario(const string &name, bool keepFactions);
|
void loadScenario(const string &name, bool keepFactions);
|
||||||
|
|
||||||
|
@ -359,6 +360,7 @@ private:
|
||||||
static int getGameWon(LuaHandle* luaHandle);
|
static int getGameWon(LuaHandle* luaHandle);
|
||||||
|
|
||||||
static int getSystemMacroValue(LuaHandle* luaHandle);
|
static int getSystemMacroValue(LuaHandle* luaHandle);
|
||||||
|
static int getPlayerName(LuaHandle* luaHandle);
|
||||||
|
|
||||||
static int loadScenario(LuaHandle* luaHandle);
|
static int loadScenario(LuaHandle* luaHandle);
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
#include "properties.h"
|
#include "properties.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
|
#include "socket.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
@ -299,6 +300,51 @@ ControlType Scenario::strToControllerType(const string &str) {
|
||||||
throw std::runtime_error(szBuf);
|
throw std::runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Scenario::controllerTypeToStr(const ControlType &ct) {
|
||||||
|
string controlString = "";
|
||||||
|
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
switch(ct) {
|
||||||
|
case ctCpuEasy:
|
||||||
|
controlString= lang.get("CpuEasy");
|
||||||
|
break;
|
||||||
|
case ctCpu:
|
||||||
|
controlString= lang.get("Cpu");
|
||||||
|
break;
|
||||||
|
case ctCpuUltra:
|
||||||
|
controlString= lang.get("CpuUltra");
|
||||||
|
break;
|
||||||
|
case ctCpuMega:
|
||||||
|
controlString= lang.get("CpuMega");
|
||||||
|
break;
|
||||||
|
case ctNetwork:
|
||||||
|
controlString= lang.get("Network");
|
||||||
|
break;
|
||||||
|
case ctHuman:
|
||||||
|
controlString= lang.get("Human");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ctNetworkCpuEasy:
|
||||||
|
controlString= lang.get("NetworkCpuEasy");
|
||||||
|
break;
|
||||||
|
case ctNetworkCpu:
|
||||||
|
controlString= lang.get("NetworkCpu");
|
||||||
|
break;
|
||||||
|
case ctNetworkCpuUltra:
|
||||||
|
controlString= lang.get("NetworkCpuUltra");
|
||||||
|
break;
|
||||||
|
case ctNetworkCpuMega:
|
||||||
|
controlString= lang.get("NetworkCpuMega");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("Error control = %d\n",ct);
|
||||||
|
//assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return controlString;
|
||||||
|
}
|
||||||
|
|
||||||
void Scenario::loadGameSettings(const vector<string> &dirList,
|
void Scenario::loadGameSettings(const vector<string> &dirList,
|
||||||
const ScenarioInfo *scenarioInfo, GameSettings *gameSettings,
|
const ScenarioInfo *scenarioInfo, GameSettings *gameSettings,
|
||||||
string scenarioDescription) {
|
string scenarioDescription) {
|
||||||
|
@ -318,6 +364,15 @@ void Scenario::loadGameSettings(const vector<string> &dirList,
|
||||||
if(ct != ctClosed) {
|
if(ct != ctClosed) {
|
||||||
if(ct == ctHuman) {
|
if(ct == ctHuman) {
|
||||||
gameSettings->setThisFactionIndex(factionCount);
|
gameSettings->setThisFactionIndex(factionCount);
|
||||||
|
|
||||||
|
if(gameSettings->getNetworkPlayerName(i) == "") {
|
||||||
|
gameSettings->setNetworkPlayerName(i,Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(gameSettings->getNetworkPlayerName(i) == "") {
|
||||||
|
gameSettings->setNetworkPlayerName(i,controllerTypeToStr(ct));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gameSettings->setFactionControl(factionCount, ct);
|
gameSettings->setFactionControl(factionCount, ct);
|
||||||
gameSettings->setResourceMultiplierIndex(factionCount, (scenarioInfo->resourceMultipliers[i]-0.5f)/0.1f);
|
gameSettings->setResourceMultiplierIndex(factionCount, (scenarioInfo->resourceMultipliers[i]-0.5f)/0.1f);
|
||||||
|
|
|
@ -108,6 +108,8 @@ public:
|
||||||
|
|
||||||
static void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo);
|
static void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo);
|
||||||
static ControlType strToControllerType(const string &str);
|
static ControlType strToControllerType(const string &str);
|
||||||
|
static string controllerTypeToStr(const ControlType &ct);
|
||||||
|
|
||||||
static void loadGameSettings(const vector<string> &dirList, const ScenarioInfo *scenarioInfo, GameSettings *gameSettings, string scenarioDescription);
|
static void loadGameSettings(const vector<string> &dirList, const ScenarioInfo *scenarioInfo, GameSettings *gameSettings, string scenarioDescription);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1100,6 +1100,10 @@ const string World::getSystemMacroValue(const string key) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string World::getPlayerName(int factionIndex) {
|
||||||
|
return game->getGameSettings()->getNetworkPlayerName(factionIndex);
|
||||||
|
}
|
||||||
|
|
||||||
void World::giveUpgradeCommand(int unitId, const string &upgradeName) {
|
void World::giveUpgradeCommand(int unitId, const string &upgradeName) {
|
||||||
Unit *unit= findUnitById(unitId);
|
Unit *unit= findUnitById(unitId);
|
||||||
if(unit != NULL) {
|
if(unit != NULL) {
|
||||||
|
|
|
@ -240,6 +240,7 @@ public:
|
||||||
int getUnitCountOfType(int factionIndex, const string &typeName);
|
int getUnitCountOfType(int factionIndex, const string &typeName);
|
||||||
|
|
||||||
const string getSystemMacroValue(const string key);
|
const string getSystemMacroValue(const string key);
|
||||||
|
const string getPlayerName(int factionIndex);
|
||||||
|
|
||||||
Game * getGame() { return game; }
|
Game * getGame() { return game; }
|
||||||
const GameSettings * getGameSettings() const;
|
const GameSettings * getGameSettings() const;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user