@supalosa/chronodivide-bot 0.2.1 → 0.2.2-a
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 +3 -3
- package/dist/bot/bot.js +7 -3
- package/dist/bot/bot.js.map +1 -0
- package/dist/bot/logic/awareness.js +12 -2
- package/dist/bot/logic/awareness.js.map +1 -0
- package/dist/bot/logic/building/ArtilleryUnit.js +29 -8
- package/dist/bot/logic/building/antiGroundStaticDefence.js +3 -2
- package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -0
- package/dist/bot/logic/building/artilleryUnit.js.map +1 -0
- package/dist/bot/logic/building/basicAirUnit.js +2 -1
- package/dist/bot/logic/building/basicAirUnit.js.map +1 -0
- package/dist/bot/logic/building/basicBuilding.js +2 -1
- package/dist/bot/logic/building/basicBuilding.js.map +1 -0
- package/dist/bot/logic/building/basicGroundUnit.js +2 -1
- package/dist/bot/logic/building/basicGroundUnit.js.map +1 -0
- package/dist/bot/logic/building/buildingRules.js +168 -0
- package/dist/bot/logic/building/buildingRules.js.map +1 -0
- package/dist/bot/logic/building/harvester.js +1 -0
- package/dist/bot/logic/building/harvester.js.map +1 -0
- package/dist/bot/logic/building/powerPlant.js +2 -1
- package/dist/bot/logic/building/powerPlant.js.map +1 -0
- package/dist/bot/logic/building/queueController.js +2 -1
- package/dist/bot/logic/building/queueController.js.map +1 -0
- package/dist/bot/logic/building/resourceCollectionBuilding.js +2 -1
- package/dist/bot/logic/building/resourceCollectionBuilding.js.map +1 -0
- package/dist/bot/logic/common/scout.js +100 -0
- package/dist/bot/logic/common/scout.js.map +1 -0
- package/dist/bot/logic/common/utils.js +14 -0
- package/dist/bot/logic/common/utils.js.map +1 -0
- package/dist/bot/logic/map/map.js +9 -25
- package/dist/bot/logic/map/map.js.map +1 -0
- package/dist/bot/logic/map/sector.js +33 -1
- package/dist/bot/logic/map/sector.js.map +1 -0
- package/dist/bot/logic/mission/mission.js +3 -1
- package/dist/bot/logic/mission/mission.js.map +1 -0
- package/dist/bot/logic/mission/missionController.js +3 -2
- package/dist/bot/logic/mission/missionController.js.map +1 -0
- package/dist/bot/logic/mission/missionFactories.js +3 -0
- package/dist/bot/logic/mission/missionFactories.js.map +1 -0
- package/dist/bot/logic/mission/missions/attackMission.js +8 -7
- package/dist/bot/logic/mission/missions/attackMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/defenceMission.js +11 -6
- package/dist/bot/logic/mission/missions/defenceMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/engineerMission.js +34 -0
- package/dist/bot/logic/mission/missions/engineerMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/expansionMission.js +5 -4
- package/dist/bot/logic/mission/missions/expansionMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/oneTimeMission.js +3 -2
- package/dist/bot/logic/mission/missions/oneTimeMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/retreatMission.js +3 -2
- package/dist/bot/logic/mission/missions/retreatMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/scoutingMission.js +8 -9
- package/dist/bot/logic/mission/missions/scoutingMission.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/combatSquad.js +19 -17
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/common.js +20 -2
- package/dist/bot/logic/squad/behaviours/common.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/engineerSquad.js +36 -0
- package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/expansionSquad.js +1 -0
- package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/retreatSquad.js +1 -0
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +66 -18
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +1 -0
- package/dist/bot/logic/squad/squad.js +4 -5
- package/dist/bot/logic/squad/squad.js.map +1 -0
- package/dist/bot/logic/squad/squadBehaviour.js +1 -0
- package/dist/bot/logic/squad/squadBehaviour.js.map +1 -0
- package/dist/bot/logic/squad/squadBehaviours.js +1 -0
- package/dist/bot/logic/squad/squadBehaviours.js.map +1 -0
- package/dist/bot/logic/squad/squadController.js +58 -18
- package/dist/bot/logic/squad/squadController.js.map +1 -0
- package/dist/bot/logic/threat/threat.js +1 -0
- package/dist/bot/logic/threat/threat.js.map +1 -0
- package/dist/bot/logic/threat/threatCalculator.js +1 -0
- package/dist/bot/logic/threat/threatCalculator.js.map +1 -0
- package/dist/exampleBot.js +7 -6
- package/dist/exampleBot.js.map +1 -0
- package/package.json +15 -7
- package/src/bot/bot.ts +10 -7
- package/src/bot/logic/awareness.ts +21 -4
- package/src/bot/logic/building/antiGroundStaticDefence.ts +60 -60
- package/src/bot/logic/building/artilleryUnit.ts +68 -0
- package/src/bot/logic/building/basicAirUnit.ts +68 -68
- package/src/bot/logic/building/basicBuilding.ts +47 -47
- package/src/bot/logic/building/basicGroundUnit.ts +1 -1
- package/src/bot/logic/building/buildingRules.ts +233 -0
- package/src/bot/logic/building/powerPlant.ts +32 -32
- package/src/bot/logic/building/queueController.ts +1 -1
- package/src/bot/logic/building/resourceCollectionBuilding.ts +56 -56
- package/src/bot/logic/common/scout.ts +127 -1
- package/src/bot/logic/common/utils.ts +17 -0
- package/src/bot/logic/map/map.ts +70 -84
- package/src/bot/logic/map/sector.ts +46 -4
- package/src/bot/logic/mission/mission.ts +2 -2
- package/src/bot/logic/mission/missionController.ts +2 -3
- package/src/bot/logic/mission/missionFactories.ts +5 -0
- package/src/bot/logic/mission/missions/attackMission.ts +25 -20
- package/src/bot/logic/mission/missions/defenceMission.ts +34 -14
- package/src/bot/logic/mission/missions/engineerMission.ts +61 -0
- package/src/bot/logic/mission/missions/expansionMission.ts +6 -4
- package/src/bot/logic/mission/missions/oneTimeMission.ts +3 -2
- package/src/bot/logic/mission/missions/retreatMission.ts +3 -2
- package/src/bot/logic/mission/missions/scoutingMission.ts +9 -6
- package/src/bot/logic/squad/behaviours/combatSquad.ts +21 -17
- package/src/bot/logic/squad/behaviours/common.ts +33 -2
- package/src/bot/logic/squad/behaviours/engineerSquad.ts +53 -0
- package/src/bot/logic/squad/behaviours/scoutingSquad.ts +79 -26
- package/src/bot/logic/squad/squad.ts +4 -4
- package/src/bot/logic/squad/squadBehaviour.ts +3 -1
- package/src/bot/logic/squad/squadController.ts +89 -44
- package/src/exampleBot.ts +6 -6
- package/tsconfig.json +73 -73
- package/src/bot/logic/building/ArtilleryUnit.ts +0 -43
- package/src/bot/logic/building/building.ts +0 -127
package/src/bot/logic/map/map.ts
CHANGED
|
@@ -1,84 +1,70 @@
|
|
|
1
|
-
import { GameApi, MapApi, PlayerData, Point2D, UnitData } from "@chronodivide/game-api";
|
|
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
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
):
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return { x: candidatePointX, y: candidatePointY };
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getDistanceBetweenPoints(startLocation: Point2D, endLocation: Point2D): number {
|
|
75
|
-
return Math.sqrt((startLocation.x - endLocation.x) ** 2 + (startLocation.y - endLocation.y) ** 2);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function getDistanceBetweenUnits(unit1: UnitData, unit2: UnitData): number {
|
|
79
|
-
return getDistanceBetweenPoints({ x: unit1.tile.rx, y: unit1.tile.ry }, { x: unit2.tile.rx, y: unit2.tile.ry });
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function getDistanceBetween(unit: UnitData, point: Point2D): number {
|
|
83
|
-
return getDistanceBetweenPoints({ x: unit.tile.rx, y: unit.tile.ry }, point);
|
|
84
|
-
}
|
|
1
|
+
import { GameApi, MapApi, PlayerData, Point2D, Tile, UnitData } from "@chronodivide/game-api";
|
|
2
|
+
import maxBy from "lodash.maxby";
|
|
3
|
+
|
|
4
|
+
const MAX_WIDTH_AND_HEIGHT = 500;
|
|
5
|
+
|
|
6
|
+
// Expensive one-time call to determine the size of the map.
|
|
7
|
+
// The result is a point just outside the bounds of the map.
|
|
8
|
+
export function determineMapBounds(mapApi: MapApi): Point2D {
|
|
9
|
+
// Probably want to ask for an API change to get this.
|
|
10
|
+
// Note that the maps is not always a rectangle!
|
|
11
|
+
const zeroTile = { rx: 0, ry: 0 } as Tile;
|
|
12
|
+
const allTiles = mapApi.getTilesInRect(zeroTile, { width: MAX_WIDTH_AND_HEIGHT, height: MAX_WIDTH_AND_HEIGHT });
|
|
13
|
+
|
|
14
|
+
const maxX = maxBy(allTiles, (tile) => tile.rx)?.rx!;
|
|
15
|
+
const maxY = maxBy(allTiles, (tile) => tile.ry)?.ry!;
|
|
16
|
+
|
|
17
|
+
return { x: maxX, y: maxY };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function calculateAreaVisibility(
|
|
21
|
+
mapApi: MapApi,
|
|
22
|
+
playerData: PlayerData,
|
|
23
|
+
startPoint: Point2D,
|
|
24
|
+
endPoint: Point2D,
|
|
25
|
+
): { visibleTiles: number; validTiles: number } {
|
|
26
|
+
let validTiles: number = 0,
|
|
27
|
+
visibleTiles: number = 0;
|
|
28
|
+
for (let xx = startPoint.x; xx < endPoint.x; ++xx) {
|
|
29
|
+
for (let yy = startPoint.y; yy < endPoint.y; ++yy) {
|
|
30
|
+
let tile = mapApi.getTile(xx, yy);
|
|
31
|
+
if (tile) {
|
|
32
|
+
++validTiles;
|
|
33
|
+
if (mapApi.isVisibleTile(tile, playerData.name)) {
|
|
34
|
+
++visibleTiles;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let result = { visibleTiles, validTiles };
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getPointTowardsOtherPoint(
|
|
44
|
+
gameApi: GameApi,
|
|
45
|
+
startLocation: Point2D,
|
|
46
|
+
endLocation: Point2D,
|
|
47
|
+
minRadius: number,
|
|
48
|
+
maxRadius: number,
|
|
49
|
+
randomAngle: number,
|
|
50
|
+
): Point2D {
|
|
51
|
+
let radius = minRadius + Math.round(gameApi.generateRandom() * (maxRadius - minRadius));
|
|
52
|
+
let directionToSpawn = Math.atan2(endLocation.y - startLocation.y, endLocation.x - startLocation.x);
|
|
53
|
+
let randomisedDirection =
|
|
54
|
+
directionToSpawn - (randomAngle * (Math.PI / 12) + 2 * randomAngle * gameApi.generateRandom() * (Math.PI / 12));
|
|
55
|
+
let candidatePointX = Math.round(startLocation.x + Math.cos(randomisedDirection) * radius);
|
|
56
|
+
let candidatePointY = Math.round(startLocation.y + Math.sin(randomisedDirection) * radius);
|
|
57
|
+
return { x: candidatePointX, y: candidatePointY };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getDistanceBetweenPoints(startLocation: Point2D, endLocation: Point2D): number {
|
|
61
|
+
return Math.sqrt((startLocation.x - endLocation.x) ** 2 + (startLocation.y - endLocation.y) ** 2);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function getDistanceBetweenUnits(unit1: UnitData, unit2: UnitData): number {
|
|
65
|
+
return getDistanceBetweenPoints({ x: unit1.tile.rx, y: unit1.tile.ry }, { x: unit2.tile.rx, y: unit2.tile.ry });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getDistanceBetween(unit: UnitData, point: Point2D): number {
|
|
69
|
+
return getDistanceBetweenPoints({ x: unit.tile.rx, y: unit.tile.ry }, point);
|
|
70
|
+
}
|
|
@@ -6,12 +6,36 @@ import { calculateAreaVisibility } from "./map.js";
|
|
|
6
6
|
export const SECTOR_SIZE = 8;
|
|
7
7
|
|
|
8
8
|
export class Sector {
|
|
9
|
+
// How many times we've attempted to enter the sector.
|
|
10
|
+
private sectorExploreAttempts: number;
|
|
11
|
+
private sectorLastExploredAt: number | undefined;
|
|
12
|
+
|
|
9
13
|
constructor(
|
|
10
14
|
public sectorStartPoint: Point2D,
|
|
11
15
|
public sectorStartTile: Tile | undefined,
|
|
12
16
|
public sectorVisibilityPct: number | undefined,
|
|
13
|
-
public sectorVisibilityLastCheckTick: number | undefined
|
|
14
|
-
) {
|
|
17
|
+
public sectorVisibilityLastCheckTick: number | undefined,
|
|
18
|
+
) {
|
|
19
|
+
this.sectorExploreAttempts = 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public onExploreAttempted(currentTick: number) {
|
|
23
|
+
this.sectorExploreAttempts++;
|
|
24
|
+
this.sectorLastExploredAt = currentTick;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Whether we should attempt to explore this sector, given the cooldown and limit of attempts.
|
|
28
|
+
public shouldAttemptExploration(currentTick: number, cooldown: number, limit: number) {
|
|
29
|
+
if (limit >= this.sectorExploreAttempts) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (this.sectorLastExploredAt && currentTick < this.sectorLastExploredAt + cooldown) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
15
39
|
}
|
|
16
40
|
|
|
17
41
|
export class SectorCache {
|
|
@@ -34,7 +58,7 @@ export class SectorCache {
|
|
|
34
58
|
{ x: xx * SECTOR_SIZE, y: yy * SECTOR_SIZE },
|
|
35
59
|
mapApi.getTile(xx * SECTOR_SIZE, yy * SECTOR_SIZE),
|
|
36
60
|
undefined,
|
|
37
|
-
undefined
|
|
61
|
+
undefined,
|
|
38
62
|
);
|
|
39
63
|
}
|
|
40
64
|
}
|
|
@@ -127,10 +151,28 @@ export class SectorCache {
|
|
|
127
151
|
return this.sectors[sectorX][sectorY];
|
|
128
152
|
}
|
|
129
153
|
|
|
130
|
-
public
|
|
154
|
+
public getSectorBounds(): Point2D {
|
|
155
|
+
return {
|
|
156
|
+
x: this.sectorsX,
|
|
157
|
+
y: this.sectorsY,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public getSectorCoordinatesForWorldPosition(x: number, y: number) {
|
|
131
162
|
if (x < 0 || x >= this.mapBounds.x || y < 0 || y >= this.mapBounds.y) {
|
|
132
163
|
return undefined;
|
|
133
164
|
}
|
|
165
|
+
return {
|
|
166
|
+
sectorX: Math.floor(x / SECTOR_SIZE),
|
|
167
|
+
sectorY: Math.floor(y / SECTOR_SIZE)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public getSectorForWorldPosition(x: number, y: number): Sector | undefined {
|
|
172
|
+
const sectorCoordinates = this.getSectorCoordinatesForWorldPosition(x, y);
|
|
173
|
+
if (!sectorCoordinates) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
134
176
|
return this.sectors[Math.floor(x / SECTOR_SIZE)][Math.floor(y / SECTOR_SIZE)];
|
|
135
177
|
}
|
|
136
178
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GameApi, PlayerData } from "@chronodivide/game-api";
|
|
2
2
|
import { Squad } from "../squad/squad.js";
|
|
3
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
4
3
|
import { MatchAwareness } from "../awareness.js";
|
|
4
|
+
import { DebugLogger } from "../common/utils.js";
|
|
5
5
|
|
|
6
6
|
// AI starts Missions based on heuristics, which have one or more squads.
|
|
7
7
|
// Missions can create squads (but squads will disband themselves).
|
|
@@ -11,7 +11,7 @@ export abstract class Mission<FailureReasons = undefined> {
|
|
|
11
11
|
|
|
12
12
|
private onFinish: (reason: FailureReasons, squad: Squad | null) => void = () => {};
|
|
13
13
|
|
|
14
|
-
constructor(private uniqueName: string, private priority: number
|
|
14
|
+
constructor(private uniqueName: string, private priority: number, protected logger: DebugLogger) {}
|
|
15
15
|
|
|
16
16
|
abstract onAiUpdate(gameApi: GameApi, playerData: PlayerData, matchAwareness: MatchAwareness): MissionAction;
|
|
17
17
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Meta-controller for forming and controlling squads.
|
|
2
2
|
|
|
3
3
|
import { GameApi, PlayerData } from "@chronodivide/game-api";
|
|
4
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
5
4
|
import { Mission, MissionAction, MissionActionDisband, MissionActionRegisterSquad } from "./mission.js";
|
|
6
5
|
import { SquadController } from "../squad/squadController.js";
|
|
7
6
|
import { MatchAwareness } from "../awareness.js";
|
|
@@ -70,9 +69,9 @@ export class MissionController {
|
|
|
70
69
|
|
|
71
70
|
// Create dynamic missions.
|
|
72
71
|
this.missionFactories.forEach((missionFactory) => {
|
|
73
|
-
missionFactory.maybeCreateMissions(gameApi, playerData, matchAwareness, this);
|
|
72
|
+
missionFactory.maybeCreateMissions(gameApi, playerData, matchAwareness, this, this.logger);
|
|
74
73
|
disbandedMissionsArray.forEach(({ reason, mission }) => {
|
|
75
|
-
missionFactory.onMissionFailed(gameApi, playerData, matchAwareness, mission, reason, this);
|
|
74
|
+
missionFactory.onMissionFailed(gameApi, playerData, matchAwareness, mission, reason, this, this.logger);
|
|
76
75
|
});
|
|
77
76
|
});
|
|
78
77
|
}
|
|
@@ -6,6 +6,8 @@ import { ScoutingMissionFactory } from "./missions/scoutingMission.js";
|
|
|
6
6
|
import { AttackMissionFactory } from "./missions/attackMission.js";
|
|
7
7
|
import { MissionController } from "./missionController.js";
|
|
8
8
|
import { DefenceMissionFactory } from "./missions/defenceMission.js";
|
|
9
|
+
import { DebugLogger } from "../common/utils.js";
|
|
10
|
+
import { EngineerMissionFactory } from "./missions/engineerMission.js";
|
|
9
11
|
|
|
10
12
|
export interface MissionFactory {
|
|
11
13
|
getName(): string;
|
|
@@ -23,6 +25,7 @@ export interface MissionFactory {
|
|
|
23
25
|
playerData: PlayerData,
|
|
24
26
|
matchAwareness: MatchAwareness,
|
|
25
27
|
missionController: MissionController,
|
|
28
|
+
logger: DebugLogger
|
|
26
29
|
): void;
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -35,6 +38,7 @@ export interface MissionFactory {
|
|
|
35
38
|
failedMission: Mission,
|
|
36
39
|
failureReason: any,
|
|
37
40
|
missionController: MissionController,
|
|
41
|
+
logger: DebugLogger
|
|
38
42
|
): void;
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -43,4 +47,5 @@ export const createMissionFactories = () => [
|
|
|
43
47
|
new ScoutingMissionFactory(),
|
|
44
48
|
new AttackMissionFactory(),
|
|
45
49
|
new DefenceMissionFactory(),
|
|
50
|
+
new EngineerMissionFactory(),
|
|
46
51
|
];
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OneTimeMission } from "./oneTimeMission.js";
|
|
1
|
+
import { GameApi, ObjectType, PlayerData, Point2D, UnitData } from "@chronodivide/game-api";
|
|
3
2
|
import { CombatSquad } from "../../squad/behaviours/combatSquad.js";
|
|
4
3
|
import { Mission, MissionAction, disbandMission, noop } from "../mission.js";
|
|
5
|
-
import { GlobalThreat } from "../../threat/threat.js";
|
|
6
4
|
import { Squad } from "../../squad/squad.js";
|
|
7
|
-
import { getDistanceBetweenPoints, getDistanceBetweenUnits } from "../../map/map.js";
|
|
8
5
|
import { MissionFactory } from "../missionFactories.js";
|
|
9
6
|
import { MatchAwareness } from "../../awareness.js";
|
|
10
7
|
import { MissionController } from "../missionController.js";
|
|
11
|
-
import { match } from "assert";
|
|
12
8
|
import { RetreatMission } from "./retreatMission.js";
|
|
13
|
-
import
|
|
9
|
+
import maxBy from "lodash.maxby";
|
|
10
|
+
import { DebugLogger } from "../../common/utils.js";
|
|
14
11
|
|
|
15
12
|
export enum AttackFailReason {
|
|
16
13
|
NoTargets = 0,
|
|
@@ -31,8 +28,9 @@ export class AttackMission extends Mission<AttackFailReason> {
|
|
|
31
28
|
private rallyArea: Point2D,
|
|
32
29
|
private attackArea: Point2D,
|
|
33
30
|
private radius: number,
|
|
31
|
+
logger: DebugLogger,
|
|
34
32
|
) {
|
|
35
|
-
super(uniqueName, priority);
|
|
33
|
+
super(uniqueName, priority, logger);
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
onAiUpdate(gameApi: GameApi, playerData: PlayerData, matchAwareness: MatchAwareness): MissionAction {
|
|
@@ -88,7 +86,7 @@ export class AttackMissionFactory implements MissionFactory {
|
|
|
88
86
|
.map((unitId) => gameApi.getUnitData(unitId))
|
|
89
87
|
.filter((u) => !!u && gameApi.getPlayerData(u.owner).isCombatant) as UnitData[];
|
|
90
88
|
|
|
91
|
-
const maxUnit =
|
|
89
|
+
const maxUnit = maxBy(enemyUnits, (u) => getTargetWeight(u, tryFocusHarvester));
|
|
92
90
|
if (maxUnit) {
|
|
93
91
|
return { x: maxUnit.tile.rx, y: maxUnit.tile.ry };
|
|
94
92
|
}
|
|
@@ -104,6 +102,7 @@ export class AttackMissionFactory implements MissionFactory {
|
|
|
104
102
|
playerData: PlayerData,
|
|
105
103
|
matchAwareness: MatchAwareness,
|
|
106
104
|
missionController: MissionController,
|
|
105
|
+
logger: DebugLogger,
|
|
107
106
|
): void {
|
|
108
107
|
if (!matchAwareness.shouldAttack()) {
|
|
109
108
|
return;
|
|
@@ -125,18 +124,24 @@ export class AttackMissionFactory implements MissionFactory {
|
|
|
125
124
|
const squadName = "globalAttack";
|
|
126
125
|
|
|
127
126
|
const tryAttack = missionController.addMission(
|
|
128
|
-
new AttackMission(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
new AttackMission(
|
|
128
|
+
squadName,
|
|
129
|
+
100,
|
|
130
|
+
matchAwareness.getMainRallyPoint(),
|
|
131
|
+
attackArea,
|
|
132
|
+
attackRadius,
|
|
133
|
+
logger,
|
|
134
|
+
).then((reason, squad) => {
|
|
135
|
+
missionController.addMission(
|
|
136
|
+
new RetreatMission(
|
|
137
|
+
"retreat-from-" + squadName + gameApi.getCurrentTick(),
|
|
138
|
+
100,
|
|
139
|
+
matchAwareness.getMainRallyPoint(),
|
|
140
|
+
squad?.getUnitIds() ?? [],
|
|
141
|
+
logger,
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
}),
|
|
140
145
|
);
|
|
141
146
|
if (tryAttack) {
|
|
142
147
|
this.lastAttackAt = gameApi.getCurrentTick();
|
|
@@ -6,6 +6,7 @@ import { MissionFactory } from "../missionFactories.js";
|
|
|
6
6
|
import { Squad } from "../../squad/squad.js";
|
|
7
7
|
import { CombatSquad } from "../../squad/behaviours/combatSquad.js";
|
|
8
8
|
import { RetreatMission } from "./retreatMission.js";
|
|
9
|
+
import { DebugLogger } from "../../common/utils.js";
|
|
9
10
|
|
|
10
11
|
export enum DefenceFailReason {
|
|
11
12
|
NoTargets,
|
|
@@ -22,8 +23,9 @@ export class DefenceMission extends Mission<DefenceFailReason> {
|
|
|
22
23
|
priority: number,
|
|
23
24
|
private defenceArea: Point2D,
|
|
24
25
|
private radius: number,
|
|
26
|
+
logger: DebugLogger,
|
|
25
27
|
) {
|
|
26
|
-
super(uniqueName, priority);
|
|
28
|
+
super(uniqueName, priority, logger);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
onAiUpdate(gameApi: GameApi, playerData: PlayerData, matchAwareness: MatchAwareness): MissionAction {
|
|
@@ -35,8 +37,15 @@ export class DefenceMission extends Mission<DefenceFailReason> {
|
|
|
35
37
|
const foundTargets = matchAwareness.getHostilesNearPoint2d(this.defenceArea, this.radius);
|
|
36
38
|
|
|
37
39
|
if (foundTargets.length === 0) {
|
|
40
|
+
this.logger(`(Defence Mission ${this.getUniqueName()}): No targets found, disbanding.`);
|
|
38
41
|
return disbandMission(DefenceFailReason.NoTargets);
|
|
39
42
|
} else {
|
|
43
|
+
const targetUnit = gameApi.getUnitData(foundTargets[0].unitId);
|
|
44
|
+
this.logger(
|
|
45
|
+
`(Defence Mission ${this.getUniqueName()}): Focused on target ${targetUnit?.name} (${
|
|
46
|
+
foundTargets.length
|
|
47
|
+
} found in area ${this.radius})`,
|
|
48
|
+
);
|
|
40
49
|
this.combatSquad?.setAttackArea({ x: foundTargets[0].x, y: foundTargets[0].y });
|
|
41
50
|
}
|
|
42
51
|
}
|
|
@@ -49,7 +58,7 @@ const DEFENCE_CHECK_TICKS = 30;
|
|
|
49
58
|
// Starting radius around the player's base to trigger defense.
|
|
50
59
|
const DEFENCE_STARTING_RADIUS = 10;
|
|
51
60
|
// Every game tick, we increase the defendable area by this amount.
|
|
52
|
-
const DEFENCE_RADIUS_INCREASE_PER_GAME_TICK = 0.
|
|
61
|
+
const DEFENCE_RADIUS_INCREASE_PER_GAME_TICK = 0.001;
|
|
53
62
|
|
|
54
63
|
export class DefenceMissionFactory implements MissionFactory {
|
|
55
64
|
private lastDefenceCheckAt = 0;
|
|
@@ -65,6 +74,7 @@ export class DefenceMissionFactory implements MissionFactory {
|
|
|
65
74
|
playerData: PlayerData,
|
|
66
75
|
matchAwareness: MatchAwareness,
|
|
67
76
|
missionController: MissionController,
|
|
77
|
+
logger: DebugLogger,
|
|
68
78
|
): void {
|
|
69
79
|
if (gameApi.getCurrentTick() < this.lastDefenceCheckAt + DEFENCE_CHECK_TICKS) {
|
|
70
80
|
return;
|
|
@@ -76,19 +86,29 @@ export class DefenceMissionFactory implements MissionFactory {
|
|
|
76
86
|
const enemiesNearSpawn = matchAwareness.getHostilesNearPoint2d(playerData.startLocation, defendableRadius);
|
|
77
87
|
|
|
78
88
|
if (enemiesNearSpawn.length > 0) {
|
|
89
|
+
logger(
|
|
90
|
+
`Starting defence mission, ${
|
|
91
|
+
enemiesNearSpawn.length
|
|
92
|
+
} found in radius ${defendableRadius} (tick ${gameApi.getCurrentTick()})`,
|
|
93
|
+
);
|
|
79
94
|
missionController.addMission(
|
|
80
|
-
new DefenceMission(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
new DefenceMission(
|
|
96
|
+
"globalDefence",
|
|
97
|
+
1000,
|
|
98
|
+
playerData.startLocation,
|
|
99
|
+
defendableRadius * 1.2,
|
|
100
|
+
logger,
|
|
101
|
+
).then((reason, squad) => {
|
|
102
|
+
missionController.addMission(
|
|
103
|
+
new RetreatMission(
|
|
104
|
+
"retreat-from-globalDefence" + gameApi.getCurrentTick(),
|
|
105
|
+
100,
|
|
106
|
+
matchAwareness.getMainRallyPoint(),
|
|
107
|
+
squad?.getUnitIds() ?? [],
|
|
108
|
+
logger,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
}),
|
|
92
112
|
);
|
|
93
113
|
}
|
|
94
114
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { GameApi, PlayerData } from "@chronodivide/game-api";
|
|
2
|
+
import { GlobalThreat } from "../../threat/threat.js";
|
|
3
|
+
import { Mission } from "../mission.js";
|
|
4
|
+
import { ExpansionSquad } from "../../squad/behaviours/expansionSquad.js";
|
|
5
|
+
import { MissionFactory } from "../missionFactories.js";
|
|
6
|
+
import { OneTimeMission } from "./oneTimeMission.js";
|
|
7
|
+
import { MatchAwareness } from "../../awareness.js";
|
|
8
|
+
import { MissionController } from "../missionController.js";
|
|
9
|
+
import { DebugLogger } from "../../common/utils.js";
|
|
10
|
+
import { EngineerSquad } from "../../squad/behaviours/engineerSquad.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A mission that tries to send an engineer into a building (e.g. to capture tech building or repair bridge)
|
|
14
|
+
*/
|
|
15
|
+
export class EngineerMission extends OneTimeMission {
|
|
16
|
+
constructor(uniqueName: string, priority: number, selectedTechBuilding: number,
|
|
17
|
+
logger: DebugLogger) {
|
|
18
|
+
super(uniqueName, priority, () => new EngineerSquad(selectedTechBuilding), logger);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Only try to capture tech buildings within this radius of the starting point.
|
|
23
|
+
const MAX_TECH_CAPTURE_RADIUS = 50;
|
|
24
|
+
|
|
25
|
+
const TECH_CHECK_INTERVAL_TICKS = 300;
|
|
26
|
+
|
|
27
|
+
export class EngineerMissionFactory implements MissionFactory {
|
|
28
|
+
private lastCheckAt = 0;
|
|
29
|
+
|
|
30
|
+
getName(): string {
|
|
31
|
+
return "EngineerMissionFactory";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
maybeCreateMissions(
|
|
35
|
+
gameApi: GameApi,
|
|
36
|
+
playerData: PlayerData,
|
|
37
|
+
matchAwareness: MatchAwareness,
|
|
38
|
+
missionController: MissionController,
|
|
39
|
+
logger: DebugLogger
|
|
40
|
+
): void {
|
|
41
|
+
if (!(gameApi.getCurrentTick() > this.lastCheckAt + TECH_CHECK_INTERVAL_TICKS)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.lastCheckAt = gameApi.getCurrentTick();
|
|
45
|
+
const eligibleTechBuildings = gameApi.getVisibleUnits(playerData.name, "hostile", (r) => r.capturable && r.produceCashAmount > 0);
|
|
46
|
+
|
|
47
|
+
eligibleTechBuildings.forEach((techBuildingId) => {
|
|
48
|
+
missionController.addMission(new EngineerMission("capture-" + techBuildingId, 100, techBuildingId, logger));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
onMissionFailed(
|
|
53
|
+
gameApi: GameApi,
|
|
54
|
+
playerData: PlayerData,
|
|
55
|
+
matchAwareness: MatchAwareness,
|
|
56
|
+
failedMission: Mission,
|
|
57
|
+
failureReason: undefined,
|
|
58
|
+
missionController: MissionController,
|
|
59
|
+
): void {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -5,15 +5,16 @@ import { ExpansionSquad } from "../../squad/behaviours/expansionSquad.js";
|
|
|
5
5
|
import { MissionFactory } from "../missionFactories.js";
|
|
6
6
|
import { OneTimeMission } from "./oneTimeMission.js";
|
|
7
7
|
import { MatchAwareness } from "../../awareness.js";
|
|
8
|
-
import { AttackFailReason, AttackMission } from "./attackMission.js";
|
|
9
8
|
import { MissionController } from "../missionController.js";
|
|
9
|
+
import { DebugLogger } from "../../common/utils.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A mission that tries to create an MCV (if it doesn't exist) and deploy it somewhere it can be deployed.
|
|
13
13
|
*/
|
|
14
14
|
export class ExpansionMission extends OneTimeMission {
|
|
15
|
-
constructor(uniqueName: string, priority: number, selectedMcv: number | null
|
|
16
|
-
|
|
15
|
+
constructor(uniqueName: string, priority: number, selectedMcv: number | null,
|
|
16
|
+
logger: DebugLogger) {
|
|
17
|
+
super(uniqueName, priority, () => new ExpansionSquad(selectedMcv), logger);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -27,13 +28,14 @@ export class ExpansionMissionFactory implements MissionFactory {
|
|
|
27
28
|
playerData: PlayerData,
|
|
28
29
|
matchAwareness: MatchAwareness,
|
|
29
30
|
missionController: MissionController,
|
|
31
|
+
logger: DebugLogger
|
|
30
32
|
): void {
|
|
31
33
|
// At this point, only expand if we have a loose MCV.
|
|
32
34
|
const mcvs = gameApi.getVisibleUnits(playerData.name, "self", (r) =>
|
|
33
35
|
gameApi.getGeneralRules().baseUnit.includes(r.name)
|
|
34
36
|
);
|
|
35
37
|
mcvs.forEach((mcv) => {
|
|
36
|
-
missionController.addMission(new ExpansionMission("expand-with-" + mcv, 100, mcv));
|
|
38
|
+
missionController.addMission(new ExpansionMission("expand-with-" + mcv, 100, mcv, logger));
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -6,6 +6,7 @@ import { Squad } from "../../squad/squad.js";
|
|
|
6
6
|
import { MissionFactory } from "../missionFactories.js";
|
|
7
7
|
import { SquadBehaviour } from "../../squad/squadBehaviour.js";
|
|
8
8
|
import { MatchAwareness } from "../../awareness.js";
|
|
9
|
+
import { DebugLogger } from "../../common/utils.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* A mission that gets dispatched once, and once the squad decides to disband, the mission is disbanded.
|
|
@@ -13,8 +14,8 @@ import { MatchAwareness } from "../../awareness.js";
|
|
|
13
14
|
export abstract class OneTimeMission<T = undefined> extends Mission<T> {
|
|
14
15
|
private hadSquad = false;
|
|
15
16
|
|
|
16
|
-
constructor(uniqueName: string, priority: number, private behaviourFactory: () => SquadBehaviour) {
|
|
17
|
-
super(uniqueName, priority);
|
|
17
|
+
constructor(uniqueName: string, priority: number, private behaviourFactory: () => SquadBehaviour, logger: DebugLogger) {
|
|
18
|
+
super(uniqueName, priority, logger);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
onAiUpdate(gameApi: GameApi, playerData: PlayerData, matchAwareness: MatchAwareness): MissionAction {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Point2D } from "@chronodivide/game-api";
|
|
2
2
|
import { OneTimeMission } from "./oneTimeMission.js";
|
|
3
3
|
import { RetreatSquad } from "../../squad/behaviours/retreatSquad.js";
|
|
4
|
+
import { DebugLogger } from "../../common/utils.js";
|
|
4
5
|
|
|
5
6
|
export class RetreatMission extends OneTimeMission {
|
|
6
|
-
constructor(uniqueName: string, priority: number, retreatToPoint: Point2D, unitIds: number[]) {
|
|
7
|
-
super(uniqueName, priority, () => new RetreatSquad(unitIds, retreatToPoint));
|
|
7
|
+
constructor(uniqueName: string, priority: number, retreatToPoint: Point2D, unitIds: number[], logger: DebugLogger) {
|
|
8
|
+
super(uniqueName, priority, () => new RetreatSquad(unitIds, retreatToPoint), logger);
|
|
8
9
|
}
|
|
9
10
|
}
|