Skip to content

Commit

Permalink
jscam: Minor fixes.
Browse files Browse the repository at this point in the history
- Fix camManageGroup to actually support position labels in data.pos.
- Fix raidTrigger label subscriber in cam1a.js.
- Clear marked tiles end of level.
- Add a new debug command, "make cc", to quickly enable minimap and design.
- On death, don't call gameOverMessage more than once.
  • Loading branch information
haoNoQ committed Dec 6, 2014
1 parent 8118c7b commit 139fcd6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
1 change: 0 additions & 1 deletion data/base/script/campaign/cam1a.js
Expand Up @@ -119,7 +119,6 @@ function eventStartLevel()
// give player briefing
hackAddMessage("CMB1_MSG", CAMP_MSG, 0, false);

setReinforcementTime(-1);
setMissionTime(-1);

// feed libcampaign.js with data to do the rest
Expand Down
1 change: 0 additions & 1 deletion data/base/script/campaign/cam1b.js
Expand Up @@ -75,7 +75,6 @@ function eventStartLevel()
centreView(startpos.x, startpos.y);
setNoGoArea(lz.x, lz.y, lz.x2, lz.y2, 0);

setReinforcementTime(-1);
setMissionTime(3600);
setAlliance(1, 6, true);
setAlliance(1, 7, true);
Expand Down
42 changes: 30 additions & 12 deletions data/base/script/campaign/libcampaign.js
Expand Up @@ -161,6 +161,9 @@ function camMakePos(xx, yy)
};
case GROUP:
default:
// already a pos-like object?
if (camDef(obj.x) && camDef(obj.y))
return { x: obj.x, y: obj.y };
camDebug("Not implemented:", obj.type);
return undefined;
}
Expand Down Expand Up @@ -382,6 +385,7 @@ function __camUpdateMarkedTiles()
function __camLetMeWin()
{
__camLetMeWinArtifacts();
hackMarkTiles(); // clear marked tiles, as they may actually remain
__camGameWon();
}

Expand Down Expand Up @@ -876,6 +880,15 @@ function camManageGroup(group, order, data)
var saneData = data;
if (!camDef(saneData))
saneData = {};
if (camDef(saneData.pos)) // sanitize pos now to make ticks faster
{
if (camIsString(saneData.pos)) // single label?
saneData.pos = [ camMakePos(saneData.pos) ];
else if (!camDef(saneData.pos.length)) // single position object?
saneData.pos = [ saneData.pos ];
for (var i = 0; i < saneData.pos.length; ++i) // array of labels?
saneData.pos[i] = camMakePos(saneData.pos[i]);
}
if (camDef(__camGroupInfo[group])
&& order !== __camGroupInfo[group].order)
{
Expand Down Expand Up @@ -996,30 +1009,25 @@ function __camPickTarget(group)
}
// fall-through! we just don't track targets on COMPROMISE
case CAM_ORDER_COMPROMISE:
var list = [];
if (camDef(gi.data.pos))
{
if (camDef(gi.data.pos.length))
list = gi.data.pos;
else
list = [ gi.data.pos ];
for (var i = 0; i < list.length && !targets.length; ++i)
for (var i = 0; i < gi.data.pos.length && !targets.length; ++i)
{
var radius = gi.data.radius;
if (!camDef(radius))
radius = __CAM_PLAYER_BASE_RADIUS;
targets = enumRange(list[i].x,
list[i].y,
targets = enumRange(gi.data.pos[i].x,
gi.data.pos[i].y,
radius,
CAM_HUMAN_PLAYER, false);
}
}
if (gi.order === CAM_ORDER_COMPROMISE && !targets.length)
{
if (!list.length)
if (!camDef(gi.data.pos))
camDebug("`pos' is required for COMPROMISE order")
else
targets = [ list[list.length - 1] ];
targets = [ gi.data.pos[gi.data.pos.length - 1] ];
}
if (!targets.length)
targets = enumStruct(CAM_HUMAN_PLAYER);
Expand Down Expand Up @@ -1183,7 +1191,7 @@ function __camTacticsTickForGroup(group)
gi.lastspot = list[camRand(list.length)];
}
gi.lastmove = gameTime;
var pos = camMakePos(gi.data.pos[gi.lastspot]);
var pos = gi.data.pos[gi.lastspot];
for (var i = 0; i < droids.length; ++i)
{
var droid = droids[i];
Expand Down Expand Up @@ -1576,12 +1584,17 @@ function __camSetOffworldLimits()
setStructureLimits("A0CommandCentre", 0, 0);
}

function __camGameLost()
function __camGameLostCB()
{
camTrace();
gameOverMessage(false);
}

function __camGameLost()
{
camCallOnce("__camGameLostCB");
}

function __camGameWon()
{
__camLevelEnded = true;
Expand Down Expand Up @@ -1824,6 +1837,11 @@ __camPreHookEvent("eventChat", function(from, to, message)
__camLetMeWin();
if (message === "win info")
__camWinInfo();
if (message === "make cc")
{
setMiniMap(true);
setDesign(true);
}
if (message.lastIndexOf("ascend ", 0) === 0)
{
__camNextLevel = message.substring(7).toUpperCase().replace(/-/g, "_");
Expand Down
2 changes: 1 addition & 1 deletion data/base/wrf/cam1/cam1a/labels.json
@@ -1,7 +1,7 @@
{
"area_1": { "label": "raidGroup", "pos1": [ 3392, 576 ], "pos2": [ 3904, 1088 ]},
"area_10": { "label": "RoadblockArea", "pos1": [ 4500, 3600 ], "pos2": [ 5500, 4700 ]},
"area_11": { "label": "raidTrigger", "pos1": [ 2900, 500 ], "pos2": [ 3800, 3000 ]},
"area_11": { "label": "raidTrigger", "subscriber": 0, "pos1": [ 2900, 500 ], "pos2": [ 3800, 3000 ]},
"area_3": { "label": "landingZone", "pos1": [ 1280, 6528 ], "pos2": [ 1536, 6784 ]},
"area_4": { "label": "LaunchScavAttack", "pos1": [ 2496, 6080 ], "pos2": [ 4928, 7232 ]},
"area_5": { "label": "scavbase1area", "pos1": [ 3520, 4416 ], "pos2": [ 4416, 5056 ]},
Expand Down

1 comment on commit 139fcd6

@haoNoQ
Copy link
Member Author

@haoNoQ haoNoQ commented on 139fcd6 Dec 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to ref #4234.

Please sign in to comment.