Commit fff624b1 authored by Stéphane Fabry's avatar Stéphane Fabry

CHG: Scenarios and AI writes theirs log into user directory.

parent ef5a26c0
......@@ -25,7 +25,7 @@ game:message("Welcome general, we are here to learn a few things togheter !\n" .
"Good luck general !")
step = 0
io.output("scenarios/log/Tutorial.log")
io.output(logPath .. "Tutorial.log")
-- Victory
function victoryCondition()
......@@ -34,7 +34,7 @@ function victoryCondition()
vehicle = human:getVehicleById(i)
if (vehicle.pos.x > 26 and vehicle.pos.y < 40) then
step = 1
io.write("step 1 completed")
io.write("step 1 completed\n")
game:message("Caution general, an ennemi tank has been detected !\n" ..
"You should prepare to defend your base, build a defense turret between your base and the ennemi.\n")
end
......@@ -43,7 +43,7 @@ function victoryCondition()
if step == 1 then
for i, v in pairs(human:getBuildingIdList()) do
if (v == "gun_turret" or v == "gun_ari" or v == "gun_missel") then
io.write("step 2 completed")
io.write("step 2 completed\n")
step = 2
game:message("Great general, prepare to defend and kill that tank !.\n")
end
......
......@@ -32,7 +32,7 @@ billy:addBuilding("gun_aa", 53, 42)
game:start()
-- Lua log file
io.output("Scenario.log")
io.output(logPath .. "Planes.log")
io.write("Starting scenario : ", scenarioName, "\n")
-- Victory
......
......@@ -2,7 +2,7 @@ local P = require("position")
local M = require("move")
-- IA file : this file will run in the context of the AI player, will have access to data limited to the data the the user can see.
io.output("scenarios/log/1_Scout_intel.log")
io.output(logPath .. "1_Scout_intel.log")
io.write("Loading AI for scout scenario.\n")
io.flush()
......
......@@ -130,6 +130,10 @@ void cLocalScenarioGame::loadLuaScript(std::string luaFilename)
Lunar<cLuaGame>::push(L, luaGame.get()); // luaGame has to be deleted from C++
lua_setglobal(L, "game");
// Add path for scenario logs as a global variable
lua_pushstring(L, getScenarioLogDir().c_str());
lua_setglobal(L, "logPath");
// Load the Lua script
int error = luaL_loadbuffer(L, luaData, (size_t)fileSize, "luaScenario") || lua_pcall(L, 0, 0, 0);
if (error) {
......
......@@ -78,6 +78,10 @@ std::string cLuaIntelligence::openLuaFile(std::string luaFilename)
Lunar<cLuaIntelligence>::push(L, this);
lua_setglobal(L, "game");
// Add path for scenario logs as a global variable
lua_pushstring(L, getScenarioLogDir().c_str());
lua_setglobal(L, "logPath");
// Set the path to the AI modules
lua_getglobal( L, "package" );
lua_getfield( L, -1, "path" );
......
......@@ -201,6 +201,35 @@ std::string getUserLogDir()
#endif
}
//--------------------------------------------------------------
std::string getScenarioLogDir()
{
#ifdef __amigaos4__
return "";
#elif defined(MAC)
char* cHome = getenv ("HOME"); //get $HOME on mac
if (cHome == NULL)
return "";
std::string homeFolder = cHome;
if (homeFolder.empty())
return "";
// store Log directly on the desktop of the user
return homeFolder + PATH_DELIMITER "Desktop" PATH_DELIMITER;
#else
if (cSettings::getInstance().getHomeDir().empty())
return "";
std::string LogDir = cSettings::getInstance().getHomeDir() + "scenario_log";
if (!DirExists (LogDir))
{
if (makeDir (LogDir.c_str()))
return LogDir + PATH_DELIMITER;
return "";
}
return LogDir + PATH_DELIMITER;
#endif
}
//--------------------------------------------------------------
uint32_t calcCheckSum (uint32_t data, uint32_t checksum)
{
......
......@@ -72,6 +72,7 @@ std::string getUserMapsDir();
std::string getUserScreenshotsDir();
std::string getUserLogDir();
std::string getScenarioLogDir();
void copyFile (const std::string& source, const std::string& dest);
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment