@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.
Files changed (134) hide show
  1. package/.env.template +4 -4
  2. package/.github/workflows/npm-publish.yml +24 -0
  3. package/README.md +108 -97
  4. package/dist/bot/bot.js +105 -105
  5. package/dist/bot/bot.js.map +1 -1
  6. package/dist/bot/logic/awareness.js +136 -136
  7. package/dist/bot/logic/building/antiAirStaticDefence.js +42 -42
  8. package/dist/bot/logic/building/antiGroundStaticDefence.js +34 -30
  9. package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -1
  10. package/dist/bot/logic/building/{ArtilleryUnit.js → artilleryUnit.js} +18 -18
  11. package/dist/bot/logic/building/basicAirUnit.js +19 -19
  12. package/dist/bot/logic/building/basicBuilding.js +26 -26
  13. package/dist/bot/logic/building/basicGroundUnit.js +19 -19
  14. package/dist/bot/logic/building/buildingRules.js +175 -174
  15. package/dist/bot/logic/building/buildingRules.js.map +1 -1
  16. package/dist/bot/logic/building/common.js +19 -18
  17. package/dist/bot/logic/building/common.js.map +1 -1
  18. package/dist/bot/logic/building/harvester.js +16 -16
  19. package/dist/bot/logic/building/powerPlant.js +20 -20
  20. package/dist/bot/logic/building/queueController.js +183 -183
  21. package/dist/bot/logic/building/resourceCollectionBuilding.js +36 -36
  22. package/dist/bot/logic/common/scout.js +126 -126
  23. package/dist/bot/logic/common/utils.js +95 -85
  24. package/dist/bot/logic/common/utils.js.map +1 -1
  25. package/dist/bot/logic/composition/alliedCompositions.js +12 -12
  26. package/dist/bot/logic/composition/common.js +1 -1
  27. package/dist/bot/logic/composition/sovietCompositions.js +12 -12
  28. package/dist/bot/logic/map/map.js +44 -44
  29. package/dist/bot/logic/map/sector.js +137 -137
  30. package/dist/bot/logic/mission/actionBatcher.js +91 -91
  31. package/dist/bot/logic/mission/mission.js +122 -122
  32. package/dist/bot/logic/mission/missionController.js +321 -321
  33. package/dist/bot/logic/mission/missionFactories.js +12 -12
  34. package/dist/bot/logic/mission/missions/attackMission.js +214 -214
  35. package/dist/bot/logic/mission/missions/defenceMission.js +82 -82
  36. package/dist/bot/logic/mission/missions/engineerMission.js +63 -63
  37. package/dist/bot/logic/mission/missions/expansionMission.js +60 -60
  38. package/dist/bot/logic/mission/missions/retreatMission.js +33 -33
  39. package/dist/bot/logic/mission/missions/scoutingMission.js +133 -133
  40. package/dist/bot/logic/mission/missions/squads/combatSquad.js +115 -115
  41. package/dist/bot/logic/mission/missions/squads/common.js +57 -57
  42. package/dist/bot/logic/mission/missions/squads/squad.js +1 -1
  43. package/dist/bot/logic/threat/threat.js +22 -22
  44. package/dist/bot/logic/threat/threatCalculator.js +73 -73
  45. package/dist/exampleBot.js +100 -112
  46. package/dist/exampleBot.js.map +1 -1
  47. package/package.json +32 -29
  48. package/src/bot/bot.ts +161 -161
  49. package/src/bot/logic/awareness.ts +245 -245
  50. package/src/bot/logic/building/antiAirStaticDefence.ts +64 -64
  51. package/src/bot/logic/building/antiGroundStaticDefence.ts +55 -51
  52. package/src/bot/logic/building/artilleryUnit.ts +39 -39
  53. package/src/bot/logic/building/basicAirUnit.ts +39 -39
  54. package/src/bot/logic/building/basicBuilding.ts +49 -49
  55. package/src/bot/logic/building/basicGroundUnit.ts +39 -39
  56. package/src/bot/logic/building/buildingRules.ts +250 -247
  57. package/src/bot/logic/building/common.ts +21 -23
  58. package/src/bot/logic/building/harvester.ts +31 -31
  59. package/src/bot/logic/building/powerPlant.ts +32 -32
  60. package/src/bot/logic/building/queueController.ts +297 -297
  61. package/src/bot/logic/building/resourceCollectionBuilding.ts +52 -52
  62. package/src/bot/logic/common/scout.ts +183 -183
  63. package/src/bot/logic/common/utils.ts +120 -112
  64. package/src/bot/logic/composition/alliedCompositions.ts +22 -22
  65. package/src/bot/logic/composition/common.ts +3 -3
  66. package/src/bot/logic/composition/sovietCompositions.ts +21 -21
  67. package/src/bot/logic/map/map.ts +66 -66
  68. package/src/bot/logic/map/sector.ts +174 -174
  69. package/src/bot/logic/mission/actionBatcher.ts +124 -124
  70. package/src/bot/logic/mission/mission.ts +232 -232
  71. package/src/bot/logic/mission/missionController.ts +413 -413
  72. package/src/bot/logic/mission/missionFactories.ts +51 -51
  73. package/src/bot/logic/mission/missions/attackMission.ts +336 -336
  74. package/src/bot/logic/mission/missions/defenceMission.ts +151 -151
  75. package/src/bot/logic/mission/missions/engineerMission.ts +113 -113
  76. package/src/bot/logic/mission/missions/expansionMission.ts +104 -104
  77. package/src/bot/logic/mission/missions/retreatMission.ts +54 -54
  78. package/src/bot/logic/mission/missions/scoutingMission.ts +186 -186
  79. package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -160
  80. package/src/bot/logic/mission/missions/squads/common.ts +63 -63
  81. package/src/bot/logic/mission/missions/squads/squad.ts +19 -19
  82. package/src/bot/logic/threat/threatCalculator.ts +100 -100
  83. package/src/exampleBot.ts +111 -124
  84. package/tsconfig.json +73 -73
  85. package/dist/bot/logic/building/building.js +0 -82
  86. package/dist/bot/logic/building/massedAntiGroundUnit.js +0 -20
  87. package/dist/bot/logic/building/queues.js +0 -19
  88. package/dist/bot/logic/knowledge.js +0 -1
  89. package/dist/bot/logic/mission/basicMission.js +0 -26
  90. package/dist/bot/logic/mission/behaviours/combatSquad.js +0 -124
  91. package/dist/bot/logic/mission/behaviours/combatSquad.js.map +0 -1
  92. package/dist/bot/logic/mission/behaviours/common.js +0 -56
  93. package/dist/bot/logic/mission/behaviours/common.js.map +0 -1
  94. package/dist/bot/logic/mission/behaviours/engineerSquad.js +0 -39
  95. package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +0 -1
  96. package/dist/bot/logic/mission/behaviours/expansionSquad.js +0 -46
  97. package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +0 -1
  98. package/dist/bot/logic/mission/behaviours/retreatSquad.js +0 -31
  99. package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +0 -1
  100. package/dist/bot/logic/mission/behaviours/scoutingSquad.js +0 -94
  101. package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +0 -1
  102. package/dist/bot/logic/mission/expansionMission.js +0 -32
  103. package/dist/bot/logic/mission/missions/basicMission.js +0 -13
  104. package/dist/bot/logic/mission/missions/basicMission.js.map +0 -1
  105. package/dist/bot/logic/mission/missions/missionBehaviour.js +0 -2
  106. package/dist/bot/logic/mission/missions/missionBehaviour.js.map +0 -1
  107. package/dist/bot/logic/mission/missions/oneTimeMission.js +0 -27
  108. package/dist/bot/logic/mission/missions/oneTimeMission.js.map +0 -1
  109. package/dist/bot/logic/squad/behaviours/actionBatcher.js +0 -36
  110. package/dist/bot/logic/squad/behaviours/actionBatcher.js.map +0 -1
  111. package/dist/bot/logic/squad/behaviours/attackSquad.js +0 -82
  112. package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -106
  113. package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
  114. package/dist/bot/logic/squad/behaviours/common.js +0 -55
  115. package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
  116. package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -48
  117. package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -38
  118. package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
  119. package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -45
  120. package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
  121. package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -31
  122. package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
  123. package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -93
  124. package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +0 -1
  125. package/dist/bot/logic/squad/behaviours/squadExpansion.js +0 -31
  126. package/dist/bot/logic/squad/behaviours/squadScouters.js +0 -8
  127. package/dist/bot/logic/squad/squad.js +0 -126
  128. package/dist/bot/logic/squad/squad.js.map +0 -1
  129. package/dist/bot/logic/squad/squadBehaviour.js +0 -6
  130. package/dist/bot/logic/squad/squadBehaviour.js.map +0 -1
  131. package/dist/bot/logic/squad/squadBehaviours.js +0 -7
  132. package/dist/bot/logic/squad/squadBehaviours.js.map +0 -1
  133. package/dist/bot/logic/squad/squadController.js +0 -215
  134. 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
- const SOVIET_COUNTRY_NAMES = ["Africans", "Arabs", "Confederation", "Russians"];
2
- export const isSoviet = (countryName) => SOVIET_COUNTRY_NAMES.includes(countryName);
3
- export const isOwnedByNeutral = (unitData) => unitData?.owner === "@@NEUTRAL@@";
4
- // Return if the given unit would have .isSelectableCombatant = true.
5
- // Usable on GameObjectData (which is faster to get than TechnoRules)
6
- export const isSelectableCombatant = (rules) => !!rules?.rules?.isSelectableCombatant;
7
- // Thanks use-strict!
8
- export function formatTimeDuration(timeSeconds, skipZeroHours = false) {
9
- let h = Math.floor(timeSeconds / 3600);
10
- timeSeconds -= h * 3600;
11
- let m = Math.floor(timeSeconds / 60);
12
- timeSeconds -= m * 60;
13
- let s = Math.floor(timeSeconds);
14
- return [...(h || !skipZeroHours ? [h] : []), pad(m, "00"), pad(s, "00")].join(":");
15
- }
16
- export function pad(n, format = "0000") {
17
- let str = "" + n;
18
- return format.substring(0, format.length - str.length) + str;
19
- }
20
- // So we don't need lodash
21
- export function minBy(array, predicate) {
22
- if (array.length === 0) {
23
- return null;
24
- }
25
- let minIdx = 0;
26
- let minVal = predicate(array[0]);
27
- for (let i = 1; i < array.length; ++i) {
28
- const newVal = predicate(array[i]);
29
- if (minVal === null || (newVal !== null && newVal < minVal)) {
30
- minIdx = i;
31
- minVal = newVal;
32
- }
33
- }
34
- return array[minIdx];
35
- }
36
- export function maxBy(array, predicate) {
37
- if (array.length === 0) {
38
- return null;
39
- }
40
- let maxIdx = 0;
41
- let maxVal = predicate(array[0]);
42
- for (let i = 1; i < array.length; ++i) {
43
- const newVal = predicate(array[i]);
44
- if (maxVal === null || (newVal !== null && newVal > maxVal)) {
45
- maxIdx = i;
46
- maxVal = newVal;
47
- }
48
- }
49
- return array[maxIdx];
50
- }
51
- export function uniqBy(array, predicate) {
52
- return Object.values(array.reduce((prev, newVal) => {
53
- const val = predicate(newVal);
54
- if (!prev[val]) {
55
- prev[val] = newVal;
56
- }
57
- return prev;
58
- }, {}));
59
- }
60
- export function countBy(array, predicate) {
61
- return array.reduce((prev, newVal) => {
62
- const val = predicate(newVal);
63
- if (val === undefined) {
64
- return prev;
65
- }
66
- if (!prev[val]) {
67
- prev[val] = 0;
68
- }
69
- prev[val] = prev[val] + 1;
70
- return prev;
71
- }, {});
72
- }
73
- export function groupBy(array, predicate) {
74
- return array.reduce((prev, newVal) => {
75
- const val = predicate(newVal);
76
- if (val === undefined) {
77
- return prev;
78
- }
79
- if (!prev.hasOwnProperty(val)) {
80
- prev[val] = [];
81
- }
82
- prev[val].push(newVal);
83
- return prev;
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":"AAIA,MAAM,oBAAoB,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC;AAEhF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAAmB,EAAE,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAE5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAA8B,EAAE,EAAE,CAAC,QAAQ,EAAE,KAAK,KAAK,aAAa,CAAC;AAEtG,qEAAqE;AACrE,qEAAqE;AACrE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAiC,EAAE,EAAE,CACvE,CAAC,CAAE,KAAK,EAAE,KAAa,EAAE,qBAAqB,CAAC;AAEnD,qBAAqB;AACrB,MAAM,UAAU,kBAAkB,CAAC,WAAmB,EAAE,aAAa,GAAG,KAAK;IACzE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACvC,WAAW,IAAI,CAAC,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC;IACrC,WAAW,IAAI,CAAC,GAAG,EAAE,CAAC;IACtB,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAEhC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAA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K,CAAC,MAAM,CACf,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;QACb,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,GAAG,KAAK,SAAS,EAAE;YACnB,OAAO,IAAI,CAAC;SACf;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACZ,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACjB;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IAChB,CAAC,EACD,EAA4B,CAC/B,CAAC;AACN,CAAC;AAED,MAAM,UAAU,OAAO,CAAsB,KAAU,EAAE,SAAwB;IAC7E,OAAO,KAAK,CAAC,MAAM,CACf,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;QACb,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,GAAG,KAAK,SAAS,EAAE;YACnB,OAAO,IAAI,CAAC;SACf;QACD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;SAClB;QACD,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC,EACD,EAAoB,CACvB,CAAC;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