- added new lua function to display playername:

getPlayerName(i)
This commit is contained in:
Mark Vejvoda 2012-01-05 00:45:17 +00:00
parent 6f924b310d
commit e351def1cb
6 changed files with 77 additions and 0 deletions

View File

@ -176,6 +176,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
luaScript.registerFunction(getGameWon, "gameWon");
luaScript.registerFunction(getSystemMacroValue, "getSystemMacroValue");
luaScript.registerFunction(getPlayerName, "getPlayerName");
luaScript.registerFunction(loadScenario, "loadScenario");
@ -1032,6 +1033,12 @@ const string ScriptManager::getSystemMacroValue(const string &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) {
//printf("[%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
@ -1484,6 +1491,12 @@ int ScriptManager::getSystemMacroValue(LuaHandle* luaHandle) {
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){
LuaArguments luaArguments(luaHandle);
luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1)));

View File

@ -272,6 +272,7 @@ private:
bool getGameWon();
const string getSystemMacroValue(const string &key);
const string getPlayerName(int factionIndex);
void loadScenario(const string &name, bool keepFactions);
@ -359,6 +360,7 @@ private:
static int getGameWon(LuaHandle* luaHandle);
static int getSystemMacroValue(LuaHandle* luaHandle);
static int getPlayerName(LuaHandle* luaHandle);
static int loadScenario(LuaHandle* luaHandle);
};

View File

@ -21,6 +21,7 @@
#include "platform_common.h"
#include "properties.h"
#include "lang.h"
#include "socket.h"
#include "config.h"
#include "leak_dumper.h"
@ -299,6 +300,51 @@ ControlType Scenario::strToControllerType(const string &str) {
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,
const ScenarioInfo *scenarioInfo, GameSettings *gameSettings,
string scenarioDescription) {
@ -318,6 +364,15 @@ void Scenario::loadGameSettings(const vector<string> &dirList,
if(ct != ctClosed) {
if(ct == ctHuman) {
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->setResourceMultiplierIndex(factionCount, (scenarioInfo->resourceMultipliers[i]-0.5f)/0.1f);

View File

@ -108,6 +108,8 @@ public:
static void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo);
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);
private:

View File

@ -1100,6 +1100,10 @@ const string World::getSystemMacroValue(const string key) {
return result;
}
const string World::getPlayerName(int factionIndex) {
return game->getGameSettings()->getNetworkPlayerName(factionIndex);
}
void World::giveUpgradeCommand(int unitId, const string &upgradeName) {
Unit *unit= findUnitById(unitId);
if(unit != NULL) {

View File

@ -240,6 +240,7 @@ public:
int getUnitCountOfType(int factionIndex, const string &typeName);
const string getSystemMacroValue(const string key);
const string getPlayerName(int factionIndex);
Game * getGame() { return game; }
const GameSettings * getGameSettings() const;