Skip to content

Commit

Permalink
feat(campaign): bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyver committed Oct 13, 2023
1 parent fa3334a commit 2737ddd
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/apps/campaign/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"zod": "3.21.4"
},
"devDependencies": {
"@foxdelta2/dcsjs": "0.2.230-next.17",
"@foxdelta2/dcsjs": "0.2.230-next.18",
"@types/leaflet": "1.9.3",
"@types/uuid": "9.0.2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ export function Structure() {
<Components.StatLabel>Deployment Score</Components.StatLabel>
<Components.StatValue>
{formatPercentage(
((structure() as DcsJs.StructureUnitCamp).deploymentScore /
getDeploymentCost(overlayStore.coalition, structure()?.type)) *
100,
Math.max(
0,
((structure() as DcsJs.StructureUnitCamp).deploymentScore /
getDeploymentCost(overlayStore.coalition, structure()?.type)) *
100,
),
)}
</Components.StatValue>
</Components.Stat>
Expand Down
25 changes: 24 additions & 1 deletion packages/apps/campaign/src/components/map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ export const Map = () => {
ewMarkers[selectedMarkerId] ??
airdromeMarkers[selectedMarkerId] ??
samCircles[selectedMarkerId] ??
shipGroupMarkers[selectedMarkerId];
shipGroupMarkers[selectedMarkerId] ??
downedPilotMarkers[selectedMarkerId];

if (oldMarker != null) {
const symbol = new MilSymbol.Symbol(oldMarker.symbolCode, {
Expand Down Expand Up @@ -768,6 +769,17 @@ export const Map = () => {
selectedMarkerId = shipName;
}

if (overlaySidebarState.state === "downed pilot") {
const id = overlaySidebarState.groundGroupId;

if (id == null) {
return;
}

marker = downedPilotMarkers[id];
selectedMarkerId = id;
}

if (marker == null) {
return;
}
Expand Down Expand Up @@ -862,6 +874,17 @@ export const Map = () => {
}
});

const airdromes = [...state.blueFaction.airdromeNames, ...state.redFaction.airdromeNames];

Object.entries(airdromeMarkers).forEach(([name, marker]) => {
if (marker == null || airdromes.some((airdromeName) => airdromeName === name)) {
return;
} else {
removeSymbol(marker.marker);
delete airdromeMarkers[name];
}
});

cleanupStructures();
});

Expand Down
15 changes: 11 additions & 4 deletions packages/apps/campaign/src/logic/cleanupGroundGroup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type * as DcsJs from "@foxdelta2/dcsjs";

import * as Domain from "../domain";
import { RunningCampaignState } from "./types";
import { getCoalitionFaction } from "./utils";

const cleanupFactionGroundGroups = (coalition: DcsJs.Coalition, state: RunningCampaignState) => {
const faction = getCoalitionFaction(coalition, state);

const cleanupFactionGroundGroups = (faction: DcsJs.CampaignFaction) => {
faction.groundGroups = faction.groundGroups.filter((gg) => {
const hasAliveUnit = gg.unitIds.some((id) => {
const unit = faction.inventory.groundUnits[id];
Expand All @@ -11,10 +15,13 @@ const cleanupFactionGroundGroups = (faction: DcsJs.CampaignFaction) => {

return hasAliveUnit;
});

faction.groundGroups = faction.groundGroups.filter((gg) => {
return Domain.Location.InFrontlineRange(coalition, gg.position, state);
});
};

export const cleanupGroundGroups = (state: RunningCampaignState) => {
cleanupFactionGroundGroups(state.blueFaction);

cleanupFactionGroundGroups(state.redFaction);
cleanupFactionGroundGroups("blue", state);
cleanupFactionGroundGroups("red", state);
};
3 changes: 2 additions & 1 deletion packages/apps/campaign/src/logic/reinforcement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const factionReinforcement = (coalition: DcsJs.Coalition, state: RunningC

if (faction.reinforcementTimer + faction.reinforcementDelay <= state.timer) {
const destroyedAircrafts = Object.values(faction.inventory.aircrafts).filter(
(ac) => ac.alive === false && ac.destroyedTime != null && ac.destroyedTime > faction.reinforcementTimer,
(ac) =>
ac.alive === false && ac.destroyedTime != null && ac.destroyedTime > faction.reinforcementTimer && !ac.disabled,
);

destroyedAircrafts.forEach((ac) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/campaign/src/logic/updateAirdrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function updateCoalitionAirdromes(
Object.values(faction.inventory.aircrafts).forEach((ac) => {
const iac = faction.inventory.aircrafts[ac.id];

if (iac == null) {
if (iac == null || iac.homeBase.name !== name) {
return;
}

Expand All @@ -56,7 +56,7 @@ function updateCoalitionAirdromes(

const homeBase: DcsJs.CampaignHomeBase = { type: "airdrome", name };

const newAircrafts = generateAircraftsForHomeBase(faction, homeBase, dataStore, false);
const newAircrafts = generateAircraftsForHomeBase(oppFaction, homeBase, dataStore, false);

newAircrafts.forEach((ac) => {
oppFaction.inventory.aircrafts[ac.id] = ac;
Expand Down
2 changes: 1 addition & 1 deletion packages/chief/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"validate:ts": "tsc --noEmit"
},
"dependencies": {
"@foxdelta2/dcsjs": "0.2.230-next.17",
"@foxdelta2/dcsjs": "0.2.230-next.18",
"adm-zip": "^0.5.10",
"chokidar": "^3.5.3",
"electron-fetch": "^1.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"solid-js": "1.7.7"
},
"devDependencies": {
"@foxdelta2/dcsjs": "0.2.230-next.17"
"@foxdelta2/dcsjs": "0.2.230-next.18"
}
}
2 changes: 1 addition & 1 deletion packages/libs/document/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"solid-js": "1.7.7"
},
"devDependencies": {
"@foxdelta2/dcsjs": "0.2.230-next.17"
"@foxdelta2/dcsjs": "0.2.230-next.18"
}
}
2 changes: 1 addition & 1 deletion packages/shared/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"zod": "^3.21.4"
},
"devDependencies": {
"@foxdelta2/dcsjs": "0.2.230-next.17"
"@foxdelta2/dcsjs": "0.2.230-next.18"
}
}
2 changes: 1 addition & 1 deletion packages/shared/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"validate:ts": "tsc --noEmit"
},
"devDependencies": {
"@foxdelta2/dcsjs": "0.2.230-next.17"
"@foxdelta2/dcsjs": "0.2.230-next.18"
}
}
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2737ddd

Please sign in to comment.