@supalosa/chronodivide-bot 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/bot/bot.js +2 -2
- package/dist/bot/bot.js.map +1 -1
- package/dist/bot/logic/awarenessImpl.js +132 -0
- package/dist/bot/logic/awarenessImpl.js.map +1 -0
- package/dist/bot/logic/building/antiGroundStaticDefence.js +6 -2
- package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -1
- package/dist/bot/logic/building/building.js +55 -11
- package/dist/bot/logic/building/building.js.map +1 -0
- package/dist/bot/logic/building/buildingRules.js +15 -14
- package/dist/bot/logic/building/buildingRules.js.map +1 -1
- package/dist/bot/logic/building/common.js +13 -12
- package/dist/bot/logic/building/common.js.map +1 -1
- package/dist/bot/logic/common/utils.js +12 -2
- package/dist/bot/logic/common/utils.js.map +1 -1
- package/dist/bot/logic/mission/behaviours/combatSquad.js +1 -1
- package/dist/bot/logic/mission/behaviours/combatSquad.js.map +1 -1
- package/dist/bot/logic/mission/behaviours/common.js +5 -3
- package/dist/bot/logic/mission/behaviours/common.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/attackSquad.js +63 -56
- package/dist/bot/logic/squad/behaviours/combatSquad.js +21 -25
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/common.js +11 -26
- package/dist/bot/logic/squad/behaviours/common.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/defenceSquad.js +15 -2
- package/dist/bot/logic/squad/behaviours/engineerSquad.js +2 -4
- package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/expansionSquad.js +2 -4
- package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/retreatSquad.js +1 -4
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +18 -25
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +1 -1
- package/dist/bot/logic/squad/squad.js +10 -10
- package/dist/bot/logic/squad/squad.js.map +1 -1
- package/dist/bot/logic/squad/squadBehaviour.js.map +1 -1
- package/dist/bot/logic/squad/squadController.js +5 -21
- package/dist/bot/logic/squad/squadController.js.map +1 -1
- package/dist/exampleBot.js +13 -24
- package/dist/exampleBot.js.map +1 -1
- package/package.json +3 -3
- package/src/bot/bot.ts +4 -4
- package/src/bot/logic/building/antiGroundStaticDefence.ts +5 -1
- package/src/bot/logic/building/buildingRules.ts +19 -16
- package/src/bot/logic/building/common.ts +13 -15
- package/src/bot/logic/common/utils.ts +12 -4
- package/src/bot/logic/threat/threat.ts +15 -15
- package/src/exampleBot.ts +10 -23
- package/dist/bot/logic/building/massedAntiGroundUnit.js +0 -20
- package/dist/bot/logic/building/queues.js +0 -19
- package/dist/bot/logic/knowledge.js +0 -1
- package/dist/bot/logic/mission/basicMission.js +0 -26
- package/dist/bot/logic/mission/expansionMission.js +0 -32
- package/dist/bot/logic/squad/behaviours/actionBatcher.js +0 -36
- package/dist/bot/logic/squad/behaviours/actionBatcher.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/squadExpansion.js +0 -31
- package/dist/bot/logic/squad/behaviours/squadScouters.js +0 -8
- /package/dist/bot/logic/building/{artilleryUnit.js.map → ArtilleryUnit.js.map} +0 -0
|
@@ -1,75 +1,45 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
-
import {
|
|
2
|
+
import { ObjectType, OrderType, } from "@chronodivide/game-api";
|
|
3
3
|
import { grabCombatants, noop } from "../squadBehaviour.js";
|
|
4
|
-
import { getDistanceBetweenPoints } from "../../map/map.js";
|
|
5
|
-
|
|
6
|
-
const
|
|
4
|
+
import { getDistanceBetweenPoints, getDistanceBetweenUnits } from "../../map/map.js";
|
|
5
|
+
// If no enemies are seen in a circle IDLE_CHECK_RADIUS*radius for IDLE_COOLDOWN_TICKS ticks, the mission is disbanded.
|
|
6
|
+
const IDLE_CHECK_RADIUS_RATIO = 2;
|
|
7
|
+
const IDLE_COOLDOWN_TICKS = 15 * 30;
|
|
8
|
+
const TARGET_UPDATE_INTERVAL_TICKS = 4;
|
|
7
9
|
const GRAB_INTERVAL_TICKS = 10;
|
|
8
10
|
const GRAB_RADIUS = 30;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const MIN_GATHER_RADIUS = 5;
|
|
12
|
-
const GATHER_RATIO = 10;
|
|
13
|
-
var SquadState;
|
|
14
|
-
(function (SquadState) {
|
|
15
|
-
SquadState[SquadState["Gathering"] = 0] = "Gathering";
|
|
16
|
-
SquadState[SquadState["Attacking"] = 1] = "Attacking";
|
|
17
|
-
})(SquadState || (SquadState = {}));
|
|
18
|
-
export class AttackOrDefenceSquad {
|
|
19
|
-
constructor(rallyArea, targetArea, radius) {
|
|
11
|
+
export class AttackSquad {
|
|
12
|
+
constructor(rallyArea, attackArea, radius) {
|
|
20
13
|
this.rallyArea = rallyArea;
|
|
21
|
-
this.
|
|
14
|
+
this.attackArea = attackArea;
|
|
22
15
|
this.radius = radius;
|
|
16
|
+
this.lastIdleCheck = null;
|
|
23
17
|
this.lastGrab = null;
|
|
24
18
|
this.lastCommand = null;
|
|
25
|
-
this.state = SquadState.Gathering;
|
|
26
19
|
}
|
|
27
|
-
setAttackArea(
|
|
28
|
-
this.
|
|
20
|
+
setAttackArea(attackArea) {
|
|
21
|
+
this.attackArea = attackArea;
|
|
29
22
|
}
|
|
30
23
|
onAiUpdate(gameApi, actionsApi, playerData, squad, matchAwareness) {
|
|
31
24
|
if (!this.lastCommand || gameApi.getCurrentTick() > this.lastCommand + TARGET_UPDATE_INTERVAL_TICKS) {
|
|
32
|
-
this.lastCommand = gameApi.getCurrentTick();
|
|
33
|
-
const centerOfMass = squad.getCenterOfMass();
|
|
34
|
-
const maxDistance = squad.getMaxDistanceToCenterOfMass();
|
|
35
25
|
const units = squad.getUnitsMatching(gameApi, (r) => r.rules.isSelectableCombatant);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
manageMoveMicro(actionsApi,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this.state = SquadState.Attacking;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const targetPoint = this.targetArea || playerData.startLocation;
|
|
57
|
-
for (const unit of units) {
|
|
58
|
-
if (unit.isIdle) {
|
|
59
|
-
const { rx: x, ry: y } = unit.tile;
|
|
60
|
-
const range = unit.primaryWeapon?.maxRange ?? unit.secondaryWeapon?.maxRange ?? 5;
|
|
61
|
-
const nearbyHostiles = matchAwareness.getHostilesNearPoint(x, y, range * 2);
|
|
62
|
-
const closest = _.minBy(nearbyHostiles, ({ x: hX, y: hY }) => getDistanceBetweenPoints({ x, y }, { x: hX, y: hY }));
|
|
63
|
-
const closestUnit = closest ? gameApi.getUnitData(closest.unitId) ?? null : null;
|
|
64
|
-
if (closestUnit) {
|
|
65
|
-
manageAttackMicro(actionsApi, unit, closestUnit);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
manageMoveMicro(actionsApi, unit, targetPoint);
|
|
69
|
-
}
|
|
26
|
+
const attackPoint = this.attackArea || playerData.startLocation;
|
|
27
|
+
for (const attacker of units) {
|
|
28
|
+
if (attacker.isIdle) {
|
|
29
|
+
const { rx: x, ry: y } = attacker.tile;
|
|
30
|
+
const range = attacker.primaryWeapon?.maxRange ?? attacker.secondaryWeapon?.maxRange ?? 5;
|
|
31
|
+
const nearbyHostiles = matchAwareness.getHostilesInRadius2(x, y, range * 2);
|
|
32
|
+
const closest = _.minBy(nearbyHostiles, ({ x: hX, y: hY }) => getDistanceBetweenPoints({ x, y }, { x: hX, y: hY }));
|
|
33
|
+
const closestUnit = closest ? gameApi.getUnitData(closest.unitId) ?? null : null;
|
|
34
|
+
if (closestUnit) {
|
|
35
|
+
this.manageAttackMicro(actionsApi, attacker, closestUnit);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.manageMoveMicro(actionsApi, attacker, attackPoint);
|
|
70
39
|
}
|
|
71
40
|
}
|
|
72
41
|
}
|
|
42
|
+
this.lastCommand = gameApi.getCurrentTick();
|
|
73
43
|
}
|
|
74
44
|
if (!this.lastGrab || gameApi.getCurrentTick() > this.lastGrab + GRAB_INTERVAL_TICKS) {
|
|
75
45
|
this.lastGrab = gameApi.getCurrentTick();
|
|
@@ -79,4 +49,41 @@ export class AttackOrDefenceSquad {
|
|
|
79
49
|
return noop();
|
|
80
50
|
}
|
|
81
51
|
}
|
|
52
|
+
// Micro methods
|
|
53
|
+
manageMoveMicro(actionsApi, attacker, attackPoint) {
|
|
54
|
+
if (attacker.name === "E1") {
|
|
55
|
+
if (attacker.canMove === false) {
|
|
56
|
+
actionsApi.orderUnits([attacker.id], OrderType.DeploySelected);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
actionsApi.orderUnits([attacker.id], OrderType.AttackMove, attackPoint.x, attackPoint.y);
|
|
60
|
+
}
|
|
61
|
+
manageAttackMicro(actionsApi, attacker, target) {
|
|
62
|
+
const distance = getDistanceBetweenUnits(attacker, target);
|
|
63
|
+
if (attacker.name === "E1") {
|
|
64
|
+
// Para (deployed weapon) range is 5.
|
|
65
|
+
const deployedWeaponRange = attacker.secondaryWeapon?.maxRange || 5;
|
|
66
|
+
actionsApi.orderUnits([attacker.id], OrderType.DeploySelected);
|
|
67
|
+
//console.dir({distance, attacker: attacker.name, canMove: attacker.canMove, primaryMaxRange: attacker.primaryWeapon?.maxRange, secondaryMaxRange: attacker.secondaryWeapon?.maxRange})
|
|
68
|
+
if (attacker.canMove && distance <= deployedWeaponRange * 0.8) {
|
|
69
|
+
actionsApi.orderUnits([attacker.id], OrderType.DeploySelected);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
else if (!attacker.canMove && distance > deployedWeaponRange) {
|
|
73
|
+
actionsApi.orderUnits([attacker.id], OrderType.DeploySelected);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
let targetData = target;
|
|
78
|
+
let orderType = OrderType.AttackMove;
|
|
79
|
+
const primaryWeaponRange = attacker.primaryWeapon?.maxRange || 5;
|
|
80
|
+
if (targetData?.type == ObjectType.Building && distance < primaryWeaponRange * 0.8) {
|
|
81
|
+
orderType = OrderType.Attack;
|
|
82
|
+
}
|
|
83
|
+
else if (targetData?.rules.canDisguise) {
|
|
84
|
+
// Special case for mirage tank/spy as otherwise they just sit next to it.
|
|
85
|
+
orderType = OrderType.Attack;
|
|
86
|
+
}
|
|
87
|
+
actionsApi.orderUnits([attacker.id], orderType, target.id);
|
|
88
|
+
}
|
|
82
89
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { MovementZone } from "@chronodivide/game-api";
|
|
2
3
|
import { grabCombatants, noop } from "../squadBehaviour.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { getDistanceBetweenPoints } from "../../map/map.js";
|
|
5
|
+
import { manageAttackMicro, manageMoveMicro } from "./common.js";
|
|
5
6
|
const TARGET_UPDATE_INTERVAL_TICKS = 10;
|
|
6
7
|
const GRAB_INTERVAL_TICKS = 10;
|
|
7
8
|
const GRAB_RADIUS = 20;
|
|
@@ -31,15 +32,11 @@ export class CombatSquad {
|
|
|
31
32
|
this.lastCommand = null;
|
|
32
33
|
this.state = SquadState.Gathering;
|
|
33
34
|
}
|
|
34
|
-
getGlobalDebugText() {
|
|
35
|
-
return this.debugLastTarget ?? "<none>";
|
|
36
|
-
}
|
|
37
35
|
setAttackArea(targetArea) {
|
|
38
36
|
this.targetArea = targetArea;
|
|
39
37
|
}
|
|
40
|
-
onAiUpdate(gameApi, actionsApi,
|
|
41
|
-
if (squad.getUnitIds().length > 0 &&
|
|
42
|
-
(!this.lastCommand || gameApi.getCurrentTick() > this.lastCommand + TARGET_UPDATE_INTERVAL_TICKS)) {
|
|
38
|
+
onAiUpdate(gameApi, actionsApi, playerData, squad, matchAwareness, logger) {
|
|
39
|
+
if (squad.getUnitIds().length > 0 && (!this.lastCommand || gameApi.getCurrentTick() > this.lastCommand + TARGET_UPDATE_INTERVAL_TICKS)) {
|
|
43
40
|
this.lastCommand = gameApi.getCurrentTick();
|
|
44
41
|
const centerOfMass = squad.getCenterOfMass();
|
|
45
42
|
const maxDistance = squad.getMaxDistanceToCenterOfMass();
|
|
@@ -50,13 +47,13 @@ export class CombatSquad {
|
|
|
50
47
|
r.rules.movementZone === MovementZone.Normal ||
|
|
51
48
|
r.rules.movementZone === MovementZone.InfantryDestroyer));
|
|
52
49
|
if (this.state === SquadState.Gathering) {
|
|
53
|
-
const requiredGatherRadius =
|
|
50
|
+
const requiredGatherRadius = Math.sqrt(groundUnits.length) * GATHER_RATIO + MIN_GATHER_RADIUS;
|
|
54
51
|
if (centerOfMass &&
|
|
55
52
|
maxDistance &&
|
|
56
53
|
gameApi.mapApi.getTile(centerOfMass.x, centerOfMass.y) !== undefined &&
|
|
57
54
|
maxDistance > requiredGatherRadius) {
|
|
58
55
|
units.forEach((unit) => {
|
|
59
|
-
|
|
56
|
+
manageMoveMicro(actionsApi, unit, centerOfMass);
|
|
60
57
|
});
|
|
61
58
|
}
|
|
62
59
|
else {
|
|
@@ -66,7 +63,7 @@ export class CombatSquad {
|
|
|
66
63
|
}
|
|
67
64
|
else {
|
|
68
65
|
const targetPoint = this.targetArea || playerData.startLocation;
|
|
69
|
-
const requiredGatherRadius =
|
|
66
|
+
const requiredGatherRadius = Math.sqrt(groundUnits.length) * GATHER_RATIO + MAX_GATHER_RADIUS;
|
|
70
67
|
if (centerOfMass &&
|
|
71
68
|
maxDistance &&
|
|
72
69
|
gameApi.mapApi.getTile(centerOfMass.x, centerOfMass.y) !== undefined &&
|
|
@@ -77,19 +74,18 @@ export class CombatSquad {
|
|
|
77
74
|
return noop();
|
|
78
75
|
}
|
|
79
76
|
for (const unit of units) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.getHostilesNearPoint(x, y, range * 2)
|
|
84
|
-
.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.debugLastTarget = `@${targetPoint.x},${targetPoint.y}`;
|
|
77
|
+
if (unit.isIdle) {
|
|
78
|
+
const { rx: x, ry: y } = unit.tile;
|
|
79
|
+
const range = unit.primaryWeapon?.maxRange ?? unit.secondaryWeapon?.maxRange ?? 5;
|
|
80
|
+
const nearbyHostiles = matchAwareness.getHostilesNearPoint(x, y, range * 2);
|
|
81
|
+
const closest = _.minBy(nearbyHostiles, ({ x: hX, y: hY }) => getDistanceBetweenPoints({ x, y }, { x: hX, y: hY }));
|
|
82
|
+
const closestUnit = closest ? gameApi.getUnitData(closest.unitId) ?? null : null;
|
|
83
|
+
if (closestUnit) {
|
|
84
|
+
manageAttackMicro(actionsApi, unit, closestUnit);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
manageMoveMicro(actionsApi, unit, targetPoint);
|
|
88
|
+
}
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combatSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/combatSquad.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"combatSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/combatSquad.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAuB,YAAY,EAAuB,MAAM,wBAAwB,CAAC;AAEhG,OAAO,EAA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C,CACvD,CAAC;wBACF,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;wBACjF,IAAI,WAAW,EAAE;4BACb,iBAAiB,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;yBACpD;6BAAM;4BACH,eAAe,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;yBAClD;qBACJ;iBACJ;aACJ;SACJ;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,QAAQ,GAAG,mBAAmB,EAAE;YAClF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;YACzC,OAAO,cAAc,CAAC,KAAK,CAAC,eAAe,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;SACjF;aAAM;YACH,OAAO,IAAI,EAAE,CAAC;SACjB;IACL,CAAC;CACJ"}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import { AttackState, ObjectType, OrderType, StanceType
|
|
2
|
-
import {
|
|
1
|
+
import { AttackState, ObjectType, OrderType, StanceType } from "@chronodivide/game-api";
|
|
2
|
+
import { getDistanceBetweenUnits } from "../../map/map.js";
|
|
3
3
|
// Micro methods
|
|
4
|
-
export function manageMoveMicro(attacker, attackPoint) {
|
|
4
|
+
export function manageMoveMicro(actionsApi, attacker, attackPoint) {
|
|
5
5
|
if (attacker.name === "E1") {
|
|
6
6
|
const isDeployed = attacker.stance === StanceType.Deployed;
|
|
7
7
|
if (isDeployed) {
|
|
8
|
-
|
|
8
|
+
actionsApi.orderUnits([attacker.id], OrderType.DeploySelected);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
actionsApi.orderUnits([attacker.id], OrderType.Move, attackPoint.x, attackPoint.y);
|
|
12
12
|
}
|
|
13
|
-
export function manageAttackMicro(attacker, target) {
|
|
13
|
+
export function manageAttackMicro(actionsApi, attacker, target) {
|
|
14
14
|
const distance = getDistanceBetweenUnits(attacker, target);
|
|
15
15
|
if (attacker.name === "E1") {
|
|
16
16
|
// Para (deployed weapon) range is 5.
|
|
17
17
|
const deployedWeaponRange = attacker.secondaryWeapon?.maxRange || 5;
|
|
18
18
|
const isDeployed = attacker.stance === StanceType.Deployed;
|
|
19
19
|
if (!isDeployed && (distance <= deployedWeaponRange || attacker.attackState === AttackState.JustFired)) {
|
|
20
|
-
|
|
20
|
+
actionsApi.orderUnits([attacker.id], OrderType.DeploySelected);
|
|
21
|
+
return;
|
|
21
22
|
}
|
|
22
23
|
else if (isDeployed && distance > deployedWeaponRange) {
|
|
23
|
-
|
|
24
|
+
actionsApi.orderUnits([attacker.id], OrderType.DeploySelected);
|
|
25
|
+
return;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
let targetData = target;
|
|
@@ -33,23 +35,6 @@ export function manageAttackMicro(attacker, target) {
|
|
|
33
35
|
// Special case for mirage tank/spy as otherwise they just sit next to it.
|
|
34
36
|
orderType = OrderType.Attack;
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param attacker
|
|
41
|
-
* @param target
|
|
42
|
-
* @returns A number describing the weight of the given target for the attacker, or null if it should not attack it.
|
|
43
|
-
*/
|
|
44
|
-
export function getAttackWeight(attacker, target) {
|
|
45
|
-
const { rx: x, ry: y } = attacker.tile;
|
|
46
|
-
const { rx: hX, ry: hY } = target.tile;
|
|
47
|
-
if (!attacker.primaryWeapon?.projectileRules.isAntiAir && target.zone === ZoneType.Air) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
if (!attacker.primaryWeapon?.projectileRules.isAntiGround && target.zone === ZoneType.Ground) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return 1000000 - getDistanceBetweenPoints(new Vector2(x, y), new Vector2(hX, hY));
|
|
38
|
+
actionsApi.orderUnits([attacker.id], orderType, target.id);
|
|
54
39
|
}
|
|
55
40
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/common.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,UAAU,EAAE,SAAS,EAAW,UAAU,EAAY,MAAM,wBAAwB,CAAC;AACvH,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,gBAAgB;AAChB,MAAM,UAAU,eAAe,CAAC,UAAsB,EAAE,QAAkB,EAAE,WAAoB;IAC5F,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE;QACxB,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC;QAC3D,IAAI,UAAU,EAAE;YACZ,UAAU,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;SAClE;KACJ;IACD,UAAU,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,UAAsB,EAAE,QAAkB,EAAE,MAAgB;IAC1F,MAAM,QAAQ,GAAG,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3D,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE;QACxB,qCAAqC;QACrC,MAAM,mBAAmB,GAAG,QAAQ,CAAC,eAAe,EAAE,QAAQ,IAAI,CAAC,CAAC;QACpE,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC;QAC3D,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,IAAI,mBAAmB,IAAI,QAAQ,CAAC,WAAW,KAAK,WAAW,CAAC,SAAS,CAAC,EAAE;YACpG,UAAU,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;YAC/D,OAAO;SACV;aAAM,IAAI,UAAU,IAAI,QAAQ,GAAG,mBAAmB,EAAE;YACrD,UAAU,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;YAC/D,OAAO;SACV;KACJ;IACD,IAAI,UAAU,GAAG,MAAM,CAAC;IACxB,IAAI,SAAS,GAAc,SAAS,CAAC,MAAM,CAAC;IAC5C,MAAM,kBAAkB,GAAG,QAAQ,CAAC,aAAa,EAAE,QAAQ,IAAI,CAAC,CAAC;IACjE,IAAI,UAAU,EAAE,IAAI,IAAI,UAAU,CAAC,QAAQ,IAAI,QAAQ,GAAG,kBAAkB,GAAG,GAAG,EAAE;QAChF,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;KAChC;SAAM,IAAI,UAAU,EAAE,KAAK,CAAC,WAAW,EAAE;QACtC,0EAA0E;QAC1E,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;KAChC;IACD,UAAU,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
+
import { OrderType, } from "@chronodivide/game-api";
|
|
2
3
|
import { disband, grabCombatants } from "../squadBehaviour.js";
|
|
3
4
|
import { getDistanceBetween, getDistanceBetweenUnits } from "../../map/map.js";
|
|
4
|
-
import { manageAttackMicro } from "./common.js";
|
|
5
5
|
// If no enemies are seen in a circle IDLE_CHECK_RADIUS*radius for IDLE_COOLDOWN_TICKS ticks, the mission is disbanded.
|
|
6
6
|
const IDLE_CHECK_RADIUS_RATIO = 2;
|
|
7
7
|
const IDLE_COOLDOWN_TICKS = 15 * 30;
|
|
@@ -39,10 +39,23 @@ export class DefenceSquad {
|
|
|
39
39
|
distance: getDistanceBetweenUnits(defender, enemy),
|
|
40
40
|
})), "distance");
|
|
41
41
|
if (closestEnemy) {
|
|
42
|
-
|
|
42
|
+
this.manageMicro(actionsApi, defender, closestEnemy.enemy, closestEnemy.distance);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
return grabCombatants(this.defenceArea, this.radius * GRAB_RADIUS);
|
|
47
47
|
}
|
|
48
|
+
// Micro methods
|
|
49
|
+
manageMicro(actionsApi, defender, closestEnemy, distance) {
|
|
50
|
+
if (defender.name === "E1") {
|
|
51
|
+
// Para (deployed weapon) range is 5.
|
|
52
|
+
if (defender.canMove && distance <= 4) {
|
|
53
|
+
actionsApi.orderUnits([defender.id], OrderType.DeploySelected);
|
|
54
|
+
}
|
|
55
|
+
else if (!defender.canMove && distance >= 5) {
|
|
56
|
+
actionsApi.orderUnits([defender.id], OrderType.DeploySelected);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
actionsApi.orderUnits([defender.id], OrderType.AttackMove, closestEnemy.tile.rx, closestEnemy.tile.ry);
|
|
60
|
+
}
|
|
48
61
|
}
|
|
@@ -10,7 +10,8 @@ export class EngineerSquad {
|
|
|
10
10
|
this.captureTarget = captureTarget;
|
|
11
11
|
this.hasAttemptedCaptureWith = null;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
;
|
|
14
|
+
onAiUpdate(gameApi, actionsApi, playerData, squad, matchAwareness) {
|
|
14
15
|
const engineerTypes = ["ENGINEER", "SENGINEER"];
|
|
15
16
|
const engineers = squad.getUnitsOfTypes(gameApi, ...engineerTypes);
|
|
16
17
|
if (engineers.length === 0) {
|
|
@@ -31,8 +32,5 @@ export class EngineerSquad {
|
|
|
31
32
|
}
|
|
32
33
|
return noop();
|
|
33
34
|
}
|
|
34
|
-
getGlobalDebugText() {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
35
|
}
|
|
38
36
|
//# sourceMappingURL=engineerSquad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineerSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/engineerSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAwB,MAAM,wBAAwB,CAAC;AAE9F,OAAO,EAA+B,OAAO,EAAE,IAAI,EAAwB,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"engineerSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/engineerSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAwB,MAAM,wBAAwB,CAAC;AAE9F,OAAO,EAA+B,OAAO,EAAE,IAAI,EAAwB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGtH,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC,gBAAgB;AAChB,MAAM,OAAO,aAAa;IAMtB;;OAEG;IACH,YAAoB,aAAqB;QAArB,kBAAa,GAAb,aAAa,CAAQ;QARjC,4BAAuB,GAGpB,IAAI,CAAC;IAMhB,CAAC;IAAA,CAAC;IAEK,UAAU,CACb,OAAgB,EAChB,UAAsB,EACtB,UAAsB,EACtB,KAAY,EACZ,cAA8B;QAE9B,MAAM,aAAa,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAChD,MAAM,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,aAAa,CAAC,CAAC;QACnE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,4EAA4E;YAC5E,IAAI,IAAI,CAAC,uBAAuB,KAAK,IAAI,EAAE;gBACvC,OAAO,OAAO,EAAE,CAAC;aACpB;YACD,OAAO,YAAY,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;SAC3C;aAAM,IACH,CAAC,IAAI,CAAC,uBAAuB;YAC7B,OAAO,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,uBAAuB,CAAC,QAAQ,GAAG,sBAAsB,EAC3F;YACE,UAAU,CAAC,UAAU,CACjB,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EACxC,SAAS,CAAC,OAAO,EACjB,IAAI,CAAC,aAAa,CACrB,CAAC;YACF,qCAAqC;YACrC,IAAI,CAAC,uBAAuB,GAAG;gBAC3B,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE;gBACvB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;aACrC,CAAC;SACL;QACD,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -11,7 +11,8 @@ export class ExpansionSquad {
|
|
|
11
11
|
this.selectedMcv = selectedMcv;
|
|
12
12
|
this.hasAttemptedDeployWith = null;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
;
|
|
15
|
+
onAiUpdate(gameApi, actionsApi, playerData, squad, matchAwareness) {
|
|
15
16
|
const mcvTypes = ["AMCV", "SMCV"];
|
|
16
17
|
const mcvs = squad.getUnitsOfTypes(gameApi, ...mcvTypes);
|
|
17
18
|
if (mcvs.length === 0) {
|
|
@@ -38,8 +39,5 @@ export class ExpansionSquad {
|
|
|
38
39
|
}
|
|
39
40
|
return noop();
|
|
40
41
|
}
|
|
41
|
-
getGlobalDebugText() {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
42
|
}
|
|
45
43
|
//# sourceMappingURL=expansionSquad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expansionSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/expansionSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAwB,MAAM,wBAAwB,CAAC;AAG9F,OAAO,EAA+B,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"expansionSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/expansionSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAwB,MAAM,wBAAwB,CAAC;AAG9F,OAAO,EAA+B,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGtH,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,6BAA6B;AAC7B,MAAM,OAAO,cAAc;IAMvB;;;OAGG;IACH,YAAoB,WAA0B;QAA1B,gBAAW,GAAX,WAAW,CAAe;QATtC,2BAAsB,GAGnB,IAAI,CAAC;IAOhB,CAAC;IAAA,CAAC;IAEK,UAAU,CACb,OAAgB,EAChB,UAAsB,EACtB,UAAsB,EACtB,KAAY,EACZ,cAA8B;QAE9B,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;QACzD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACnB,4EAA4E;YAC5E,IAAI,IAAI,CAAC,sBAAsB,KAAK,IAAI,EAAE;gBACtC,OAAO,OAAO,EAAE,CAAC;aACpB;YACD,kBAAkB;YAClB,IAAI,IAAI,CAAC,WAAW,EAAE;gBAClB,OAAO,oBAAoB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,CAAC;aACxD;iBAAM;gBACH,OAAO,YAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;aACtC;SACJ;aAAM,IACH,CAAC,IAAI,CAAC,sBAAsB;YAC5B,OAAO,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,sBAAsB,CAAC,QAAQ,GAAG,qBAAqB,EACzF;YACE,UAAU,CAAC,UAAU,CACjB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EACzB,SAAS,CAAC,cAAc,CAC3B,CAAC;YACF,qCAAqC;YACrC,IAAI,CAAC,sBAAsB,GAAG;gBAC1B,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;gBAClB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;aACrC,CAAC;SACL;QACD,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -7,7 +7,7 @@ export class RetreatSquad {
|
|
|
7
7
|
this.retreatToPoint = retreatToPoint;
|
|
8
8
|
this.createdAt = null;
|
|
9
9
|
}
|
|
10
|
-
onAiUpdate(gameApi, actionsApi,
|
|
10
|
+
onAiUpdate(gameApi, actionsApi, playerData, squad, matchAwareness) {
|
|
11
11
|
if (!this.createdAt) {
|
|
12
12
|
this.createdAt = gameApi.getCurrentTick();
|
|
13
13
|
}
|
|
@@ -24,8 +24,5 @@ export class RetreatSquad {
|
|
|
24
24
|
return requestSpecificUnits(this.unitIds, 1000);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
getGlobalDebugText() {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
27
|
}
|
|
31
28
|
//# sourceMappingURL=retreatSquad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retreatSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/retreatSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,
|
|
1
|
+
{"version":3,"file":"retreatSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/retreatSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAiC,MAAM,wBAAwB,CAAC;AAGvG,OAAO,EAA+B,OAAO,EAAQ,oBAAoB,EAAgB,MAAM,sBAAsB,CAAC;AAGtH,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,MAAM,OAAO,YAAY;IAGrB,YACY,OAAiB,EACjB,cAAuB;QADvB,YAAO,GAAP,OAAO,CAAU;QACjB,mBAAc,GAAd,cAAc,CAAS;QAJ3B,cAAS,GAAkB,IAAI,CAAC;IAKrC,CAAC;IAEG,UAAU,CACb,OAAgB,EAChB,UAAsB,EACtB,UAAsB,EACtB,KAAY,EACZ,cAA8B;QAE9B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACjB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;SAC7C;QACD,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/B,gEAAgE;YAChE,UAAU,CAAC,UAAU,CACjB,KAAK,CAAC,UAAU,EAAE,EAClB,SAAS,CAAC,UAAU,EACpB,IAAI,CAAC,cAAc,CAAC,CAAC,EACrB,IAAI,CAAC,cAAc,CAAC,CAAC,CACxB,CAAC;YACF,OAAO,OAAO,EAAE,CAAC;SACpB;QACD,IAAI,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,SAAS,GAAG,GAAG,EAAE;YACnE,sFAAsF;YACtF,OAAO,OAAO,EAAE,CAAC;SACpB;aAAM;YACH,OAAO,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SACnD;IACL,CAAC;CACJ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { OrderType } from "@chronodivide/game-api";
|
|
2
2
|
import { disband, noop, requestUnits } from "../squadBehaviour.js";
|
|
3
|
-
import
|
|
3
|
+
import _ from "lodash";
|
|
4
|
+
import { getDistanceBetweenPoints } from "../../map/map.js";
|
|
4
5
|
const SCOUT_MOVE_COOLDOWN_TICKS = 30;
|
|
5
6
|
// Max units to spend on a particular scout target.
|
|
6
7
|
const MAX_ATTEMPTS_PER_TARGET = 5;
|
|
@@ -13,10 +14,9 @@ export class ScoutingSquad {
|
|
|
13
14
|
this.attemptsOnCurrentTarget = 0;
|
|
14
15
|
this.scoutTargetRefreshedAt = 0;
|
|
15
16
|
this.lastMoveCommandTick = 0;
|
|
16
|
-
this.scoutTargetIsPermanent = false;
|
|
17
17
|
this.hadUnit = false;
|
|
18
18
|
}
|
|
19
|
-
onAiUpdate(gameApi, actionsApi,
|
|
19
|
+
onAiUpdate(gameApi, actionsApi, playerData, squad, matchAwareness, logger) {
|
|
20
20
|
const scoutNames = ["ADOG", "DOG", "E1", "E2", "FV", "HTK"];
|
|
21
21
|
const scouts = squad.getUnitsOfTypes(gameApi, ...scoutNames);
|
|
22
22
|
if ((matchAwareness.getSectorCache().getOverallVisibility() || 0) > 0.9) {
|
|
@@ -32,17 +32,15 @@ export class ScoutingSquad {
|
|
|
32
32
|
}
|
|
33
33
|
else if (this.scoutTarget) {
|
|
34
34
|
this.hadUnit = true;
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return noop();
|
|
45
|
-
}
|
|
35
|
+
if (this.attemptsOnCurrentTarget > MAX_ATTEMPTS_PER_TARGET) {
|
|
36
|
+
logger(`Scout target ${this.scoutTarget.x},${this.scoutTarget.y} took too many attempts, moving to next`);
|
|
37
|
+
this.setScoutTarget(null, 0);
|
|
38
|
+
return noop();
|
|
39
|
+
}
|
|
40
|
+
if (gameApi.getCurrentTick() > this.scoutTargetRefreshedAt + MAX_TICKS_PER_TARGET) {
|
|
41
|
+
logger(`Scout target ${this.scoutTarget.x},${this.scoutTarget.y} took too long, moving to next`);
|
|
42
|
+
this.setScoutTarget(null, 0);
|
|
43
|
+
return noop();
|
|
46
44
|
}
|
|
47
45
|
const targetTile = gameApi.mapApi.getTile(this.scoutTarget.x, this.scoutTarget.y);
|
|
48
46
|
if (!targetTile) {
|
|
@@ -56,8 +54,7 @@ export class ScoutingSquad {
|
|
|
56
54
|
}
|
|
57
55
|
});
|
|
58
56
|
// Check that a scout is actually moving closer to the target.
|
|
59
|
-
const
|
|
60
|
-
const newMinDistance = Math.min(...distances);
|
|
57
|
+
const newMinDistance = _.min(scouts.map((unit) => getDistanceBetweenPoints({ x: unit.tile.rx, y: unit.tile.ry }, this.scoutTarget)));
|
|
61
58
|
if (!this.scoutMinDistance || newMinDistance < this.scoutMinDistance) {
|
|
62
59
|
logger(`Scout timeout refreshed because unit moved closer to point (${newMinDistance} < ${this.scoutMinDistance})`);
|
|
63
60
|
this.scoutTargetRefreshedAt = gameApi.getCurrentTick();
|
|
@@ -70,24 +67,20 @@ export class ScoutingSquad {
|
|
|
70
67
|
}
|
|
71
68
|
}
|
|
72
69
|
else {
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
70
|
+
const candidatePoint = matchAwareness.getScoutingManager().getNewScoutTarget()?.asPoint2D();
|
|
71
|
+
if (!candidatePoint) {
|
|
75
72
|
logger(`No more scouting targets available, disbanding.`);
|
|
76
73
|
return disband();
|
|
77
74
|
}
|
|
78
|
-
this.setScoutTarget(
|
|
75
|
+
this.setScoutTarget(candidatePoint, gameApi.getCurrentTick());
|
|
79
76
|
}
|
|
80
77
|
return noop();
|
|
81
78
|
}
|
|
82
|
-
setScoutTarget(
|
|
79
|
+
setScoutTarget(point, currentTick) {
|
|
83
80
|
this.attemptsOnCurrentTarget = 0;
|
|
84
81
|
this.scoutTargetRefreshedAt = currentTick;
|
|
85
|
-
this.scoutTarget =
|
|
82
|
+
this.scoutTarget = point;
|
|
86
83
|
this.scoutMinDistance = undefined;
|
|
87
|
-
this.scoutTargetIsPermanent = target?.isPermanent ?? false;
|
|
88
|
-
}
|
|
89
|
-
getGlobalDebugText() {
|
|
90
|
-
return undefined;
|
|
91
84
|
}
|
|
92
85
|
}
|
|
93
86
|
//# sourceMappingURL=scoutingSquad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoutingSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/scoutingSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,
|
|
1
|
+
{"version":3,"file":"scoutingSquad.js","sourceRoot":"","sources":["../../../../../src/bot/logic/squad/behaviours/scoutingSquad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAiC,MAAM,wBAAwB,CAAC;AAGvG,OAAO,EAA+B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAKhG,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAA2B,MAAM,kBAAkB,CAAC;AAErF,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,mDAAmD;AACnD,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAElC,wFAAwF;AACxF,oEAAoE;AACpE,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,MAAM,OAAO,aAAa;IAA1B;QACY,gBAAW,GAAmB,IAAI,CAAC;QACnC,4BAAuB,GAAW,CAAC,CAAC;QACpC,2BAAsB,GAAW,CAAC,CAAC;QACnC,wBAAmB,GAAW,CAAC,CAAC;QAKhC,YAAO,GAAY,KAAK,CAAC;IAoFrC,CAAC;IAlFU,UAAU,CACb,OAAgB,EAChB,UAAsB,EACtB,UAAsB,EACtB,KAAY,EACZ,cAA8B,EAC9B,MAAmB;QAEnB,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,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AAC,IAAI,CAAC,EAAE;gBAC3D,MAAM,CAAC,gBAAgB,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,uCAAuC,CAAC,CAAC;gBACxG,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;aACvD;SACJ;aAAM;YACH,MAAM,cAAc,GAAG,cAAc,CAAC,kBAAkB,EAAE,CAAC,iBAAiB,EAAE,EAAE,SAAS,EAAE,CAAC;YAC5F,IAAI,CAAC,cAAc,EAAE;gBACjB,MAAM,CAAC,iDAAiD,CAAC,CAAC;gBAC1D,OAAO,OAAO,EAAE,CAAC;aACpB;YACD,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;SACjE;QACD,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC;IAED,cAAc,CAAC,KAAqB,EAAE,WAAmB;QACrD,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,sBAAsB,GAAG,WAAW,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;IACtC,CAAC;CACJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Vector2 } from "@chronodivide/game-api";
|
|
2
1
|
import { disband } from "./squadBehaviour.js";
|
|
3
|
-
import {
|
|
2
|
+
import { getDistanceBetweenPoints } from "../map/map.js";
|
|
3
|
+
import _ from "lodash";
|
|
4
4
|
export var SquadLiveness;
|
|
5
5
|
(function (SquadLiveness) {
|
|
6
6
|
SquadLiveness[SquadLiveness["SquadDead"] = 0] = "SquadDead";
|
|
@@ -17,10 +17,13 @@ const calculateCenterOfMass = (unitTiles) => {
|
|
|
17
17
|
y: y + (tile?.ry || 0),
|
|
18
18
|
};
|
|
19
19
|
}, { x: 0, y: 0 });
|
|
20
|
-
const centerOfMass =
|
|
20
|
+
const centerOfMass = {
|
|
21
|
+
x: Math.round(sums.x / unitTiles.length),
|
|
22
|
+
y: Math.round(sums.y / unitTiles.length),
|
|
23
|
+
};
|
|
21
24
|
// max distance of units to the center of mass
|
|
22
|
-
const distances = unitTiles.map((tile) =>
|
|
23
|
-
const maxDistance =
|
|
25
|
+
const distances = unitTiles.map((tile) => getDistanceBetweenPoints({ x: tile.rx, y: tile.ry }, centerOfMass));
|
|
26
|
+
const maxDistance = _.max(distances);
|
|
24
27
|
return { centerOfMass, maxDistance };
|
|
25
28
|
};
|
|
26
29
|
export class Squad {
|
|
@@ -44,7 +47,7 @@ export class Squad {
|
|
|
44
47
|
getMaxDistanceToCenterOfMass() {
|
|
45
48
|
return this.maxDistanceToCenterOfMass;
|
|
46
49
|
}
|
|
47
|
-
onAiUpdate(gameApi, actionsApi,
|
|
50
|
+
onAiUpdate(gameApi, actionsApi, playerData, matchAwareness, logger) {
|
|
48
51
|
this.updateLiveness(gameApi);
|
|
49
52
|
const movableUnitTiles = this.unitIds
|
|
50
53
|
.map((unitId) => gameApi.getUnitData(unitId))
|
|
@@ -69,7 +72,7 @@ export class Squad {
|
|
|
69
72
|
else if (!this.mission) {
|
|
70
73
|
return disband();
|
|
71
74
|
}
|
|
72
|
-
return this.behaviour.onAiUpdate(gameApi, actionsApi,
|
|
75
|
+
return this.behaviour.onAiUpdate(gameApi, actionsApi, playerData, this, matchAwareness, logger);
|
|
73
76
|
}
|
|
74
77
|
getMission() {
|
|
75
78
|
return this.mission;
|
|
@@ -119,8 +122,5 @@ export class Squad {
|
|
|
119
122
|
getLiveness() {
|
|
120
123
|
return this.liveness;
|
|
121
124
|
}
|
|
122
|
-
getGlobalDebugText() {
|
|
123
|
-
return this.behaviour.getGlobalDebugText();
|
|
124
|
-
}
|
|
125
125
|
}
|
|
126
126
|
//# sourceMappingURL=squad.js.map
|