@supalosa/chronodivide-bot 0.5.4 → 0.6.6-beta.1

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,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,96 +1,96 @@
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
- }
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
+ }
96
96
  //# sourceMappingURL=utils.js.map
@@ -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