Differential D3225 Diff 15473 binaries/data/mods/public/maps/scenarios/unit_dancing_test_triggers.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/scenarios/unit_dancing_test_triggers.js
Show All 33 Lines | ProcessCommand(owner, { | ||||
"x": x, | "x": x, | ||||
"z": z, | "z": z, | ||||
"queued": queued, | "queued": queued, | ||||
"force": true, | "force": true, | ||||
}); | }); | ||||
return ent; | return ent; | ||||
}; | }; | ||||
var FormationWalkTo = function(x, z, queued, ent, owner=1) | |||||
{ | |||||
ProcessCommand(owner, { | |||||
"type": "walk", | |||||
"entities": Array.isArray(ent) ? ent : [ent], | |||||
"x": x, | |||||
"z": z, | |||||
"queued": queued, | |||||
"force": true, | |||||
"formation": "special/formations/box" | |||||
}); | |||||
return ent; | |||||
}; | |||||
var Patrol = function(x, z, queued, ent, owner=1) | var Patrol = function(x, z, queued, ent, owner=1) | ||||
{ | { | ||||
ProcessCommand(owner, { | ProcessCommand(owner, { | ||||
"type": "patrol", | "type": "patrol", | ||||
"entities": Array.isArray(ent) ? ent : [ent], | "entities": Array.isArray(ent) ? ent : [ent], | ||||
"x": x, | "x": x, | ||||
"z": z, | "z": z, | ||||
Show All 27 Lines | return () => { | ||||
let dancer = QuickSpawn(gx, gy, target); | let dancer = QuickSpawn(gx, gy, target); | ||||
for (let i = 0; i < 100; ++i) | for (let i = 0; i < 100; ++i) | ||||
WalkTo(gx, gy + dance_distance * (i % 2), true, dancer); | WalkTo(gx, gy + dance_distance * (i % 2), true, dancer); | ||||
let attackers = []; | let attackers = []; | ||||
for (let i = 0; i < n_attackers; ++i) | for (let i = 0; i < n_attackers; ++i) | ||||
attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | ||||
return [dancer, attackers]; | return [[dancer], attackers]; | ||||
}; | }; | ||||
}; | }; | ||||
var manual_square_dance = function(attacker, target, dance_distance, att_distance = 50, n_attackers = 1) | var manual_square_dance = function(attacker, target, dance_distance, att_distance = 50, n_attackers = 1) | ||||
{ | { | ||||
return () => { | return () => { | ||||
let dancer = QuickSpawn(gx, gy, target); | let dancer = QuickSpawn(gx, gy, target); | ||||
for (let i = 0; i < 25; ++i) | for (let i = 0; i < 25; ++i) | ||||
{ | { | ||||
WalkTo(gx + dance_distance / 2, gy + dance_distance / 2, true, dancer); | WalkTo(gx + dance_distance / 2, gy + dance_distance / 2, true, dancer); | ||||
WalkTo(gx + dance_distance / 2, gy - dance_distance / 2, true, dancer); | WalkTo(gx + dance_distance / 2, gy - dance_distance / 2, true, dancer); | ||||
WalkTo(gx - dance_distance / 2, gy - dance_distance / 2, true, dancer); | WalkTo(gx - dance_distance / 2, gy - dance_distance / 2, true, dancer); | ||||
WalkTo(gx - dance_distance / 2, gy + dance_distance / 2, true, dancer); | WalkTo(gx - dance_distance / 2, gy + dance_distance / 2, true, dancer); | ||||
} | } | ||||
let attackers = []; | let attackers = []; | ||||
for (let i = 0; i < n_attackers; ++i) | for (let i = 0; i < n_attackers; ++i) | ||||
attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | ||||
return [dancer, attackers]; | return [[dancer], attackers]; | ||||
}; | }; | ||||
}; | }; | ||||
var manual_zigzag_dance = function(attacker, target, dance_distance, att_distance = 50, n_attackers = 1) | var manual_zigzag_dance = function(attacker, target, dance_distance, att_distance = 50, n_attackers = 1) | ||||
{ | { | ||||
return () => { | return () => { | ||||
let dancer = QuickSpawn(gx, gy, target); | let dancer = QuickSpawn(gx, gy, target); | ||||
for (let i = 0; i < 12; ++i) | for (let i = 0; i < 12; ++i) | ||||
Show All 11 Lines | for (let i = 0; i < 12; ++i) | ||||
WalkTo(gx + dance_distance * 3, gy + dance_distance, true, dancer); | WalkTo(gx + dance_distance * 3, gy + dance_distance, true, dancer); | ||||
WalkTo(gx + dance_distance * 2, gy - dance_distance, true, dancer); | WalkTo(gx + dance_distance * 2, gy - dance_distance, true, dancer); | ||||
} | } | ||||
let attackers = []; | let attackers = []; | ||||
for (let i = 0; i < n_attackers; ++i) | for (let i = 0; i < n_attackers; ++i) | ||||
attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | ||||
return [dancer, attackers]; | return [[dancer], attackers]; | ||||
}; | }; | ||||
}; | }; | ||||
var patrol_dance = function(attacker, target, dance_distance, att_distance = 50, n_attackers = 1) | var patrol_dance = function(attacker, target, dance_distance, att_distance = 50, n_attackers = 1) | ||||
{ | { | ||||
return () => { | return () => { | ||||
let dancer = QuickSpawn(gx, gy, target); | let dancer = QuickSpawn(gx, gy, target); | ||||
Patrol(gx, gy + dance_distance, true, dancer); | Patrol(gx, gy + dance_distance, true, dancer); | ||||
let attackers = []; | let attackers = []; | ||||
for (let i = 0; i < n_attackers; ++i) | for (let i = 0; i < n_attackers; ++i) | ||||
attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | attackers.push(Attack(dancer, WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | ||||
return [dancer, attackers]; | return [[dancer], attackers]; | ||||
}; | |||||
}; | |||||
var manual_formation_dance = function(attacker, target, dance_distance, att_distance = 50, n_attackers = 1) | |||||
{ | |||||
return () => { | |||||
let dancers = []; | |||||
for (let x = 0; x < 4; x++) | |||||
for (let z = 0; z < 4; z++) | |||||
dancers.push(QuickSpawn(gx+x, gy+z, target)); | |||||
for (let i = 0; i < 100; ++i) | |||||
FormationWalkTo(gx, gy + dance_distance * (i % 2), i != 0, dancers); | |||||
let attackers = []; | |||||
for (let i = 0; i < n_attackers; ++i) | |||||
attackers.push(Attack(dancers[0], WalkTo(gx + att_distance, gy + i * 2, true, QuickSpawn(gx + att_distance + i, gy, attacker, ATTACKER), ATTACKER))); | |||||
return [dancers, attackers.concat(dancers)]; | |||||
}; | }; | ||||
}; | }; | ||||
experiments.unit_manual_dance_archer = { | experiments.unit_manual_dance_archer = { | ||||
"spawn": manual_dance(ARCHER_TEMPLATE, REG_UNIT_TEMPLATE, 5) | "spawn": manual_dance(ARCHER_TEMPLATE, REG_UNIT_TEMPLATE, 5) | ||||
}; | }; | ||||
experiments.unit_manual_bad_dance_archer = { | experiments.unit_manual_bad_dance_archer = { | ||||
"spawn": manual_dance(ARCHER_TEMPLATE, REG_UNIT_TEMPLATE, 20) | "spawn": manual_dance(ARCHER_TEMPLATE, REG_UNIT_TEMPLATE, 20) | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
experiments.fast_zizag_archer = { | experiments.fast_zizag_archer = { | ||||
"spawn": manual_zigzag_dance(ARCHER_TEMPLATE, FAST_UNIT_TEMPLATE, 3, 50) | "spawn": manual_zigzag_dance(ARCHER_TEMPLATE, FAST_UNIT_TEMPLATE, 3, 50) | ||||
}; | }; | ||||
experiments.fast_zizag_archer_multi = { | experiments.fast_zizag_archer_multi = { | ||||
"spawn": manual_zigzag_dance(ARCHER_TEMPLATE, FAST_UNIT_TEMPLATE, 3, 50, 5) | "spawn": manual_zigzag_dance(ARCHER_TEMPLATE, FAST_UNIT_TEMPLATE, 3, 50, 5) | ||||
}; | }; | ||||
experiments.formation_dance_slow_archer = { | |||||
"spawn": manual_formation_dance(ARCHER_TEMPLATE, REG_UNIT_TEMPLATE, 25, 50, 5) | |||||
}; | |||||
experiments.formation_dance_fast_archer = { | |||||
"spawn": manual_formation_dance(ARCHER_TEMPLATE, FAST_UNIT_TEMPLATE, 25, 50, 5) | |||||
}; | |||||
experiments.formation_bad_dance_slow_archer = { | |||||
"spawn": manual_formation_dance(ARCHER_TEMPLATE, REG_UNIT_TEMPLATE, 50, 50, 5) | |||||
}; | |||||
experiments.formation_bad_dance_fast_archer = { | |||||
"spawn": manual_formation_dance(ARCHER_TEMPLATE, FAST_UNIT_TEMPLATE, 50, 50, 5) | |||||
}; | |||||
var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | ||||
Trigger.prototype.SetupUnits = function() | Trigger.prototype.SetupUnits = function() | ||||
{ | { | ||||
warn("Experiment start"); | warn("Experiment start"); | ||||
let start = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime(); | let start = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime(); | ||||
gx = 100; | gx = 100; | ||||
gy = 100; | gy = 100; | ||||
for (let key in experiments) | for (let key in experiments) | ||||
{ | { | ||||
let [dancer, attackers] = experiments[key].spawn(); | let [dancers, attackers] = experiments[key].spawn(); | ||||
let ReportResults = (killed) => { | let ReportResults = (killed) => { | ||||
warn((killed ? "Success " : "Failure ") + "(" + (Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime() - start) + | warn((killed ? "Success " : "Failure ") + "(" + (Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime() - start) + | ||||
"): Experiment " + key + " finished: target was " + (killed ? "killed" : "not killed")); | "): Experiment " + key + " finished: target was " + (killed ? "killed" : "not killed")); | ||||
if (!killed) | |||||
ProcessCommand(1, { | ProcessCommand(1, { | ||||
"type": "delete-entities", | "type": "delete-entities", | ||||
"entities": [dancer], | "entities": dancers, | ||||
"controlAllUnits": true | "controlAllUnits": true | ||||
}); | }); | ||||
ProcessCommand(2, { | ProcessCommand(2, { | ||||
"type": "delete-entities", | "type": "delete-entities", | ||||
"entities": attackers, | "entities": attackers, | ||||
"controlAllUnits": true | "controlAllUnits": true | ||||
}); | }); | ||||
}; | }; | ||||
// xxtreme hack: hook into UnitAI | // xxtreme hack: hook into UnitAI | ||||
let uai = Engine.QueryInterface(dancer, IID_UnitAI); | let uai = Engine.QueryInterface(dancers[0], IID_UnitAI); | ||||
let odes = uai.OnDestroy; | let odes = uai.OnDestroy; | ||||
uai.OnDestroy = () => ReportResults(true) && odes(); | uai.OnDestroy = () => ReportResults(true) && odes(); | ||||
uai.FindNewTargets = () => { | uai.FindNewTargets = () => { | ||||
ReportResults(false); | ReportResults(false); | ||||
uai.OnDestroy = odes; | uai.OnDestroy = odes; | ||||
}; | }; | ||||
gx += 70; | gx += 70; | ||||
if (gx >= 450) | if (gx >= 520) | ||||
{ | { | ||||
gx = 100; | gx = 100; | ||||
gy += 70; | gy += 70; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
Show All 37 Lines |
Wildfire Games · Phabricator