Skip to content

Commit

Permalink
jscam: Convert cam1-2s.{vlo,slo} into cam1-2s.js.
Browse files Browse the repository at this point in the history
In the process:
- add a new sort of victory conditions for the pre-away mission.
- fix defeat on mission timeout (aint automatic).
- start fixing loading rules.js for the converted levels.
- fix the POTFILES.in file, adding campaign scripts here.
- add a new function: camSetupTransporter.
- fix crash when "let me win" is called and some
  in-object artifacts were already picked up

refs ticket:4234
  • Loading branch information
haoNoQ committed Nov 1, 2014
1 parent cf6a369 commit efc04bd
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 161 deletions.
12 changes: 12 additions & 0 deletions data/base/script/campaign/cam1-2s.js
@@ -0,0 +1,12 @@

include("script/campaign/libcampaign.js");

function eventStartLevel()
{
camSetupTransporter(11, 52, 39, 1);
centreView(13, 52);
setNoGoArea(10, 51, 12, 53, 0);
setMissionTime(1800);
hackAddMessage("SB1_2_MSG", MISS_MSG, 0, true);
camSetStandardWinLossConditions(CAM_VICTORY_PRE_OFFWORLD, "SUB_1_2");
}
101 changes: 82 additions & 19 deletions data/base/script/campaign/libcampaign.js
Expand Up @@ -524,7 +524,7 @@ function __camLetMeWinArtifacts()
{
var label = __camGetArtifactLabel(alabel);
var artifact = getObject(label);
if (!camDef(artifact))
if (!camDef(artifact) || !artifact)
continue;
__camPickupArtifact(artifact);
}
Expand Down Expand Up @@ -627,7 +627,7 @@ function camSetEnemyBases(bases)
var s = structs[i];
if (s.type !== STRUCTURE || __camIsValidLeftover(s))
continue;
camTrace("Auto-adding" + s.id + "to base" + blabel);
camTrace("Auto-adding", s.id, "to base", blabel);
groupAdd(bi.group, s);
}
}
Expand Down Expand Up @@ -1233,34 +1233,48 @@ function __camContinueProduction(structure)
//;; received by milking this time limit down.
function camNextLevel(nextLevel)
{
var bonusTime = getMissionTime();
if (bonusTime > 0)
if (__camNeedBonusTime)
{
camTrace("Bonus time", bonusTime);
setPowerModifier(125); // 25% bonus to completing fast
extraPowerTime(bonusTime);
setPowerModifier(100);
var bonusTime = getMissionTime();
if (bonusTime > 0)
{
camTrace("Bonus time", bonusTime);
setPowerModifier(125); // 25% bonus to completing fast
extraPowerTime(bonusTime);
setPowerModifier(100);
}
}
loadLevel(nextLevel);
}

const CAM_VICTORY_STANDARD = 0;
const CAM_VICTORY_PRE_OFFWORLD = 1;

//;; \subsection{camSetStandardWinLossConditions(kind, nextLevel)}
//;; Set victory and defeat conditions to one of the common
//;; options. On victory, load nextLevel. The following
//;; options are available:
//;; \begin{description}
//;; \item[CAM_VICTORY_STANDARD] Defeat if all ground factories
//;; and construction droids are lost. Victory when all enemy bases
//;; are destroyed and all artifacts are recovered.
//;; and construction droids are lost, or on mission timeout.
//;; Victory when all enemy bases are destroyed and all artifacts
//;; are recovered.
//;; \item[CAM_VICTORY_PRE_OFFWORLD] Defeat on timeout. Victory on
//;; transporter launch, then load the sub-level.
//;; \end{description}
function camSetStandardWinLossConditions(kind, nextLevel)
{
switch(kind)
{
case CAM_VICTORY_STANDARD:
__camWinLossCallback = "__camVictoryStandard";
__camNeedBonusTime = true;
__camDefeatOnTimeout = true;
break;
case CAM_VICTORY_PRE_OFFWORLD:
__camWinLossCallback = "__camVictoryPreOffworld";
__camNeedBonusTime = false;
__camDefeatOnTimeout = true;
break;
default:
camDebug("Unknown standard victory condition", kind);
Expand All @@ -1274,6 +1288,8 @@ function camSetStandardWinLossConditions(kind, nextLevel)
var __camWinLossCallback;
var __camNextLevel;
var __camWinLossAlreadyFired;
var __camNeedBonusTime;
var __camDefeatOnTimeout;

function __camGameLost()
{
Expand All @@ -1288,25 +1304,52 @@ function __camGameWon()
camNextLevel(__camNextLevel);
}

function __camPlayerDead()
{
if (countStruct("A0LightFactory") + countStruct("A0CyborgFactory") > 0)
return false;
return (countDroid(DROID_CONSTRUCT) === 0);
}

function __camVictoryPreOffworld()
{
if (__camPlayerDead())
{
queue("__camGameLost", 4000); // wait 4 secs before throwing the game
__camWinLossAlreadyFired = true;
}
}

function __camVictoryStandard()
{
if (__camWinLossAlreadyFired)
return;
// check if game is lost
var factories = countStruct("A0LightFactory")
+ countStruct("A0CyborgFactory");
var droids = countDroid(DROID_CONSTRUCT);
if (droids === 0 && factories === 0) {
if (__camPlayerDead())
{
queue("__camGameLost", 4000); // wait 4 secs before throwing the game
__camWinLossAlreadyFired = true;
}
// check if game is won
if (camAllArtifactsPickedUp() && camAllEnemyBasesEliminated()) {
if (camAllArtifactsPickedUp() && camAllEnemyBasesEliminated())
{
queue("__camGameWon", 6000); // wait 6 secs before giving it
__camWinLossAlreadyFired = true;
}
}

////////////////////////////////////////////////////////////////////////////////
// Transporter management.
////////////////////////////////////////////////////////////////////////////////

//;; \subsection{camSetupTransport(place x, place y, exit x, exit y)}
//;; A convenient function for placing the standard campaign transport
//;; for loading in pre-away missions. The exit point for the transport
//;; is set up as well.
function camSetupTransporter(x, y, x1, y1)
{
addDroid(CAM_HUMAN_PLAYER, x, y, "Transport",
"TransporterBody", "V-Tol", 0, 0, "MG3-VTOL");
setTransporterExit(x1, y1, CAM_HUMAN_PLAYER);
}

////////////////////////////////////////////////////////////////////////////////
// Event hooks magic. This makes all the library catch all the necessary events
Expand Down Expand Up @@ -1359,12 +1402,12 @@ function __camPreHookEvent(eventname, hookcode)
}


/* Called every second after eventStartLevel(). */
/* Called every 5 seconds after eventStartLevel(). */
function __camTick()
{
__camTacticsTick();
__camBasesTick();
if (camDef(__camWinLossCallback))
if (camDef(__camWinLossCallback) && !__camWinLossAlreadyFired)
__camGlobalContext[__camWinLossCallback]();
}

Expand Down Expand Up @@ -1435,6 +1478,8 @@ __camPreHookEvent("eventStartLevel", function()
__camFactoryInfo = {};
isReceivingAllEvents = true;
__camWinLossAlreadyFired = false;
__camNeedBonusTime = false;
__camDefeatOnTimeout = false;
setTimer("__camTick", 5000);
});

Expand All @@ -1457,3 +1502,21 @@ __camPreHookEvent("eventObjectSeen", function(viewer, seen)
{
__camCheckBaseSeen(seen);
});

__camPreHookEvent("eventTransporterExit", function(transport)
{
if (__camWinLossCallback === "__camVictoryPreOffworld")
{
camTrace("Transporter is away.");
camNextLevel(__camNextLevel);
}
});

__camPreHookEvent("eventMissionTimeout", function()
{
if (__camDefeatOnTimeout)
{
camTrace("0 minutes remaining.");
__camGameLost();
}
});
42 changes: 0 additions & 42 deletions data/base/script/data/cam1-2s.vlo

This file was deleted.

88 changes: 0 additions & 88 deletions data/base/script/text/cam1-2s.slo

This file was deleted.

3 changes: 0 additions & 3 deletions data/base/wrf/basic.wrf
Expand Up @@ -187,6 +187,3 @@ file ANI "cybdpjmp.ani"
file ANI "cybdplnd.ani"
file ANI "cybdprun.ani"
file ANIMCFG "anim.cfg"

directory "script"
file JAVASCRIPT "rules.js"
7 changes: 5 additions & 2 deletions data/base/wrf/cam1/cam1a.wrf
Expand Up @@ -18,5 +18,8 @@ file SCRIPT "cam1daynight.slo"
directory "script/data"
file SCRIPTVAL "cam1day.vlo"

directory "script/campaign"
file JAVASCRIPT "cam1a.js"
/* Directory for javascript files*/
directory "script"
file JAVASCRIPT "rules.js"
directory "script/campaign"
file JAVASCRIPT "cam1a.js"
7 changes: 5 additions & 2 deletions data/base/wrf/cam1/cam1b.wrf
Expand Up @@ -18,5 +18,8 @@ file SCRIPT "cam1daynight.slo"
directory "script/data"
file SCRIPTVAL "cam1day.vlo"

directory "script/campaign"
file JAVASCRIPT "cam1b.js"
/* Directory for javascript files*/
directory "script"
file JAVASCRIPT "rules.js"
directory "script/campaign"
file JAVASCRIPT "cam1b.js"
10 changes: 6 additions & 4 deletions data/base/wrf/cam1/sub1-2s.wrf
Expand Up @@ -10,12 +10,14 @@ file SMSG "brief1-2.txt"

/* Directory for uncompiled script files */
directory "script/text"

file SCRIPT "cam1-2s.slo"
file SCRIPT "cam1daynight.slo"

/* Directory for script value files*/
directory "script/data"

file SCRIPTVAL "cam1-2s.vlo"
file SCRIPTVAL "cam1day.vlo"

/* Directory for javascript files*/
directory "script"
file JAVASCRIPT "rules.js"
directory "script/campaign"
file JAVASCRIPT "cam1-2s.js"
3 changes: 3 additions & 0 deletions data/base/wrf/fastplay/fastdemo.wrf
Expand Up @@ -25,3 +25,6 @@ file SCRIPTVAL "start.vlo"
directory "script/data"
file SCRIPTVAL "cam1day.vlo"

/* Directory for javascript files*/
directory "script"
file JAVASCRIPT "rules.js"

0 comments on commit efc04bd

Please sign in to comment.