@supalosa/chronodivide-bot 0.5.3 → 0.6.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/.env.template +4 -4
- package/.github/workflows/npm-publish.yml +24 -0
- package/README.md +108 -97
- package/dist/bot/bot.js +105 -105
- package/dist/bot/bot.js.map +1 -1
- package/dist/bot/logic/awareness.js +136 -136
- package/dist/bot/logic/building/antiAirStaticDefence.js +42 -42
- package/dist/bot/logic/building/antiGroundStaticDefence.js +34 -30
- package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -1
- package/dist/bot/logic/building/{ArtilleryUnit.js → artilleryUnit.js} +18 -18
- package/dist/bot/logic/building/basicAirUnit.js +19 -19
- package/dist/bot/logic/building/basicBuilding.js +26 -26
- package/dist/bot/logic/building/basicGroundUnit.js +19 -19
- package/dist/bot/logic/building/buildingRules.js +175 -174
- package/dist/bot/logic/building/buildingRules.js.map +1 -1
- package/dist/bot/logic/building/common.js +19 -18
- package/dist/bot/logic/building/common.js.map +1 -1
- package/dist/bot/logic/building/harvester.js +16 -16
- package/dist/bot/logic/building/powerPlant.js +20 -20
- package/dist/bot/logic/building/queueController.js +183 -183
- package/dist/bot/logic/building/resourceCollectionBuilding.js +36 -36
- package/dist/bot/logic/common/scout.js +126 -126
- package/dist/bot/logic/common/utils.js +95 -85
- package/dist/bot/logic/common/utils.js.map +1 -1
- package/dist/bot/logic/composition/alliedCompositions.js +12 -12
- package/dist/bot/logic/composition/common.js +1 -1
- package/dist/bot/logic/composition/sovietCompositions.js +12 -12
- package/dist/bot/logic/map/map.js +44 -44
- package/dist/bot/logic/map/sector.js +137 -137
- package/dist/bot/logic/mission/actionBatcher.js +91 -91
- package/dist/bot/logic/mission/mission.js +122 -122
- package/dist/bot/logic/mission/missionController.js +321 -321
- package/dist/bot/logic/mission/missionFactories.js +12 -12
- package/dist/bot/logic/mission/missions/attackMission.js +214 -214
- package/dist/bot/logic/mission/missions/defenceMission.js +82 -82
- package/dist/bot/logic/mission/missions/engineerMission.js +63 -63
- package/dist/bot/logic/mission/missions/expansionMission.js +60 -60
- package/dist/bot/logic/mission/missions/retreatMission.js +33 -33
- package/dist/bot/logic/mission/missions/scoutingMission.js +133 -133
- package/dist/bot/logic/mission/missions/squads/combatSquad.js +115 -115
- package/dist/bot/logic/mission/missions/squads/common.js +57 -57
- package/dist/bot/logic/mission/missions/squads/squad.js +1 -1
- package/dist/bot/logic/threat/threat.js +22 -22
- package/dist/bot/logic/threat/threatCalculator.js +73 -73
- package/dist/exampleBot.js +100 -112
- package/dist/exampleBot.js.map +1 -1
- package/package.json +32 -29
- package/src/bot/bot.ts +161 -161
- package/src/bot/logic/awareness.ts +245 -245
- package/src/bot/logic/building/antiAirStaticDefence.ts +64 -64
- package/src/bot/logic/building/antiGroundStaticDefence.ts +55 -51
- package/src/bot/logic/building/artilleryUnit.ts +39 -39
- package/src/bot/logic/building/basicAirUnit.ts +39 -39
- package/src/bot/logic/building/basicBuilding.ts +49 -49
- package/src/bot/logic/building/basicGroundUnit.ts +39 -39
- package/src/bot/logic/building/buildingRules.ts +250 -247
- package/src/bot/logic/building/common.ts +21 -23
- package/src/bot/logic/building/harvester.ts +31 -31
- package/src/bot/logic/building/powerPlant.ts +32 -32
- package/src/bot/logic/building/queueController.ts +297 -297
- package/src/bot/logic/building/resourceCollectionBuilding.ts +52 -52
- package/src/bot/logic/common/scout.ts +183 -183
- package/src/bot/logic/common/utils.ts +120 -112
- package/src/bot/logic/composition/alliedCompositions.ts +22 -22
- package/src/bot/logic/composition/common.ts +3 -3
- package/src/bot/logic/composition/sovietCompositions.ts +21 -21
- package/src/bot/logic/map/map.ts +66 -66
- package/src/bot/logic/map/sector.ts +174 -174
- package/src/bot/logic/mission/actionBatcher.ts +124 -124
- package/src/bot/logic/mission/mission.ts +232 -232
- package/src/bot/logic/mission/missionController.ts +413 -413
- package/src/bot/logic/mission/missionFactories.ts +51 -51
- package/src/bot/logic/mission/missions/attackMission.ts +336 -336
- package/src/bot/logic/mission/missions/defenceMission.ts +151 -151
- package/src/bot/logic/mission/missions/engineerMission.ts +113 -113
- package/src/bot/logic/mission/missions/expansionMission.ts +104 -104
- package/src/bot/logic/mission/missions/retreatMission.ts +54 -54
- package/src/bot/logic/mission/missions/scoutingMission.ts +186 -186
- package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -160
- package/src/bot/logic/mission/missions/squads/common.ts +63 -63
- package/src/bot/logic/mission/missions/squads/squad.ts +19 -19
- package/src/bot/logic/threat/threatCalculator.ts +100 -100
- package/src/exampleBot.ts +111 -124
- package/tsconfig.json +73 -73
- package/dist/bot/logic/building/building.js +0 -82
- 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/behaviours/combatSquad.js +0 -124
- package/dist/bot/logic/mission/behaviours/combatSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/common.js +0 -56
- package/dist/bot/logic/mission/behaviours/common.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/engineerSquad.js +0 -39
- package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/expansionSquad.js +0 -46
- package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/retreatSquad.js +0 -31
- package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/scoutingSquad.js +0 -94
- package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +0 -1
- package/dist/bot/logic/mission/expansionMission.js +0 -32
- package/dist/bot/logic/mission/missions/basicMission.js +0 -13
- package/dist/bot/logic/mission/missions/basicMission.js.map +0 -1
- package/dist/bot/logic/mission/missions/missionBehaviour.js +0 -2
- package/dist/bot/logic/mission/missions/missionBehaviour.js.map +0 -1
- package/dist/bot/logic/mission/missions/oneTimeMission.js +0 -27
- package/dist/bot/logic/mission/missions/oneTimeMission.js.map +0 -1
- 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/attackSquad.js +0 -82
- package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -106
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/common.js +0 -55
- package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -48
- package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -38
- package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -45
- package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -31
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -93
- package/dist/bot/logic/squad/behaviours/scoutingSquad.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/squad/squad.js +0 -126
- package/dist/bot/logic/squad/squad.js.map +0 -1
- package/dist/bot/logic/squad/squadBehaviour.js +0 -6
- package/dist/bot/logic/squad/squadBehaviour.js.map +0 -1
- package/dist/bot/logic/squad/squadBehaviours.js +0 -7
- package/dist/bot/logic/squad/squadBehaviours.js.map +0 -1
- package/dist/bot/logic/squad/squadController.js +0 -215
- package/dist/bot/logic/squad/squadController.js.map +0 -1
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import { GameMath } from "@chronodivide/game-api";
|
|
2
|
-
import { PriorityQueue } from "@datastructures-js/priority-queue";
|
|
3
|
-
export const getUnseenStartingLocations = (gameApi, playerData) => {
|
|
4
|
-
const unseenStartingLocations = gameApi.mapApi.getStartingLocations().filter((startingLocation) => {
|
|
5
|
-
if (startingLocation == playerData.startLocation) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
|
|
9
|
-
return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
|
|
10
|
-
});
|
|
11
|
-
return unseenStartingLocations;
|
|
12
|
-
};
|
|
13
|
-
export class PrioritisedScoutTarget {
|
|
14
|
-
constructor(priority, target, permanent = false) {
|
|
15
|
-
this.permanent = permanent;
|
|
16
|
-
if (target.hasOwnProperty("x") && target.hasOwnProperty("y")) {
|
|
17
|
-
this._targetPoint = target;
|
|
18
|
-
}
|
|
19
|
-
else if (target.hasOwnProperty("sectorStartPoint")) {
|
|
20
|
-
this._targetSector = target;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
throw new TypeError(`invalid object passed as target: ${target}`);
|
|
24
|
-
}
|
|
25
|
-
this._priority = priority;
|
|
26
|
-
}
|
|
27
|
-
get priority() {
|
|
28
|
-
return this._priority;
|
|
29
|
-
}
|
|
30
|
-
asVector2() {
|
|
31
|
-
return this._targetPoint ?? this._targetSector?.sectorStartPoint ?? null;
|
|
32
|
-
}
|
|
33
|
-
get targetSector() {
|
|
34
|
-
return this._targetSector;
|
|
35
|
-
}
|
|
36
|
-
get isPermanent() {
|
|
37
|
-
return this.permanent;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const ENEMY_SPAWN_POINT_PRIORITY = 100;
|
|
41
|
-
// Amount of sectors around the starting sector to try to scout.
|
|
42
|
-
const NEARBY_SECTOR_STARTING_RADIUS = 2;
|
|
43
|
-
const NEARBY_SECTOR_BASE_PRIORITY = 1000;
|
|
44
|
-
// Amount of ticks per 'radius' to expand for scouting.
|
|
45
|
-
const SCOUTING_RADIUS_EXPANSION_TICKS = 9000; // 10 minutes
|
|
46
|
-
export class ScoutingManager {
|
|
47
|
-
constructor(logger) {
|
|
48
|
-
this.logger = logger;
|
|
49
|
-
this.queuedRadius = NEARBY_SECTOR_STARTING_RADIUS;
|
|
50
|
-
// Order by descending priority.
|
|
51
|
-
this.scoutingQueue = new PriorityQueue((a, b) => b.priority - a.priority);
|
|
52
|
-
}
|
|
53
|
-
addRadiusToScout(gameApi, centerPoint, sectorCache, radius, startingPriority) {
|
|
54
|
-
const { x: startX, y: startY } = centerPoint;
|
|
55
|
-
const { width: sectorsX, height: sectorsY } = sectorCache.getSectorBounds();
|
|
56
|
-
const startingSector = sectorCache.getSectorCoordinatesForWorldPosition(startX, startY);
|
|
57
|
-
if (!startingSector) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
for (let x = Math.max(0, startingSector.sectorX - radius); x < Math.min(sectorsX, startingSector.sectorX + radius); ++x) {
|
|
61
|
-
for (let y = Math.max(0, startingSector.sectorY - radius); y < Math.min(sectorsY, startingSector.sectorY + radius); ++y) {
|
|
62
|
-
if (x === startingSector?.sectorX && y === startingSector?.sectorY) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
// Make it scout closer sectors first.
|
|
66
|
-
const distanceFactor = GameMath.pow(x - startingSector.sectorX, 2) + GameMath.pow(y - startingSector.sectorY, 2);
|
|
67
|
-
const sector = sectorCache.getSector(x, y);
|
|
68
|
-
if (sector) {
|
|
69
|
-
const maybeTarget = new PrioritisedScoutTarget(startingPriority - distanceFactor, sector);
|
|
70
|
-
const maybePoint = maybeTarget.asVector2();
|
|
71
|
-
if (maybePoint && gameApi.mapApi.getTile(maybePoint.x, maybePoint.y)) {
|
|
72
|
-
this.scoutingQueue.enqueue(maybeTarget);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
onGameStart(gameApi, playerData, sectorCache) {
|
|
79
|
-
// Queue hostile starting locations with high priority and as permanent scouting candidates.
|
|
80
|
-
gameApi.mapApi
|
|
81
|
-
.getStartingLocations()
|
|
82
|
-
.filter((startingLocation) => {
|
|
83
|
-
if (startingLocation == playerData.startLocation) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
|
|
87
|
-
return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
|
|
88
|
-
})
|
|
89
|
-
.map((tile) => new PrioritisedScoutTarget(ENEMY_SPAWN_POINT_PRIORITY, tile, true))
|
|
90
|
-
.forEach((target) => {
|
|
91
|
-
this.logger(`Adding ${target.asVector2()?.x},${target.asVector2()?.y} to initial scouting queue`);
|
|
92
|
-
this.scoutingQueue.enqueue(target);
|
|
93
|
-
});
|
|
94
|
-
// Queue sectors near the spawn point.
|
|
95
|
-
this.addRadiusToScout(gameApi, playerData.startLocation, sectorCache, NEARBY_SECTOR_STARTING_RADIUS, NEARBY_SECTOR_BASE_PRIORITY);
|
|
96
|
-
}
|
|
97
|
-
onAiUpdate(gameApi, playerData, sectorCache) {
|
|
98
|
-
const currentHead = this.scoutingQueue.front();
|
|
99
|
-
if (!currentHead) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const head = currentHead.asVector2();
|
|
103
|
-
if (!head) {
|
|
104
|
-
this.scoutingQueue.dequeue();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const { x, y } = head;
|
|
108
|
-
const tile = gameApi.mapApi.getTile(x, y);
|
|
109
|
-
if (tile && gameApi.mapApi.isVisibleTile(tile, playerData.name)) {
|
|
110
|
-
this.logger(`head point is visible, dequeueing`);
|
|
111
|
-
this.scoutingQueue.dequeue();
|
|
112
|
-
}
|
|
113
|
-
const requiredRadius = Math.floor(gameApi.getCurrentTick() / SCOUTING_RADIUS_EXPANSION_TICKS);
|
|
114
|
-
if (requiredRadius > this.queuedRadius) {
|
|
115
|
-
this.logger(`expanding scouting radius from ${this.queuedRadius} to ${requiredRadius}`);
|
|
116
|
-
this.addRadiusToScout(gameApi, playerData.startLocation, sectorCache, requiredRadius, NEARBY_SECTOR_BASE_PRIORITY);
|
|
117
|
-
this.queuedRadius = requiredRadius;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
getNewScoutTarget() {
|
|
121
|
-
return this.scoutingQueue.dequeue();
|
|
122
|
-
}
|
|
123
|
-
hasScoutTargets() {
|
|
124
|
-
return !this.scoutingQueue.isEmpty();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
1
|
+
import { GameMath } from "@chronodivide/game-api";
|
|
2
|
+
import { PriorityQueue } from "@datastructures-js/priority-queue";
|
|
3
|
+
export const getUnseenStartingLocations = (gameApi, playerData) => {
|
|
4
|
+
const unseenStartingLocations = gameApi.mapApi.getStartingLocations().filter((startingLocation) => {
|
|
5
|
+
if (startingLocation == playerData.startLocation) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
|
|
9
|
+
return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
|
|
10
|
+
});
|
|
11
|
+
return unseenStartingLocations;
|
|
12
|
+
};
|
|
13
|
+
export class PrioritisedScoutTarget {
|
|
14
|
+
constructor(priority, target, permanent = false) {
|
|
15
|
+
this.permanent = permanent;
|
|
16
|
+
if (target.hasOwnProperty("x") && target.hasOwnProperty("y")) {
|
|
17
|
+
this._targetPoint = target;
|
|
18
|
+
}
|
|
19
|
+
else if (target.hasOwnProperty("sectorStartPoint")) {
|
|
20
|
+
this._targetSector = target;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new TypeError(`invalid object passed as target: ${target}`);
|
|
24
|
+
}
|
|
25
|
+
this._priority = priority;
|
|
26
|
+
}
|
|
27
|
+
get priority() {
|
|
28
|
+
return this._priority;
|
|
29
|
+
}
|
|
30
|
+
asVector2() {
|
|
31
|
+
return this._targetPoint ?? this._targetSector?.sectorStartPoint ?? null;
|
|
32
|
+
}
|
|
33
|
+
get targetSector() {
|
|
34
|
+
return this._targetSector;
|
|
35
|
+
}
|
|
36
|
+
get isPermanent() {
|
|
37
|
+
return this.permanent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const ENEMY_SPAWN_POINT_PRIORITY = 100;
|
|
41
|
+
// Amount of sectors around the starting sector to try to scout.
|
|
42
|
+
const NEARBY_SECTOR_STARTING_RADIUS = 2;
|
|
43
|
+
const NEARBY_SECTOR_BASE_PRIORITY = 1000;
|
|
44
|
+
// Amount of ticks per 'radius' to expand for scouting.
|
|
45
|
+
const SCOUTING_RADIUS_EXPANSION_TICKS = 9000; // 10 minutes
|
|
46
|
+
export class ScoutingManager {
|
|
47
|
+
constructor(logger) {
|
|
48
|
+
this.logger = logger;
|
|
49
|
+
this.queuedRadius = NEARBY_SECTOR_STARTING_RADIUS;
|
|
50
|
+
// Order by descending priority.
|
|
51
|
+
this.scoutingQueue = new PriorityQueue((a, b) => b.priority - a.priority);
|
|
52
|
+
}
|
|
53
|
+
addRadiusToScout(gameApi, centerPoint, sectorCache, radius, startingPriority) {
|
|
54
|
+
const { x: startX, y: startY } = centerPoint;
|
|
55
|
+
const { width: sectorsX, height: sectorsY } = sectorCache.getSectorBounds();
|
|
56
|
+
const startingSector = sectorCache.getSectorCoordinatesForWorldPosition(startX, startY);
|
|
57
|
+
if (!startingSector) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for (let x = Math.max(0, startingSector.sectorX - radius); x < Math.min(sectorsX, startingSector.sectorX + radius); ++x) {
|
|
61
|
+
for (let y = Math.max(0, startingSector.sectorY - radius); y < Math.min(sectorsY, startingSector.sectorY + radius); ++y) {
|
|
62
|
+
if (x === startingSector?.sectorX && y === startingSector?.sectorY) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
// Make it scout closer sectors first.
|
|
66
|
+
const distanceFactor = GameMath.pow(x - startingSector.sectorX, 2) + GameMath.pow(y - startingSector.sectorY, 2);
|
|
67
|
+
const sector = sectorCache.getSector(x, y);
|
|
68
|
+
if (sector) {
|
|
69
|
+
const maybeTarget = new PrioritisedScoutTarget(startingPriority - distanceFactor, sector);
|
|
70
|
+
const maybePoint = maybeTarget.asVector2();
|
|
71
|
+
if (maybePoint && gameApi.mapApi.getTile(maybePoint.x, maybePoint.y)) {
|
|
72
|
+
this.scoutingQueue.enqueue(maybeTarget);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
onGameStart(gameApi, playerData, sectorCache) {
|
|
79
|
+
// Queue hostile starting locations with high priority and as permanent scouting candidates.
|
|
80
|
+
gameApi.mapApi
|
|
81
|
+
.getStartingLocations()
|
|
82
|
+
.filter((startingLocation) => {
|
|
83
|
+
if (startingLocation == playerData.startLocation) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
|
|
87
|
+
return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
|
|
88
|
+
})
|
|
89
|
+
.map((tile) => new PrioritisedScoutTarget(ENEMY_SPAWN_POINT_PRIORITY, tile, true))
|
|
90
|
+
.forEach((target) => {
|
|
91
|
+
this.logger(`Adding ${target.asVector2()?.x},${target.asVector2()?.y} to initial scouting queue`);
|
|
92
|
+
this.scoutingQueue.enqueue(target);
|
|
93
|
+
});
|
|
94
|
+
// Queue sectors near the spawn point.
|
|
95
|
+
this.addRadiusToScout(gameApi, playerData.startLocation, sectorCache, NEARBY_SECTOR_STARTING_RADIUS, NEARBY_SECTOR_BASE_PRIORITY);
|
|
96
|
+
}
|
|
97
|
+
onAiUpdate(gameApi, playerData, sectorCache) {
|
|
98
|
+
const currentHead = this.scoutingQueue.front();
|
|
99
|
+
if (!currentHead) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const head = currentHead.asVector2();
|
|
103
|
+
if (!head) {
|
|
104
|
+
this.scoutingQueue.dequeue();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const { x, y } = head;
|
|
108
|
+
const tile = gameApi.mapApi.getTile(x, y);
|
|
109
|
+
if (tile && gameApi.mapApi.isVisibleTile(tile, playerData.name)) {
|
|
110
|
+
this.logger(`head point is visible, dequeueing`);
|
|
111
|
+
this.scoutingQueue.dequeue();
|
|
112
|
+
}
|
|
113
|
+
const requiredRadius = Math.floor(gameApi.getCurrentTick() / SCOUTING_RADIUS_EXPANSION_TICKS);
|
|
114
|
+
if (requiredRadius > this.queuedRadius) {
|
|
115
|
+
this.logger(`expanding scouting radius from ${this.queuedRadius} to ${requiredRadius}`);
|
|
116
|
+
this.addRadiusToScout(gameApi, playerData.startLocation, sectorCache, requiredRadius, NEARBY_SECTOR_BASE_PRIORITY);
|
|
117
|
+
this.queuedRadius = requiredRadius;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
getNewScoutTarget() {
|
|
121
|
+
return this.scoutingQueue.dequeue();
|
|
122
|
+
}
|
|
123
|
+
hasScoutTargets() {
|
|
124
|
+
return !this.scoutingQueue.isEmpty();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
127
|
//# sourceMappingURL=scout.js.map
|
|
@@ -1,86 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
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
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (val
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
export var Countries;
|
|
2
|
+
(function (Countries) {
|
|
3
|
+
Countries["USA"] = "Americans";
|
|
4
|
+
Countries["KOREA"] = "Alliance";
|
|
5
|
+
Countries["FRANCE"] = "French";
|
|
6
|
+
Countries["GERMANY"] = "Germans";
|
|
7
|
+
Countries["GREAT_BRITAIN"] = "British";
|
|
8
|
+
Countries["LIBYA"] = "Africans";
|
|
9
|
+
Countries["IRAQ"] = "Arabs";
|
|
10
|
+
Countries["CUBA"] = "Confederation";
|
|
11
|
+
Countries["RUSSIA"] = "Russians";
|
|
12
|
+
})(Countries || (Countries = {}));
|
|
13
|
+
export const isOwnedByNeutral = (unitData) => unitData?.owner === "@@NEUTRAL@@";
|
|
14
|
+
// Return if the given unit would have .isSelectableCombatant = true.
|
|
15
|
+
// Usable on GameObjectData (which is faster to get than TechnoRules)
|
|
16
|
+
export const isSelectableCombatant = (rules) => !!rules?.rules?.isSelectableCombatant;
|
|
17
|
+
// Thanks use-strict!
|
|
18
|
+
export function formatTimeDuration(timeSeconds, skipZeroHours = false) {
|
|
19
|
+
let h = Math.floor(timeSeconds / 3600);
|
|
20
|
+
timeSeconds -= h * 3600;
|
|
21
|
+
let m = Math.floor(timeSeconds / 60);
|
|
22
|
+
timeSeconds -= m * 60;
|
|
23
|
+
let s = Math.floor(timeSeconds);
|
|
24
|
+
return [...(h || !skipZeroHours ? [h] : []), pad(m, "00"), pad(s, "00")].join(":");
|
|
25
|
+
}
|
|
26
|
+
export function pad(n, format = "0000") {
|
|
27
|
+
let str = "" + n;
|
|
28
|
+
return format.substring(0, format.length - str.length) + str;
|
|
29
|
+
}
|
|
30
|
+
// So we don't need lodash
|
|
31
|
+
export function minBy(array, predicate) {
|
|
32
|
+
if (array.length === 0) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
let minIdx = 0;
|
|
36
|
+
let minVal = predicate(array[0]);
|
|
37
|
+
for (let i = 1; i < array.length; ++i) {
|
|
38
|
+
const newVal = predicate(array[i]);
|
|
39
|
+
if (minVal === null || (newVal !== null && newVal < minVal)) {
|
|
40
|
+
minIdx = i;
|
|
41
|
+
minVal = newVal;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return array[minIdx];
|
|
45
|
+
}
|
|
46
|
+
export function maxBy(array, predicate) {
|
|
47
|
+
if (array.length === 0) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
let maxIdx = 0;
|
|
51
|
+
let maxVal = predicate(array[0]);
|
|
52
|
+
for (let i = 1; i < array.length; ++i) {
|
|
53
|
+
const newVal = predicate(array[i]);
|
|
54
|
+
if (maxVal === null || (newVal !== null && newVal > maxVal)) {
|
|
55
|
+
maxIdx = i;
|
|
56
|
+
maxVal = newVal;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return array[maxIdx];
|
|
60
|
+
}
|
|
61
|
+
export function uniqBy(array, predicate) {
|
|
62
|
+
return Object.values(array.reduce((prev, newVal) => {
|
|
63
|
+
const val = predicate(newVal);
|
|
64
|
+
if (!prev[val]) {
|
|
65
|
+
prev[val] = newVal;
|
|
66
|
+
}
|
|
67
|
+
return prev;
|
|
68
|
+
}, {}));
|
|
69
|
+
}
|
|
70
|
+
export function countBy(array, predicate) {
|
|
71
|
+
return array.reduce((prev, newVal) => {
|
|
72
|
+
const val = predicate(newVal);
|
|
73
|
+
if (val === undefined) {
|
|
74
|
+
return prev;
|
|
75
|
+
}
|
|
76
|
+
if (!prev[val]) {
|
|
77
|
+
prev[val] = 0;
|
|
78
|
+
}
|
|
79
|
+
prev[val] = prev[val] + 1;
|
|
80
|
+
return prev;
|
|
81
|
+
}, {});
|
|
82
|
+
}
|
|
83
|
+
export function groupBy(array, predicate) {
|
|
84
|
+
return array.reduce((prev, newVal) => {
|
|
85
|
+
const val = predicate(newVal);
|
|
86
|
+
if (val === undefined) {
|
|
87
|
+
return prev;
|
|
88
|
+
}
|
|
89
|
+
if (!prev.hasOwnProperty(val)) {
|
|
90
|
+
prev[val] = [];
|
|
91
|
+
}
|
|
92
|
+
prev[val].push(newVal);
|
|
93
|
+
return prev;
|
|
94
|
+
}, {});
|
|
95
|
+
}
|
|
86
96
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/bot/logic/common/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/bot/logic/common/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,SAUX;AAVD,WAAY,SAAS;IACjB,8BAAiB,CAAA;IACjB,+BAAkB,CAAA;IAClB,8BAAiB,CAAA;IACjB,gCAAmB,CAAA;IACnB,sCAAyB,CAAA;IACzB,+BAAkB,CAAA;IAClB,2BAAc,CAAA;IACd,mCAAsB,CAAA;IACtB,gCAAmB,CAAA;AACvB,CAAC,EAVW,SAAS,KAAT,SAAS,QAUpB;AAID,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAA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;AACN,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export const getAlliedCompositions = (gameApi, playerData, matchAwareness) => {
|
|
2
|
-
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAWEAP").length > 0;
|
|
3
|
-
const hasAirforce = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAAIRC" || r.name === "AMRADR").length > 0;
|
|
4
|
-
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GATECH").length > 0;
|
|
5
|
-
const includeInfantry = !hasAirforce && !hasBattleLab;
|
|
6
|
-
return {
|
|
7
|
-
...(includeInfantry && { E1: 5 }),
|
|
8
|
-
...(hasWarFactory && { MTNK: 3, FV: 2 }),
|
|
9
|
-
...(hasAirforce && { JUMPJET: 6 }),
|
|
10
|
-
...(hasBattleLab && { SREF: 2, MGTK: 3 }),
|
|
11
|
-
};
|
|
12
|
-
};
|
|
1
|
+
export const getAlliedCompositions = (gameApi, playerData, matchAwareness) => {
|
|
2
|
+
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAWEAP").length > 0;
|
|
3
|
+
const hasAirforce = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GAAIRC" || r.name === "AMRADR").length > 0;
|
|
4
|
+
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "GATECH").length > 0;
|
|
5
|
+
const includeInfantry = !hasAirforce && !hasBattleLab;
|
|
6
|
+
return {
|
|
7
|
+
...(includeInfantry && { E1: 5 }),
|
|
8
|
+
...(hasWarFactory && { MTNK: 3, FV: 2 }),
|
|
9
|
+
...(hasAirforce && { JUMPJET: 6 }),
|
|
10
|
+
...(hasBattleLab && { SREF: 2, MGTK: 3 }),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
13
|
//# sourceMappingURL=alliedCompositions.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=common.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export const getSovietComposition = (gameApi, playerData, matchAwareness) => {
|
|
2
|
-
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NAWEAP").length > 0;
|
|
3
|
-
const hasRadar = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NARADR").length > 0;
|
|
4
|
-
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NATECH").length > 0;
|
|
5
|
-
const includeInfantry = !hasBattleLab;
|
|
6
|
-
return {
|
|
7
|
-
...(includeInfantry && { E2: 10 }),
|
|
8
|
-
...(hasWarFactory && { HTNK: 3, HTK: 2 }),
|
|
9
|
-
...(hasRadar && { V3: 1 }),
|
|
10
|
-
...(hasBattleLab && { APOC: 2 }),
|
|
11
|
-
};
|
|
12
|
-
};
|
|
1
|
+
export const getSovietComposition = (gameApi, playerData, matchAwareness) => {
|
|
2
|
+
const hasWarFactory = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NAWEAP").length > 0;
|
|
3
|
+
const hasRadar = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NARADR").length > 0;
|
|
4
|
+
const hasBattleLab = gameApi.getVisibleUnits(playerData.name, "self", (r) => r.name === "NATECH").length > 0;
|
|
5
|
+
const includeInfantry = !hasBattleLab;
|
|
6
|
+
return {
|
|
7
|
+
...(includeInfantry && { E2: 10 }),
|
|
8
|
+
...(hasWarFactory && { HTNK: 3, HTK: 2 }),
|
|
9
|
+
...(hasRadar && { V3: 1 }),
|
|
10
|
+
...(hasBattleLab && { APOC: 2 }),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
13
|
//# sourceMappingURL=sovietCompositions.js.map
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { GameMath, Vector2 } from "@chronodivide/game-api";
|
|
2
|
-
export function determineMapBounds(mapApi) {
|
|
3
|
-
return mapApi.getRealMapSize();
|
|
4
|
-
}
|
|
5
|
-
export function calculateAreaVisibility(mapApi, playerData, startPoint, endPoint) {
|
|
6
|
-
let validTiles = 0, visibleTiles = 0;
|
|
7
|
-
for (let xx = startPoint.x; xx < endPoint.x; ++xx) {
|
|
8
|
-
for (let yy = startPoint.y; yy < endPoint.y; ++yy) {
|
|
9
|
-
let tile = mapApi.getTile(xx, yy);
|
|
10
|
-
if (tile) {
|
|
11
|
-
++validTiles;
|
|
12
|
-
if (mapApi.isVisibleTile(tile, playerData.name)) {
|
|
13
|
-
++visibleTiles;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
let result = { visibleTiles, validTiles };
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
export function getPointTowardsOtherPoint(gameApi, startLocation, endLocation, minRadius, maxRadius, randomAngle) {
|
|
22
|
-
// TODO: Use proper vector maths here.
|
|
23
|
-
let radius = minRadius + Math.round(gameApi.generateRandom() * (maxRadius - minRadius));
|
|
24
|
-
let directionToEndLocation = GameMath.atan2(endLocation.y - startLocation.y, endLocation.x - startLocation.x);
|
|
25
|
-
let randomisedDirection = directionToEndLocation -
|
|
26
|
-
(randomAngle * (Math.PI / 12) + 2 * randomAngle * gameApi.generateRandom() * (Math.PI / 12));
|
|
27
|
-
let candidatePointX = Math.round(startLocation.x + GameMath.cos(randomisedDirection) * radius);
|
|
28
|
-
let candidatePointY = Math.round(startLocation.y + GameMath.sin(randomisedDirection) * radius);
|
|
29
|
-
return new Vector2(candidatePointX, candidatePointY);
|
|
30
|
-
}
|
|
31
|
-
export function getDistanceBetweenPoints(startLocation, endLocation) {
|
|
32
|
-
// TODO: Remove this now we have Vector2s.
|
|
33
|
-
return startLocation.distanceTo(endLocation);
|
|
34
|
-
}
|
|
35
|
-
export function getDistanceBetweenTileAndPoint(tile, vector) {
|
|
36
|
-
// TODO: Remove this now we have Vector2s.
|
|
37
|
-
return new Vector2(tile.rx, tile.ry).distanceTo(vector);
|
|
38
|
-
}
|
|
39
|
-
export function getDistanceBetweenUnits(unit1, unit2) {
|
|
40
|
-
return new Vector2(unit1.tile.rx, unit1.tile.ry).distanceTo(new Vector2(unit2.tile.rx, unit2.tile.ry));
|
|
41
|
-
}
|
|
42
|
-
export function getDistanceBetween(unit, point) {
|
|
43
|
-
return getDistanceBetweenPoints(new Vector2(unit.tile.rx, unit.tile.ry), point);
|
|
44
|
-
}
|
|
1
|
+
import { GameMath, Vector2 } from "@chronodivide/game-api";
|
|
2
|
+
export function determineMapBounds(mapApi) {
|
|
3
|
+
return mapApi.getRealMapSize();
|
|
4
|
+
}
|
|
5
|
+
export function calculateAreaVisibility(mapApi, playerData, startPoint, endPoint) {
|
|
6
|
+
let validTiles = 0, visibleTiles = 0;
|
|
7
|
+
for (let xx = startPoint.x; xx < endPoint.x; ++xx) {
|
|
8
|
+
for (let yy = startPoint.y; yy < endPoint.y; ++yy) {
|
|
9
|
+
let tile = mapApi.getTile(xx, yy);
|
|
10
|
+
if (tile) {
|
|
11
|
+
++validTiles;
|
|
12
|
+
if (mapApi.isVisibleTile(tile, playerData.name)) {
|
|
13
|
+
++visibleTiles;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
let result = { visibleTiles, validTiles };
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
export function getPointTowardsOtherPoint(gameApi, startLocation, endLocation, minRadius, maxRadius, randomAngle) {
|
|
22
|
+
// TODO: Use proper vector maths here.
|
|
23
|
+
let radius = minRadius + Math.round(gameApi.generateRandom() * (maxRadius - minRadius));
|
|
24
|
+
let directionToEndLocation = GameMath.atan2(endLocation.y - startLocation.y, endLocation.x - startLocation.x);
|
|
25
|
+
let randomisedDirection = directionToEndLocation -
|
|
26
|
+
(randomAngle * (Math.PI / 12) + 2 * randomAngle * gameApi.generateRandom() * (Math.PI / 12));
|
|
27
|
+
let candidatePointX = Math.round(startLocation.x + GameMath.cos(randomisedDirection) * radius);
|
|
28
|
+
let candidatePointY = Math.round(startLocation.y + GameMath.sin(randomisedDirection) * radius);
|
|
29
|
+
return new Vector2(candidatePointX, candidatePointY);
|
|
30
|
+
}
|
|
31
|
+
export function getDistanceBetweenPoints(startLocation, endLocation) {
|
|
32
|
+
// TODO: Remove this now we have Vector2s.
|
|
33
|
+
return startLocation.distanceTo(endLocation);
|
|
34
|
+
}
|
|
35
|
+
export function getDistanceBetweenTileAndPoint(tile, vector) {
|
|
36
|
+
// TODO: Remove this now we have Vector2s.
|
|
37
|
+
return new Vector2(tile.rx, tile.ry).distanceTo(vector);
|
|
38
|
+
}
|
|
39
|
+
export function getDistanceBetweenUnits(unit1, unit2) {
|
|
40
|
+
return new Vector2(unit1.tile.rx, unit1.tile.ry).distanceTo(new Vector2(unit2.tile.rx, unit2.tile.ry));
|
|
41
|
+
}
|
|
42
|
+
export function getDistanceBetween(unit, point) {
|
|
43
|
+
return getDistanceBetweenPoints(new Vector2(unit.tile.rx, unit.tile.ry), point);
|
|
44
|
+
}
|
|
45
45
|
//# sourceMappingURL=map.js.map
|