@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,137 +1,137 @@
|
|
|
1
|
-
import { Vector2 } from "@chronodivide/game-api";
|
|
2
|
-
import { calculateGlobalThreat } from "./threat/threatCalculator.js";
|
|
3
|
-
import { getPointTowardsOtherPoint } from "./map/map.js";
|
|
4
|
-
import { Circle, Quadtree } from "@timohausmann/quadtree-ts";
|
|
5
|
-
import { ScoutingManager } from "./common/scout.js";
|
|
6
|
-
const SECTORS_TO_UPDATE_PER_CYCLE = 8;
|
|
7
|
-
const RALLY_POINT_UPDATE_INTERVAL_TICKS = 90;
|
|
8
|
-
const THREAT_UPDATE_INTERVAL_TICKS = 30;
|
|
9
|
-
const rebuildQuadtree = (quadtree, units) => {
|
|
10
|
-
quadtree.clear();
|
|
11
|
-
units.forEach((unit) => {
|
|
12
|
-
quadtree.insert(new Circle({ x: unit.tile.rx, y: unit.tile.ry, r: 1, data: unit.id }));
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
export class MatchAwarenessImpl {
|
|
16
|
-
constructor(threatCache, sectorCache, mainRallyPoint, logger) {
|
|
17
|
-
this.threatCache = threatCache;
|
|
18
|
-
this.sectorCache = sectorCache;
|
|
19
|
-
this.mainRallyPoint = mainRallyPoint;
|
|
20
|
-
this.logger = logger;
|
|
21
|
-
this._shouldAttack = false;
|
|
22
|
-
const { width, height } = sectorCache.getMapBounds();
|
|
23
|
-
this.hostileQuadTree = new Quadtree({ width, height });
|
|
24
|
-
this.scoutingManager = new ScoutingManager(logger);
|
|
25
|
-
}
|
|
26
|
-
getHostilesNearPoint2d(point, radius) {
|
|
27
|
-
return this.getHostilesNearPoint(point.x, point.y, radius);
|
|
28
|
-
}
|
|
29
|
-
getHostilesNearPoint(searchX, searchY, radius) {
|
|
30
|
-
const intersections = this.hostileQuadTree.retrieve(new Circle({ x: searchX, y: searchY, r: radius }));
|
|
31
|
-
return intersections
|
|
32
|
-
.map(({ x, y, data: unitId }) => ({ x, y, unitId: unitId }))
|
|
33
|
-
.filter(({ x, y }) => new Vector2(x, y).distanceTo(new Vector2(searchX, searchY)) <= radius)
|
|
34
|
-
.filter(({ unitId }) => !!unitId);
|
|
35
|
-
}
|
|
36
|
-
getThreatCache() {
|
|
37
|
-
return this.threatCache;
|
|
38
|
-
}
|
|
39
|
-
getSectorCache() {
|
|
40
|
-
return this.sectorCache;
|
|
41
|
-
}
|
|
42
|
-
getMainRallyPoint() {
|
|
43
|
-
return this.mainRallyPoint;
|
|
44
|
-
}
|
|
45
|
-
getScoutingManager() {
|
|
46
|
-
return this.scoutingManager;
|
|
47
|
-
}
|
|
48
|
-
shouldAttack() {
|
|
49
|
-
return this._shouldAttack;
|
|
50
|
-
}
|
|
51
|
-
checkShouldAttack(threatCache, threatFactor) {
|
|
52
|
-
let scaledGroundPower = threatCache.totalAvailableAntiGroundFirepower * 1.1;
|
|
53
|
-
let scaledGroundThreat = (threatFactor * threatCache.totalOffensiveLandThreat + threatCache.totalDefensiveThreat) * 1.1;
|
|
54
|
-
let scaledAirPower = threatCache.totalAvailableAirPower * 1.1;
|
|
55
|
-
let scaledAirThreat = (threatFactor * threatCache.totalOffensiveAntiAirThreat + threatCache.totalDefensiveThreat) * 1.1;
|
|
56
|
-
return scaledGroundPower > scaledGroundThreat || scaledAirPower > scaledAirThreat;
|
|
57
|
-
}
|
|
58
|
-
isHostileUnit(unit, hostilePlayerNames) {
|
|
59
|
-
if (!unit) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return hostilePlayerNames.includes(unit.owner);
|
|
63
|
-
}
|
|
64
|
-
onGameStart(gameApi, playerData) {
|
|
65
|
-
this.scoutingManager.onGameStart(gameApi, playerData, this.sectorCache);
|
|
66
|
-
}
|
|
67
|
-
onAiUpdate(game, playerData) {
|
|
68
|
-
const sectorCache = this.sectorCache;
|
|
69
|
-
sectorCache.updateSectors(game.getCurrentTick(), SECTORS_TO_UPDATE_PER_CYCLE, game.mapApi, playerData);
|
|
70
|
-
this.scoutingManager.onAiUpdate(game, playerData, sectorCache);
|
|
71
|
-
let updateRatio = sectorCache?.getSectorUpdateRatio(game.getCurrentTick() - game.getTickRate() * 60);
|
|
72
|
-
if (updateRatio && updateRatio < 1.0) {
|
|
73
|
-
this.logger(`${updateRatio * 100.0}% of sectors updated in last 60 seconds.`);
|
|
74
|
-
}
|
|
75
|
-
const hostilePlayerNames = game
|
|
76
|
-
.getPlayers()
|
|
77
|
-
.map((name) => game.getPlayerData(name))
|
|
78
|
-
.filter((other) => other.name !== playerData.name &&
|
|
79
|
-
other.isCombatant &&
|
|
80
|
-
!game.areAlliedPlayers(playerData.name, other.name))
|
|
81
|
-
.map((other) => other.name);
|
|
82
|
-
// Build the quadtree, if this is too slow we should consider doing this periodically.
|
|
83
|
-
const hostileUnitIds = game.getVisibleUnits(playerData.name, "enemy");
|
|
84
|
-
try {
|
|
85
|
-
const hostileUnits = hostileUnitIds
|
|
86
|
-
.map((id) => game.getGameObjectData(id))
|
|
87
|
-
.filter((gameObjectData) => gameObjectData !== undefined);
|
|
88
|
-
rebuildQuadtree(this.hostileQuadTree, hostileUnits);
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
// Hack. Will be fixed soon.
|
|
92
|
-
console.error(`caught error`, hostileUnitIds);
|
|
93
|
-
}
|
|
94
|
-
if (game.getCurrentTick() % THREAT_UPDATE_INTERVAL_TICKS == 0) {
|
|
95
|
-
let visibility = sectorCache?.getOverallVisibility();
|
|
96
|
-
if (visibility) {
|
|
97
|
-
this.logger(`${Math.round(visibility * 1000.0) / 10}% of tiles visible. Calculating threat.`);
|
|
98
|
-
// Update the global threat cache
|
|
99
|
-
this.threatCache = calculateGlobalThreat(game, playerData, visibility);
|
|
100
|
-
// As the game approaches 2 hours, be more willing to attack. (15 ticks per second)
|
|
101
|
-
const gameLengthFactor = Math.max(0, 1.0 - game.getCurrentTick() / (15 * 7200.0));
|
|
102
|
-
this.logger(`Game length multiplier: ${gameLengthFactor}`);
|
|
103
|
-
if (!this._shouldAttack) {
|
|
104
|
-
// If not attacking, make it harder to switch to attack mode by multiplying the opponent's threat.
|
|
105
|
-
this._shouldAttack = this.checkShouldAttack(this.threatCache, 1.25 * gameLengthFactor);
|
|
106
|
-
if (this._shouldAttack) {
|
|
107
|
-
this.logger(`Globally switched to attack mode.`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
// If currently attacking, make it harder to switch to defence mode my dampening the opponent's threat.
|
|
112
|
-
this._shouldAttack = this.checkShouldAttack(this.threatCache, 0.75 * gameLengthFactor);
|
|
113
|
-
if (!this._shouldAttack) {
|
|
114
|
-
this.logger(`Globally switched to defence mode.`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// Update rally point every few ticks.
|
|
120
|
-
if (game.getCurrentTick() % RALLY_POINT_UPDATE_INTERVAL_TICKS === 0) {
|
|
121
|
-
const enemyPlayers = game
|
|
122
|
-
.getPlayers()
|
|
123
|
-
.filter((p) => p !== playerData.name && !game.areAlliedPlayers(playerData.name, p));
|
|
124
|
-
const enemy = game.getPlayerData(enemyPlayers[0]);
|
|
125
|
-
this.mainRallyPoint = getPointTowardsOtherPoint(game, playerData.startLocation, enemy.startLocation, 10, 10, 0);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
getGlobalDebugText() {
|
|
129
|
-
if (!this.threatCache) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
return (`Threat LAND: Them ${Math.round(this.threatCache.totalOffensiveLandThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiGroundFirepower)}.\n` +
|
|
133
|
-
`Threat DEFENSIVE: Them ${Math.round(this.threatCache.totalDefensiveThreat)}, us: ${Math.round(this.threatCache.totalDefensivePower)}.\n` +
|
|
134
|
-
`Threat AIR: Them ${Math.round(this.threatCache.totalOffensiveAirThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiAirFirepower)}.`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
1
|
+
import { Vector2 } from "@chronodivide/game-api";
|
|
2
|
+
import { calculateGlobalThreat } from "./threat/threatCalculator.js";
|
|
3
|
+
import { getPointTowardsOtherPoint } from "./map/map.js";
|
|
4
|
+
import { Circle, Quadtree } from "@timohausmann/quadtree-ts";
|
|
5
|
+
import { ScoutingManager } from "./common/scout.js";
|
|
6
|
+
const SECTORS_TO_UPDATE_PER_CYCLE = 8;
|
|
7
|
+
const RALLY_POINT_UPDATE_INTERVAL_TICKS = 90;
|
|
8
|
+
const THREAT_UPDATE_INTERVAL_TICKS = 30;
|
|
9
|
+
const rebuildQuadtree = (quadtree, units) => {
|
|
10
|
+
quadtree.clear();
|
|
11
|
+
units.forEach((unit) => {
|
|
12
|
+
quadtree.insert(new Circle({ x: unit.tile.rx, y: unit.tile.ry, r: 1, data: unit.id }));
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export class MatchAwarenessImpl {
|
|
16
|
+
constructor(threatCache, sectorCache, mainRallyPoint, logger) {
|
|
17
|
+
this.threatCache = threatCache;
|
|
18
|
+
this.sectorCache = sectorCache;
|
|
19
|
+
this.mainRallyPoint = mainRallyPoint;
|
|
20
|
+
this.logger = logger;
|
|
21
|
+
this._shouldAttack = false;
|
|
22
|
+
const { width, height } = sectorCache.getMapBounds();
|
|
23
|
+
this.hostileQuadTree = new Quadtree({ width, height });
|
|
24
|
+
this.scoutingManager = new ScoutingManager(logger);
|
|
25
|
+
}
|
|
26
|
+
getHostilesNearPoint2d(point, radius) {
|
|
27
|
+
return this.getHostilesNearPoint(point.x, point.y, radius);
|
|
28
|
+
}
|
|
29
|
+
getHostilesNearPoint(searchX, searchY, radius) {
|
|
30
|
+
const intersections = this.hostileQuadTree.retrieve(new Circle({ x: searchX, y: searchY, r: radius }));
|
|
31
|
+
return intersections
|
|
32
|
+
.map(({ x, y, data: unitId }) => ({ x, y, unitId: unitId }))
|
|
33
|
+
.filter(({ x, y }) => new Vector2(x, y).distanceTo(new Vector2(searchX, searchY)) <= radius)
|
|
34
|
+
.filter(({ unitId }) => !!unitId);
|
|
35
|
+
}
|
|
36
|
+
getThreatCache() {
|
|
37
|
+
return this.threatCache;
|
|
38
|
+
}
|
|
39
|
+
getSectorCache() {
|
|
40
|
+
return this.sectorCache;
|
|
41
|
+
}
|
|
42
|
+
getMainRallyPoint() {
|
|
43
|
+
return this.mainRallyPoint;
|
|
44
|
+
}
|
|
45
|
+
getScoutingManager() {
|
|
46
|
+
return this.scoutingManager;
|
|
47
|
+
}
|
|
48
|
+
shouldAttack() {
|
|
49
|
+
return this._shouldAttack;
|
|
50
|
+
}
|
|
51
|
+
checkShouldAttack(threatCache, threatFactor) {
|
|
52
|
+
let scaledGroundPower = threatCache.totalAvailableAntiGroundFirepower * 1.1;
|
|
53
|
+
let scaledGroundThreat = (threatFactor * threatCache.totalOffensiveLandThreat + threatCache.totalDefensiveThreat) * 1.1;
|
|
54
|
+
let scaledAirPower = threatCache.totalAvailableAirPower * 1.1;
|
|
55
|
+
let scaledAirThreat = (threatFactor * threatCache.totalOffensiveAntiAirThreat + threatCache.totalDefensiveThreat) * 1.1;
|
|
56
|
+
return scaledGroundPower > scaledGroundThreat || scaledAirPower > scaledAirThreat;
|
|
57
|
+
}
|
|
58
|
+
isHostileUnit(unit, hostilePlayerNames) {
|
|
59
|
+
if (!unit) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return hostilePlayerNames.includes(unit.owner);
|
|
63
|
+
}
|
|
64
|
+
onGameStart(gameApi, playerData) {
|
|
65
|
+
this.scoutingManager.onGameStart(gameApi, playerData, this.sectorCache);
|
|
66
|
+
}
|
|
67
|
+
onAiUpdate(game, playerData) {
|
|
68
|
+
const sectorCache = this.sectorCache;
|
|
69
|
+
sectorCache.updateSectors(game.getCurrentTick(), SECTORS_TO_UPDATE_PER_CYCLE, game.mapApi, playerData);
|
|
70
|
+
this.scoutingManager.onAiUpdate(game, playerData, sectorCache);
|
|
71
|
+
let updateRatio = sectorCache?.getSectorUpdateRatio(game.getCurrentTick() - game.getTickRate() * 60);
|
|
72
|
+
if (updateRatio && updateRatio < 1.0) {
|
|
73
|
+
this.logger(`${updateRatio * 100.0}% of sectors updated in last 60 seconds.`);
|
|
74
|
+
}
|
|
75
|
+
const hostilePlayerNames = game
|
|
76
|
+
.getPlayers()
|
|
77
|
+
.map((name) => game.getPlayerData(name))
|
|
78
|
+
.filter((other) => other.name !== playerData.name &&
|
|
79
|
+
other.isCombatant &&
|
|
80
|
+
!game.areAlliedPlayers(playerData.name, other.name))
|
|
81
|
+
.map((other) => other.name);
|
|
82
|
+
// Build the quadtree, if this is too slow we should consider doing this periodically.
|
|
83
|
+
const hostileUnitIds = game.getVisibleUnits(playerData.name, "enemy");
|
|
84
|
+
try {
|
|
85
|
+
const hostileUnits = hostileUnitIds
|
|
86
|
+
.map((id) => game.getGameObjectData(id))
|
|
87
|
+
.filter((gameObjectData) => gameObjectData !== undefined);
|
|
88
|
+
rebuildQuadtree(this.hostileQuadTree, hostileUnits);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
// Hack. Will be fixed soon.
|
|
92
|
+
console.error(`caught error`, hostileUnitIds);
|
|
93
|
+
}
|
|
94
|
+
if (game.getCurrentTick() % THREAT_UPDATE_INTERVAL_TICKS == 0) {
|
|
95
|
+
let visibility = sectorCache?.getOverallVisibility();
|
|
96
|
+
if (visibility) {
|
|
97
|
+
this.logger(`${Math.round(visibility * 1000.0) / 10}% of tiles visible. Calculating threat.`);
|
|
98
|
+
// Update the global threat cache
|
|
99
|
+
this.threatCache = calculateGlobalThreat(game, playerData, visibility);
|
|
100
|
+
// As the game approaches 2 hours, be more willing to attack. (15 ticks per second)
|
|
101
|
+
const gameLengthFactor = Math.max(0, 1.0 - game.getCurrentTick() / (15 * 7200.0));
|
|
102
|
+
this.logger(`Game length multiplier: ${gameLengthFactor}`);
|
|
103
|
+
if (!this._shouldAttack) {
|
|
104
|
+
// If not attacking, make it harder to switch to attack mode by multiplying the opponent's threat.
|
|
105
|
+
this._shouldAttack = this.checkShouldAttack(this.threatCache, 1.25 * gameLengthFactor);
|
|
106
|
+
if (this._shouldAttack) {
|
|
107
|
+
this.logger(`Globally switched to attack mode.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// If currently attacking, make it harder to switch to defence mode my dampening the opponent's threat.
|
|
112
|
+
this._shouldAttack = this.checkShouldAttack(this.threatCache, 0.75 * gameLengthFactor);
|
|
113
|
+
if (!this._shouldAttack) {
|
|
114
|
+
this.logger(`Globally switched to defence mode.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Update rally point every few ticks.
|
|
120
|
+
if (game.getCurrentTick() % RALLY_POINT_UPDATE_INTERVAL_TICKS === 0) {
|
|
121
|
+
const enemyPlayers = game
|
|
122
|
+
.getPlayers()
|
|
123
|
+
.filter((p) => p !== playerData.name && !game.areAlliedPlayers(playerData.name, p));
|
|
124
|
+
const enemy = game.getPlayerData(enemyPlayers[0]);
|
|
125
|
+
this.mainRallyPoint = getPointTowardsOtherPoint(game, playerData.startLocation, enemy.startLocation, 10, 10, 0);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
getGlobalDebugText() {
|
|
129
|
+
if (!this.threatCache) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
return (`Threat LAND: Them ${Math.round(this.threatCache.totalOffensiveLandThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiGroundFirepower)}.\n` +
|
|
133
|
+
`Threat DEFENSIVE: Them ${Math.round(this.threatCache.totalDefensiveThreat)}, us: ${Math.round(this.threatCache.totalDefensivePower)}.\n` +
|
|
134
|
+
`Threat AIR: Them ${Math.round(this.threatCache.totalOffensiveAirThreat)}, us: ${Math.round(this.threatCache.totalAvailableAntiAirFirepower)}.`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
137
|
//# sourceMappingURL=awareness.js.map
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { getPointTowardsOtherPoint } from "../map/map.js";
|
|
2
|
-
import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
3
|
-
export class AntiAirStaticDefence {
|
|
4
|
-
constructor(basePriority, baseAmount, airStrength) {
|
|
5
|
-
this.basePriority = basePriority;
|
|
6
|
-
this.baseAmount = baseAmount;
|
|
7
|
-
this.airStrength = airStrength;
|
|
8
|
-
}
|
|
9
|
-
getPlacementLocation(game, playerData, technoRules) {
|
|
10
|
-
// Prefer front towards enemy.
|
|
11
|
-
let startLocation = playerData.startLocation;
|
|
12
|
-
let players = game.getPlayers();
|
|
13
|
-
let enemyFacingLocationCandidates = [];
|
|
14
|
-
for (let i = 0; i < players.length; ++i) {
|
|
15
|
-
let playerName = players[i];
|
|
16
|
-
if (playerName == playerData.name) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
let enemyPlayer = game.getPlayerData(playerName);
|
|
20
|
-
enemyFacingLocationCandidates.push(getPointTowardsOtherPoint(game, startLocation, enemyPlayer.startLocation, 4, 16, 1.5));
|
|
21
|
-
}
|
|
22
|
-
let selectedLocation = enemyFacingLocationCandidates[Math.floor(game.generateRandom() * enemyFacingLocationCandidates.length)];
|
|
23
|
-
return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules, false, 0);
|
|
24
|
-
}
|
|
25
|
-
getPriority(game, playerData, technoRules, threatCache) {
|
|
26
|
-
if (threatCache) {
|
|
27
|
-
let denominator = threatCache.totalAvailableAntiAirFirepower + this.airStrength;
|
|
28
|
-
if (threatCache.totalOffensiveAirThreat > denominator * 1.1) {
|
|
29
|
-
return this.basePriority * (threatCache.totalOffensiveAirThreat / Math.max(1, denominator));
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const strengthPerCost = (this.airStrength / technoRules.cost) * 1000;
|
|
36
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
37
|
-
return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
|
|
38
|
-
}
|
|
39
|
-
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
import { getPointTowardsOtherPoint } from "../map/map.js";
|
|
2
|
+
import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
3
|
+
export class AntiAirStaticDefence {
|
|
4
|
+
constructor(basePriority, baseAmount, airStrength) {
|
|
5
|
+
this.basePriority = basePriority;
|
|
6
|
+
this.baseAmount = baseAmount;
|
|
7
|
+
this.airStrength = airStrength;
|
|
8
|
+
}
|
|
9
|
+
getPlacementLocation(game, playerData, technoRules) {
|
|
10
|
+
// Prefer front towards enemy.
|
|
11
|
+
let startLocation = playerData.startLocation;
|
|
12
|
+
let players = game.getPlayers();
|
|
13
|
+
let enemyFacingLocationCandidates = [];
|
|
14
|
+
for (let i = 0; i < players.length; ++i) {
|
|
15
|
+
let playerName = players[i];
|
|
16
|
+
if (playerName == playerData.name) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
let enemyPlayer = game.getPlayerData(playerName);
|
|
20
|
+
enemyFacingLocationCandidates.push(getPointTowardsOtherPoint(game, startLocation, enemyPlayer.startLocation, 4, 16, 1.5));
|
|
21
|
+
}
|
|
22
|
+
let selectedLocation = enemyFacingLocationCandidates[Math.floor(game.generateRandom() * enemyFacingLocationCandidates.length)];
|
|
23
|
+
return getDefaultPlacementLocation(game, playerData, selectedLocation, technoRules, false, 0);
|
|
24
|
+
}
|
|
25
|
+
getPriority(game, playerData, technoRules, threatCache) {
|
|
26
|
+
if (threatCache) {
|
|
27
|
+
let denominator = threatCache.totalAvailableAntiAirFirepower + this.airStrength;
|
|
28
|
+
if (threatCache.totalOffensiveAirThreat > denominator * 1.1) {
|
|
29
|
+
return this.basePriority * (threatCache.totalOffensiveAirThreat / Math.max(1, denominator));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const strengthPerCost = (this.airStrength / technoRules.cost) * 1000;
|
|
36
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
37
|
+
return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
|
|
38
|
+
}
|
|
39
|
+
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
43
|
//# sourceMappingURL=antiAirStaticDefence.js.map
|
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
import { numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
2
|
-
import { getStaticDefencePlacement } from "./common.js";
|
|
3
|
-
export class AntiGroundStaticDefence {
|
|
4
|
-
constructor(basePriority, baseAmount, groundStrength) {
|
|
5
|
-
this.basePriority = basePriority;
|
|
6
|
-
this.baseAmount = baseAmount;
|
|
7
|
-
this.groundStrength = groundStrength;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
1
|
+
import { numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
2
|
+
import { getStaticDefencePlacement } from "./common.js";
|
|
3
|
+
export class AntiGroundStaticDefence {
|
|
4
|
+
constructor(basePriority, baseAmount, groundStrength, limit) {
|
|
5
|
+
this.basePriority = basePriority;
|
|
6
|
+
this.baseAmount = baseAmount;
|
|
7
|
+
this.groundStrength = groundStrength;
|
|
8
|
+
this.limit = limit;
|
|
9
|
+
}
|
|
10
|
+
getPlacementLocation(game, playerData, technoRules) {
|
|
11
|
+
return getStaticDefencePlacement(game, playerData, technoRules);
|
|
12
|
+
}
|
|
13
|
+
getPriority(game, playerData, technoRules, threatCache) {
|
|
14
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
15
|
+
if (numOwned >= this.limit) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
// If the enemy's ground power is increasing we should try to keep up.
|
|
19
|
+
if (threatCache) {
|
|
20
|
+
let denominator = threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.groundStrength;
|
|
21
|
+
if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
|
|
22
|
+
return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const strengthPerCost = (this.groundStrength / technoRules.cost) * 1000;
|
|
29
|
+
return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
|
|
30
|
+
}
|
|
31
|
+
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
31
35
|
//# sourceMappingURL=antiGroundStaticDefence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"antiGroundStaticDefence.js","sourceRoot":"","sources":["../../../../src/bot/logic/building/antiGroundStaticDefence.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgD,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,OAAO,uBAAuB;IAChC,YACY,YAAoB,EACpB,UAAkB,EAClB,cAAsB;
|
|
1
|
+
{"version":3,"file":"antiGroundStaticDefence.js","sourceRoot":"","sources":["../../../../src/bot/logic/building/antiGroundStaticDefence.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgD,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,OAAO,uBAAuB;IAChC,YACY,YAAoB,EACpB,UAAkB,EAClB,cAAsB,EACtB,KAAa;QAHb,iBAAY,GAAZ,YAAY,CAAQ;QACpB,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAQ;QACtB,UAAK,GAAL,KAAK,CAAQ;IACtB,CAAC;IAEJ,oBAAoB,CAChB,IAAa,EACb,UAAsB,EACtB,WAAwB;QAExB,OAAO,yBAAyB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC;IAED,WAAW,CACP,IAAa,EACb,UAAsB,EACtB,WAAwB,EACxB,WAAgC;QAEhC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QACxE,IAAI,QAAQ,IAAI,IAAI,CAAC,KAAK,EAAE;YACxB,OAAO,CAAC,CAAC;SACZ;QACD,sEAAsE;QACtE,IAAI,WAAW,EAAE;YACb,IAAI,WAAW,GACX,WAAW,CAAC,iCAAiC,GAAG,WAAW,CAAC,mBAAmB,GAAG,IAAI,CAAC,cAAc,CAAC;YAC1G,IAAI,WAAW,CAAC,wBAAwB,GAAG,WAAW,GAAG,GAAG,EAAE;gBAC1D,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,WAAW,CAAC,wBAAwB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;aAChG;iBAAM;gBACH,OAAO,CAAC,CAAC;aACZ;SACJ;QACD,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACxE,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,GAAG,GAAG,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC;IACpF,CAAC;IAED,WAAW,CACP,IAAa,EACb,UAAsB,EACtB,WAAwB,EACxB,WAAgC;QAEhC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export class ArtilleryUnit {
|
|
2
|
-
constructor(basePriority, artilleryPower, antiGroundPower, baseAmount) {
|
|
3
|
-
this.basePriority = basePriority;
|
|
4
|
-
this.artilleryPower = artilleryPower;
|
|
5
|
-
this.antiGroundPower = antiGroundPower;
|
|
6
|
-
this.baseAmount = baseAmount;
|
|
7
|
-
}
|
|
8
|
-
getPlacementLocation(game, playerData, technoRules) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
getPriority(game, playerData, technoRules, threatCache) {
|
|
12
|
-
// Units aren't built automatically, but are instead requested by missions.
|
|
13
|
-
return 0;
|
|
14
|
-
}
|
|
15
|
-
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
export class ArtilleryUnit {
|
|
2
|
+
constructor(basePriority, artilleryPower, antiGroundPower, baseAmount) {
|
|
3
|
+
this.basePriority = basePriority;
|
|
4
|
+
this.artilleryPower = artilleryPower;
|
|
5
|
+
this.antiGroundPower = antiGroundPower;
|
|
6
|
+
this.baseAmount = baseAmount;
|
|
7
|
+
}
|
|
8
|
+
getPlacementLocation(game, playerData, technoRules) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
getPriority(game, playerData, technoRules, threatCache) {
|
|
12
|
+
// Units aren't built automatically, but are instead requested by missions.
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
19
|
//# sourceMappingURL=artilleryUnit.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export class BasicAirUnit {
|
|
2
|
-
constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
|
|
3
|
-
antiAirPower = 0) {
|
|
4
|
-
this.basePriority = basePriority;
|
|
5
|
-
this.baseAmount = baseAmount;
|
|
6
|
-
this.antiGroundPower = antiGroundPower;
|
|
7
|
-
this.antiAirPower = antiAirPower;
|
|
8
|
-
}
|
|
9
|
-
getPlacementLocation(game, playerData, technoRules) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
getPriority(game, playerData, technoRules, threatCache) {
|
|
13
|
-
// Units aren't built automatically, but are instead requested by missions.
|
|
14
|
-
return 0;
|
|
15
|
-
}
|
|
16
|
-
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
export class BasicAirUnit {
|
|
2
|
+
constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
|
|
3
|
+
antiAirPower = 0) {
|
|
4
|
+
this.basePriority = basePriority;
|
|
5
|
+
this.baseAmount = baseAmount;
|
|
6
|
+
this.antiGroundPower = antiGroundPower;
|
|
7
|
+
this.antiAirPower = antiAirPower;
|
|
8
|
+
}
|
|
9
|
+
getPlacementLocation(game, playerData, technoRules) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
getPriority(game, playerData, technoRules, threatCache) {
|
|
13
|
+
// Units aren't built automatically, but are instead requested by missions.
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
20
|
//# sourceMappingURL=basicAirUnit.js.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
2
|
-
export class BasicBuilding {
|
|
3
|
-
constructor(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount) {
|
|
4
|
-
this.basePriority = basePriority;
|
|
5
|
-
this.maxNeeded = maxNeeded;
|
|
6
|
-
this.onlyBuildWhenFloatingCreditsAmount = onlyBuildWhenFloatingCreditsAmount;
|
|
7
|
-
}
|
|
8
|
-
getPlacementLocation(game, playerData, technoRules) {
|
|
9
|
-
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
10
|
-
}
|
|
11
|
-
getPriority(game, playerData, technoRules, threatCache) {
|
|
12
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
13
|
-
const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
|
|
14
|
-
if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
|
|
15
|
-
return -100;
|
|
16
|
-
}
|
|
17
|
-
const priority = this.basePriority * (1.0 - numOwned / this.maxNeeded);
|
|
18
|
-
if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
|
|
19
|
-
return priority * (playerData.credits / this.onlyBuildWhenFloatingCreditsAmount);
|
|
20
|
-
}
|
|
21
|
-
return priority;
|
|
22
|
-
}
|
|
23
|
-
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
24
|
-
return this.maxNeeded;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
import { getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
2
|
+
export class BasicBuilding {
|
|
3
|
+
constructor(basePriority, maxNeeded, onlyBuildWhenFloatingCreditsAmount) {
|
|
4
|
+
this.basePriority = basePriority;
|
|
5
|
+
this.maxNeeded = maxNeeded;
|
|
6
|
+
this.onlyBuildWhenFloatingCreditsAmount = onlyBuildWhenFloatingCreditsAmount;
|
|
7
|
+
}
|
|
8
|
+
getPlacementLocation(game, playerData, technoRules) {
|
|
9
|
+
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
10
|
+
}
|
|
11
|
+
getPriority(game, playerData, technoRules, threatCache) {
|
|
12
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
13
|
+
const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
|
|
14
|
+
if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
|
|
15
|
+
return -100;
|
|
16
|
+
}
|
|
17
|
+
const priority = this.basePriority * (1.0 - numOwned / this.maxNeeded);
|
|
18
|
+
if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
|
|
19
|
+
return priority * (playerData.credits / this.onlyBuildWhenFloatingCreditsAmount);
|
|
20
|
+
}
|
|
21
|
+
return priority;
|
|
22
|
+
}
|
|
23
|
+
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
24
|
+
return this.maxNeeded;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
27
|
//# sourceMappingURL=basicBuilding.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export class BasicGroundUnit {
|
|
2
|
-
constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
|
|
3
|
-
antiAirPower = 0) {
|
|
4
|
-
this.basePriority = basePriority;
|
|
5
|
-
this.baseAmount = baseAmount;
|
|
6
|
-
this.antiGroundPower = antiGroundPower;
|
|
7
|
-
this.antiAirPower = antiAirPower;
|
|
8
|
-
}
|
|
9
|
-
getPlacementLocation(game, playerData, technoRules) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
getPriority(game, playerData, technoRules, threatCache) {
|
|
13
|
-
// Units aren't built automatically, but are instead requested by missions.
|
|
14
|
-
return 0;
|
|
15
|
-
}
|
|
16
|
-
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
export class BasicGroundUnit {
|
|
2
|
+
constructor(basePriority, baseAmount, antiGroundPower = 1, // boolean for now, but will eventually be used in weighting.
|
|
3
|
+
antiAirPower = 0) {
|
|
4
|
+
this.basePriority = basePriority;
|
|
5
|
+
this.baseAmount = baseAmount;
|
|
6
|
+
this.antiGroundPower = antiGroundPower;
|
|
7
|
+
this.antiAirPower = antiAirPower;
|
|
8
|
+
}
|
|
9
|
+
getPlacementLocation(game, playerData, technoRules) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
getPriority(game, playerData, technoRules, threatCache) {
|
|
13
|
+
// Units aren't built automatically, but are instead requested by missions.
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
getMaxCount(game, playerData, technoRules, threatCache) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
20
|
//# sourceMappingURL=basicGroundUnit.js.map
|