Skip to content

Commit

Permalink
jscam: Bring clarity into proximity messages.
Browse files Browse the repository at this point in the history
Now "enemy base detected" messages are defined
in enemy base structures and played automatically
on seen. Beacons are placed and removed automatically.
New function: camDetectEnemyBase() to manually
highlight an enemy base.

refs ticket:4234
  • Loading branch information
haoNoQ committed Oct 25, 2014
1 parent c0f45c0 commit 51db9f6
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 50 deletions.
35 changes: 5 additions & 30 deletions data/base/script/campaign/cam1a.js
Expand Up @@ -44,7 +44,6 @@ function doAmbush()
camAreaEvent("ScavAttack1", me, function(droid)
{
hackRemoveMessage("C1A_OBJ1", PROX_MSG, 0);
hackAddMessage("C1A_BASE0", PROX_MSG, 0, false);
queue("runAway", 1000);
queue("doAmbush", 5000);
});
Expand Down Expand Up @@ -76,37 +75,9 @@ camAreaEvent("scavbase3area", me, function(droid)
camEnableFactory("base2factory2");
});

function playDelayed374(where)
{
var spos = getObject(where);
playSound("pcv374.ogg", spos.x, spos.y, 0);
}

function camEnemyBaseEliminated_scavgroup1()
{
hackRemoveMessage("C1A_BASE0", PROX_MSG, 0);
hackAddMessage("C1A_BASE1", PROX_MSG, 0, false);
queue("playDelayed374", 2000, "scav2soundpos");
}

function camEnemyBaseEliminated_scavgroup2()
{
hackRemoveMessage("C1A_BASE1", PROX_MSG, 0);
hackAddMessage("C1A_BASE2", PROX_MSG, 0, false);
queue("playDelayed374", 2000, "scav3soundpos");
}

function camEnemyBaseEliminated_scavgroup3()
{
hackRemoveMessage("C1A_BASE2", PROX_MSG, 0);
hackAddMessage("C1A_BASE3", PROX_MSG, 0, false);
queue("playDelayed374", 2000, "retreat4");
camEnableFactory("base2factory2");
}

function camEnemyBaseEliminated_scavgroup4()
{
hackRemoveMessage("C1A_BASE3", PROX_MSG, 0);
queue("camDetectEnemyBase", 2000, "scavgroup3");
}

function eventStructureBuilt(structure, droid)
Expand Down Expand Up @@ -162,21 +133,25 @@ function eventStartLevel()
camSetEnemyBases({
"scavgroup1": {
cleanup: "scavbase1area",
detectMsg: "C1A_BASE0",
detectSnd: "pcv375.ogg",
eliminateSnd: "pcv391.ogg"
},
"scavgroup2": {
cleanup: "scavbase2area",
detectMsg: "C1A_BASE1",
detectSnd: "pcv374.ogg",
eliminateSnd: "pcv392.ogg"
},
"scavgroup3": {
cleanup: "scavbase3area",
detectMsg: "C1A_BASE2",
detectSnd: "pcv374.ogg",
eliminateSnd: "pcv392.ogg"
},
"scavgroup4": {
cleanup: "scavbase4area",
detectMsg: "C1A_BASE3",
detectSnd: "pcv374.ogg",
eliminateSnd: "pcv392.ogg"
},
Expand Down
18 changes: 9 additions & 9 deletions data/base/script/campaign/cam1b.js
Expand Up @@ -33,11 +33,6 @@ camAreaEvent("AttackArea2", me, function(droid)
camEnableFactory("base4factory");
});

function camEnemyBaseEliminated_base4group()
{
hackRemoveMessage("C1B_BASE2", PROX_MSG, 0);
}

function eventObjectSeen(viewer, seen)
{
if (NPRetreating || viewer !== 0 || seen.id !== NPScout.id)
Expand Down Expand Up @@ -76,9 +71,6 @@ function eventStartLevel()
setPower(200, 6);
setPower(200, 7);

hackAddMessage("MB1B_MSG", MISS_MSG, 0, true);
hackAddMessage("C1B_BASE2", PROX_MSG, 0, false);

camSetArtifacts({
"base1factory": { tech: "R-Wpn-Flamer-Damage01" },
"base2factory": { tech: "R-Wpn-MG2Mk1" },
Expand All @@ -89,24 +81,32 @@ function eventStartLevel()
camSetEnemyBases({
"base1group": {
cleanup: "enemybase1",
detectMsg: "C1B_BASE1",
detectSnd: "pcv374.ogg",
eliminateSnd: "pcv392.ogg",
},
"base2group": {
cleanup: "enemybase2",
detectMsg: "C1B_BASE0",
detectSnd: "pcv374.ogg",
eliminateSnd: "pcv392.ogg",
},
"base3group": {
// sensor tower; no cleanup
detectMsg: "C1B_OBJ1",
detectSnd: "pcv375.ogg",
eliminateSnd: "pcv391.ogg",
},
"base4group": {
cleanup: "enemybase4",
detectMsg: "C1B_BASE2",
detectSnd: "pcv374.ogg",
eliminateSnd: "pcv392.ogg",
},
});

hackAddMessage("MB1B_MSG", MISS_MSG, 0, true);
camDetectEnemyBase("base4group"); // power surge detected

with (camTemplates) camSetFactories({
"base1factory": {
assembly: "assembly1",
Expand Down
93 changes: 82 additions & 11 deletions data/base/script/campaign/libcampaign.js
Expand Up @@ -555,6 +555,7 @@ function __camLetMeWinArtifacts()
//;; destroyed. If base id is not a group label, this field is required
//;; in order to auto-create the group of stuff in the area which doesn't
//;; qualify as a valid leftover.
//;; \item[detectMsg] A PROX_MSG message id to play when the base is detected.
//;; \item[detectSnd] A sound file to play when the base is detected.
//;; \item[eliminateSnd] A sound file to play when the base is eliminated.
//;; The sound is played in the center of the cleanup area,
Expand All @@ -581,6 +582,33 @@ function camSetEnemyBases(bases)
if (camDef(obj) && obj) // group already defined
{
bi.group = obj.id;
if (!camDef(bi.cleanup)) // auto-detect cleanup area
{
var objs = enumGroup(bi.group);
if (objs.length > 0) {
var a = {
type: AREA,
x: mapWidth, y: mapHeight,
x2: 0, y2: 0
};
// smallest rectangle to contain all objects
for (var i = 0; i < objs.length; ++i)
{
var o = objs[i];
if (o.x < a.x) a.x = o.x;
if (o.y < a.y) a.y = o.y;
if (o.x > a.x2) a.x2 = o.x;
if (o.y > a.y2) a.y2 = o.y;
}
// but a bit wider
a.x -= 2; a.y -= 2; a.x2 += 2; a.y2 += 2;
camTrace("Auto-detected cleanup area for", blabel, ":",
a.x, a.y,
a.x2, a.y2);
bi.cleanup = "__cam_enemy_base_cleanup__" + blabel
addLabel(a, bi.cleanup);
}
}
}
else // define a group automatically
{
Expand All @@ -605,8 +633,39 @@ function camSetEnemyBases(bases)
groupAdd(bi.group, s);
}
}
bi.seen = false;
bi.detected = false;
bi.eliminated = false;
}
}

//;; \subsection{camDetectEnemyBase(base label)}
//;; Plays the "enemy base detected" message and places a beacon
//;; for the enemy base defined by the label, as if the base
//;; was actually found by the player.
function camDetectEnemyBase(blabel)
{
var bi = __camEnemyBases[blabel];
if (bi.detected || bi.eliminated)
return;
camTrace("Enemy base", blabel, "detected");
bi.detected = true;
if (camDef(bi.detectSnd))
{
var pos = camMakePos(bi.cleanup);
if (!camDef(pos)) // auto-detect sound position by group object pos
{
var objs = enumGroup(bi.group);
if (objs.length > 0)
pos = camMakePos(objs[0]);
}
if (camDef(pos))
playSound(bi.detectSnd, pos.x, pos.y, 0);
if (camDef(bi.detectMsg))
hackAddMessage(bi.detectMsg, PROX_MSG, 0, false);
}
var callback = __camGlobalContext["camEnemyBaseDetected_" + blabel];
if (camDef(callback))
callback();
}

//;; \subsection{camAllEnemyBasesEliminated()}
Expand Down Expand Up @@ -634,15 +693,7 @@ function __camCheckBaseSeen(seen)
var bi = __camEnemyBases[blabel];
if (bi.group !== group)
continue;
if (bi.seen)
break;
camTrace("Enemy base", blabel, "detected");
bi.seen = true;
if (camDef(bi.detectSnd) && camDef(seen))
playSound(bi.detectSnd, seen.x, seen.y, 0);
var callback = __camGlobalContext["camEnemyBaseDetected_" + blabel];
if (camDef(callback))
callback();
camDetectEnemyBase(blabel);
}
}

Expand All @@ -666,6 +717,7 @@ function __camCheckBaseEliminated(group)
if (bi.group !== group)
continue;
camTrace("Enemy base", blabel, "eliminated");
bi.eliminated = true;
if (camDef(bi.cleanup))
{
var leftovers = enumArea(bi.cleanup);
Expand All @@ -685,14 +737,32 @@ function __camCheckBaseEliminated(group)
playSound(bi.eliminateSnd, pos.x, pos.y, 0);
}
}
if (camDef(bi.detectMsg) && bi.detected) // remove the beacon
hackRemoveMessage(bi.detectMsg, PROX_MSG, 0);
// bump counter before the callback, so that it was
// actual during the callback
++__camNumEnemyBases;
var callback = __camGlobalContext["camEnemyBaseEliminated_" + blabel];
if (camDef(callback))
callback();
++__camNumEnemyBases;
break;
}
}

// we need this because eventObjectSeen is unreliable
function __camBasesTick()
{
for (var blabel in __camEnemyBases)
{
var bi = __camEnemyBases[blabel];
if (bi.detected)
continue;
var objs = enumArea(bi.cleanup, ENEMIES, true); // "true" for "seen"
if (!objs.length)
continue;
camDetectEnemyBase(blabel);
}
}

////////////////////////////////////////////////////////////////////////////////
// AI droid movement automation.
Expand Down Expand Up @@ -1295,6 +1365,7 @@ function __camPreHookEvent(eventname, hookcode)
function __camTick()
{
__camTacticsTick();
__camBasesTick();
if (camDef(__camWinLossCallback))
__camGlobalContext[__camWinLossCallback]();
}
Expand Down

0 comments on commit 51db9f6

Please sign in to comment.