@supalosa/chronodivide-bot 0.5.4 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.template +4 -4
- package/.github/workflows/npm-publish.yml +24 -0
- package/README.md +108 -103
- package/dist/bot/bot.js +105 -105
- 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 -34
- 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 -175
- package/dist/bot/logic/building/common.js +19 -19
- 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 -95
- 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 -100
- 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 -55
- 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 -250
- package/src/bot/logic/building/common.ts +21 -21
- 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 -120
- 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/threat.ts +15 -15
- package/src/bot/logic/threat/threatCalculator.ts +100 -100
- package/src/exampleBot.ts +111 -111
- package/tsconfig.json +73 -73
- package/dist/bot/logic/awarenessImpl.js +0 -132
- package/dist/bot/logic/awarenessImpl.js.map +0 -1
- package/dist/bot/logic/building/building.js +0 -126
- package/dist/bot/logic/building/building.js.map +0 -1
- 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 -58
- 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/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/attackSquad.js +0 -89
- package/dist/bot/logic/squad/behaviours/combatSquad.js +0 -102
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/common.js +0 -40
- package/dist/bot/logic/squad/behaviours/common.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/defenceSquad.js +0 -61
- package/dist/bot/logic/squad/behaviours/engineerSquad.js +0 -36
- package/dist/bot/logic/squad/behaviours/engineerSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/expansionSquad.js +0 -43
- package/dist/bot/logic/squad/behaviours/expansionSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/retreatSquad.js +0 -28
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +0 -1
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +0 -86
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +0 -1
- 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 -199
- package/dist/bot/logic/squad/squadController.js.map +0 -1
- /package/dist/bot/logic/building/{ArtilleryUnit.js.map → artilleryUnit.js.map} +0 -0
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { GameApi, PlayerData, TechnoRules, Vector2 } from "@chronodivide/game-api";
|
|
2
|
-
import { getPointTowardsOtherPoint } from "../map/map.js";
|
|
3
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
5
|
-
import { getStaticDefencePlacement } from "./common.js";
|
|
6
|
-
|
|
7
|
-
export class AntiGroundStaticDefence implements AiBuildingRules {
|
|
8
|
-
constructor(
|
|
9
|
-
private basePriority: number,
|
|
10
|
-
private baseAmount: number,
|
|
11
|
-
private groundStrength: number,
|
|
12
|
-
private limit: number,
|
|
13
|
-
) {}
|
|
14
|
-
|
|
15
|
-
getPlacementLocation(
|
|
16
|
-
game: GameApi,
|
|
17
|
-
playerData: PlayerData,
|
|
18
|
-
technoRules: TechnoRules,
|
|
19
|
-
): { rx: number; ry: number } | undefined {
|
|
20
|
-
return getStaticDefencePlacement(game, playerData, technoRules);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getPriority(
|
|
24
|
-
game: GameApi,
|
|
25
|
-
playerData: PlayerData,
|
|
26
|
-
technoRules: TechnoRules,
|
|
27
|
-
threatCache: GlobalThreat | null,
|
|
28
|
-
): number {
|
|
29
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
30
|
-
if (numOwned >= this.limit) {
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
// If the enemy's ground power is increasing we should try to keep up.
|
|
34
|
-
if (threatCache) {
|
|
35
|
-
let denominator =
|
|
36
|
-
threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.groundStrength;
|
|
37
|
-
if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
|
|
38
|
-
return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
|
|
39
|
-
} else {
|
|
40
|
-
return 0;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const strengthPerCost = (this.groundStrength / technoRules.cost) * 1000;
|
|
44
|
-
return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getMaxCount(
|
|
48
|
-
game: GameApi,
|
|
49
|
-
playerData: PlayerData,
|
|
50
|
-
technoRules: TechnoRules,
|
|
51
|
-
threatCache: GlobalThreat | null,
|
|
52
|
-
): number | null {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, TechnoRules, Vector2 } from "@chronodivide/game-api";
|
|
2
|
+
import { getPointTowardsOtherPoint } from "../map/map.js";
|
|
3
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
5
|
+
import { getStaticDefencePlacement } from "./common.js";
|
|
6
|
+
|
|
7
|
+
export class AntiGroundStaticDefence implements AiBuildingRules {
|
|
8
|
+
constructor(
|
|
9
|
+
private basePriority: number,
|
|
10
|
+
private baseAmount: number,
|
|
11
|
+
private groundStrength: number,
|
|
12
|
+
private limit: number,
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
getPlacementLocation(
|
|
16
|
+
game: GameApi,
|
|
17
|
+
playerData: PlayerData,
|
|
18
|
+
technoRules: TechnoRules,
|
|
19
|
+
): { rx: number; ry: number } | undefined {
|
|
20
|
+
return getStaticDefencePlacement(game, playerData, technoRules);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getPriority(
|
|
24
|
+
game: GameApi,
|
|
25
|
+
playerData: PlayerData,
|
|
26
|
+
technoRules: TechnoRules,
|
|
27
|
+
threatCache: GlobalThreat | null,
|
|
28
|
+
): number {
|
|
29
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
30
|
+
if (numOwned >= this.limit) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
// If the enemy's ground power is increasing we should try to keep up.
|
|
34
|
+
if (threatCache) {
|
|
35
|
+
let denominator =
|
|
36
|
+
threatCache.totalAvailableAntiGroundFirepower + threatCache.totalDefensivePower + this.groundStrength;
|
|
37
|
+
if (threatCache.totalOffensiveLandThreat > denominator * 1.1) {
|
|
38
|
+
return this.basePriority * (threatCache.totalOffensiveLandThreat / Math.max(1, denominator));
|
|
39
|
+
} else {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const strengthPerCost = (this.groundStrength / technoRules.cost) * 1000;
|
|
44
|
+
return this.basePriority * (1.0 - numOwned / this.baseAmount) * strengthPerCost;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getMaxCount(
|
|
48
|
+
game: GameApi,
|
|
49
|
+
playerData: PlayerData,
|
|
50
|
+
technoRules: TechnoRules,
|
|
51
|
+
threatCache: GlobalThreat | null,
|
|
52
|
+
): number | null {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { GameApi, GameMath, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
-
import { AiBuildingRules, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
4
|
-
|
|
5
|
-
export class ArtilleryUnit implements AiBuildingRules {
|
|
6
|
-
constructor(
|
|
7
|
-
private basePriority: number,
|
|
8
|
-
private artilleryPower: number,
|
|
9
|
-
private antiGroundPower: number,
|
|
10
|
-
private baseAmount: number,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
getPlacementLocation(
|
|
14
|
-
game: GameApi,
|
|
15
|
-
playerData: PlayerData,
|
|
16
|
-
technoRules: TechnoRules,
|
|
17
|
-
): { rx: number; ry: number } | undefined {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getPriority(
|
|
22
|
-
game: GameApi,
|
|
23
|
-
playerData: PlayerData,
|
|
24
|
-
technoRules: TechnoRules,
|
|
25
|
-
threatCache: GlobalThreat | null,
|
|
26
|
-
): number {
|
|
27
|
-
// Units aren't built automatically, but are instead requested by missions.
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getMaxCount(
|
|
32
|
-
game: GameApi,
|
|
33
|
-
playerData: PlayerData,
|
|
34
|
-
technoRules: TechnoRules,
|
|
35
|
-
threatCache: GlobalThreat | null,
|
|
36
|
-
): number | null {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
import { GameApi, GameMath, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
+
import { AiBuildingRules, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
4
|
+
|
|
5
|
+
export class ArtilleryUnit implements AiBuildingRules {
|
|
6
|
+
constructor(
|
|
7
|
+
private basePriority: number,
|
|
8
|
+
private artilleryPower: number,
|
|
9
|
+
private antiGroundPower: number,
|
|
10
|
+
private baseAmount: number,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
getPlacementLocation(
|
|
14
|
+
game: GameApi,
|
|
15
|
+
playerData: PlayerData,
|
|
16
|
+
technoRules: TechnoRules,
|
|
17
|
+
): { rx: number; ry: number } | undefined {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getPriority(
|
|
22
|
+
game: GameApi,
|
|
23
|
+
playerData: PlayerData,
|
|
24
|
+
technoRules: TechnoRules,
|
|
25
|
+
threatCache: GlobalThreat | null,
|
|
26
|
+
): number {
|
|
27
|
+
// Units aren't built automatically, but are instead requested by missions.
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getMaxCount(
|
|
32
|
+
game: GameApi,
|
|
33
|
+
playerData: PlayerData,
|
|
34
|
+
technoRules: TechnoRules,
|
|
35
|
+
threatCache: GlobalThreat | null,
|
|
36
|
+
): number | null {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { GameApi, GameMath, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
4
|
-
|
|
5
|
-
export class BasicAirUnit implements AiBuildingRules {
|
|
6
|
-
constructor(
|
|
7
|
-
private basePriority: number,
|
|
8
|
-
private baseAmount: number,
|
|
9
|
-
private antiGroundPower: number = 1, // boolean for now, but will eventually be used in weighting.
|
|
10
|
-
private antiAirPower: number = 0,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
getPlacementLocation(
|
|
14
|
-
game: GameApi,
|
|
15
|
-
playerData: PlayerData,
|
|
16
|
-
technoRules: TechnoRules,
|
|
17
|
-
): { rx: number; ry: number } | undefined {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getPriority(
|
|
22
|
-
game: GameApi,
|
|
23
|
-
playerData: PlayerData,
|
|
24
|
-
technoRules: TechnoRules,
|
|
25
|
-
threatCache: GlobalThreat | null,
|
|
26
|
-
): number {
|
|
27
|
-
// Units aren't built automatically, but are instead requested by missions.
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getMaxCount(
|
|
32
|
-
game: GameApi,
|
|
33
|
-
playerData: PlayerData,
|
|
34
|
-
technoRules: TechnoRules,
|
|
35
|
-
threatCache: GlobalThreat | null,
|
|
36
|
-
): number | null {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
import { GameApi, GameMath, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
4
|
+
|
|
5
|
+
export class BasicAirUnit implements AiBuildingRules {
|
|
6
|
+
constructor(
|
|
7
|
+
private basePriority: number,
|
|
8
|
+
private baseAmount: number,
|
|
9
|
+
private antiGroundPower: number = 1, // boolean for now, but will eventually be used in weighting.
|
|
10
|
+
private antiAirPower: number = 0,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
getPlacementLocation(
|
|
14
|
+
game: GameApi,
|
|
15
|
+
playerData: PlayerData,
|
|
16
|
+
technoRules: TechnoRules,
|
|
17
|
+
): { rx: number; ry: number } | undefined {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getPriority(
|
|
22
|
+
game: GameApi,
|
|
23
|
+
playerData: PlayerData,
|
|
24
|
+
technoRules: TechnoRules,
|
|
25
|
+
threatCache: GlobalThreat | null,
|
|
26
|
+
): number {
|
|
27
|
+
// Units aren't built automatically, but are instead requested by missions.
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getMaxCount(
|
|
32
|
+
game: GameApi,
|
|
33
|
+
playerData: PlayerData,
|
|
34
|
+
technoRules: TechnoRules,
|
|
35
|
+
threatCache: GlobalThreat | null,
|
|
36
|
+
): number | null {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
3
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
-
|
|
5
|
-
export class BasicBuilding implements AiBuildingRules {
|
|
6
|
-
constructor(
|
|
7
|
-
protected basePriority: number,
|
|
8
|
-
protected maxNeeded: number,
|
|
9
|
-
protected onlyBuildWhenFloatingCreditsAmount?: number,
|
|
10
|
-
) {}
|
|
11
|
-
|
|
12
|
-
getPlacementLocation(
|
|
13
|
-
game: GameApi,
|
|
14
|
-
playerData: PlayerData,
|
|
15
|
-
technoRules: TechnoRules,
|
|
16
|
-
): { rx: number; ry: number } | undefined {
|
|
17
|
-
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getPriority(
|
|
21
|
-
game: GameApi,
|
|
22
|
-
playerData: PlayerData,
|
|
23
|
-
technoRules: TechnoRules,
|
|
24
|
-
threatCache: GlobalThreat | null,
|
|
25
|
-
): number {
|
|
26
|
-
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
27
|
-
const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
|
|
28
|
-
if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
|
|
29
|
-
return -100;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const priority = this.basePriority * (1.0 - numOwned / this.maxNeeded);
|
|
33
|
-
|
|
34
|
-
if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
|
|
35
|
-
return priority * (playerData.credits / this.onlyBuildWhenFloatingCreditsAmount);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return priority;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getMaxCount(
|
|
42
|
-
game: GameApi,
|
|
43
|
-
playerData: PlayerData,
|
|
44
|
-
technoRules: TechnoRules,
|
|
45
|
-
threatCache: GlobalThreat | null,
|
|
46
|
-
): number | null {
|
|
47
|
-
return this.maxNeeded;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
import { GameApi, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
3
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
4
|
+
|
|
5
|
+
export class BasicBuilding implements AiBuildingRules {
|
|
6
|
+
constructor(
|
|
7
|
+
protected basePriority: number,
|
|
8
|
+
protected maxNeeded: number,
|
|
9
|
+
protected onlyBuildWhenFloatingCreditsAmount?: number,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
getPlacementLocation(
|
|
13
|
+
game: GameApi,
|
|
14
|
+
playerData: PlayerData,
|
|
15
|
+
technoRules: TechnoRules,
|
|
16
|
+
): { rx: number; ry: number } | undefined {
|
|
17
|
+
return getDefaultPlacementLocation(game, playerData, playerData.startLocation, technoRules);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getPriority(
|
|
21
|
+
game: GameApi,
|
|
22
|
+
playerData: PlayerData,
|
|
23
|
+
technoRules: TechnoRules,
|
|
24
|
+
threatCache: GlobalThreat | null,
|
|
25
|
+
): number {
|
|
26
|
+
const numOwned = numBuildingsOwnedOfType(game, playerData, technoRules);
|
|
27
|
+
const calcMaxCount = this.getMaxCount(game, playerData, technoRules, threatCache);
|
|
28
|
+
if (numOwned >= (calcMaxCount ?? this.maxNeeded)) {
|
|
29
|
+
return -100;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const priority = this.basePriority * (1.0 - numOwned / this.maxNeeded);
|
|
33
|
+
|
|
34
|
+
if (this.onlyBuildWhenFloatingCreditsAmount && playerData.credits < this.onlyBuildWhenFloatingCreditsAmount) {
|
|
35
|
+
return priority * (playerData.credits / this.onlyBuildWhenFloatingCreditsAmount);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return priority;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getMaxCount(
|
|
42
|
+
game: GameApi,
|
|
43
|
+
playerData: PlayerData,
|
|
44
|
+
technoRules: TechnoRules,
|
|
45
|
+
threatCache: GlobalThreat | null,
|
|
46
|
+
): number | null {
|
|
47
|
+
return this.maxNeeded;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { GameApi, GameMath, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
-
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
-
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
4
|
-
|
|
5
|
-
export class BasicGroundUnit implements AiBuildingRules {
|
|
6
|
-
constructor(
|
|
7
|
-
protected basePriority: number,
|
|
8
|
-
protected baseAmount: number,
|
|
9
|
-
protected antiGroundPower: number = 1, // boolean for now, but will eventually be used in weighting.
|
|
10
|
-
protected antiAirPower: number = 0,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
getPlacementLocation(
|
|
14
|
-
game: GameApi,
|
|
15
|
-
playerData: PlayerData,
|
|
16
|
-
technoRules: TechnoRules,
|
|
17
|
-
): { rx: number; ry: number } | undefined {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getPriority(
|
|
22
|
-
game: GameApi,
|
|
23
|
-
playerData: PlayerData,
|
|
24
|
-
technoRules: TechnoRules,
|
|
25
|
-
threatCache: GlobalThreat | null,
|
|
26
|
-
): number {
|
|
27
|
-
// Units aren't built automatically, but are instead requested by missions.
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getMaxCount(
|
|
32
|
-
game: GameApi,
|
|
33
|
-
playerData: PlayerData,
|
|
34
|
-
technoRules: TechnoRules,
|
|
35
|
-
threatCache: GlobalThreat | null,
|
|
36
|
-
): number | null {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
import { GameApi, GameMath, PlayerData, TechnoRules } from "@chronodivide/game-api";
|
|
2
|
+
import { GlobalThreat } from "../threat/threat.js";
|
|
3
|
+
import { AiBuildingRules, getDefaultPlacementLocation, numBuildingsOwnedOfType } from "./buildingRules.js";
|
|
4
|
+
|
|
5
|
+
export class BasicGroundUnit implements AiBuildingRules {
|
|
6
|
+
constructor(
|
|
7
|
+
protected basePriority: number,
|
|
8
|
+
protected baseAmount: number,
|
|
9
|
+
protected antiGroundPower: number = 1, // boolean for now, but will eventually be used in weighting.
|
|
10
|
+
protected antiAirPower: number = 0,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
getPlacementLocation(
|
|
14
|
+
game: GameApi,
|
|
15
|
+
playerData: PlayerData,
|
|
16
|
+
technoRules: TechnoRules,
|
|
17
|
+
): { rx: number; ry: number } | undefined {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getPriority(
|
|
22
|
+
game: GameApi,
|
|
23
|
+
playerData: PlayerData,
|
|
24
|
+
technoRules: TechnoRules,
|
|
25
|
+
threatCache: GlobalThreat | null,
|
|
26
|
+
): number {
|
|
27
|
+
// Units aren't built automatically, but are instead requested by missions.
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getMaxCount(
|
|
32
|
+
game: GameApi,
|
|
33
|
+
playerData: PlayerData,
|
|
34
|
+
technoRules: TechnoRules,
|
|
35
|
+
threatCache: GlobalThreat | null,
|
|
36
|
+
): number | null {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|