Permalink
Browse files

Move cam1ca script function to library.

camCountStructuresInArea(label) can now be used in all other mission scripts if needed.
Fix an error message about non droids being moved again.
  • Loading branch information...
KJeff01 committed Sep 8, 2017
1 parent f96be71 commit e0f0a420dac828744c8f903dd4a85bfac7d6757b
Showing with 27 additions and 22 deletions.
  1. +2 −19 data/base/script/campaign/cam1ca.js
  2. +25 −3 data/base/script/campaign/libcampaign.js
@@ -9,23 +9,6 @@ var baseEstablished;
var lastLZ, lastHeavy;
var totalTransportLoads;
// mimics wzscript's numStructsButNotWallsInArea(),
// not sure if worth including in libcampaign.
function countStructuresInBuildArea()
{
var list = enumArea("buildArea", CAM_HUMAN_PLAYER, false);
var ret = 0;
for (var i = 0; i < list.length; ++i)
{
if (list[i].type === STRUCTURE && list[i].stattype !== WALL
&& list[i].status === BUILT)
{
++ret;
}
}
return ret;
}
// a simple extra victory condition callback
function extraVictoryCondition()
{
@@ -36,7 +19,7 @@ function extraVictoryCondition()
{
if (baseEstablished) // if base is destroyed later, we don't care
return true;
if (countStructuresInBuildArea() >= initialStructures + 4)
if (camCountStructuresInArea("buildArea") >= initialStructures + 4)
{
baseEstablished = true;
hackRemoveMessage("C1CA_OBJ1", PROX_MSG, CAM_HUMAN_PLAYER);
@@ -118,7 +101,7 @@ function sendTransport()
function eventStartLevel()
{
totalTransportLoads = 0;
initialStructures = countStructuresInBuildArea();
initialStructures = camCountStructuresInArea("buildArea");
baseEstablished = false;
camSetStandardWinLossConditions(CAM_VICTORY_STANDARD, "SUB_1_4AS", {
@@ -232,6 +232,23 @@ function camRemoveDuplicates(array)
});
}
//;; \subsection{camCountStructuresInArea(label)}
//;; Mimics wzscript's numStructsButNotWallsInArea().
function camCountStructuresInArea(lab)
{
var list = enumArea(lab, CAM_HUMAN_PLAYER, false);
var ret = 0;
for (var i = 0, l = list.length; i < l; ++i)
{
if (list[i].type === STRUCTURE && list[i].stattype !== WALL
&& list[i].status === BUILT)
{
++ret;
}
}
return ret;
}
//;; \subsection{camChangeOnDiff(numeric value, [bool])}
//;; Change a numeric value based on campaign difficulty. If the second option is defined
//;; then the opposite effect will occur on that value.
@@ -1602,15 +1619,20 @@ function __camTacticsTickForGroup(group)
var ret = __camFindClusters(healthyDroids, __CAM_CLUSTER_SIZE);
var groupX = ret.xav[ret.maxIdx];
var groupY = ret.yav[ret.maxIdx];
droids = ret.clusters[ret.maxIdx];
droids = ret.clusters[ret.maxIdx].filter(function(obj) {
return obj.type === DROID;
});
for (var i = 0; i < ret.clusters.length; ++i)
{
if (i != ret.maxIdx) // move other droids towards main cluster
{
for (var j = 0; j < ret.clusters[i].length; ++j)
{
var droid = ret.clusters[i][j];
orderDroidLoc(droid, DORDER_MOVE, groupX, groupY);
if (droid.type === DROID)
{
orderDroidLoc(droid, DORDER_MOVE, groupX, groupY);
}
}
}
}
@@ -2772,7 +2794,7 @@ function camAbsorbPlayer(playerNumber, to)
//Steal a droid or structure from a player.
function camHackIntoPlayer(player, to)
{
if (camGetNexusState() === false)
if (__camNexusActivated === false)
{
return;
}

0 comments on commit e0f0a42

Please sign in to comment.