-
-
Notifications
You must be signed in to change notification settings - Fork 531
/
cam3-ab.js
326 lines (291 loc) · 9.27 KB
/
cam3-ab.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
include("script/campaign/libcampaign.js");
include("script/campaign/templates.js");
const mis_nexusRes = [
"R-Sys-Engineering03", "R-Defense-WallUpgrade09", "R-Struc-Materials09",
"R-Struc-VTOLPad-Upgrade06", "R-Wpn-Bomb-Damage03", "R-Sys-NEXUSrepair",
"R-Vehicle-Prop-Hover02", "R-Vehicle-Prop-VTOL02", "R-Cyborg-Legs02",
"R-Wpn-Mortar-Acc03", "R-Wpn-MG-Damage10", "R-Wpn-Mortar-ROF04",
"R-Vehicle-Engine08", "R-Vehicle-Metals08", "R-Vehicle-Armor-Heat05",
"R-Cyborg-Metals08", "R-Cyborg-Armor-Heat05", "R-Wpn-RocketSlow-ROF06",
"R-Wpn-AAGun-Damage06", "R-Wpn-AAGun-ROF06", "R-Wpn-Howitzer-Damage09",
"R-Wpn-Howitzer-ROF04", "R-Wpn-Cannon-Damage09", "R-Wpn-Cannon-ROF06",
"R-Wpn-Missile-Damage01", "R-Wpn-Missile-ROF01", "R-Wpn-Missile-Accuracy01",
"R-Wpn-Rail-Damage01", "R-Wpn-Rail-ROF01", "R-Wpn-Rail-Accuracy01",
"R-Wpn-Energy-Damage03", "R-Wpn-Energy-ROF03", "R-Wpn-Energy-Accuracy01",
"R-Wpn-AAGun-Accuracy03", "R-Wpn-Howitzer-Accuracy03", "R-Sys-NEXUSsensor",
];
const mis_nexusResClassic = [
"R-Defense-WallUpgrade09", "R-Struc-Materials09", "R-Struc-Factory-Upgrade06",
"R-Struc-VTOLPad-Upgrade06", "R-Vehicle-Engine09", "R-Vehicle-Metals07",
"R-Cyborg-Metals07", "R-Vehicle-Armor-Heat05", "R-Cyborg-Armor-Heat05",
"R-Sys-Engineering03", "R-Vehicle-Prop-Hover02", "R-Vehicle-Prop-VTOL02",
"R-Wpn-Bomb-Damage03", "R-Wpn-Energy-Accuracy01", "R-Wpn-Energy-Damage02",
"R-Wpn-Energy-ROF02", "R-Wpn-Missile-Accuracy01", "R-Wpn-Missile-Damage02",
"R-Wpn-Rail-Damage02", "R-Wpn-Rail-ROF02", "R-Sys-Sensor-Upgrade01",
"R-Sys-NEXUSrepair", "R-Wpn-Flamer-Damage06", "R-Sys-NEXUSsensor",
];
var hackFailChance; //chance the Nexus Intruder Program will fail
var winFlag;
//Remove Nexus VTOL droids.
camAreaEvent("vtolRemoveZone", function(droid)
{
if (droid.player !== CAM_HUMAN_PLAYER)
{
if (isVTOL(droid))
{
camSafeRemoveObject(droid, false);
}
}
resetLabel("vtolRemoveZone", CAM_NEXUS);
});
function sendEdgeMapDroids()
{
let unitCount = 16 + camRand(5); // 16 - 20.
if (difficulty === INSANE)
{
unitCount = 14 + camRand(3); // 14 - 16.
}
const edge = ["SWPhantomFactory", "NWPhantomFactory"];
let list = [
cTempl.nxcyrail, cTempl.nxcyscou, cTempl.nxcylas,
cTempl.nxlflash, cTempl.nxmrailh, cTempl.nxmlinkh,
cTempl.nxmscouh, cTempl.nxmsamh,
];
if (difficulty >= HARD)
{
list = list.concat(cTempl.nxmangel);
}
let droids = [];
for (let i = 0; i < unitCount; ++i)
{
droids.push(list[camRand(list.length)]);
}
droids = droids.concat(cTempl.nxmsens);
camSendReinforcement(CAM_NEXUS, camMakePos(edge[camRand(edge.length)]), droids,
CAM_REINFORCE_GROUND, {
data: {regroup: false, count: -1}
}
);
}
function wave2()
{
const list = [cTempl.nxlscouv, cTempl.nxlscouv];
const ext = {
limit: [3, 3], //paired with list array
alternate: true,
altIdx: 0
};
camSetVtolData(CAM_NEXUS, (difficulty === INSANE) ? undefined : "vtolAppearPos", "vtolRemovePos", list, camChangeOnDiff(camMinutesToMilliseconds(3.5)), undefined, ext);
}
function wave3()
{
const list = [cTempl.nxlneedv, cTempl.nxlneedv];
const ext = {
limit: [3, 3], //paired with list array
alternate: true,
altIdx: 0
};
camSetVtolData(CAM_NEXUS, (difficulty === INSANE) ? undefined : "vtolAppearPos", "vtolRemovePos", list, camChangeOnDiff(camMinutesToMilliseconds(3.5)), undefined, ext);
}
//Setup Nexus VTOL hit and runners. NOTE: These do not go away in this mission.
function vtolAttack()
{
if (camClassicMode())
{
const list = [cTempl.nxmheapv, cTempl.nxmheapv, cTempl.nxmtherv];
const ext = {
limit: [4, 4, 5], //paired with list array
alternate: true,
altIdx: 0
};
camSetVtolData(CAM_NEXUS, (difficulty === INSANE) ? undefined : "vtolAppearPos", "vtolRemovePos", list, camChangeOnDiff(camMinutesToMilliseconds(2)), undefined, ext);
}
else
{
const list = [cTempl.nxmtherv, cTempl.nxmheapv];
const ext = {
limit: [3, 3], //paired with list array
alternate: true,
altIdx: 0
};
camSetVtolData(CAM_NEXUS, (difficulty === INSANE) ? undefined : "vtolAppearPos", "vtolRemovePos", list, camChangeOnDiff(camMinutesToMilliseconds(3.5)), undefined, ext);
queue("wave2", camChangeOnDiff(camSecondsToMilliseconds(30)));
queue("wave3", camChangeOnDiff(camSecondsToMilliseconds(60)));
}
}
// Order any absorbed trucks to start building defenses near themselves.
function truckDefense()
{
const droids = enumDroid(CAM_NEXUS, DROID_CONSTRUCT);
const defenses = [
"Sys-NEXUSLinkTOW", "P0-AASite-SAM2", "Emplacement-PrisLas",
"NX-Tower-ATMiss", "Sys-NX-CBTower",
];
for (let i = 0, len = droids.length; i < len; ++i)
{
const truck = droids[i];
if (truck.order !== DORDER_BUILD)
{
const _DEFENSE = defenses[camRand(defenses.length)];
const loc = pickStructLocation(truck, _DEFENSE, truck.x, truck.y);
enableStructure(_DEFENSE, CAM_NEXUS);
if (camDef(loc))
{
orderDroidBuild(truck, DORDER_BUILD, _DEFENSE, truck.x, truck.y);
}
}
}
}
function hackManufacture(structure, template)
{
makeComponentAvailable(template.body, structure.player);
makeComponentAvailable(template.prop, structure.player);
makeComponentAvailable(template.weap, structure.player);
return buildDroid(structure, "Nexus unit", template.body, template.prop, "", "", template.weap);
}
function nexusManufacture()
{
if (countDroid(DROID_ANY, CAM_NEXUS) > 100)
{
return;
}
const factoryType = [
{structure: FACTORY, temps: [cTempl.nxmrailh, cTempl.nxmlinkh, cTempl.nxmscouh, cTempl.nxlflash,]},
{structure: CYBORG_FACTORY, temps: [cTempl.nxcyrail, cTempl.nxcyscou, cTempl.nxcylas,]},
{structure: VTOL_FACTORY, temps: [cTempl.nxlscouv, cTempl.nxmtherv, cTempl.nxmheapv,]},
];
for (let i = 0; i < factoryType.length; ++i)
{
const factories = enumStruct(CAM_NEXUS, factoryType[i].structure);
const templs = factoryType[i].temps;
for (let j = 0, len = factories.length; j < len; ++j)
{
const fac = factories[j];
if (fac.status !== BUILT || !structureIdle(fac))
{
return;
}
hackManufacture(fac, templs[camRand(templs.length)]);
}
}
queue("manualGrouping", camSecondsToMilliseconds(1.5));
}
function manualGrouping()
{
const vtols = enumDroid(CAM_NEXUS).filter((obj) => (obj.group === null && isVTOL(obj)));
const nonVtols = enumDroid(CAM_NEXUS).filter((obj) => (obj.group === null && !isVTOL(obj)));
if (vtols.length)
{
camManageGroup(camMakeGroup(vtols), CAM_ORDER_ATTACK, { regroup: false, count: -1 });
}
if (nonVtols.length)
{
camManageGroup(camMakeGroup(nonVtols), CAM_ORDER_ATTACK, { regroup: false, count: -1 });
}
}
function eventObjectTransfer(obj, from)
{
if (obj.player === CAM_NEXUS && from === CAM_HUMAN_PLAYER)
{
if (obj.type === STRUCTURE)
{
if (obj.stattype === FACTORY || obj.stattype === CYBORG_FACTORY || obj.stattype === VTOL_FACTORY)
{
queue("nexusManufacture", camSecondsToMilliseconds(0.1)); //build immediately if possible.
}
}
}
}
function powerTransfer()
{
setPower(playerPower(CAM_HUMAN_PLAYER) + 5000);
playSound(cam_sounds.powerTransferred);
}
function eventResearched(research, structure, player)
{
if (research.name === cam_resistance_circuits.first)
{
hackFailChance = 60;
if (camClassicMode())
{
camSetNexusState(false);
}
}
else if (research.name === cam_resistance_circuits.second)
{
hackFailChance = 75;
}
else if (research.name === cam_resistance_circuits.third)
{
hackFailChance = 90;
if (camClassicMode())
{
winFlag = true;
}
}
else if (research.name === cam_resistance_circuits.fourth)
{
winFlag = true;
hackFailChance = 100;
camSetNexusState(false);
}
}
function hackPlayer()
{
if (!camGetNexusState())
{
removeTimer("hackPlayer");
return;
}
if (camRand(100) < hackFailChance)
{
return;
}
camHackIntoPlayer(CAM_HUMAN_PLAYER, CAM_NEXUS);
}
function synapticsSound()
{
playSound(cam_sounds.nexus.synapticLinksActivated);
camHackIntoPlayer(CAM_HUMAN_PLAYER, CAM_NEXUS);
}
//winFlag is set in eventResearched.
function resistanceResearched()
{
if (winFlag)
{
return true;
}
}
function eventStartLevel()
{
camSetExtraObjectiveMessage(_("Research resistance circuits and survive the assault from Nexus"));
const startPos = getObject("startPosition");
const lz = getObject("landingZone");
camSetStandardWinLossConditions(CAM_VICTORY_STANDARD, cam_levels.gamma6, {
callback: "resistanceResearched"
});
camSetNexusState(true);
camPlayVideos([{video: "MB3_AB_MSG", type: CAMP_MSG}, {video: "MB3_AB_MSG2", type: CAMP_MSG}, {video: "MB3_AB_MSG3", type: MISS_MSG}]);
centreView(startPos.x, startPos.y);
setNoGoArea(lz.x, lz.y, lz.x2, lz.y2, CAM_HUMAN_PLAYER);
setMissionTime(camChangeOnDiff(camHoursToSeconds(1)));
if (camClassicMode())
{
camClassicResearch(mis_nexusResClassic, CAM_NEXUS);
}
else
{
camCompleteRequiredResearch(mis_nexusRes, CAM_NEXUS);
}
enableResearch(cam_resistance_circuits.first, CAM_HUMAN_PLAYER);
winFlag = false;
hackFailChance = (difficulty <= EASY) ? 45 : 33;
queue("vtolAttack", camChangeOnDiff(camMinutesToMilliseconds(2)));
queue("powerTransfer", camSecondsToMilliseconds(0.8));
queue("synapticsSound", camSecondsToMilliseconds(2.5));
queue("sendEdgeMapDroids", camSecondsToMilliseconds(15));
setTimer("truckDefense", camSecondsToMilliseconds(2));
setTimer("hackPlayer", camChangeOnDiff(camSecondsToMilliseconds(8)));
setTimer("nexusManufacture", camSecondsToMilliseconds(10));
setTimer("sendEdgeMapDroids", camChangeOnDiff(camMinutesToMilliseconds(4)));
}