@supalosa/chronodivide-bot 0.3.1 → 0.5.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.
- package/.env.template +5 -0
- package/README.md +57 -39
- package/dist/bot/bot.js +27 -37
- package/dist/bot/bot.js.map +1 -1
- package/dist/bot/logic/awareness.js +13 -8
- package/dist/bot/logic/awareness.js.map +1 -1
- package/dist/bot/logic/awarenessImpl.js +132 -0
- package/dist/bot/logic/awarenessImpl.js.map +1 -0
- package/dist/bot/logic/building/ArtilleryUnit.js +2 -29
- package/dist/bot/logic/building/ArtilleryUnit.js.map +1 -0
- package/dist/bot/logic/building/antiAirStaticDefence.js +43 -0
- package/dist/bot/logic/building/antiAirStaticDefence.js.map +1 -0
- package/dist/bot/logic/building/antiGroundStaticDefence.js +8 -5
- package/dist/bot/logic/building/antiGroundStaticDefence.js.map +1 -1
- package/dist/bot/logic/building/basicAirUnit.js +2 -23
- package/dist/bot/logic/building/basicAirUnit.js.map +1 -1
- package/dist/bot/logic/building/basicBuilding.js +3 -2
- package/dist/bot/logic/building/basicBuilding.js.map +1 -1
- package/dist/bot/logic/building/basicGroundUnit.js +2 -43
- package/dist/bot/logic/building/basicGroundUnit.js.map +1 -1
- package/dist/bot/logic/building/building.js +55 -11
- package/dist/bot/logic/building/building.js.map +1 -0
- package/dist/bot/logic/building/buildingRules.js +62 -50
- package/dist/bot/logic/building/buildingRules.js.map +1 -1
- package/dist/bot/logic/building/common.js +19 -0
- package/dist/bot/logic/building/common.js.map +1 -0
- package/dist/bot/logic/building/harvester.js +2 -1
- package/dist/bot/logic/building/harvester.js.map +1 -1
- package/dist/bot/logic/building/queueController.js +73 -41
- package/dist/bot/logic/building/queueController.js.map +1 -1
- package/dist/bot/logic/common/utils.js +35 -0
- package/dist/bot/logic/common/utils.js.map +1 -1
- package/dist/bot/logic/composition/alliedCompositions.js +13 -0
- package/dist/bot/logic/composition/alliedCompositions.js.map +1 -0
- package/dist/bot/logic/composition/common.js +2 -0
- package/dist/bot/logic/composition/common.js.map +1 -0
- package/dist/bot/logic/composition/sovietCompositions.js +13 -0
- package/dist/bot/logic/composition/sovietCompositions.js.map +1 -0
- package/dist/bot/logic/mission/actionBatcher.js +92 -0
- package/dist/bot/logic/mission/actionBatcher.js.map +1 -0
- package/dist/bot/logic/mission/behaviours/combatSquad.js +124 -0
- package/dist/bot/logic/mission/behaviours/combatSquad.js.map +1 -0
- package/dist/bot/logic/mission/behaviours/common.js +58 -0
- package/dist/bot/logic/mission/behaviours/common.js.map +1 -0
- package/dist/bot/logic/mission/behaviours/engineerSquad.js +39 -0
- package/dist/bot/logic/mission/behaviours/engineerSquad.js.map +1 -0
- package/dist/bot/logic/mission/behaviours/expansionSquad.js +46 -0
- package/dist/bot/logic/mission/behaviours/expansionSquad.js.map +1 -0
- package/dist/bot/logic/mission/behaviours/retreatSquad.js +31 -0
- package/dist/bot/logic/mission/behaviours/retreatSquad.js.map +1 -0
- package/{src/bot/logic/squad/behaviours/scoutingSquad.ts → dist/bot/logic/mission/behaviours/scoutingSquad.js} +29 -47
- package/dist/bot/logic/mission/behaviours/scoutingSquad.js.map +1 -0
- package/dist/bot/logic/mission/mission.js +91 -19
- package/dist/bot/logic/mission/mission.js.map +1 -1
- package/dist/bot/logic/mission/missionController.js +262 -21
- package/dist/bot/logic/mission/missionController.js.map +1 -1
- package/dist/bot/logic/mission/missions/attackMission.js +159 -52
- package/dist/bot/logic/mission/missions/attackMission.js.map +1 -1
- package/dist/bot/logic/mission/missions/basicMission.js +13 -0
- package/dist/bot/logic/mission/missions/basicMission.js.map +1 -0
- package/dist/bot/logic/mission/missions/defenceMission.js +43 -28
- package/dist/bot/logic/mission/missions/defenceMission.js.map +1 -1
- package/dist/bot/logic/mission/missions/engineerMission.js +37 -7
- package/dist/bot/logic/mission/missions/engineerMission.js.map +1 -1
- package/dist/bot/logic/mission/missions/expansionMission.js +42 -6
- package/dist/bot/logic/mission/missions/expansionMission.js.map +1 -1
- package/dist/bot/logic/mission/missions/missionBehaviour.js +2 -0
- package/dist/bot/logic/mission/missions/missionBehaviour.js.map +1 -0
- package/dist/bot/logic/mission/missions/retreatMission.js +31 -5
- package/dist/bot/logic/mission/missions/retreatMission.js.map +1 -1
- package/dist/bot/logic/mission/missions/scoutingMission.js +103 -6
- package/dist/bot/logic/mission/missions/scoutingMission.js.map +1 -1
- package/dist/bot/logic/mission/missions/squads/combatSquad.js +116 -0
- package/dist/bot/logic/mission/missions/squads/combatSquad.js.map +1 -0
- package/dist/bot/logic/mission/missions/squads/common.js +58 -0
- package/dist/bot/logic/mission/missions/squads/common.js.map +1 -0
- package/dist/bot/logic/mission/missions/squads/squad.js +2 -0
- package/dist/bot/logic/mission/missions/squads/squad.js.map +1 -0
- package/dist/bot/logic/squad/behaviours/attackSquad.js +63 -56
- package/dist/bot/logic/squad/behaviours/combatSquad.js +19 -18
- package/dist/bot/logic/squad/behaviours/combatSquad.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/common.js +2 -19
- package/dist/bot/logic/squad/behaviours/common.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/defenceSquad.js +15 -2
- package/dist/bot/logic/squad/behaviours/retreatSquad.js.map +1 -1
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js +17 -21
- package/dist/bot/logic/squad/behaviours/scoutingSquad.js.map +1 -1
- package/dist/bot/logic/squad/squad.js +8 -5
- package/dist/bot/logic/squad/squad.js.map +1 -1
- package/dist/bot/logic/squad/squadBehaviour.js.map +1 -1
- package/dist/bot/logic/squad/squadController.js +3 -2
- package/dist/bot/logic/squad/squadController.js.map +1 -1
- package/dist/bot/logic/threat/threatCalculator.js +5 -5
- package/dist/bot/logic/threat/threatCalculator.js.map +1 -1
- package/dist/exampleBot.js +53 -16
- package/dist/exampleBot.js.map +1 -1
- package/package.json +5 -4
- package/src/bot/bot.ts +38 -53
- package/src/bot/logic/awareness.ts +34 -22
- package/src/bot/logic/building/antiAirStaticDefence.ts +64 -0
- package/src/bot/logic/building/antiGroundStaticDefence.ts +7 -20
- package/src/bot/logic/building/artilleryUnit.ts +2 -28
- package/src/bot/logic/building/basicAirUnit.ts +2 -33
- package/src/bot/logic/building/basicBuilding.ts +8 -6
- package/src/bot/logic/building/basicGroundUnit.ts +2 -46
- package/src/bot/logic/building/buildingRules.ts +73 -57
- package/src/bot/logic/building/common.ts +23 -0
- package/src/bot/logic/building/harvester.ts +2 -1
- package/src/bot/logic/building/queueController.ts +105 -42
- package/src/bot/logic/common/utils.ts +47 -0
- package/src/bot/logic/composition/alliedCompositions.ts +22 -0
- package/src/bot/logic/composition/common.ts +3 -0
- package/src/bot/logic/composition/sovietCompositions.ts +21 -0
- package/src/bot/logic/mission/actionBatcher.ts +124 -0
- package/src/bot/logic/mission/mission.ts +186 -37
- package/src/bot/logic/mission/missionController.ts +340 -31
- package/src/bot/logic/mission/missionFactories.ts +3 -3
- package/src/bot/logic/mission/missions/attackMission.ts +234 -56
- package/src/bot/logic/mission/missions/defenceMission.ts +72 -45
- package/src/bot/logic/mission/missions/engineerMission.ts +67 -15
- package/src/bot/logic/mission/missions/expansionMission.ts +67 -14
- package/src/bot/logic/mission/missions/retreatMission.ts +50 -6
- package/src/bot/logic/mission/missions/scoutingMission.ts +138 -14
- package/src/bot/logic/mission/missions/squads/combatSquad.ts +160 -0
- package/src/bot/logic/{squad/behaviours → mission/missions/squads}/common.ts +14 -20
- package/src/bot/logic/mission/missions/squads/squad.ts +19 -0
- package/src/bot/logic/threat/threat.ts +15 -15
- package/src/bot/logic/threat/threatCalculator.ts +10 -10
- package/src/exampleBot.ts +59 -19
- package/.prettierrc +0 -5
- package/TODO.md +0 -18
- package/dist/bot/logic/building/artilleryUnit.js.map +0 -1
- 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/expansionMission.js +0 -32
- package/dist/bot/logic/squad/behaviours/squadExpansion.js +0 -31
- package/dist/bot/logic/squad/behaviours/squadScouters.js +0 -8
- package/rules.ini +0 -23126
- package/src/bot/logic/mission/missions/oneTimeMission.ts +0 -33
- package/src/bot/logic/squad/behaviours/combatSquad.ts +0 -127
- package/src/bot/logic/squad/behaviours/engineerSquad.ts +0 -53
- package/src/bot/logic/squad/behaviours/expansionSquad.ts +0 -59
- package/src/bot/logic/squad/behaviours/retreatSquad.ts +0 -44
- package/src/bot/logic/squad/squad.ts +0 -159
- package/src/bot/logic/squad/squadBehaviour.ts +0 -62
- package/src/bot/logic/squad/squadBehaviours.ts +0 -8
- package/src/bot/logic/squad/squadController.ts +0 -254
|
@@ -1,51 +1,233 @@
|
|
|
1
|
-
// Meta-controller for forming and controlling
|
|
1
|
+
// Meta-controller for forming and controlling missions.
|
|
2
|
+
// Missions are groups of zero or more units that aim to accomplish a particular goal.
|
|
3
|
+
import { Vector2 } from "@chronodivide/game-api";
|
|
4
|
+
import { isDisbandMission, isGrabCombatants, isReleaseUnits, isRequestSpecificUnits, isRequestUnits, } from "./mission.js";
|
|
2
5
|
import { createMissionFactories } from "./missionFactories.js";
|
|
6
|
+
import { ActionBatcher } from "./actionBatcher.js";
|
|
7
|
+
import { countBy, isSelectableCombatant } from "../common/utils.js";
|
|
8
|
+
// `missingUnitTypes` priority decays by this much every update loop.
|
|
9
|
+
const MISSING_UNIT_TYPE_REQUEST_DECAY_MULT_RATE = 0.75;
|
|
10
|
+
const MISSING_UNIT_TYPE_REQUEST_DECAY_FLAT_RATE = 1;
|
|
3
11
|
export class MissionController {
|
|
4
12
|
constructor(logger) {
|
|
5
13
|
this.logger = logger;
|
|
6
14
|
this.missions = [];
|
|
15
|
+
// A mapping of unit IDs to the missions they are assigned to. This may contain units that are dead, but
|
|
16
|
+
// is periodically cleaned in the update loop.
|
|
17
|
+
this.unitIdToMission = new Map();
|
|
18
|
+
// A mapping of unit types to the highest priority requested for a mission.
|
|
19
|
+
// This decays over time if requests are not 'refreshed' by mission.
|
|
20
|
+
this.requestedUnitTypes = new Map();
|
|
21
|
+
// Tracks missions to be externally disbanded the next time the mission update loop occurs.
|
|
7
22
|
this.forceDisbandedMissions = [];
|
|
8
23
|
this.missionFactories = createMissionFactories();
|
|
9
24
|
}
|
|
10
|
-
|
|
25
|
+
updateUnitIds(gameApi) {
|
|
26
|
+
// Check for units in multiple missions, this shouldn't happen.
|
|
27
|
+
this.unitIdToMission = new Map();
|
|
28
|
+
this.missions.forEach((mission) => {
|
|
29
|
+
const toRemove = [];
|
|
30
|
+
mission.getUnitIds().forEach((unitId) => {
|
|
31
|
+
if (this.unitIdToMission.has(unitId)) {
|
|
32
|
+
this.logger(`WARNING: unit ${unitId} is in multiple missions, please debug.`);
|
|
33
|
+
}
|
|
34
|
+
else if (!gameApi.getGameObjectData(unitId)) {
|
|
35
|
+
// say, if a unit was killed
|
|
36
|
+
toRemove.push(unitId);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.unitIdToMission.set(unitId, mission);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
toRemove.forEach((unitId) => mission.removeUnit(unitId));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
onAiUpdate(gameApi, actionsApi, playerData, matchAwareness) {
|
|
11
46
|
// Remove inactive missions.
|
|
12
47
|
this.missions = this.missions.filter((missions) => missions.isActive());
|
|
48
|
+
this.updateUnitIds(gameApi);
|
|
49
|
+
// Batch actions to reduce spamming of actions for larger armies.
|
|
50
|
+
const actionBatcher = new ActionBatcher();
|
|
13
51
|
// Poll missions for requested actions.
|
|
14
52
|
const missionActions = this.missions.map((mission) => ({
|
|
15
53
|
mission,
|
|
16
|
-
action: mission.onAiUpdate(gameApi, playerData, matchAwareness),
|
|
54
|
+
action: mission.onAiUpdate(gameApi, actionsApi, playerData, matchAwareness, actionBatcher),
|
|
17
55
|
}));
|
|
18
56
|
// Handle disbands and merges.
|
|
19
|
-
const isDisband = (a) => a.type == "disband";
|
|
20
57
|
const disbandedMissions = new Map();
|
|
21
58
|
const disbandedMissionsArray = [];
|
|
22
59
|
this.forceDisbandedMissions.forEach((name) => disbandedMissions.set(name, null));
|
|
23
60
|
this.forceDisbandedMissions = [];
|
|
24
|
-
missionActions
|
|
25
|
-
.
|
|
26
|
-
.forEach((
|
|
61
|
+
missionActions.filter(isDisbandMission).forEach((a) => {
|
|
62
|
+
this.logger(`Mission ${a.mission.getUniqueName()} disbanding as requested.`);
|
|
63
|
+
a.mission.getUnitIds().forEach((unitId) => {
|
|
64
|
+
this.unitIdToMission.delete(unitId);
|
|
65
|
+
actionsApi.setUnitDebugText(unitId, undefined);
|
|
66
|
+
});
|
|
27
67
|
disbandedMissions.set(a.mission.getUniqueName(), a.action.reason);
|
|
28
68
|
});
|
|
29
|
-
//
|
|
69
|
+
// Handle unit requests.
|
|
70
|
+
// Release units
|
|
71
|
+
missionActions.filter(isReleaseUnits).forEach((a) => {
|
|
72
|
+
a.action.unitIds.forEach((unitId) => {
|
|
73
|
+
if (this.unitIdToMission.get(unitId)?.getUniqueName() === a.mission.getUniqueName()) {
|
|
74
|
+
this.removeUnitFromMission(a.mission, unitId, actionsApi);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
// Request specific units by ID
|
|
79
|
+
const unitIdToHighestRequest = missionActions.filter(isRequestSpecificUnits).reduce((prev, missionWithAction) => {
|
|
80
|
+
const { unitIds } = missionWithAction.action;
|
|
81
|
+
unitIds.forEach((unitId) => {
|
|
82
|
+
if (prev.hasOwnProperty(unitId)) {
|
|
83
|
+
if (prev[unitId].action.priority > prev[unitId].action.priority) {
|
|
84
|
+
prev[unitId] = missionWithAction;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
prev[unitId] = missionWithAction;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return prev;
|
|
92
|
+
}, {});
|
|
93
|
+
// Map of Mission ID to Unit Type to Count.
|
|
94
|
+
const newMissionAssignments = Object.entries(unitIdToHighestRequest)
|
|
95
|
+
.flatMap(([id, request]) => {
|
|
96
|
+
const unitId = Number.parseInt(id);
|
|
97
|
+
const unit = gameApi.getGameObjectData(unitId);
|
|
98
|
+
const { mission: requestingMission } = request;
|
|
99
|
+
const missionName = requestingMission.getUniqueName();
|
|
100
|
+
if (!unit) {
|
|
101
|
+
this.logger(`mission ${missionName} requested non-existent unit ${unitId}`);
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
if (!this.unitIdToMission.has(unitId)) {
|
|
105
|
+
this.addUnitToMission(requestingMission, unit, actionsApi);
|
|
106
|
+
return [{ unitName: unit?.name, mission: requestingMission.getUniqueName() }];
|
|
107
|
+
}
|
|
108
|
+
return [];
|
|
109
|
+
})
|
|
110
|
+
.reduce((acc, curr) => {
|
|
111
|
+
if (!acc[curr.mission]) {
|
|
112
|
+
acc[curr.mission] = {};
|
|
113
|
+
}
|
|
114
|
+
if (!acc[curr.mission][curr.unitName]) {
|
|
115
|
+
acc[curr.mission][curr.unitName] = 0;
|
|
116
|
+
}
|
|
117
|
+
acc[curr.mission][curr.unitName] = acc[curr.mission][curr.unitName] + 1;
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
Object.entries(newMissionAssignments).forEach(([mission, assignments]) => {
|
|
121
|
+
this.logger(`Mission ${mission} received: ${Object.entries(assignments)
|
|
122
|
+
.map(([unitType, count]) => unitType + " x " + count)
|
|
123
|
+
.join(", ")}`);
|
|
124
|
+
});
|
|
125
|
+
// Request units by type - store the highest priority mission for each unit type.
|
|
126
|
+
const unitTypeToHighestRequest = missionActions.filter(isRequestUnits).reduce((prev, missionWithAction) => {
|
|
127
|
+
const { unitNames } = missionWithAction.action;
|
|
128
|
+
unitNames.forEach((unitName) => {
|
|
129
|
+
if (prev.hasOwnProperty(unitName)) {
|
|
130
|
+
if (prev[unitName].action.priority > prev[unitName].action.priority) {
|
|
131
|
+
prev[unitName] = missionWithAction;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
prev[unitName] = missionWithAction;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return prev;
|
|
139
|
+
}, {});
|
|
140
|
+
// Request combat-capable units in an area
|
|
141
|
+
const grabRequests = missionActions.filter(isGrabCombatants);
|
|
142
|
+
// Find un-assigned units and distribute them among all the requesting missions.
|
|
143
|
+
const unitIds = gameApi.getVisibleUnits(playerData.name, "self");
|
|
144
|
+
// List of units that are unassigned or not in a locked mission.
|
|
145
|
+
const freeUnits = unitIds
|
|
146
|
+
.map((unitId) => gameApi.getGameObjectData(unitId))
|
|
147
|
+
.filter((unit) => !!unit)
|
|
148
|
+
.map((unit) => ({
|
|
149
|
+
unit,
|
|
150
|
+
mission: this.unitIdToMission.get(unit.id),
|
|
151
|
+
}))
|
|
152
|
+
.filter((unitWithMission) => !unitWithMission.mission || unitWithMission.mission.isUnitsLocked() === false);
|
|
153
|
+
// Sort free units so that unassigned units get chosen before assigned (but unlocked) units.
|
|
154
|
+
freeUnits.sort((u1, u2) => (u1.mission?.getPriority() ?? 0) - (u2.mission?.getPriority() ?? 0));
|
|
155
|
+
const newAssignmentsByType = freeUnits
|
|
156
|
+
.flatMap(({ unit: freeUnit, mission: donatingMission }) => {
|
|
157
|
+
if (unitTypeToHighestRequest.hasOwnProperty(freeUnit.name)) {
|
|
158
|
+
const { mission: requestingMission } = unitTypeToHighestRequest[freeUnit.name];
|
|
159
|
+
if (donatingMission) {
|
|
160
|
+
if (donatingMission === requestingMission ||
|
|
161
|
+
donatingMission.getPriority() > requestingMission.getPriority()) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
this.removeUnitFromMission(donatingMission, freeUnit.id, actionsApi);
|
|
165
|
+
}
|
|
166
|
+
this.logger(`granting unit ${freeUnit.id}#${freeUnit.name} to mission ${requestingMission.getUniqueName()}`);
|
|
167
|
+
this.addUnitToMission(requestingMission, freeUnit, actionsApi);
|
|
168
|
+
delete unitTypeToHighestRequest[freeUnit.name];
|
|
169
|
+
return [
|
|
170
|
+
{ unitName: freeUnit.name, missionName: requestingMission.getUniqueName(), method: "type" },
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
else if (grabRequests.length > 0) {
|
|
174
|
+
const grantedMission = grabRequests.find((request) => {
|
|
175
|
+
const canGrabUnit = isSelectableCombatant(freeUnit);
|
|
176
|
+
return (canGrabUnit &&
|
|
177
|
+
request.action.point.distanceTo(new Vector2(freeUnit.tile.rx, freeUnit.tile.ry)) <=
|
|
178
|
+
request.action.radius);
|
|
179
|
+
});
|
|
180
|
+
if (grantedMission) {
|
|
181
|
+
if (donatingMission) {
|
|
182
|
+
if (donatingMission === grantedMission.mission ||
|
|
183
|
+
donatingMission.getPriority() > grantedMission.mission.getPriority()) {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
this.removeUnitFromMission(donatingMission, freeUnit.id, actionsApi);
|
|
187
|
+
}
|
|
188
|
+
this.addUnitToMission(grantedMission.mission, freeUnit, actionsApi);
|
|
189
|
+
return [
|
|
190
|
+
{
|
|
191
|
+
unitName: freeUnit.name,
|
|
192
|
+
missionName: grantedMission.mission.getUniqueName(),
|
|
193
|
+
method: "grab",
|
|
194
|
+
},
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return [];
|
|
199
|
+
})
|
|
200
|
+
.reduce((acc, curr) => {
|
|
201
|
+
if (!acc[curr.missionName]) {
|
|
202
|
+
acc[curr.missionName] = {};
|
|
203
|
+
}
|
|
204
|
+
if (!acc[curr.missionName][curr.unitName]) {
|
|
205
|
+
acc[curr.missionName][curr.unitName] = { grab: 0, type: 0 };
|
|
206
|
+
}
|
|
207
|
+
acc[curr.missionName][curr.unitName][curr.method] =
|
|
208
|
+
acc[curr.missionName][curr.unitName][curr.method] + 1;
|
|
209
|
+
return acc;
|
|
210
|
+
}, {});
|
|
211
|
+
Object.entries(newAssignmentsByType).forEach(([mission, assignments]) => {
|
|
212
|
+
this.logger(`Mission ${mission} received: ${Object.entries(assignments)
|
|
213
|
+
.flatMap(([unitType, methodToCount]) => Object.entries(methodToCount)
|
|
214
|
+
.filter(([, count]) => count > 0)
|
|
215
|
+
.map(([method, count]) => unitType + " x " + count + " (by " + method + ")"))
|
|
216
|
+
.join(", ")}`);
|
|
217
|
+
});
|
|
218
|
+
this.updateRequestedUnitTypes(unitTypeToHighestRequest);
|
|
219
|
+
// Send all actions that can be batched together.
|
|
220
|
+
actionBatcher.resolve(actionsApi);
|
|
221
|
+
// Remove disbanded and merged missions.
|
|
30
222
|
this.missions
|
|
31
223
|
.filter((missions) => disbandedMissions.has(missions.getUniqueName()))
|
|
32
224
|
.forEach((disbandedMission) => {
|
|
33
225
|
const reason = disbandedMissions.get(disbandedMission.getUniqueName());
|
|
34
|
-
this.logger(`mission disbanded: ${disbandedMission.getUniqueName()}, reason: ${reason}
|
|
226
|
+
this.logger(`mission disbanded: ${disbandedMission.getUniqueName()}, reason: ${reason}`);
|
|
35
227
|
disbandedMissionsArray.push({ mission: disbandedMission, reason });
|
|
36
228
|
disbandedMission.endMission(disbandedMissions.get(disbandedMission.getUniqueName()));
|
|
37
|
-
disbandedMission.getSquad()?.setMission(null);
|
|
38
229
|
});
|
|
39
230
|
this.missions = this.missions.filter((missions) => !disbandedMissions.has(missions.getUniqueName()));
|
|
40
|
-
// Register new squads
|
|
41
|
-
const isNewSquad = (a) => a.type == "registerSquad";
|
|
42
|
-
missionActions
|
|
43
|
-
.filter((a) => isNewSquad(a.action))
|
|
44
|
-
.forEach((a) => {
|
|
45
|
-
const action = a.action;
|
|
46
|
-
squadController.registerSquad(action.squad);
|
|
47
|
-
this.logger(`registered a squad: ${action.squad.getName()}`);
|
|
48
|
-
});
|
|
49
231
|
// Create dynamic missions.
|
|
50
232
|
this.missionFactories.forEach((missionFactory) => {
|
|
51
233
|
missionFactory.maybeCreateMissions(gameApi, playerData, matchAwareness, this, this.logger);
|
|
@@ -54,6 +236,43 @@ export class MissionController {
|
|
|
54
236
|
});
|
|
55
237
|
});
|
|
56
238
|
}
|
|
239
|
+
updateRequestedUnitTypes(missingUnitTypeToHighestRequest) {
|
|
240
|
+
// Decay the priority over time.
|
|
241
|
+
const currentUnitTypes = Array.from(this.requestedUnitTypes.keys());
|
|
242
|
+
for (const unitType of currentUnitTypes) {
|
|
243
|
+
const newPriority = this.requestedUnitTypes.get(unitType) * MISSING_UNIT_TYPE_REQUEST_DECAY_MULT_RATE -
|
|
244
|
+
MISSING_UNIT_TYPE_REQUEST_DECAY_FLAT_RATE;
|
|
245
|
+
if (newPriority > 0.5) {
|
|
246
|
+
this.requestedUnitTypes.set(unitType, newPriority);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
this.requestedUnitTypes.delete(unitType);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Add the new missing units to the priority set, if the request is higher than the existing value.
|
|
253
|
+
Object.entries(missingUnitTypeToHighestRequest).forEach(([unitType, request]) => {
|
|
254
|
+
const currentPriority = this.requestedUnitTypes.get(unitType);
|
|
255
|
+
this.requestedUnitTypes.set(unitType, currentPriority ? Math.max(currentPriority, request.action.priority) : request.action.priority);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Returns the set of units that have been requested for production by the missions.
|
|
260
|
+
*
|
|
261
|
+
* @returns A map of unit type to the highest priority for that unit type.
|
|
262
|
+
*/
|
|
263
|
+
getRequestedUnitTypes() {
|
|
264
|
+
return this.requestedUnitTypes;
|
|
265
|
+
}
|
|
266
|
+
addUnitToMission(mission, unit, actionsApi) {
|
|
267
|
+
mission.addUnit(unit.id);
|
|
268
|
+
this.unitIdToMission.set(unit.id, mission);
|
|
269
|
+
actionsApi.setUnitDebugText(unit.id, mission.getUniqueName() + "_" + unit.id);
|
|
270
|
+
}
|
|
271
|
+
removeUnitFromMission(mission, unitId, actionsApi) {
|
|
272
|
+
mission.removeUnit(unitId);
|
|
273
|
+
this.unitIdToMission.delete(unitId);
|
|
274
|
+
actionsApi.setUnitDebugText(unitId, undefined);
|
|
275
|
+
}
|
|
57
276
|
/**
|
|
58
277
|
* Attempts to add a mission to the active set.
|
|
59
278
|
* @param mission
|
|
@@ -74,8 +293,30 @@ export class MissionController {
|
|
|
74
293
|
disbandMission(missionName) {
|
|
75
294
|
this.forceDisbandedMissions.push(missionName);
|
|
76
295
|
}
|
|
77
|
-
|
|
78
|
-
|
|
296
|
+
// return text to display for global debug
|
|
297
|
+
getGlobalDebugText(gameApi) {
|
|
298
|
+
const unitsInMission = (unitIds) => countBy(unitIds, (unitId) => gameApi.getGameObjectData(unitId)?.name);
|
|
299
|
+
let globalDebugText = "";
|
|
300
|
+
this.missions.forEach((mission) => {
|
|
301
|
+
this.logger(`Mission ${mission.getUniqueName()}: ${Object.entries(unitsInMission(mission.getUnitIds()))
|
|
302
|
+
.map(([unitName, count]) => `${unitName} x ${count}`)
|
|
303
|
+
.join(", ")}`);
|
|
304
|
+
const missionDebugText = mission.getGlobalDebugText();
|
|
305
|
+
if (missionDebugText) {
|
|
306
|
+
globalDebugText += mission.getUniqueName() + ": " + missionDebugText + "\n";
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
return globalDebugText;
|
|
310
|
+
}
|
|
311
|
+
updateDebugText(actionsApi) {
|
|
312
|
+
this.missions.forEach((mission) => {
|
|
313
|
+
mission
|
|
314
|
+
.getUnitIds()
|
|
315
|
+
.forEach((unitId) => actionsApi.setUnitDebugText(unitId, `${unitId}: ${mission.getUniqueName()}`));
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
getMissions() {
|
|
319
|
+
return this.missions;
|
|
79
320
|
}
|
|
80
321
|
}
|
|
81
322
|
//# sourceMappingURL=missionController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missionController.js","sourceRoot":"","sources":["../../../../src/bot/logic/mission/missionController.ts"],"names":[],"mappings":"AAAA,sDAAsD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,WAAW,CAAC,CAAC;IAClD,CAAC;IAEM,cAAc;QACjB,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,CAAC,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjH,CAAC;CACJ"}
|
|
1
|
+
{"version":3,"file":"missionController.js","sourceRoot":"","sources":["../../../../src/bot/logic/mission/missionController.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,sFAAsF;AAEtF,OAAO,EAAyE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACxH,OAAO,EASH,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,cAAc,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAkB,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAGpE,qEAAqE;AACrE,MAAM,yCAAyC,GAAG,IAAI,CAAC;AACvD,MAAM,yCAAyC,GAAG,CAAC,CAAC;AAEpD,MAAM,OAAO,iBAAiB;IAe1B,YAAoB,MAAsD;QAAtD,WAAM,GAAN,MAAM,CAAgD;QAblE,aAAQ,GAAmB,EAAE,CAAC;QAEtC,wGAAwG;QACxG,8CAA8C;QACtC,oBAAe,GAA8B,IAAI,GAAG,EAAE,CAAC;QAE/D,2EAA2E;QAC3E,oEAAoE;QAC5D,uBAAkB,GAAwB,IAAI,GAAG,EAAE,CAAC;QAE5D,2FAA2F;QACnF,2BAAsB,GAAa,EAAE,CAAC;QAG1C,IAAI,CAAC,gBAAgB,GAAG,sBAAsB,EAAE,CAAC;IACrD,CAAC;IAEO,aAAa,CAAC,OAAgB;QAClC,+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CACJ"}
|
|
@@ -1,47 +1,128 @@
|
|
|
1
|
-
import { ObjectType, Vector2 } from "@chronodivide/game-api";
|
|
2
|
-
import { CombatSquad } from "
|
|
3
|
-
import { Mission, disbandMission, noop } from "../mission.js";
|
|
4
|
-
import { Squad } from "../../squad/squad.js";
|
|
1
|
+
import { ObjectType, SideType, Vector2 } from "@chronodivide/game-api";
|
|
2
|
+
import { CombatSquad } from "./squads/combatSquad.js";
|
|
3
|
+
import { Mission, disbandMission, noop, requestUnits } from "../mission.js";
|
|
5
4
|
import { RetreatMission } from "./retreatMission.js";
|
|
6
|
-
import { maxBy } from "../../common/utils.js";
|
|
5
|
+
import { countBy, isOwnedByNeutral, maxBy } from "../../common/utils.js";
|
|
6
|
+
import { getSovietComposition } from "../../composition/sovietCompositions.js";
|
|
7
|
+
import { getAlliedCompositions } from "../../composition/alliedCompositions.js";
|
|
8
|
+
import { manageMoveMicro } from "./squads/common.js";
|
|
7
9
|
export var AttackFailReason;
|
|
8
10
|
(function (AttackFailReason) {
|
|
9
11
|
AttackFailReason[AttackFailReason["NoTargets"] = 0] = "NoTargets";
|
|
10
12
|
AttackFailReason[AttackFailReason["DefenceTooStrong"] = 1] = "DefenceTooStrong";
|
|
11
13
|
})(AttackFailReason || (AttackFailReason = {}));
|
|
12
|
-
|
|
14
|
+
var AttackMissionState;
|
|
15
|
+
(function (AttackMissionState) {
|
|
16
|
+
AttackMissionState[AttackMissionState["Preparing"] = 0] = "Preparing";
|
|
17
|
+
AttackMissionState[AttackMissionState["Attacking"] = 1] = "Attacking";
|
|
18
|
+
AttackMissionState[AttackMissionState["Retreating"] = 2] = "Retreating";
|
|
19
|
+
})(AttackMissionState || (AttackMissionState = {}));
|
|
20
|
+
const NO_TARGET_RETARGET_TICKS = 450;
|
|
21
|
+
const NO_TARGET_IDLE_TIMEOUT_TICKS = 900;
|
|
22
|
+
function calculateTargetComposition(gameApi, playerData, matchAwareness) {
|
|
23
|
+
if (!playerData.country) {
|
|
24
|
+
throw new Error(`player ${playerData.name} has no country`);
|
|
25
|
+
}
|
|
26
|
+
else if (playerData.country.side === SideType.Nod) {
|
|
27
|
+
return getSovietComposition(gameApi, playerData, matchAwareness);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return getAlliedCompositions(gameApi, playerData, matchAwareness);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const ATTACK_MISSION_PRIORITY_RAMP = 1.01;
|
|
34
|
+
const ATTACK_MISSION_MAX_PRIORITY = 50;
|
|
13
35
|
/**
|
|
14
36
|
* A mission that tries to attack a certain area.
|
|
15
37
|
*/
|
|
16
38
|
export class AttackMission extends Mission {
|
|
17
|
-
constructor(uniqueName, priority, rallyArea, attackArea, radius, logger) {
|
|
18
|
-
super(uniqueName,
|
|
19
|
-
this.
|
|
39
|
+
constructor(uniqueName, priority, rallyArea, attackArea, radius, composition, logger) {
|
|
40
|
+
super(uniqueName, logger);
|
|
41
|
+
this.priority = priority;
|
|
20
42
|
this.attackArea = attackArea;
|
|
21
43
|
this.radius = radius;
|
|
44
|
+
this.composition = composition;
|
|
22
45
|
this.lastTargetSeenAt = 0;
|
|
46
|
+
this.hasPickedNewTarget = false;
|
|
47
|
+
this.state = AttackMissionState.Preparing;
|
|
48
|
+
this.squad = new CombatSquad(rallyArea, attackArea, radius);
|
|
49
|
+
}
|
|
50
|
+
_onAiUpdate(gameApi, actionsApi, playerData, matchAwareness, actionBatcher) {
|
|
51
|
+
switch (this.state) {
|
|
52
|
+
case AttackMissionState.Preparing:
|
|
53
|
+
return this.handlePreparingState(gameApi, actionsApi, playerData, matchAwareness, actionBatcher);
|
|
54
|
+
case AttackMissionState.Attacking:
|
|
55
|
+
return this.handleAttackingState(gameApi, actionsApi, playerData, matchAwareness, actionBatcher);
|
|
56
|
+
case AttackMissionState.Retreating:
|
|
57
|
+
return this.handleRetreatingState(gameApi, actionsApi, playerData, matchAwareness, actionBatcher);
|
|
58
|
+
}
|
|
23
59
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
60
|
+
handlePreparingState(gameApi, actionsApi, playerData, matchAwareness, actionBatcher) {
|
|
61
|
+
const currentComposition = countBy(this.getUnits(gameApi), (unit) => unit.name);
|
|
62
|
+
const missingUnits = Object.entries(this.composition).filter(([unitType, targetAmount]) => {
|
|
63
|
+
return !currentComposition[unitType] || currentComposition[unitType] < targetAmount;
|
|
64
|
+
});
|
|
65
|
+
if (missingUnits.length > 0) {
|
|
66
|
+
this.priority = Math.min(this.priority * ATTACK_MISSION_PRIORITY_RAMP, ATTACK_MISSION_MAX_PRIORITY);
|
|
67
|
+
return requestUnits(missingUnits.map(([unitName]) => unitName), this.priority);
|
|
27
68
|
}
|
|
28
69
|
else {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
70
|
+
this.priority = ATTACK_MISSION_INITIAL_PRIORITY;
|
|
71
|
+
this.state = AttackMissionState.Attacking;
|
|
72
|
+
return noop();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
handleAttackingState(gameApi, actionsApi, playerData, matchAwareness, actionBatcher) {
|
|
76
|
+
if (this.getUnitIds().length === 0) {
|
|
77
|
+
// TODO: disband directly (we no longer retreat when losing)
|
|
78
|
+
this.state = AttackMissionState.Retreating;
|
|
79
|
+
return noop();
|
|
80
|
+
}
|
|
81
|
+
const foundTargets = matchAwareness
|
|
82
|
+
.getHostilesNearPoint2d(this.attackArea, this.radius)
|
|
83
|
+
.map((unit) => gameApi.getUnitData(unit.unitId))
|
|
84
|
+
.filter((unit) => !isOwnedByNeutral(unit));
|
|
85
|
+
const update = this.squad.onAiUpdate(gameApi, actionsApi, actionBatcher, playerData, this, matchAwareness, this.logger);
|
|
86
|
+
if (update.type !== "noop") {
|
|
87
|
+
return update;
|
|
88
|
+
}
|
|
89
|
+
if (foundTargets.length > 0) {
|
|
90
|
+
this.lastTargetSeenAt = gameApi.getCurrentTick();
|
|
91
|
+
this.hasPickedNewTarget = false;
|
|
92
|
+
}
|
|
93
|
+
else if (gameApi.getCurrentTick() > this.lastTargetSeenAt + NO_TARGET_IDLE_TIMEOUT_TICKS) {
|
|
94
|
+
return disbandMission(AttackFailReason.NoTargets);
|
|
95
|
+
}
|
|
96
|
+
else if (!this.hasPickedNewTarget &&
|
|
97
|
+
gameApi.getCurrentTick() > this.lastTargetSeenAt + NO_TARGET_RETARGET_TICKS) {
|
|
98
|
+
const newTarget = generateTarget(gameApi, playerData, matchAwareness);
|
|
99
|
+
if (newTarget) {
|
|
100
|
+
this.squad.setAttackArea(newTarget);
|
|
101
|
+
this.hasPickedNewTarget = true;
|
|
39
102
|
}
|
|
40
103
|
}
|
|
41
104
|
return noop();
|
|
42
105
|
}
|
|
106
|
+
handleRetreatingState(gameApi, actionsApi, playerData, matchAwareness, actionBatcher) {
|
|
107
|
+
this.getUnits(gameApi).forEach((unitId) => {
|
|
108
|
+
actionBatcher.push(manageMoveMicro(unitId, matchAwareness.getMainRallyPoint()));
|
|
109
|
+
});
|
|
110
|
+
return disbandMission();
|
|
111
|
+
}
|
|
112
|
+
getGlobalDebugText() {
|
|
113
|
+
return this.squad.getGlobalDebugText() ?? "<none>";
|
|
114
|
+
}
|
|
115
|
+
getState() {
|
|
116
|
+
return this.state;
|
|
117
|
+
}
|
|
118
|
+
// This mission can give up its units while preparing.
|
|
119
|
+
isUnitsLocked() {
|
|
120
|
+
return this.state !== AttackMissionState.Preparing;
|
|
121
|
+
}
|
|
122
|
+
getPriority() {
|
|
123
|
+
return this.priority;
|
|
124
|
+
}
|
|
43
125
|
}
|
|
44
|
-
const ATTACK_COOLDOWN_TICKS = 120;
|
|
45
126
|
// Calculates the weight for initiating an attack on the position of a unit or building.
|
|
46
127
|
// This is separate from unit micro; the squad will be ordered to attack in the vicinity of the point.
|
|
47
128
|
const getTargetWeight = (unitData, tryFocusHarvester) => {
|
|
@@ -55,49 +136,75 @@ const getTargetWeight = (unitData, tryFocusHarvester) => {
|
|
|
55
136
|
return unitData.maxHitPoints;
|
|
56
137
|
}
|
|
57
138
|
};
|
|
139
|
+
function generateTarget(gameApi, playerData, matchAwareness, includeBaseLocations = false) {
|
|
140
|
+
// Randomly decide between harvester and base.
|
|
141
|
+
try {
|
|
142
|
+
const tryFocusHarvester = gameApi.generateRandomInt(0, 1) === 0;
|
|
143
|
+
const enemyUnits = gameApi
|
|
144
|
+
.getVisibleUnits(playerData.name, "enemy")
|
|
145
|
+
.map((unitId) => gameApi.getUnitData(unitId))
|
|
146
|
+
.filter((u) => !!u && gameApi.getPlayerData(u.owner).isCombatant);
|
|
147
|
+
const maxUnit = maxBy(enemyUnits, (u) => getTargetWeight(u, tryFocusHarvester));
|
|
148
|
+
if (maxUnit) {
|
|
149
|
+
return new Vector2(maxUnit.tile.rx, maxUnit.tile.ry);
|
|
150
|
+
}
|
|
151
|
+
if (includeBaseLocations) {
|
|
152
|
+
const mapApi = gameApi.mapApi;
|
|
153
|
+
const enemyPlayers = gameApi
|
|
154
|
+
.getPlayers()
|
|
155
|
+
.map(gameApi.getPlayerData)
|
|
156
|
+
.filter((otherPlayer) => !gameApi.areAlliedPlayers(playerData.name, otherPlayer.name));
|
|
157
|
+
const unexploredEnemyLocations = enemyPlayers.filter((otherPlayer) => {
|
|
158
|
+
const tile = mapApi.getTile(otherPlayer.startLocation.x, otherPlayer.startLocation.y);
|
|
159
|
+
if (!tile) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return !mapApi.isVisibleTile(tile, playerData.name);
|
|
163
|
+
});
|
|
164
|
+
if (unexploredEnemyLocations.length > 0) {
|
|
165
|
+
const idx = gameApi.generateRandomInt(0, unexploredEnemyLocations.length - 1);
|
|
166
|
+
return unexploredEnemyLocations[idx].startLocation;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
// There's a crash here when accessing a building that got destroyed. Will catch and ignore or now.
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
// Number of ticks between attacking visible targets.
|
|
177
|
+
const VISIBLE_TARGET_ATTACK_COOLDOWN_TICKS = 120;
|
|
178
|
+
// Number of ticks between attacking "bases" (enemy starting locations).
|
|
179
|
+
const BASE_ATTACK_COOLDOWN_TICKS = 1800;
|
|
180
|
+
const ATTACK_MISSION_INITIAL_PRIORITY = 1;
|
|
58
181
|
export class AttackMissionFactory {
|
|
59
|
-
constructor(lastAttackAt = -
|
|
182
|
+
constructor(lastAttackAt = -VISIBLE_TARGET_ATTACK_COOLDOWN_TICKS) {
|
|
60
183
|
this.lastAttackAt = lastAttackAt;
|
|
61
184
|
}
|
|
62
185
|
getName() {
|
|
63
186
|
return "AttackMissionFactory";
|
|
64
187
|
}
|
|
65
|
-
generateTarget(gameApi, playerData, matchAwareness) {
|
|
66
|
-
// Randomly decide between harvester and base.
|
|
67
|
-
try {
|
|
68
|
-
const tryFocusHarvester = gameApi.generateRandomInt(0, 1) === 0;
|
|
69
|
-
const enemyUnits = gameApi
|
|
70
|
-
.getVisibleUnits(playerData.name, "hostile")
|
|
71
|
-
.map((unitId) => gameApi.getUnitData(unitId))
|
|
72
|
-
.filter((u) => !!u && gameApi.getPlayerData(u.owner).isCombatant);
|
|
73
|
-
const maxUnit = maxBy(enemyUnits, (u) => getTargetWeight(u, tryFocusHarvester));
|
|
74
|
-
if (maxUnit) {
|
|
75
|
-
return new Vector2(maxUnit.tile.rx, maxUnit.tile.ry);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
// There's a crash here when accessing a building that got destroyed. Will catch and ignore or now.
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
188
|
maybeCreateMissions(gameApi, playerData, matchAwareness, missionController, logger) {
|
|
85
|
-
if (
|
|
189
|
+
if (gameApi.getCurrentTick() < this.lastAttackAt + VISIBLE_TARGET_ATTACK_COOLDOWN_TICKS) {
|
|
86
190
|
return;
|
|
87
191
|
}
|
|
88
|
-
|
|
192
|
+
// can only have one attack 'preparing' at once.
|
|
193
|
+
if (missionController
|
|
194
|
+
.getMissions()
|
|
195
|
+
.some((mission) => mission instanceof AttackMission && mission.getState() === AttackMissionState.Preparing)) {
|
|
89
196
|
return;
|
|
90
197
|
}
|
|
91
|
-
const attackRadius =
|
|
92
|
-
const
|
|
198
|
+
const attackRadius = 10;
|
|
199
|
+
const includeEnemyBases = gameApi.getCurrentTick() > this.lastAttackAt + BASE_ATTACK_COOLDOWN_TICKS;
|
|
200
|
+
const attackArea = generateTarget(gameApi, playerData, matchAwareness, includeEnemyBases);
|
|
93
201
|
if (!attackArea) {
|
|
94
|
-
// Nothing to attack.
|
|
95
202
|
return;
|
|
96
203
|
}
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
const tryAttack = missionController.addMission(new AttackMission(squadName,
|
|
100
|
-
missionController.addMission(new RetreatMission("retreat-from-" + squadName + gameApi.getCurrentTick(),
|
|
204
|
+
const squadName = "attack_" + gameApi.getCurrentTick();
|
|
205
|
+
const composition = calculateTargetComposition(gameApi, playerData, matchAwareness);
|
|
206
|
+
const tryAttack = missionController.addMission(new AttackMission(squadName, ATTACK_MISSION_INITIAL_PRIORITY, matchAwareness.getMainRallyPoint(), attackArea, attackRadius, composition, logger).then((unitIds, reason) => {
|
|
207
|
+
missionController.addMission(new RetreatMission("retreat-from-" + squadName + gameApi.getCurrentTick(), matchAwareness.getMainRallyPoint(), unitIds, logger));
|
|
101
208
|
}));
|
|
102
209
|
if (tryAttack) {
|
|
103
210
|
this.lastAttackAt = gameApi.getCurrentTick();
|