Fixed LUA bugs

This commit is contained in:
mathusummut
2019-03-08 22:46:54 +01:00
parent 541b61ef47
commit 2f857ccdc5
8 changed files with 82 additions and 77 deletions

View File

@@ -4435,6 +4435,8 @@ namespace Game {
if (faction->getFactionDisconnectHandled() == false &&
(faction->getControlType() == ctNetwork)) {
if (aiInterfaces.size() <= i)
aiInterfaces.push_back(NULL);
if (aiInterfaces[i] == NULL && (server == NULL ||
server->isClientConnected(faction->getStartLocationIndex()) == false)) {

View File

@@ -555,8 +555,7 @@ namespace Game {
luaScript.registerFunction(storeSaveGameData, "storeSaveGameData");
luaScript.registerFunction(loadSaveGameData, "loadSaveGameData");
luaScript.registerFunction(getFactionPlayerType,
"getFactionPlayerType");
luaScript.registerFunction(getPlayerType, "getPlayerType");
map<string, pair<Script, vector<string>>> scripts;
map<string, pair<Script, vector<string>>>::iterator iter;
@@ -3397,7 +3396,9 @@ namespace Game {
}
ControlType
ScriptManager::getFactionPlayerType(int factionIndex) {
ScriptManager::getPlayerType(int factionIndex) {
if (factionIndex < 0 || factionIndex >= world->getFactionCount())
return ctClosed;
Faction *
faction = world->getFaction(factionIndex);
if (faction != NULL) {
@@ -6104,12 +6105,12 @@ namespace Game {
}
int
ScriptManager::getFactionPlayerType(LuaHandle * luaHandle) {
ScriptManager::getPlayerType(LuaHandle * luaHandle) {
LuaArguments
luaArguments(luaHandle);
try {
luaArguments.returnInt(thisScriptManager->
getFactionPlayerType(luaArguments.
getPlayerType(luaArguments.
getInt(-1)));
} catch (const game_runtime_error & ex) {
error(luaHandle, &ex, __FILE__, __FUNCTION__, __LINE__);

View File

@@ -768,8 +768,7 @@ namespace Game {
string
loadSaveGameData(string name);
ControlType
getFactionPlayerType(int factionIndex);
ControlType getPlayerType(int factionIndex);
// -----------------------------------------------------------------------
static void
@@ -1091,8 +1090,7 @@ namespace Game {
static int
loadSaveGameData(LuaHandle * luaHandle);
static int
getFactionPlayerType(LuaHandle * luaHandle);
static int getPlayerType(LuaHandle * luaHandle);
};
} //end namespace

View File

@@ -53,15 +53,20 @@ namespace Game {
case ctCpuEasy:
controlString = lang.getString("CpuEasy");
break;
case ctCpu:controlString = lang.getString("Cpu");
case ctCpu:
controlString = lang.getString("Cpu");
break;
case ctCpuUltra:controlString = lang.getString("CpuUltra");
case ctCpuUltra:
controlString = lang.getString("CpuUltra");
break;
case ctCpuGlest:controlString = lang.getString("CpuGlest");
case ctCpuGlest:
controlString = lang.getString("CpuGlest");
break;
case ctNetwork:controlString = lang.getString("Network");
case ctNetwork:
controlString = lang.getString("Network");
break;
case ctHuman:controlString = lang.getString("Human");
case ctHuman:
controlString = lang.getString("Human");
break;
default:
controlString = lang.getString("Closed");

View File

@@ -275,66 +275,69 @@ namespace Game {
GameConstants::OBSERVER_SLOTNAME
&& fileExists(factionDefinitionXML) == true) {
if (SystemFlags::VERBOSE_MODE_ENABLED)
printf("#2 tech [%s] faction [%s]\n",
currentTechName_factionPreview.c_str(),
currentFactionName_factionPreview.c_str());
try {
if (SystemFlags::VERBOSE_MODE_ENABLED)
printf("#2 tech [%s] faction [%s]\n",
currentTechName_factionPreview.c_str(),
currentFactionName_factionPreview.c_str());
XmlTree xmlTree;
std::map < string, string > mapExtraTagReplacementValues;
xmlTree.load(factionDefinitionXML,
Properties::getTagReplacementValues
(&mapExtraTagReplacementValues));
const XmlNode *
factionNode = xmlTree.getRootNode();
if (won == true) {
if (factionNode->hasAttribute("battle-end-win-music") == true) {
result =
factionNode->
getAttribute("battle-end-win-music")->getValue();
XmlTree xmlTree;
std::map < string, string > mapExtraTagReplacementValues;
xmlTree.load(factionDefinitionXML,
Properties::getTagReplacementValues
(&mapExtraTagReplacementValues));
const XmlNode *
factionNode = xmlTree.getRootNode();
if (won == true) {
if (factionNode->hasAttribute("battle-end-win-music") == true) {
result =
factionNode->
getAttribute("battle-end-win-music")->getValue();
}
} else {
if (factionNode->hasAttribute("battle-end-lose-music") == true) {
result =
factionNode->
getAttribute("battle-end-lose-music")->getValue();
}
}
} else {
if (factionNode->hasAttribute("battle-end-lose-music") == true) {
result =
factionNode->
getAttribute("battle-end-lose-music")->getValue();
if (result != "" && fileExists(result) == false) {
string techTreePath = "";
string factionPath = "";
std::vector < std::string > factionPartsList;
Tokenize(factionDefinitionXML, factionPartsList, "factions/");
if (factionPartsList.size() > 1) {
techTreePath = factionPartsList[0];
string
factionPath =
techTreePath + "factions/" +
currentFactionName_factionPreview;
endPathWithSlash(factionPath);
result = factionPath + result;
}
}
}
if (result != "" && fileExists(result) == false) {
string techTreePath = "";
string factionPath = "";
std::vector < std::string > factionPartsList;
Tokenize(factionDefinitionXML, factionPartsList, "factions/");
if (factionPartsList.size() > 1) {
techTreePath = factionPartsList[0];
string
factionPath =
techTreePath + "factions/" +
currentFactionName_factionPreview;
endPathWithSlash(factionPath);
result = factionPath + result;
if (won == true) {
resultFallback =
Game::findFactionLogoFile(gameSettings, NULL,
"battle_end_win_music.*");
} else {
resultFallback =
Game::findFactionLogoFile(gameSettings, NULL,
"battle_end_lose_music.*");
}
}
if (won == true) {
resultFallback =
Game::findFactionLogoFile(gameSettings, NULL,
"battle_end_win_music.*");
} else {
resultFallback =
Game::findFactionLogoFile(gameSettings, NULL,
"battle_end_lose_music.*");
}
if (SystemFlags::VERBOSE_MODE_ENABLED)
printf("#3 result [%s] resultFallback [%s]\n", result.c_str(),
resultFallback.c_str());
//printf("#3 result [%s] resultFallback [%s]\n",result.c_str(),resultFallback.c_str());
if (SystemFlags::VERBOSE_MODE_ENABLED)
printf("#3 result [%s] resultFallback [%s]\n", result.c_str(),
resultFallback.c_str());
//printf("#3 result [%s] resultFallback [%s]\n",result.c_str(),resultFallback.c_str());
if (result == "") {
result = resultFallback;
if (result == "") {
result = resultFallback;
}
} catch (...) {
}
}
//printf("currentFactionName_factionPreview [%s] random [%s] observer [%s] factionVideoUrl [%s]\n",currentFactionName_factionPreview.c_str(),GameConstants::RANDOMFACTION_SLOTNAME,GameConstants::OBSERVER_SLOTNAME,factionVideoUrl.c_str());

View File

@@ -5873,7 +5873,7 @@ namespace Game {
lastSelectedTeamIndex[i] =
listBoxTeams[i].getSelectedItemIndex();
}
// Alow Neutral cpu players
// Allow Neutral cpu players
else if (listBoxControls[i].getSelectedItemIndex() ==
ctCpuEasy
|| listBoxControls[i].getSelectedItemIndex() ==

View File

@@ -1900,18 +1900,14 @@ namespace Game {
void World::highlightUnit(int unitId, float radius, float thickness, Vec4f color) {
Unit* unit = findUnitById(unitId);
if (unit == NULL) {
throw game_runtime_error("Can not find unit to set highlight unitId = " + intToStr(unitId), true);
}
game->highlightUnit(unitId, radius, thickness, color);
if (unit != NULL)
game->highlightUnit(unitId, radius, thickness, color);
}
void World::unhighlightUnit(int unitId) {
Unit* unit = findUnitById(unitId);
if (unit == NULL) {
throw game_runtime_error("Can not find unit to set highlight unitId = " + intToStr(unitId), true);
}
game->unhighlightUnit(unitId);
if (unit != NULL)
game->unhighlightUnit(unitId);
}

View File

@@ -2,4 +2,4 @@
#define G3D_VIEWER_VERSION "1.0"
#define MAP_EDITOR_VERSION "1.0"
//Month then Day
#define GAME_BUILD_DATE "0306"
#define GAME_BUILD_DATE "0308"