@supalosa/chronodivide-bot 0.5.4 → 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.
Files changed (124) hide show
  1. package/.env.template +4 -4
  2. package/.github/workflows/npm-publish.yml +24 -0
  3. package/README.md +108 -103
  4. package/dist/bot/bot.js +105 -105
  5. package/dist/bot/logic/awareness.js +136 -136
  6. package/dist/bot/logic/building/antiAirStaticDefence.js +42 -42
  7. package/dist/bot/logic/building/antiGroundStaticDefence.js +34 -34
  8. package/dist/bot/logic/building/{ArtilleryUnit.js → artilleryUnit.js} +18 -18
  9. package/dist/bot/logic/building/basicAirUnit.js +19 -19
  10. package/dist/bot/logic/building/basicBuilding.js +26 -26
  11. package/dist/bot/logic/building/basicGroundUnit.js +19 -19
  12. package/dist/bot/logic/building/buildingRules.js +175 -175
  13. package/dist/bot/logic/building/common.js +19 -19
  14. package/dist/bot/logic/building/harvester.js +16 -16
  15. package/dist/bot/logic/building/powerPlant.js +20 -20
  16. package/dist/bot/logic/building/queueController.js +183 -183
  17. package/dist/bot/logic/building/resourceCollectionBuilding.js +36 -36
  18. package/dist/bot/logic/common/scout.js +126 -126
  19. package/dist/bot/logic/common/utils.js +95 -95
  20. package/dist/bot/logic/composition/alliedCompositions.js +12 -12
  21. package/dist/bot/logic/composition/common.js +1 -1
  22. package/dist/bot/logic/composition/sovietCompositions.js +12 -12
  23. package/dist/bot/logic/map/map.js +44 -44
  24. package/dist/bot/logic/map/sector.js +137 -137
  25. package/dist/bot/logic/mission/actionBatcher.js +91 -91
  26. package/dist/bot/logic/mission/mission.js +122 -122
  27. package/dist/bot/logic/mission/missionController.js +321 -321
  28. package/dist/bot/logic/mission/missionFactories.js +12 -12
  29. package/dist/bot/logic/mission/missions/attackMission.js +214 -214
  30. package/dist/bot/logic/mission/missions/defenceMission.js +82 -82
  31. package/dist/bot/logic/mission/missions/engineerMission.js +63 -63
  32. package/dist/bot/logic/mission/missions/expansionMission.js +60 -60
  33. package/dist/bot/logic/mission/missions/retreatMission.js +33 -33
  34. package/dist/bot/logic/mission/missions/scoutingMission.js +133 -133
  35. package/dist/bot/logic/mission/missions/squads/combatSquad.js +115 -115
  36. package/dist/bot/logic/mission/missions/squads/common.js +57 -57
  37. package/dist/bot/logic/mission/missions/squads/squad.js +1 -1
  38. package/dist/bot/logic/threat/threat.js +22 -22
  39. package/dist/bot/logic/threat/threatCalculator.js +73 -73
  40. package/dist/exampleBot.js +100 -100
  41. package/package.json +32 -29
  42. package/src/bot/bot.ts +161 -161
  43. package/src/bot/logic/awareness.ts +245 -245
  44. package/src/bot/logic/building/antiAirStaticDefence.ts +64 -64
  45. package/src/bot/logic/building/antiGroundStaticDefence.ts +55 -55
  46. package/src/bot/logic/building/artilleryUnit.ts +39 -39
  47. package/src/bot/logic/building/basicAirUnit.ts +39 -39
  48. package/src/bot/logic/building/basicBuilding.ts +49 -49
  49. package/src/bot/logic/building/basicGroundUnit.ts +39 -39
  50. package/src/bot/logic/building/buildingRules.ts +250 -250
  51. package/src/bot/logic/building/common.ts +21 -21
  52. package/src/bot/logic/building/harvester.ts +31 -31
  53. package/src/bot/logic/building/powerPlant.ts +32 -32
  54. package/src/bot/logic/building/queueController.ts +297 -297
  55. package/src/bot/logic/building/resourceCollectionBuilding.ts +52 -52
  56. package/src/bot/logic/common/scout.ts +183 -183
  57. package/src/bot/logic/common/utils.ts +120 -120
  58. package/src/bot/logic/composition/alliedCompositions.ts +22 -22
  59. package/src/bot/logic/composition/common.ts +3 -3
  60. package/src/bot/logic/composition/sovietCompositions.ts +21 -21
  61. package/src/bot/logic/map/map.ts +66 -66
  62. package/src/bot/logic/map/sector.ts +174 -174
  63. package/src/bot/logic/mission/actionBatcher.ts +124 -124
  64. package/src/bot/logic/mission/mission.ts +232 -232
  65. package/src/bot/logic/mission/missionController.ts +413 -413
  66. package/src/bot/logic/mission/missionFactories.ts +51 -51
  67. package/src/bot/logic/mission/missions/attackMission.ts +336 -336
  68. package/src/bot/logic/mission/missions/defenceMission.ts +151 -151
  69. package/src/bot/logic/mission/missions/engineerMission.ts +113 -113
  70. package/src/bot/logic/mission/missions/expansionMission.ts +104 -104
  71. package/src/bot/logic/mission/missions/retreatMission.ts +54 -54
  72. package/src/bot/logic/mission/missions/scoutingMission.ts +186 -186
  73. package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -160
  74. package/src/bot/logic/mission/missions/squads/common.ts +63 -63
  75. package/src/bot/logic/mission/missions/squads/squad.ts +19 -19
  76. package/src/bot/logic/threat/threat.ts +15 -15
  77. package/src/bot/logic/threat/threatCalculator.ts +100 -100
  78. package/src/exampleBot.ts +111 -111
  79. package/tsconfig.json +73 -73
  80. package/dist/bot/logic/awarenessImpl.js +0 -132
  81. package/dist/bot/logic/awarenessImpl.js.map +0 -1
  82. package/dist/bot/logic/building/building.js +0 -126
  83. package/dist/bot/logic/building/building.js.map +0 -1
  84. package/dist/bot/logic/mission/behaviours/combatSquad.js +0 -124
  85. package/dist/bot/logic/mission/behaviours/combatSquad.js.map +0 -1
  86. package/dist/bot/logic/mission/behaviours/common.js +0 -58
  87. package/dist/bot/logic/mission/behaviours/common.js.map +0 -1
  88. package/dist/bot/logic/mission/behaviours/engineerSquad.js +0 -39
  89. package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +0 -1
  90. package/dist/bot/logic/mission/behaviours/expansionSquad.js +0 -46
  91. package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +0 -1
  92. package/dist/bot/logic/mission/behaviours/retreatSquad.js +0 -31
  93. package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +0 -1
  94. package/dist/bot/logic/mission/behaviours/scoutingSquad.js +0 -94
  95. package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +0 -1
  96. package/dist/bot/logic/mission/missions/basicMission.js +0 -13
  97. package/dist/bot/logic/mission/missions/basicMission.js.map +0 -1
  98. package/dist/bot/logic/mission/missions/missionBehaviour.js +0 -2
  99. package/dist/bot/logic/mission/missions/missionBehaviour.js.map +0 -1
  100. package/dist/bot/logic/mission/missions/oneTimeMission.js +0 -27
  101. package/dist/bot/logic/mission/missions/oneTimeMission.js.map +0 -1
  102. package/dist/bot/logic/squad/behaviours/attackSquad.js +0 -89
  103. package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -102
  104. package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
  105. package/dist/bot/logic/squad/behaviours/common.js +0 -40
  106. package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
  107. package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -61
  108. package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -36
  109. package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
  110. package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -43
  111. package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
  112. package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -28
  113. package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
  114. package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -86
  115. package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +0 -1
  116. package/dist/bot/logic/squad/squad.js +0 -126
  117. package/dist/bot/logic/squad/squad.js.map +0 -1
  118. package/dist/bot/logic/squad/squadBehaviour.js +0 -6
  119. package/dist/bot/logic/squad/squadBehaviour.js.map +0 -1
  120. package/dist/bot/logic/squad/squadBehaviours.js +0 -7
  121. package/dist/bot/logic/squad/squadBehaviours.js.map +0 -1
  122. package/dist/bot/logic/squad/squadController.js +0 -199
  123. package/dist/bot/logic/squad/squadController.js.map +0 -1
  124. /package/dist/bot/logic/building/{ArtilleryUnit.js.map → artilleryUnit.js.map} +0 -0
@@ -1,52 +1,52 @@
1
- import { GameApi, GameMath, PlayerData, TechnoRules, Tile } from "@chronodivide/game-api";
2
- import { GlobalThreat } from "../threat/threat.js";
3
- import { BasicBuilding } from "./basicBuilding.js";
4
- import { getDefaultPlacementLocation } from "./buildingRules.js";
5
- import { Vector2 } from "three";
6
-
7
- export class ResourceCollectionBuilding extends BasicBuilding {
8
- constructor(basePriority: number, maxNeeded: number, onlyBuildWhenFloatingCreditsAmount?: number) {
9
- super(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount);
10
- }
11
-
12
- getPlacementLocation(
13
- game: GameApi,
14
- playerData: PlayerData,
15
- technoRules: TechnoRules,
16
- ): { rx: number; ry: number } | undefined {
17
- // Prefer spawning close to ore.
18
- let selectedLocation = playerData.startLocation;
19
-
20
- var closeOre: Tile | undefined;
21
- var closeOreDist: number | undefined;
22
- let allTileResourceData = game.mapApi.getAllTilesResourceData();
23
- for (let i = 0; i < allTileResourceData.length; ++i) {
24
- let tileResourceData = allTileResourceData[i];
25
- if (tileResourceData.spawnsOre) {
26
- let dist = GameMath.sqrt(
27
- (selectedLocation.x - tileResourceData.tile.rx) ** 2 +
28
- (selectedLocation.y - tileResourceData.tile.ry) ** 2,
29
- );
30
- if (closeOreDist == undefined || dist < closeOreDist) {
31
- closeOreDist = dist;
32
- closeOre = tileResourceData.tile;
33
- }
34
- }
35
- }
36
- if (closeOre) {
37
- selectedLocation = new Vector2(closeOre.rx, closeOre.ry);
38
- }
39
- return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules);
40
- }
41
-
42
- // Don't build/start selling these if we don't have any harvesters
43
- getMaxCount(
44
- game: GameApi,
45
- playerData: PlayerData,
46
- technoRules: TechnoRules,
47
- threatCache: GlobalThreat | null,
48
- ): number | null {
49
- const harvesters = game.getVisibleUnits(playerData.name, "self", (r) => r.harvester).length;
50
- return Math.max(1, harvesters * 2);
51
- }
52
- }
1
+ import { GameApi, GameMath, PlayerData, TechnoRules, Tile } from "@chronodivide/game-api";
2
+ import { GlobalThreat } from "../threat/threat.js";
3
+ import { BasicBuilding } from "./basicBuilding.js";
4
+ import { getDefaultPlacementLocation } from "./buildingRules.js";
5
+ import { Vector2 } from "three";
6
+
7
+ export class ResourceCollectionBuilding extends BasicBuilding {
8
+ constructor(basePriority: number, maxNeeded: number, onlyBuildWhenFloatingCreditsAmount?: number) {
9
+ super(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount);
10
+ }
11
+
12
+ getPlacementLocation(
13
+ game: GameApi,
14
+ playerData: PlayerData,
15
+ technoRules: TechnoRules,
16
+ ): { rx: number; ry: number } | undefined {
17
+ // Prefer spawning close to ore.
18
+ let selectedLocation = playerData.startLocation;
19
+
20
+ var closeOre: Tile | undefined;
21
+ var closeOreDist: number | undefined;
22
+ let allTileResourceData = game.mapApi.getAllTilesResourceData();
23
+ for (let i = 0; i < allTileResourceData.length; ++i) {
24
+ let tileResourceData = allTileResourceData[i];
25
+ if (tileResourceData.spawnsOre) {
26
+ let dist = GameMath.sqrt(
27
+ (selectedLocation.x - tileResourceData.tile.rx) ** 2 +
28
+ (selectedLocation.y - tileResourceData.tile.ry) ** 2,
29
+ );
30
+ if (closeOreDist == undefined || dist < closeOreDist) {
31
+ closeOreDist = dist;
32
+ closeOre = tileResourceData.tile;
33
+ }
34
+ }
35
+ }
36
+ if (closeOre) {
37
+ selectedLocation = new Vector2(closeOre.rx, closeOre.ry);
38
+ }
39
+ return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules);
40
+ }
41
+
42
+ // Don't build/start selling these if we don't have any harvesters
43
+ getMaxCount(
44
+ game: GameApi,
45
+ playerData: PlayerData,
46
+ technoRules: TechnoRules,
47
+ threatCache: GlobalThreat | null,
48
+ ): number | null {
49
+ const harvesters = game.getVisibleUnits(playerData.name, "self", (r) => r.harvester).length;
50
+ return Math.max(1, harvesters * 2);
51
+ }
52
+ }
@@ -1,183 +1,183 @@
1
- import { GameApi, GameMath, PlayerData, Vector2 } from "@chronodivide/game-api";
2
- import { Sector, SectorCache } from "../map/sector";
3
- import { DebugLogger } from "./utils";
4
- import { PriorityQueue } from "@datastructures-js/priority-queue";
5
-
6
- export const getUnseenStartingLocations = (gameApi: GameApi, playerData: PlayerData) => {
7
- const unseenStartingLocations = gameApi.mapApi.getStartingLocations().filter((startingLocation) => {
8
- if (startingLocation == playerData.startLocation) {
9
- return false;
10
- }
11
- let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
12
- return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
13
- });
14
- return unseenStartingLocations;
15
- };
16
-
17
- export class PrioritisedScoutTarget {
18
- private _targetPoint?: Vector2;
19
- private _targetSector?: Sector;
20
- private _priority: number;
21
-
22
- constructor(
23
- priority: number,
24
- target: Vector2 | Sector,
25
- private permanent: boolean = false,
26
- ) {
27
- if (target.hasOwnProperty("x") && target.hasOwnProperty("y")) {
28
- this._targetPoint = target as Vector2;
29
- } else if (target.hasOwnProperty("sectorStartPoint")) {
30
- this._targetSector = target as Sector;
31
- } else {
32
- throw new TypeError(`invalid object passed as target: ${target}`);
33
- }
34
- this._priority = priority;
35
- }
36
-
37
- get priority() {
38
- return this._priority;
39
- }
40
-
41
- asVector2() {
42
- return this._targetPoint ?? this._targetSector?.sectorStartPoint ?? null;
43
- }
44
-
45
- get targetSector() {
46
- return this._targetSector;
47
- }
48
-
49
- get isPermanent() {
50
- return this.permanent;
51
- }
52
- }
53
-
54
- const ENEMY_SPAWN_POINT_PRIORITY = 100;
55
-
56
- // Amount of sectors around the starting sector to try to scout.
57
- const NEARBY_SECTOR_STARTING_RADIUS = 2;
58
- const NEARBY_SECTOR_BASE_PRIORITY = 1000;
59
-
60
- // Amount of ticks per 'radius' to expand for scouting.
61
- const SCOUTING_RADIUS_EXPANSION_TICKS = 9000; // 10 minutes
62
-
63
- export class ScoutingManager {
64
- private scoutingQueue: PriorityQueue<PrioritisedScoutTarget>;
65
-
66
- private queuedRadius = NEARBY_SECTOR_STARTING_RADIUS;
67
-
68
- constructor(private logger: DebugLogger) {
69
- // Order by descending priority.
70
- this.scoutingQueue = new PriorityQueue(
71
- (a: PrioritisedScoutTarget, b: PrioritisedScoutTarget) => b.priority - a.priority,
72
- );
73
- }
74
-
75
- addRadiusToScout(
76
- gameApi: GameApi,
77
- centerPoint: Vector2,
78
- sectorCache: SectorCache,
79
- radius: number,
80
- startingPriority: number,
81
- ) {
82
- const { x: startX, y: startY } = centerPoint;
83
- const { width: sectorsX, height: sectorsY } = sectorCache.getSectorBounds();
84
- const startingSector = sectorCache.getSectorCoordinatesForWorldPosition(startX, startY);
85
-
86
- if (!startingSector) {
87
- return;
88
- }
89
-
90
- for (
91
- let x: number = Math.max(0, startingSector.sectorX - radius);
92
- x < Math.min(sectorsX, startingSector.sectorX + radius);
93
- ++x
94
- ) {
95
- for (
96
- let y: number = Math.max(0, startingSector.sectorY - radius);
97
- y < Math.min(sectorsY, startingSector.sectorY + radius);
98
- ++y
99
- ) {
100
- if (x === startingSector?.sectorX && y === startingSector?.sectorY) {
101
- continue;
102
- }
103
- // Make it scout closer sectors first.
104
- const distanceFactor =
105
- GameMath.pow(x - startingSector.sectorX, 2) + GameMath.pow(y - startingSector.sectorY, 2);
106
- const sector = sectorCache.getSector(x, y);
107
- if (sector) {
108
- const maybeTarget = new PrioritisedScoutTarget(startingPriority - distanceFactor, sector);
109
- const maybePoint = maybeTarget.asVector2();
110
- if (maybePoint && gameApi.mapApi.getTile(maybePoint.x, maybePoint.y)) {
111
- this.scoutingQueue.enqueue(maybeTarget);
112
- }
113
- }
114
- }
115
- }
116
- }
117
-
118
- onGameStart(gameApi: GameApi, playerData: PlayerData, sectorCache: SectorCache) {
119
- // Queue hostile starting locations with high priority and as permanent scouting candidates.
120
- gameApi.mapApi
121
- .getStartingLocations()
122
- .filter((startingLocation) => {
123
- if (startingLocation == playerData.startLocation) {
124
- return false;
125
- }
126
- let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
127
- return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
128
- })
129
- .map((tile) => new PrioritisedScoutTarget(ENEMY_SPAWN_POINT_PRIORITY, tile, true))
130
- .forEach((target) => {
131
- this.logger(`Adding ${target.asVector2()?.x},${target.asVector2()?.y} to initial scouting queue`);
132
- this.scoutingQueue.enqueue(target);
133
- });
134
-
135
- // Queue sectors near the spawn point.
136
- this.addRadiusToScout(
137
- gameApi,
138
- playerData.startLocation,
139
- sectorCache,
140
- NEARBY_SECTOR_STARTING_RADIUS,
141
- NEARBY_SECTOR_BASE_PRIORITY,
142
- );
143
- }
144
-
145
- onAiUpdate(gameApi: GameApi, playerData: PlayerData, sectorCache: SectorCache) {
146
- const currentHead = this.scoutingQueue.front();
147
- if (!currentHead) {
148
- return;
149
- }
150
- const head = currentHead.asVector2();
151
- if (!head) {
152
- this.scoutingQueue.dequeue();
153
- return;
154
- }
155
- const { x, y } = head;
156
- const tile = gameApi.mapApi.getTile(x, y);
157
- if (tile && gameApi.mapApi.isVisibleTile(tile, playerData.name)) {
158
- this.logger(`head point is visible, dequeueing`);
159
- this.scoutingQueue.dequeue();
160
- }
161
-
162
- const requiredRadius = Math.floor(gameApi.getCurrentTick() / SCOUTING_RADIUS_EXPANSION_TICKS);
163
- if (requiredRadius > this.queuedRadius) {
164
- this.logger(`expanding scouting radius from ${this.queuedRadius} to ${requiredRadius}`);
165
- this.addRadiusToScout(
166
- gameApi,
167
- playerData.startLocation,
168
- sectorCache,
169
- requiredRadius,
170
- NEARBY_SECTOR_BASE_PRIORITY,
171
- );
172
- this.queuedRadius = requiredRadius;
173
- }
174
- }
175
-
176
- getNewScoutTarget() {
177
- return this.scoutingQueue.dequeue();
178
- }
179
-
180
- hasScoutTargets() {
181
- return !this.scoutingQueue.isEmpty();
182
- }
183
- }
1
+ import { GameApi, GameMath, PlayerData, Vector2 } from "@chronodivide/game-api";
2
+ import { Sector, SectorCache } from "../map/sector";
3
+ import { DebugLogger } from "./utils";
4
+ import { PriorityQueue } from "@datastructures-js/priority-queue";
5
+
6
+ export const getUnseenStartingLocations = (gameApi: GameApi, playerData: PlayerData) => {
7
+ const unseenStartingLocations = gameApi.mapApi.getStartingLocations().filter((startingLocation) => {
8
+ if (startingLocation == playerData.startLocation) {
9
+ return false;
10
+ }
11
+ let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
12
+ return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
13
+ });
14
+ return unseenStartingLocations;
15
+ };
16
+
17
+ export class PrioritisedScoutTarget {
18
+ private _targetPoint?: Vector2;
19
+ private _targetSector?: Sector;
20
+ private _priority: number;
21
+
22
+ constructor(
23
+ priority: number,
24
+ target: Vector2 | Sector,
25
+ private permanent: boolean = false,
26
+ ) {
27
+ if (target.hasOwnProperty("x") && target.hasOwnProperty("y")) {
28
+ this._targetPoint = target as Vector2;
29
+ } else if (target.hasOwnProperty("sectorStartPoint")) {
30
+ this._targetSector = target as Sector;
31
+ } else {
32
+ throw new TypeError(`invalid object passed as target: ${target}`);
33
+ }
34
+ this._priority = priority;
35
+ }
36
+
37
+ get priority() {
38
+ return this._priority;
39
+ }
40
+
41
+ asVector2() {
42
+ return this._targetPoint ?? this._targetSector?.sectorStartPoint ?? null;
43
+ }
44
+
45
+ get targetSector() {
46
+ return this._targetSector;
47
+ }
48
+
49
+ get isPermanent() {
50
+ return this.permanent;
51
+ }
52
+ }
53
+
54
+ const ENEMY_SPAWN_POINT_PRIORITY = 100;
55
+
56
+ // Amount of sectors around the starting sector to try to scout.
57
+ const NEARBY_SECTOR_STARTING_RADIUS = 2;
58
+ const NEARBY_SECTOR_BASE_PRIORITY = 1000;
59
+
60
+ // Amount of ticks per 'radius' to expand for scouting.
61
+ const SCOUTING_RADIUS_EXPANSION_TICKS = 9000; // 10 minutes
62
+
63
+ export class ScoutingManager {
64
+ private scoutingQueue: PriorityQueue<PrioritisedScoutTarget>;
65
+
66
+ private queuedRadius = NEARBY_SECTOR_STARTING_RADIUS;
67
+
68
+ constructor(private logger: DebugLogger) {
69
+ // Order by descending priority.
70
+ this.scoutingQueue = new PriorityQueue(
71
+ (a: PrioritisedScoutTarget, b: PrioritisedScoutTarget) => b.priority - a.priority,
72
+ );
73
+ }
74
+
75
+ addRadiusToScout(
76
+ gameApi: GameApi,
77
+ centerPoint: Vector2,
78
+ sectorCache: SectorCache,
79
+ radius: number,
80
+ startingPriority: number,
81
+ ) {
82
+ const { x: startX, y: startY } = centerPoint;
83
+ const { width: sectorsX, height: sectorsY } = sectorCache.getSectorBounds();
84
+ const startingSector = sectorCache.getSectorCoordinatesForWorldPosition(startX, startY);
85
+
86
+ if (!startingSector) {
87
+ return;
88
+ }
89
+
90
+ for (
91
+ let x: number = Math.max(0, startingSector.sectorX - radius);
92
+ x < Math.min(sectorsX, startingSector.sectorX + radius);
93
+ ++x
94
+ ) {
95
+ for (
96
+ let y: number = Math.max(0, startingSector.sectorY - radius);
97
+ y < Math.min(sectorsY, startingSector.sectorY + radius);
98
+ ++y
99
+ ) {
100
+ if (x === startingSector?.sectorX && y === startingSector?.sectorY) {
101
+ continue;
102
+ }
103
+ // Make it scout closer sectors first.
104
+ const distanceFactor =
105
+ GameMath.pow(x - startingSector.sectorX, 2) + GameMath.pow(y - startingSector.sectorY, 2);
106
+ const sector = sectorCache.getSector(x, y);
107
+ if (sector) {
108
+ const maybeTarget = new PrioritisedScoutTarget(startingPriority - distanceFactor, sector);
109
+ const maybePoint = maybeTarget.asVector2();
110
+ if (maybePoint && gameApi.mapApi.getTile(maybePoint.x, maybePoint.y)) {
111
+ this.scoutingQueue.enqueue(maybeTarget);
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+
118
+ onGameStart(gameApi: GameApi, playerData: PlayerData, sectorCache: SectorCache) {
119
+ // Queue hostile starting locations with high priority and as permanent scouting candidates.
120
+ gameApi.mapApi
121
+ .getStartingLocations()
122
+ .filter((startingLocation) => {
123
+ if (startingLocation == playerData.startLocation) {
124
+ return false;
125
+ }
126
+ let tile = gameApi.mapApi.getTile(startingLocation.x, startingLocation.y);
127
+ return tile ? !gameApi.mapApi.isVisibleTile(tile, playerData.name) : false;
128
+ })
129
+ .map((tile) => new PrioritisedScoutTarget(ENEMY_SPAWN_POINT_PRIORITY, tile, true))
130
+ .forEach((target) => {
131
+ this.logger(`Adding ${target.asVector2()?.x},${target.asVector2()?.y} to initial scouting queue`);
132
+ this.scoutingQueue.enqueue(target);
133
+ });
134
+
135
+ // Queue sectors near the spawn point.
136
+ this.addRadiusToScout(
137
+ gameApi,
138
+ playerData.startLocation,
139
+ sectorCache,
140
+ NEARBY_SECTOR_STARTING_RADIUS,
141
+ NEARBY_SECTOR_BASE_PRIORITY,
142
+ );
143
+ }
144
+
145
+ onAiUpdate(gameApi: GameApi, playerData: PlayerData, sectorCache: SectorCache) {
146
+ const currentHead = this.scoutingQueue.front();
147
+ if (!currentHead) {
148
+ return;
149
+ }
150
+ const head = currentHead.asVector2();
151
+ if (!head) {
152
+ this.scoutingQueue.dequeue();
153
+ return;
154
+ }
155
+ const { x, y } = head;
156
+ const tile = gameApi.mapApi.getTile(x, y);
157
+ if (tile && gameApi.mapApi.isVisibleTile(tile, playerData.name)) {
158
+ this.logger(`head point is visible, dequeueing`);
159
+ this.scoutingQueue.dequeue();
160
+ }
161
+
162
+ const requiredRadius = Math.floor(gameApi.getCurrentTick() / SCOUTING_RADIUS_EXPANSION_TICKS);
163
+ if (requiredRadius > this.queuedRadius) {
164
+ this.logger(`expanding scouting radius from ${this.queuedRadius} to ${requiredRadius}`);
165
+ this.addRadiusToScout(
166
+ gameApi,
167
+ playerData.startLocation,
168
+ sectorCache,
169
+ requiredRadius,
170
+ NEARBY_SECTOR_BASE_PRIORITY,
171
+ );
172
+ this.queuedRadius = requiredRadius;
173
+ }
174
+ }
175
+
176
+ getNewScoutTarget() {
177
+ return this.scoutingQueue.dequeue();
178
+ }
179
+
180
+ hasScoutTargets() {
181
+ return !this.scoutingQueue.isEmpty();
182
+ }
183
+ }