@supalosa/chronodivide-bot 0.5.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.template +4 -4
- package/.github/workflows/npm-publish.yml +24 -0
- package/README.md +108 -97
- package/dist/bot/bot.js +105 -105
- package/dist/bot/bot.js.map +1 -1
- package/dist/bot/logic/awareness.js +136 -136
- package/dist/bot/logic/building/antiAirStaticDefence.js +42 -42
- package/dist/bot/logic/building/antiGroundStaticDefence.js +34 -30
- package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -1
- package/dist/bot/logic/building/{ArtilleryUnit.js → artilleryUnit.js} +18 -18
- package/dist/bot/logic/building/basicAirUnit.js +19 -19
- package/dist/bot/logic/building/basicBuilding.js +26 -26
- package/dist/bot/logic/building/basicGroundUnit.js +19 -19
- package/dist/bot/logic/building/buildingRules.js +175 -174
- package/dist/bot/logic/building/buildingRules.js.map +1 -1
- package/dist/bot/logic/building/common.js +19 -18
- package/dist/bot/logic/building/common.js.map +1 -1
- package/dist/bot/logic/building/harvester.js +16 -16
- package/dist/bot/logic/building/powerPlant.js +20 -20
- package/dist/bot/logic/building/queueController.js +183 -183
- package/dist/bot/logic/building/resourceCollectionBuilding.js +36 -36
- package/dist/bot/logic/common/scout.js +126 -126
- package/dist/bot/logic/common/utils.js +95 -85
- package/dist/bot/logic/common/utils.js.map +1 -1
- package/dist/bot/logic/composition/alliedCompositions.js +12 -12
- package/dist/bot/logic/composition/common.js +1 -1
- package/dist/bot/logic/composition/sovietCompositions.js +12 -12
- package/dist/bot/logic/map/map.js +44 -44
- package/dist/bot/logic/map/sector.js +137 -137
- package/dist/bot/logic/mission/actionBatcher.js +91 -91
- package/dist/bot/logic/mission/mission.js +122 -122
- package/dist/bot/logic/mission/missionController.js +321 -321
- package/dist/bot/logic/mission/missionFactories.js +12 -12
- package/dist/bot/logic/mission/missions/attackMission.js +214 -214
- package/dist/bot/logic/mission/missions/defenceMission.js +82 -82
- package/dist/bot/logic/mission/missions/engineerMission.js +63 -63
- package/dist/bot/logic/mission/missions/expansionMission.js +60 -60
- package/dist/bot/logic/mission/missions/retreatMission.js +33 -33
- package/dist/bot/logic/mission/missions/scoutingMission.js +133 -133
- package/dist/bot/logic/mission/missions/squads/combatSquad.js +115 -115
- package/dist/bot/logic/mission/missions/squads/common.js +57 -57
- package/dist/bot/logic/mission/missions/squads/squad.js +1 -1
- package/dist/bot/logic/threat/threat.js +22 -22
- package/dist/bot/logic/threat/threatCalculator.js +73 -73
- package/dist/exampleBot.js +100 -112
- package/dist/exampleBot.js.map +1 -1
- package/package.json +32 -29
- package/src/bot/bot.ts +161 -161
- package/src/bot/logic/awareness.ts +245 -245
- package/src/bot/logic/building/antiAirStaticDefence.ts +64 -64
- package/src/bot/logic/building/antiGroundStaticDefence.ts +55 -51
- package/src/bot/logic/building/artilleryUnit.ts +39 -39
- package/src/bot/logic/building/basicAirUnit.ts +39 -39
- package/src/bot/logic/building/basicBuilding.ts +49 -49
- package/src/bot/logic/building/basicGroundUnit.ts +39 -39
- package/src/bot/logic/building/buildingRules.ts +250 -247
- package/src/bot/logic/building/common.ts +21 -23
- package/src/bot/logic/building/harvester.ts +31 -31
- package/src/bot/logic/building/powerPlant.ts +32 -32
- package/src/bot/logic/building/queueController.ts +297 -297
- package/src/bot/logic/building/resourceCollectionBuilding.ts +52 -52
- package/src/bot/logic/common/scout.ts +183 -183
- package/src/bot/logic/common/utils.ts +120 -112
- package/src/bot/logic/composition/alliedCompositions.ts +22 -22
- package/src/bot/logic/composition/common.ts +3 -3
- package/src/bot/logic/composition/sovietCompositions.ts +21 -21
- package/src/bot/logic/map/map.ts +66 -66
- package/src/bot/logic/map/sector.ts +174 -174
- package/src/bot/logic/mission/actionBatcher.ts +124 -124
- package/src/bot/logic/mission/mission.ts +232 -232
- package/src/bot/logic/mission/missionController.ts +413 -413
- package/src/bot/logic/mission/missionFactories.ts +51 -51
- package/src/bot/logic/mission/missions/attackMission.ts +336 -336
- package/src/bot/logic/mission/missions/defenceMission.ts +151 -151
- package/src/bot/logic/mission/missions/engineerMission.ts +113 -113
- package/src/bot/logic/mission/missions/expansionMission.ts +104 -104
- package/src/bot/logic/mission/missions/retreatMission.ts +54 -54
- package/src/bot/logic/mission/missions/scoutingMission.ts +186 -186
- package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -160
- package/src/bot/logic/mission/missions/squads/common.ts +63 -63
- package/src/bot/logic/mission/missions/squads/squad.ts +19 -19
- package/src/bot/logic/threat/threatCalculator.ts +100 -100
- package/src/exampleBot.ts +111 -124
- package/tsconfig.json +73 -73
- package/dist/bot/logic/building/building.js +0 -82
- package/dist/bot/logic/building/massedAntiGroundUnit.js +0 -20
- package/dist/bot/logic/building/queues.js +0 -19
- package/dist/bot/logic/knowledge.js +0 -1
- package/dist/bot/logic/mission/basicMission.js +0 -26
- package/dist/bot/logic/mission/behaviours/combatSquad.js +0 -124
- package/dist/bot/logic/mission/behaviours/combatSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/common.js +0 -56
- package/dist/bot/logic/mission/behaviours/common.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/engineerSquad.js +0 -39
- package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/expansionSquad.js +0 -46
- package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/retreatSquad.js +0 -31
- package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +0 -1
- package/dist/bot/logic/mission/behaviours/scoutingSquad.js +0 -94
- package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +0 -1
- package/dist/bot/logic/mission/expansionMission.js +0 -32
- package/dist/bot/logic/mission/missions/basicMission.js +0 -13
- package/dist/bot/logic/mission/missions/basicMission.js.map +0 -1
- package/dist/bot/logic/mission/missions/missionBehaviour.js +0 -2
- package/dist/bot/logic/mission/missions/missionBehaviour.js.map +0 -1
- package/dist/bot/logic/mission/missions/oneTimeMission.js +0 -27
- package/dist/bot/logic/mission/missions/oneTimeMission.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/actionBatcher.js +0 -36
- package/dist/bot/logic/squad/behaviours/actionBatcher.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/attackSquad.js +0 -82
- package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -106
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/common.js +0 -55
- package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -48
- package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -38
- package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -45
- package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -31
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -93
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/squadExpansion.js +0 -31
- package/dist/bot/logic/squad/behaviours/squadScouters.js +0 -8
- package/dist/bot/logic/squad/squad.js +0 -126
- package/dist/bot/logic/squad/squad.js.map +0 -1
- package/dist/bot/logic/squad/squadBehaviour.js +0 -6
- package/dist/bot/logic/squad/squadBehaviour.js.map +0 -1
- package/dist/bot/logic/squad/squadBehaviours.js +0 -7
- package/dist/bot/logic/squad/squadBehaviours.js.map +0 -1
- package/dist/bot/logic/squad/squadController.js +0 -215
- package/dist/bot/logic/squad/squadController.js.map +0 -1
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
// A sector is a uniform-sized segment of the map.
|
|
2
|
-
import { Vector2 } from "@chronodivide/game-api";
|
|
3
|
-
import { calculateAreaVisibility } from "./map.js";
|
|
4
|
-
export const SECTOR_SIZE = 8;
|
|
5
|
-
export class Sector {
|
|
6
|
-
constructor(sectorStartPoint, sectorStartTile, sectorVisibilityPct, sectorVisibilityLastCheckTick) {
|
|
7
|
-
this.sectorStartPoint = sectorStartPoint;
|
|
8
|
-
this.sectorStartTile = sectorStartTile;
|
|
9
|
-
this.sectorVisibilityPct = sectorVisibilityPct;
|
|
10
|
-
this.sectorVisibilityLastCheckTick = sectorVisibilityLastCheckTick;
|
|
11
|
-
this.sectorExploreAttempts = 0;
|
|
12
|
-
}
|
|
13
|
-
onExploreAttempted(currentTick) {
|
|
14
|
-
this.sectorExploreAttempts++;
|
|
15
|
-
this.sectorLastExploredAt = currentTick;
|
|
16
|
-
}
|
|
17
|
-
// Whether we should attempt to explore this sector, given the cooldown and limit of attempts.
|
|
18
|
-
shouldAttemptExploration(currentTick, cooldown, limit) {
|
|
19
|
-
if (limit >= this.sectorExploreAttempts) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (this.sectorLastExploredAt && currentTick < this.sectorLastExploredAt + cooldown) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export class SectorCache {
|
|
29
|
-
constructor(mapApi, mapBounds) {
|
|
30
|
-
this.sectors = [];
|
|
31
|
-
this.mapBounds = mapBounds;
|
|
32
|
-
this.sectorsX = Math.ceil(mapBounds.width / SECTOR_SIZE);
|
|
33
|
-
this.sectorsY = Math.ceil(mapBounds.height / SECTOR_SIZE);
|
|
34
|
-
this.sectors = new Array(this.sectorsX);
|
|
35
|
-
for (let xx = 0; xx < this.sectorsX; ++xx) {
|
|
36
|
-
this.sectors[xx] = new Array(this.sectorsY);
|
|
37
|
-
for (let yy = 0; yy < this.sectorsY; ++yy) {
|
|
38
|
-
const tileX = xx * SECTOR_SIZE;
|
|
39
|
-
const tileY = yy * SECTOR_SIZE;
|
|
40
|
-
this.sectors[xx][yy] = new Sector(new Vector2(tileX, tileY), mapApi.getTile(tileX, tileY), undefined, undefined);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
getMapBounds() {
|
|
45
|
-
return this.mapBounds;
|
|
46
|
-
}
|
|
47
|
-
updateSectors(currentGameTick, maxSectorsToUpdate, mapApi, playerData) {
|
|
48
|
-
let nextSectorX = this.lastUpdatedSectorX ? this.lastUpdatedSectorX + 1 : 0;
|
|
49
|
-
let nextSectorY = this.lastUpdatedSectorY ? this.lastUpdatedSectorY : 0;
|
|
50
|
-
let updatedThisCycle = 0;
|
|
51
|
-
while (updatedThisCycle < maxSectorsToUpdate) {
|
|
52
|
-
if (nextSectorX >= this.sectorsX) {
|
|
53
|
-
nextSectorX = 0;
|
|
54
|
-
++nextSectorY;
|
|
55
|
-
}
|
|
56
|
-
if (nextSectorY >= this.sectorsY) {
|
|
57
|
-
nextSectorY = 0;
|
|
58
|
-
nextSectorX = 0;
|
|
59
|
-
}
|
|
60
|
-
let sector = this.getSector(nextSectorX, nextSectorY);
|
|
61
|
-
if (sector) {
|
|
62
|
-
sector.sectorVisibilityLastCheckTick = currentGameTick;
|
|
63
|
-
let sp = sector.sectorStartPoint;
|
|
64
|
-
let ep = new Vector2(sp.x + SECTOR_SIZE, sp.y + SECTOR_SIZE);
|
|
65
|
-
let visibility = calculateAreaVisibility(mapApi, playerData, sp, ep);
|
|
66
|
-
if (visibility.validTiles > 0) {
|
|
67
|
-
sector.sectorVisibilityPct = visibility.visibleTiles / visibility.validTiles;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
sector.sectorVisibilityPct = undefined;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
this.lastUpdatedSectorX = nextSectorX;
|
|
74
|
-
this.lastUpdatedSectorY = nextSectorY;
|
|
75
|
-
++nextSectorX;
|
|
76
|
-
++updatedThisCycle;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Return % of sectors that are updated.
|
|
80
|
-
getSectorUpdateRatio(sectorsUpdatedSinceGameTick) {
|
|
81
|
-
let updated = 0, total = 0;
|
|
82
|
-
for (let xx = 0; xx < this.sectorsX; ++xx) {
|
|
83
|
-
for (let yy = 0; yy < this.sectorsY; ++yy) {
|
|
84
|
-
let sector = this.sectors[xx][yy];
|
|
85
|
-
if (sector &&
|
|
86
|
-
sector.sectorVisibilityLastCheckTick &&
|
|
87
|
-
sector.sectorVisibilityLastCheckTick >= sectorsUpdatedSinceGameTick) {
|
|
88
|
-
++updated;
|
|
89
|
-
}
|
|
90
|
-
++total;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return updated / total;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Return the ratio (0-1) of tiles that are visible. Returns undefined if we haven't scanned the whole map yet.
|
|
97
|
-
*/
|
|
98
|
-
getOverallVisibility() {
|
|
99
|
-
let visible = 0, total = 0;
|
|
100
|
-
for (let xx = 0; xx < this.sectorsX; ++xx) {
|
|
101
|
-
for (let yy = 0; yy < this.sectorsY; ++yy) {
|
|
102
|
-
let sector = this.sectors[xx][yy];
|
|
103
|
-
// Undefined visibility.
|
|
104
|
-
if (sector.sectorVisibilityPct != undefined) {
|
|
105
|
-
visible += sector.sectorVisibilityPct;
|
|
106
|
-
total += 1.0;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return visible / total;
|
|
111
|
-
}
|
|
112
|
-
getSector(sectorX, sectorY) {
|
|
113
|
-
if (sectorX < 0 || sectorX >= this.sectorsX || sectorY < 0 || sectorY >= this.sectorsY) {
|
|
114
|
-
return undefined;
|
|
115
|
-
}
|
|
116
|
-
return this.sectors[sectorX][sectorY];
|
|
117
|
-
}
|
|
118
|
-
getSectorBounds() {
|
|
119
|
-
return { width: this.sectorsX, height: this.sectorsY };
|
|
120
|
-
}
|
|
121
|
-
getSectorCoordinatesForWorldPosition(x, y) {
|
|
122
|
-
if (x < 0 || x >= this.mapBounds.width || y < 0 || y >= this.mapBounds.height) {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
sectorX: Math.floor(x / SECTOR_SIZE),
|
|
127
|
-
sectorY: Math.floor(y / SECTOR_SIZE),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
getSectorForWorldPosition(x, y) {
|
|
131
|
-
const sectorCoordinates = this.getSectorCoordinatesForWorldPosition(x, y);
|
|
132
|
-
if (!sectorCoordinates) {
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
return this.sectors[Math.floor(x / SECTOR_SIZE)][Math.floor(y / SECTOR_SIZE)];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
1
|
+
// A sector is a uniform-sized segment of the map.
|
|
2
|
+
import { Vector2 } from "@chronodivide/game-api";
|
|
3
|
+
import { calculateAreaVisibility } from "./map.js";
|
|
4
|
+
export const SECTOR_SIZE = 8;
|
|
5
|
+
export class Sector {
|
|
6
|
+
constructor(sectorStartPoint, sectorStartTile, sectorVisibilityPct, sectorVisibilityLastCheckTick) {
|
|
7
|
+
this.sectorStartPoint = sectorStartPoint;
|
|
8
|
+
this.sectorStartTile = sectorStartTile;
|
|
9
|
+
this.sectorVisibilityPct = sectorVisibilityPct;
|
|
10
|
+
this.sectorVisibilityLastCheckTick = sectorVisibilityLastCheckTick;
|
|
11
|
+
this.sectorExploreAttempts = 0;
|
|
12
|
+
}
|
|
13
|
+
onExploreAttempted(currentTick) {
|
|
14
|
+
this.sectorExploreAttempts++;
|
|
15
|
+
this.sectorLastExploredAt = currentTick;
|
|
16
|
+
}
|
|
17
|
+
// Whether we should attempt to explore this sector, given the cooldown and limit of attempts.
|
|
18
|
+
shouldAttemptExploration(currentTick, cooldown, limit) {
|
|
19
|
+
if (limit >= this.sectorExploreAttempts) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (this.sectorLastExploredAt && currentTick < this.sectorLastExploredAt + cooldown) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class SectorCache {
|
|
29
|
+
constructor(mapApi, mapBounds) {
|
|
30
|
+
this.sectors = [];
|
|
31
|
+
this.mapBounds = mapBounds;
|
|
32
|
+
this.sectorsX = Math.ceil(mapBounds.width / SECTOR_SIZE);
|
|
33
|
+
this.sectorsY = Math.ceil(mapBounds.height / SECTOR_SIZE);
|
|
34
|
+
this.sectors = new Array(this.sectorsX);
|
|
35
|
+
for (let xx = 0; xx < this.sectorsX; ++xx) {
|
|
36
|
+
this.sectors[xx] = new Array(this.sectorsY);
|
|
37
|
+
for (let yy = 0; yy < this.sectorsY; ++yy) {
|
|
38
|
+
const tileX = xx * SECTOR_SIZE;
|
|
39
|
+
const tileY = yy * SECTOR_SIZE;
|
|
40
|
+
this.sectors[xx][yy] = new Sector(new Vector2(tileX, tileY), mapApi.getTile(tileX, tileY), undefined, undefined);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
getMapBounds() {
|
|
45
|
+
return this.mapBounds;
|
|
46
|
+
}
|
|
47
|
+
updateSectors(currentGameTick, maxSectorsToUpdate, mapApi, playerData) {
|
|
48
|
+
let nextSectorX = this.lastUpdatedSectorX ? this.lastUpdatedSectorX + 1 : 0;
|
|
49
|
+
let nextSectorY = this.lastUpdatedSectorY ? this.lastUpdatedSectorY : 0;
|
|
50
|
+
let updatedThisCycle = 0;
|
|
51
|
+
while (updatedThisCycle < maxSectorsToUpdate) {
|
|
52
|
+
if (nextSectorX >= this.sectorsX) {
|
|
53
|
+
nextSectorX = 0;
|
|
54
|
+
++nextSectorY;
|
|
55
|
+
}
|
|
56
|
+
if (nextSectorY >= this.sectorsY) {
|
|
57
|
+
nextSectorY = 0;
|
|
58
|
+
nextSectorX = 0;
|
|
59
|
+
}
|
|
60
|
+
let sector = this.getSector(nextSectorX, nextSectorY);
|
|
61
|
+
if (sector) {
|
|
62
|
+
sector.sectorVisibilityLastCheckTick = currentGameTick;
|
|
63
|
+
let sp = sector.sectorStartPoint;
|
|
64
|
+
let ep = new Vector2(sp.x + SECTOR_SIZE, sp.y + SECTOR_SIZE);
|
|
65
|
+
let visibility = calculateAreaVisibility(mapApi, playerData, sp, ep);
|
|
66
|
+
if (visibility.validTiles > 0) {
|
|
67
|
+
sector.sectorVisibilityPct = visibility.visibleTiles / visibility.validTiles;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
sector.sectorVisibilityPct = undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.lastUpdatedSectorX = nextSectorX;
|
|
74
|
+
this.lastUpdatedSectorY = nextSectorY;
|
|
75
|
+
++nextSectorX;
|
|
76
|
+
++updatedThisCycle;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Return % of sectors that are updated.
|
|
80
|
+
getSectorUpdateRatio(sectorsUpdatedSinceGameTick) {
|
|
81
|
+
let updated = 0, total = 0;
|
|
82
|
+
for (let xx = 0; xx < this.sectorsX; ++xx) {
|
|
83
|
+
for (let yy = 0; yy < this.sectorsY; ++yy) {
|
|
84
|
+
let sector = this.sectors[xx][yy];
|
|
85
|
+
if (sector &&
|
|
86
|
+
sector.sectorVisibilityLastCheckTick &&
|
|
87
|
+
sector.sectorVisibilityLastCheckTick >= sectorsUpdatedSinceGameTick) {
|
|
88
|
+
++updated;
|
|
89
|
+
}
|
|
90
|
+
++total;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return updated / total;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Return the ratio (0-1) of tiles that are visible. Returns undefined if we haven't scanned the whole map yet.
|
|
97
|
+
*/
|
|
98
|
+
getOverallVisibility() {
|
|
99
|
+
let visible = 0, total = 0;
|
|
100
|
+
for (let xx = 0; xx < this.sectorsX; ++xx) {
|
|
101
|
+
for (let yy = 0; yy < this.sectorsY; ++yy) {
|
|
102
|
+
let sector = this.sectors[xx][yy];
|
|
103
|
+
// Undefined visibility.
|
|
104
|
+
if (sector.sectorVisibilityPct != undefined) {
|
|
105
|
+
visible += sector.sectorVisibilityPct;
|
|
106
|
+
total += 1.0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return visible / total;
|
|
111
|
+
}
|
|
112
|
+
getSector(sectorX, sectorY) {
|
|
113
|
+
if (sectorX < 0 || sectorX >= this.sectorsX || sectorY < 0 || sectorY >= this.sectorsY) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
return this.sectors[sectorX][sectorY];
|
|
117
|
+
}
|
|
118
|
+
getSectorBounds() {
|
|
119
|
+
return { width: this.sectorsX, height: this.sectorsY };
|
|
120
|
+
}
|
|
121
|
+
getSectorCoordinatesForWorldPosition(x, y) {
|
|
122
|
+
if (x < 0 || x >= this.mapBounds.width || y < 0 || y >= this.mapBounds.height) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
sectorX: Math.floor(x / SECTOR_SIZE),
|
|
127
|
+
sectorY: Math.floor(y / SECTOR_SIZE),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
getSectorForWorldPosition(x, y) {
|
|
131
|
+
const sectorCoordinates = this.getSectorCoordinatesForWorldPosition(x, y);
|
|
132
|
+
if (!sectorCoordinates) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
return this.sectors[Math.floor(x / SECTOR_SIZE)][Math.floor(y / SECTOR_SIZE)];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
138
|
//# sourceMappingURL=sector.js.map
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
// Used to group related actions together to minimise actionApi calls. For example, if multiple units
|
|
2
|
-
import { Vector2 } from "@chronodivide/game-api";
|
|
3
|
-
import { groupBy } from "../common/utils.js";
|
|
4
|
-
// are ordered to move to the same location, all of them will be ordered to move in a single action.
|
|
5
|
-
export class BatchableAction {
|
|
6
|
-
constructor(_unitId, _orderType, _point, _targetId,
|
|
7
|
-
// If you don't want this action to be swallowed by dedupe, provide a unique nonce
|
|
8
|
-
_nonce = 0) {
|
|
9
|
-
this._unitId = _unitId;
|
|
10
|
-
this._orderType = _orderType;
|
|
11
|
-
this._point = _point;
|
|
12
|
-
this._targetId = _targetId;
|
|
13
|
-
this._nonce = _nonce;
|
|
14
|
-
}
|
|
15
|
-
static noTarget(unitId, orderType, nonce = 0) {
|
|
16
|
-
return new BatchableAction(unitId, orderType, undefined, undefined, nonce);
|
|
17
|
-
}
|
|
18
|
-
static toPoint(unitId, orderType, point, nonce = 0) {
|
|
19
|
-
return new BatchableAction(unitId, orderType, point, undefined);
|
|
20
|
-
}
|
|
21
|
-
static toTargetId(unitId, orderType, targetId, nonce = 0) {
|
|
22
|
-
return new BatchableAction(unitId, orderType, undefined, targetId, nonce);
|
|
23
|
-
}
|
|
24
|
-
get unitId() {
|
|
25
|
-
return this._unitId;
|
|
26
|
-
}
|
|
27
|
-
get orderType() {
|
|
28
|
-
return this._orderType;
|
|
29
|
-
}
|
|
30
|
-
get point() {
|
|
31
|
-
return this._point;
|
|
32
|
-
}
|
|
33
|
-
get targetId() {
|
|
34
|
-
return this._targetId;
|
|
35
|
-
}
|
|
36
|
-
isSameAs(other) {
|
|
37
|
-
if (this._unitId !== other._unitId) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
if (this._orderType !== other._orderType) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (this._point !== other._point) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (this._targetId !== other._targetId) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
if (this._nonce !== other._nonce) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export class ActionBatcher {
|
|
56
|
-
constructor() {
|
|
57
|
-
this.actions = [];
|
|
58
|
-
}
|
|
59
|
-
push(action) {
|
|
60
|
-
this.actions.push(action);
|
|
61
|
-
}
|
|
62
|
-
resolve(actionsApi) {
|
|
63
|
-
const groupedCommands = groupBy(this.actions, (action) => action.orderType.valueOf().toString());
|
|
64
|
-
const vectorToStr = (v) => v.x + "," + v.y;
|
|
65
|
-
const strToVector = (str) => {
|
|
66
|
-
const [x, y] = str.split(",");
|
|
67
|
-
return new Vector2(parseInt(x), parseInt(y));
|
|
68
|
-
};
|
|
69
|
-
// Group by command type.
|
|
70
|
-
Object.entries(groupedCommands).forEach(([commandValue, commands]) => {
|
|
71
|
-
// i hate this
|
|
72
|
-
const commandType = parseInt(commandValue);
|
|
73
|
-
// Group by command target ID.
|
|
74
|
-
const byTarget = groupBy(commands.filter((command) => !!command.targetId), (command) => command.targetId?.toString());
|
|
75
|
-
Object.entries(byTarget).forEach(([targetId, unitCommands]) => {
|
|
76
|
-
actionsApi.orderUnits(unitCommands.map((command) => command.unitId), commandType, parseInt(targetId));
|
|
77
|
-
});
|
|
78
|
-
// Group by position (the vector is encoded as a string of the form "x,y")
|
|
79
|
-
const byPosition = groupBy(commands.filter((command) => !!command.point), (command) => vectorToStr(command.point));
|
|
80
|
-
Object.entries(byPosition).forEach(([point, unitCommands]) => {
|
|
81
|
-
const vector = strToVector(point);
|
|
82
|
-
actionsApi.orderUnits(unitCommands.map((command) => command.unitId), commandType, vector.x, vector.y);
|
|
83
|
-
});
|
|
84
|
-
// Actions with no targets
|
|
85
|
-
const noTargets = commands.filter((command) => !command.targetId && !command.point);
|
|
86
|
-
if (noTargets.length > 0) {
|
|
87
|
-
actionsApi.orderUnits(noTargets.map((action) => action.unitId), commandType);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
1
|
+
// Used to group related actions together to minimise actionApi calls. For example, if multiple units
|
|
2
|
+
import { Vector2 } from "@chronodivide/game-api";
|
|
3
|
+
import { groupBy } from "../common/utils.js";
|
|
4
|
+
// are ordered to move to the same location, all of them will be ordered to move in a single action.
|
|
5
|
+
export class BatchableAction {
|
|
6
|
+
constructor(_unitId, _orderType, _point, _targetId,
|
|
7
|
+
// If you don't want this action to be swallowed by dedupe, provide a unique nonce
|
|
8
|
+
_nonce = 0) {
|
|
9
|
+
this._unitId = _unitId;
|
|
10
|
+
this._orderType = _orderType;
|
|
11
|
+
this._point = _point;
|
|
12
|
+
this._targetId = _targetId;
|
|
13
|
+
this._nonce = _nonce;
|
|
14
|
+
}
|
|
15
|
+
static noTarget(unitId, orderType, nonce = 0) {
|
|
16
|
+
return new BatchableAction(unitId, orderType, undefined, undefined, nonce);
|
|
17
|
+
}
|
|
18
|
+
static toPoint(unitId, orderType, point, nonce = 0) {
|
|
19
|
+
return new BatchableAction(unitId, orderType, point, undefined);
|
|
20
|
+
}
|
|
21
|
+
static toTargetId(unitId, orderType, targetId, nonce = 0) {
|
|
22
|
+
return new BatchableAction(unitId, orderType, undefined, targetId, nonce);
|
|
23
|
+
}
|
|
24
|
+
get unitId() {
|
|
25
|
+
return this._unitId;
|
|
26
|
+
}
|
|
27
|
+
get orderType() {
|
|
28
|
+
return this._orderType;
|
|
29
|
+
}
|
|
30
|
+
get point() {
|
|
31
|
+
return this._point;
|
|
32
|
+
}
|
|
33
|
+
get targetId() {
|
|
34
|
+
return this._targetId;
|
|
35
|
+
}
|
|
36
|
+
isSameAs(other) {
|
|
37
|
+
if (this._unitId !== other._unitId) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (this._orderType !== other._orderType) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (this._point !== other._point) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (this._targetId !== other._targetId) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (this._nonce !== other._nonce) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class ActionBatcher {
|
|
56
|
+
constructor() {
|
|
57
|
+
this.actions = [];
|
|
58
|
+
}
|
|
59
|
+
push(action) {
|
|
60
|
+
this.actions.push(action);
|
|
61
|
+
}
|
|
62
|
+
resolve(actionsApi) {
|
|
63
|
+
const groupedCommands = groupBy(this.actions, (action) => action.orderType.valueOf().toString());
|
|
64
|
+
const vectorToStr = (v) => v.x + "," + v.y;
|
|
65
|
+
const strToVector = (str) => {
|
|
66
|
+
const [x, y] = str.split(",");
|
|
67
|
+
return new Vector2(parseInt(x), parseInt(y));
|
|
68
|
+
};
|
|
69
|
+
// Group by command type.
|
|
70
|
+
Object.entries(groupedCommands).forEach(([commandValue, commands]) => {
|
|
71
|
+
// i hate this
|
|
72
|
+
const commandType = parseInt(commandValue);
|
|
73
|
+
// Group by command target ID.
|
|
74
|
+
const byTarget = groupBy(commands.filter((command) => !!command.targetId), (command) => command.targetId?.toString());
|
|
75
|
+
Object.entries(byTarget).forEach(([targetId, unitCommands]) => {
|
|
76
|
+
actionsApi.orderUnits(unitCommands.map((command) => command.unitId), commandType, parseInt(targetId));
|
|
77
|
+
});
|
|
78
|
+
// Group by position (the vector is encoded as a string of the form "x,y")
|
|
79
|
+
const byPosition = groupBy(commands.filter((command) => !!command.point), (command) => vectorToStr(command.point));
|
|
80
|
+
Object.entries(byPosition).forEach(([point, unitCommands]) => {
|
|
81
|
+
const vector = strToVector(point);
|
|
82
|
+
actionsApi.orderUnits(unitCommands.map((command) => command.unitId), commandType, vector.x, vector.y);
|
|
83
|
+
});
|
|
84
|
+
// Actions with no targets
|
|
85
|
+
const noTargets = commands.filter((command) => !command.targetId && !command.point);
|
|
86
|
+
if (noTargets.length > 0) {
|
|
87
|
+
actionsApi.orderUnits(noTargets.map((action) => action.unitId), commandType);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
92
|
//# sourceMappingURL=actionBatcher.js.map
|