Skip to content

Commit

Permalink
qtscript: Add functions missionTime() and extraPowerTime(time[, playe…
Browse files Browse the repository at this point in the history
…r]). Change time precision for setMissionTime().

campaign: Give bonus power if finishing cam1a before time runs out. Swap engineering and flamer research artifacts.
  • Loading branch information
perim committed Dec 15, 2012
1 parent 3740eca commit 9b38f61
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
14 changes: 11 additions & 3 deletions data/base/script/campaign/cam1a.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ function eventCheatMode(entered)
// proceed to next level
function gameWon()
{
enableResearch("R-Wpn-MG1Mk1"); // bonus research topic on level end
var bonusTime = missionTime();
if (bonusTime > 0)
{
setPowerModifier(125); // 25% bonus to completing fast
extraPowerTime(bonusTime);
setPowerModifier(100);
}
loadLevel("CAM_1B");
}

Expand Down Expand Up @@ -278,7 +286,7 @@ function eventStructureBuilt(structure, droid)
}
if (timercoming == 2)
{
setMissionTime(36000);
setMissionTime(3600);
}
}

Expand All @@ -300,7 +308,7 @@ function eventPickup(feature, droid)
}
else if (lab == "artifact2") // second artifact
{
enableResearch("R-Wpn-Flamer01Mk1");
enableResearch("R-Sys-Engineering01");
numArtifact++;
}
else if (lab == "artifact3") // third artifact
Expand All @@ -310,7 +318,7 @@ function eventPickup(feature, droid)
}
else if (lab == "artifact4") // final artifact
{
enableResearch("R-Sys-Engineering01");
enableResearch("R-Wpn-Flamer01Mk1");
numArtifact++;
}
else
Expand Down
12 changes: 6 additions & 6 deletions src/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
bool powerCalculated;

/* Updates the current power based on the extracted power and a Power Generator*/
static void updateCurrentPower(POWER_GEN *psPowerGen, UDWORD player);
static void updateCurrentPower(POWER_GEN *psPowerGen, UDWORD player, int ticks);
static int64_t updateExtractedPower(STRUCTURE *psBuilding);

//returns the relevant list based on OffWorld or OnWorld
Expand Down Expand Up @@ -249,20 +249,20 @@ STRUCTURE* powerStructList(int player)
}

/* Update current power based on what Power Generators exist */
void updatePlayerPower(UDWORD player)
void updatePlayerPower(int player, int ticks)
{
STRUCTURE *psStruct;//, *psList;
int64_t powerBefore = asPower[player].currentPower;

ASSERT(player < MAX_PLAYERS, "updatePlayerPower: Bad player");
ASSERT(player < MAX_PLAYERS, "Bad player %d", player);

syncDebugEconomy(player, '<');

for (psStruct = powerStructList(player); psStruct != NULL; psStruct = psStruct->psNext)
{
if (psStruct->pStructureType->type == REF_POWER_GEN && psStruct->status == SS_BUILT)
{
updateCurrentPower((POWER_GEN *)psStruct->pFunctionality, player);
updateCurrentPower((POWER_GEN *)psStruct->pFunctionality, player, ticks);
}
}
syncDebug("updatePlayerPower%u %"PRId64"->%"PRId64"", player, powerBefore, asPower[player].currentPower);
Expand All @@ -271,7 +271,7 @@ void updatePlayerPower(UDWORD player)
}

/* Updates the current power based on the extracted power and a Power Generator*/
static void updateCurrentPower(POWER_GEN *psPowerGen, UDWORD player)
static void updateCurrentPower(POWER_GEN *psPowerGen, UDWORD player, int ticks)
{
int i;
int64_t extractedPower;
Expand All @@ -298,7 +298,7 @@ static void updateCurrentPower(POWER_GEN *psPowerGen, UDWORD player)

syncDebug("updateCurrentPower%d = %"PRId64",%u", player, extractedPower, psPowerGen->multiplier);

asPower[player].currentPower += (extractedPower * psPowerGen->multiplier) / 100;
asPower[player].currentPower += (extractedPower * psPowerGen->multiplier) / 100 * ticks;
ASSERT(asPower[player].currentPower >= 0, "negative power");
if (asPower[player].currentPower > MAX_POWER*FP_ONE)
{
Expand Down
5 changes: 3 additions & 2 deletions src/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ extern void addPower(int player, int32_t quantity);

void usePower(int player, uint32_t quantity);

/** Update current power based on what was extracted during the last cycle and what Power Generators exist. */
extern void updatePlayerPower(UDWORD player);
/** Update current power based on what was extracted during the last cycle and what Power Generators exist.
* If ticks is set, this is the number of game ticks to process for at once. */
extern void updatePlayerPower(int player, int ticks = 1);

/** Used in multiplayer to force power levels. */
void setPower(unsigned player, int32_t power);
Expand Down
33 changes: 31 additions & 2 deletions src/qtscriptfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,10 +2055,11 @@ static QScriptValue js_orderDroidLoc(QScriptContext *context, QScriptEngine *)
return QScriptValue();
}

//-- \subsection{setMissionTime(time)} Set mission countdown.
//-- \subsection{setMissionTime(time)} Set mission countdown in seconds.
static QScriptValue js_setMissionTime(QScriptContext *context, QScriptEngine *)
{
int value = context->argument(0).toInt32() * 100;
int value = context->argument(0).toInt32() * 1000;
mission.startTime = gameTime;
mission.time = value;
setMissionCountDown();
if (mission.time >= 0)
Expand All @@ -2074,6 +2075,12 @@ static QScriptValue js_setMissionTime(QScriptContext *context, QScriptEngine *)
return QScriptValue();
}

//-- \subsection{missionTime()} Get time remaining on mission countdown in seconds.
static QScriptValue js_missionTime(QScriptContext *, QScriptEngine *)
{
return QScriptValue((mission.time - (gameTime - mission.startTime)) / 1000);
}

//-- \subsection{setReinforcementTime(time)} Set time for reinforcements to arrive. If time is
//-- negative, the reinforcement GUI is removed and the timer stopped.
static QScriptValue js_setReinforcementTime(QScriptContext *context, QScriptEngine *)
Expand Down Expand Up @@ -2270,6 +2277,26 @@ static QScriptValue js_enableResearch(QScriptContext *context, QScriptEngine *en
return QScriptValue();
}

//-- \subsection{extraPowerTime(time, player)}
//-- Increase a player's power as if that player had power income equal to current income
//-- over the given amount of extra time.
static QScriptValue js_extraPowerTime(QScriptContext *context, QScriptEngine *engine)
{
int ticks = context->argument(0).toInt32() * GAME_UPDATES_PER_SEC;
int player;
if (context->argumentCount() > 1)
{
player = context->argument(1).toInt32();
SCRIPT_ASSERT_PLAYER(context, player);
}
else
{
player = engine->globalObject().property("me").toInt32();
}
updatePlayerPower(player, ticks);
return QScriptValue();
}

//-- \subsection{setPower(power[, player])}
//-- Set a player's power directly. (Do not use this in an AI script.)
static QScriptValue js_setPower(QScriptContext *context, QScriptEngine *engine)
Expand Down Expand Up @@ -3524,11 +3551,13 @@ bool registerFunctions(QScriptEngine *engine, QString scriptName)
engine->globalObject().setProperty("setStructureLimits", engine->newFunction(js_setStructureLimits));
engine->globalObject().setProperty("applyLimitSet", engine->newFunction(js_applyLimitSet));
engine->globalObject().setProperty("setMissionTime", engine->newFunction(js_setMissionTime));
engine->globalObject().setProperty("missionTime", engine->newFunction(js_missionTime));
engine->globalObject().setProperty("setReinforcementTime", engine->newFunction(js_setReinforcementTime));
engine->globalObject().setProperty("completeResearch", engine->newFunction(js_completeResearch));
engine->globalObject().setProperty("enableResearch", engine->newFunction(js_enableResearch));
engine->globalObject().setProperty("setPower", engine->newFunction(js_setPower));
engine->globalObject().setProperty("setPowerModifier", engine->newFunction(js_setPowerModifier));
engine->globalObject().setProperty("extraPowerTime", engine->newFunction(js_extraPowerTime));
engine->globalObject().setProperty("setTutorialMode", engine->newFunction(js_setTutorialMode));
engine->globalObject().setProperty("setDesign", engine->newFunction(js_setDesign));
engine->globalObject().setProperty("enableTemplate", engine->newFunction(js_enableTemplate));
Expand Down

0 comments on commit 9b38f61

Please sign in to comment.