Fix more bugs in research qtscript code. Add support for random research topics in semperfi js.

master
Per Inge Mathisen 2011-12-26 23:39:57 +01:00
parent 6045537360
commit a4e616151f
4 changed files with 31 additions and 13 deletions

View File

@ -115,8 +115,9 @@ function conDroids()
function eventResearched(labparam)
{
var anyfound = true; // assume success
var lablist;
if (labparam)
if (labparam) // check if called with parameter or not
{
lablist = [];
lablist[0] = labparam;
@ -133,12 +134,20 @@ function eventResearched(labparam)
var found = pursueResearch(lab, "R-Struc-Research-Upgrade06");
if (!found)
{
// TBD - find random research
return;
// Find a random research item
var reslist = enumResearch();
if (reslist.length == 0)
{
// No research left, salvage res lab
debug("TBD - salvage research lab");
}
else
{
pursueResearch(lab, reslist[0].name); // doing first for now, TODO use random
}
}
}
}
// TBD - no research left, salvage res labs
}
function buildFundamentals()

View File

@ -299,7 +299,8 @@ void loadMultiScripts()
resLoadFile("SCRIPT", aidata[NetPlay.players[i].ai].slo);
resLoadFile("SCRIPTVAL", aidata[NetPlay.players[i].ai].vlo);
}
if (aidata[NetPlay.players[i].ai].js[0] != '\0')
// autogames are to be implemented differently for qtscript, do not start for human players yet
if (!NetPlay.players[i].allocated && aidata[NetPlay.players[i].ai].js[0] != '\0')
{
loadPlayerScript(QString("multiplay/skirmish/") + aidata[NetPlay.players[i].ai].js, i, NetPlay.players[i].difficulty);
}

View File

@ -542,9 +542,17 @@ bool triggerStructureAttacked(STRUCTURE *psVictim, BASE_OBJECT *psAttacker)
bool triggerResearched(STRUCTURE *psStruct)
{
QScriptEngine *engine = scripts.at(psStruct->player);
QScriptValueList args;
args += convStructure(psStruct, engine);
callFunction(engine, "eventResearched", args);
for (int i = 0; i < scripts.size(); ++i)
{
QScriptEngine *engine = scripts.at(i);
int player = engine->globalObject().property("me").toInt32();
if (player == psStruct->player)
{
QScriptEngine *engine = scripts.at(i);
QScriptValueList args;
args += convStructure(psStruct, engine);
callFunction(engine, "eventResearched", args);
}
}
return true;
}

View File

@ -73,7 +73,6 @@ QScriptValue convResearch(RESEARCH *psResearch, QScriptEngine *engine, int playe
}
}
value.setProperty("started", started); // including whether an ally has started it
value.setProperty("available", researchAvailable(psResearch->index, player));
value.setProperty("name", psResearch->pName);
return value;
}
@ -334,9 +333,9 @@ static QScriptValue js_pursueResearch(QScriptContext *context, QScriptEngine *en
SCRIPT_ASSERT(context, psStruct->pStructureType->type == REF_RESEARCH, "Not a research lab: %s", objInfo(psStruct));
RESEARCH_FACILITY *psResLab = (RESEARCH_FACILITY *)psStruct->pFunctionality;
SCRIPT_ASSERT(context, psResLab->psSubject == NULL, "Research lab not ready");
SCRIPT_ASSERT(context, !(plrRes->ResearchStatus & RESEARCHED), "Research item already completed: %s", psResearch->pName);
if (IsResearchStartedPending(plrRes) || IsResearchCompleted(plrRes))
{
debug(LOG_SCRIPT, "Research already started or completed for player %d: %s", player, psResearch->pName);
return QScriptValue(false);
}
// Go down the requirements list for the desired tech
@ -401,9 +400,10 @@ static QScriptValue js_enumResearch(QScriptContext *context, QScriptEngine *engi
int player = engine->globalObject().property("me").toInt32();
for (int i = 0; i < asResearch.size(); i++)
{
if (!IsResearchCompleted(&asPlayerResList[player][i]))
RESEARCH *psResearch = &asResearch[i];
if (!IsResearchCompleted(&asPlayerResList[player][i]) && researchAvailable(i, player))
{
reslist += &asResearch[i];
reslist += psResearch;
}
}
QScriptValue result = engine->newArray(reslist.size());