Skip to content

Commit

Permalink
jscam: Implement auto-detection of enemy bases.
Browse files Browse the repository at this point in the history
Group labels for enemy bases are no longer required
most of the time.

Fix base2factory in cam1b.js in the process.

refs ticket:4234
  • Loading branch information
haoNoQ committed Oct 25, 2014
1 parent b615352 commit 0498184
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 96 deletions.
41 changes: 36 additions & 5 deletions data/base/script/campaign/libcampaign.js
Expand Up @@ -546,11 +546,15 @@ function __camLetMeWinArtifacts()
//;; Management assumes auto-cleanup of leftovers on destruction, and also
//;; counting how many bases have been successfully destroyed by the player.
//;; The argument is a JavaScript map from group labels to base descriptions.
//;; Each label points to a group of vital base structures. Once this group
//;; is eradicated, the base is considered to be destroyed. Base description
//;; Each label points to a group of vital base structures. If no group label
//;; with this name is defined, a group is created automatically
//;; based on \textbf{cleanup} area and labeled. Base description
//;; is a JavaScript object with the following optional fields:
//;; \begin{description}
//;; \item[cleanup] An area label to clean up features in once base is destroyed.
//;; \item[cleanup] An area label to clean up features in once base is
//;; 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[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 @@ -573,7 +577,34 @@ function camSetEnemyBases(bases)
for (var blabel in __camEnemyBases)
{
var bi = __camEnemyBases[blabel];
bi.group = getObject(blabel).id;
var obj = getObject(blabel);
if (camDef(obj) && obj) // group already defined
{
bi.group = obj.id;
}
else // define a group automatically
{
if (!camDef(bi.cleanup))
{
camDebug("Neither group nor cleanup area found for", blabel);
continue;
}
bi.group = newGroup();
addLabel({
type: GROUP,
id: bi.group,
player: 0,
}, blabel);
var structs = enumArea(bi.cleanup, ENEMIES, false);
for (var i = 0; i < structs.length; ++i)
{
var s = structs[i];
if (s.type !== STRUCTURE || __camIsValidLeftover(s))
continue;
camTrace("Auto-adding" + s.id + "to base" + blabel);
groupAdd(bi.group, s);
}
}
bi.seen = false;
}
}
Expand Down Expand Up @@ -618,7 +649,7 @@ function __camCheckBaseSeen(seen)
function __camIsValidLeftover(obj)
{
if (camPlayerMatchesFilter(obj.player, ENEMIES))
if (obj.type === STRUCTURE)
if (obj.type === STRUCTURE && obj.stattype === WALL)
return true;
if (obj.type === FEATURE)
if (obj.stattype === BUILDING)
Expand Down
45 changes: 0 additions & 45 deletions data/base/wrf/cam1/cam1a/labels.json
Expand Up @@ -111,51 +111,6 @@
7232
]
},
"group_0": {
"label": "scavgroup1",
"members": [
914,
912,
915,
3418,
928
],
"player": 7
},
"group_1": {
"label": "scavgroup2",
"members": [
8,
7,
927,
802,
800
],
"player": 7
},
"group_2": {
"label": "scavgroup3",
"members": [
840,
845,
31,
39,
20
],
"player": 6
},
"group_3": {
"label": "scavgroup4",
"members": [
1249,
3448,
3474,
3473,
1255,
1256
],
"player": 6
},
"object_0": {
"id": 8,
"label": "base1factory",
Expand Down
47 changes: 1 addition & 46 deletions data/base/wrf/cam1/cam1b/labels.json
Expand Up @@ -29,7 +29,7 @@
],
"pos2": [
2496,
10688
9728
]
},
"area_4": {
Expand Down Expand Up @@ -87,31 +87,6 @@
9536
]
},
"group_0": {
"label": "base1group",
"members": [
43,
42,
56,
53,
54,
3450
],
"player": 6
},
"group_1": {
"label": "base2group",
"members": [
3434,
3454,
3478,
3456,
3475,
3476,
3453
],
"player": 7
},
"group_2": {
"id": "group_2",
"label": "base3group",
Expand All @@ -120,26 +95,6 @@
],
"player": 7
},
"group_3": {
"label": "base4group",
"members": [
97,
62,
61,
248,
249,
933,
961,
1017,
1018,
1019,
3426,
3428,
3479,
3480
],
"player": 7
},
"object_0": {
"id": 43,
"label": "base1factory",
Expand Down

0 comments on commit 0498184

Please sign in to comment.