mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
fix: Laser and infrared correctly removed
This commit is contained in:
@@ -89,7 +89,7 @@ export interface BullseyesData {
|
|||||||
|
|
||||||
export interface SpotsData {
|
export interface SpotsData {
|
||||||
spots: {
|
spots: {
|
||||||
[key: string]: { type: string; targetPosition: { lat: number; lng: number }; sourceUnitID: number; code?: number };
|
[key: string]: { active: boolean; type: string; targetPosition: { lat: number; lng: number }; sourceUnitID: number; code?: number };
|
||||||
};
|
};
|
||||||
sessionHash: string;
|
sessionHash: string;
|
||||||
time: number;
|
time: number;
|
||||||
|
|||||||
@@ -6,13 +6,20 @@ import { BLUE_COMMANDER, GAME_MASTER, NONE, RED_COMMANDER } from "../constants/c
|
|||||||
import { AirbasesData, BullseyesData, CommandModeOptions, DateAndTime, MissionData, SpotsData } from "../interfaces";
|
import { AirbasesData, BullseyesData, CommandModeOptions, DateAndTime, MissionData, SpotsData } from "../interfaces";
|
||||||
import { Coalition } from "../types/types";
|
import { Coalition } from "../types/types";
|
||||||
import { Carrier } from "./carrier";
|
import { Carrier } from "./carrier";
|
||||||
import { AirbaseSelectedEvent, AppStateChangedEvent, BullseyesDataChangedEvent, CommandModeOptionsChangedEvent, EnabledCommandModesChangedEvent, MissionDataChangedEvent } from "../events";
|
import {
|
||||||
|
AirbaseSelectedEvent,
|
||||||
|
AppStateChangedEvent,
|
||||||
|
BullseyesDataChangedEvent,
|
||||||
|
CommandModeOptionsChangedEvent,
|
||||||
|
EnabledCommandModesChangedEvent,
|
||||||
|
MissionDataChangedEvent,
|
||||||
|
} from "../events";
|
||||||
import { Spot } from "./spot";
|
import { Spot } from "./spot";
|
||||||
|
|
||||||
/** The MissionManager */
|
/** The MissionManager */
|
||||||
export class MissionManager {
|
export class MissionManager {
|
||||||
#bullseyes: { [name: string]: Bullseye } = {};
|
#bullseyes: { [name: string]: Bullseye } = {};
|
||||||
#spots: {[key: string]: Spot} = {};
|
#spots: { [key: string]: Spot } = {};
|
||||||
#airbases: { [name: string]: Airbase | Carrier } = {};
|
#airbases: { [name: string]: Airbase | Carrier } = {};
|
||||||
#theatre: string = "";
|
#theatre: string = "";
|
||||||
#dateAndTime: DateAndTime = {
|
#dateAndTime: DateAndTime = {
|
||||||
@@ -39,7 +46,7 @@ export class MissionManager {
|
|||||||
constructor() {
|
constructor() {
|
||||||
AppStateChangedEvent.on((state, subState) => {
|
AppStateChangedEvent.on((state, subState) => {
|
||||||
if (this.getSelectedAirbase() !== null) AirbaseSelectedEvent.dispatch(null);
|
if (this.getSelectedAirbase() !== null) AirbaseSelectedEvent.dispatch(null);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update location of bullseyes
|
/** Update location of bullseyes
|
||||||
@@ -63,7 +70,7 @@ export class MissionManager {
|
|||||||
this.#bullseyes[idx].setCoalition(bullseye.coalition);
|
this.#bullseyes[idx].setCoalition(bullseye.coalition);
|
||||||
}
|
}
|
||||||
|
|
||||||
BullseyesDataChangedEvent.dispatch(this.#bullseyes)
|
BullseyesDataChangedEvent.dispatch(this.#bullseyes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,18 +79,18 @@ export class MissionManager {
|
|||||||
const spotID = Number(idx);
|
const spotID = Number(idx);
|
||||||
const spot = data.spots[idx];
|
const spot = data.spots[idx];
|
||||||
if (this.#spots[spotID] === undefined) {
|
if (this.#spots[spotID] === undefined) {
|
||||||
this.#spots[spotID] = new Spot(spotID, spot.type, new LatLng(spot.targetPosition.lat, spot.targetPosition.lng), spot.sourceUnitID, spot.code);
|
this.#spots[spotID] = new Spot(
|
||||||
|
spotID,
|
||||||
|
spot.type,
|
||||||
|
new LatLng(spot.targetPosition.lat, spot.targetPosition.lng),
|
||||||
|
spot.sourceUnitID,
|
||||||
|
spot.active,
|
||||||
|
spot.code
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (spot.type === "laser")
|
if (spot.type === "laser") this.#spots[spotID].setCode(spot.code ?? 0);
|
||||||
this.#spots[spotID].setCode(spot.code ?? 0)
|
this.#spots[spotID].setActive(spot.active);
|
||||||
this.#spots[spotID].setTargetPosition( new LatLng(spot.targetPosition.lat, spot.targetPosition.lng));
|
this.#spots[spotID].setTargetPosition(new LatLng(spot.targetPosition.lat, spot.targetPosition.lng));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Iterate the existing spots and remove all spots that where deleted */
|
|
||||||
for (let idx in this.#spots) {
|
|
||||||
if (data.spots[idx] === undefined) {
|
|
||||||
delete this.#spots[idx];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +106,7 @@ export class MissionManager {
|
|||||||
updateAirbases(data: AirbasesData) {
|
updateAirbases(data: AirbasesData) {
|
||||||
for (let idx in data.airbases) {
|
for (let idx in data.airbases) {
|
||||||
var airbase = data.airbases[idx];
|
var airbase = data.airbases[idx];
|
||||||
var airbaseCallsign = airbase.callsign !== ""? airbase.callsign: `carrier-${airbase.unitId}`
|
var airbaseCallsign = airbase.callsign !== "" ? airbase.callsign : `carrier-${airbase.unitId}`;
|
||||||
if (this.#airbases[airbaseCallsign] === undefined) {
|
if (this.#airbases[airbaseCallsign] === undefined) {
|
||||||
if (airbase.callsign != "") {
|
if (airbase.callsign != "") {
|
||||||
this.#airbases[airbaseCallsign] = new Airbase({
|
this.#airbases[airbaseCallsign] = new Airbase({
|
||||||
|
|||||||
@@ -2,47 +2,57 @@ import { LatLng } from "leaflet";
|
|||||||
import { getApp } from "../olympusapp";
|
import { getApp } from "../olympusapp";
|
||||||
|
|
||||||
export class Spot {
|
export class Spot {
|
||||||
private ID: number;
|
#ID: number;
|
||||||
private type: string;
|
#type: string;
|
||||||
private targetPosition: LatLng;
|
#targetPosition: LatLng;
|
||||||
private sourceUnitID: number;
|
#sourceUnitID: number;
|
||||||
private code?: number;
|
#active: boolean;
|
||||||
|
#code?: number;
|
||||||
|
|
||||||
constructor(ID: number, type: string, targetPosition: LatLng, sourceUnitID: number, code?: number) {
|
constructor(ID: number, type: string, targetPosition: LatLng, sourceUnitID: number, active: boolean, code?: number) {
|
||||||
this.ID = ID;
|
this.#ID = ID;
|
||||||
this.type = type;
|
this.#type = type;
|
||||||
this.targetPosition = targetPosition;
|
this.#targetPosition = targetPosition;
|
||||||
this.sourceUnitID = sourceUnitID;
|
this.#sourceUnitID = sourceUnitID;
|
||||||
this.code = code;
|
this.#code = code;
|
||||||
|
this.#active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getter methods
|
// Getter methods
|
||||||
getID() {
|
getID() {
|
||||||
return this.ID;
|
return this.#ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
getType() {
|
getType() {
|
||||||
return this.type;
|
return this.#type;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTargetPosition() {
|
getTargetPosition() {
|
||||||
return this.targetPosition;
|
return this.#targetPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
getSourceUnitID() {
|
getSourceUnitID() {
|
||||||
return this.sourceUnitID;
|
return this.#sourceUnitID;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCode() {
|
getCode() {
|
||||||
return this.code;
|
return this.#code;
|
||||||
|
}
|
||||||
|
|
||||||
|
getActive() {
|
||||||
|
return this.#active;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setter methods
|
// Setter methods
|
||||||
setTargetPosition(position: LatLng) {
|
setTargetPosition(position: LatLng) {
|
||||||
this.targetPosition = position;
|
this.#targetPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
setCode(code: number) {
|
setCode(code: number) {
|
||||||
this.code = code;
|
this.#code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
setActive(active: boolean) {
|
||||||
|
this.#active = active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1953,21 +1953,29 @@ export abstract class Unit extends CustomMarker {
|
|||||||
// Iterate over all spots and draw lines, edit markers, and markers
|
// Iterate over all spots and draw lines, edit markers, and markers
|
||||||
Object.values(getApp().getMissionManager().getSpots()).forEach((spot: Spot) => {
|
Object.values(getApp().getMissionManager().getSpots()).forEach((spot: Spot) => {
|
||||||
if (spot.getSourceUnitID() === this.ID) {
|
if (spot.getSourceUnitID() === this.ID) {
|
||||||
const spotBearing = deg2rad(bearing(this.getPosition().lat, this.getPosition().lng, spot.getTargetPosition().lat, spot.getTargetPosition().lng, false));
|
if (spot.getActive()) {
|
||||||
const spotDistance = this.getPosition().distanceTo(spot.getTargetPosition());
|
const spotBearing = deg2rad(
|
||||||
const midPosition = bearingAndDistanceToLatLng(this.getPosition().lat, this.getPosition().lng, spotBearing, spotDistance / 2);
|
bearing(this.getPosition().lat, this.getPosition().lng, spot.getTargetPosition().lat, spot.getTargetPosition().lng, false)
|
||||||
|
);
|
||||||
|
const spotDistance = this.getPosition().distanceTo(spot.getTargetPosition());
|
||||||
|
const midPosition = bearingAndDistanceToLatLng(this.getPosition().lat, this.getPosition().lng, spotBearing, spotDistance / 2);
|
||||||
|
|
||||||
// Draw the spot line
|
// Draw the spot line
|
||||||
this.#drawSpotLine(spot, spotBearing);
|
this.#drawSpotLine(spot, spotBearing);
|
||||||
|
|
||||||
// Draw the spot edit marker if the map is zoomed in enough
|
// Draw the spot edit marker if the map is zoomed in enough
|
||||||
if (getApp().getMap().getZoom() >= SPOTS_EDIT_ZOOM_TRANSITION) {
|
if (getApp().getMap().getZoom() >= SPOTS_EDIT_ZOOM_TRANSITION) {
|
||||||
// Draw the spot edit marker
|
// Draw the spot edit marker
|
||||||
this.#drawSpotEditMarker(spot, midPosition, spotBearing);
|
this.#drawSpotEditMarker(spot, midPosition, spotBearing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the spot marker
|
||||||
|
this.#drawSpotMarker(spot);
|
||||||
|
} else {
|
||||||
|
this.#spotLines[spot.getID()]?.removeFrom(getApp().getMap());
|
||||||
|
this.#spotEditMarkers[spot.getID()]?.removeFrom(getApp().getMap());
|
||||||
|
this.#spotMarkers[spot.getID()]?.removeFrom(getApp().getMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the spot marker
|
|
||||||
this.#drawSpotMarker(spot);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -589,6 +589,7 @@ function Olympus.fireLaser(ID, code, lat, lng)
|
|||||||
lat = lat,
|
lat = lat,
|
||||||
lng = lng
|
lng = lng
|
||||||
},
|
},
|
||||||
|
active = true,
|
||||||
code = code
|
code = code
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -611,13 +612,15 @@ function Olympus.fireInfrared(ID, lat, lng)
|
|||||||
targetPosition = {
|
targetPosition = {
|
||||||
lat = lat,
|
lat = lat,
|
||||||
lng = lng
|
lng = lng
|
||||||
}
|
},
|
||||||
|
active = true
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set new laser code
|
-- Set new laser code
|
||||||
function Olympus.setLaserCode(spotID, code)
|
function Olympus.setLaserCode(spotID, code)
|
||||||
|
Olympus.debug("Olympus.setLaserCode " .. spotID .. " -> " .. code, 2)
|
||||||
local spot = Olympus.spots[spotID]
|
local spot = Olympus.spots[spotID]
|
||||||
if spot ~= nil and spot.type == "laser" then
|
if spot ~= nil and spot.type == "laser" then
|
||||||
spot.object:setCode(code)
|
spot.object:setCode(code)
|
||||||
@@ -627,19 +630,21 @@ end
|
|||||||
|
|
||||||
-- Move spot to a new location
|
-- Move spot to a new location
|
||||||
function Olympus.moveSpot(spotID, lat, lng)
|
function Olympus.moveSpot(spotID, lat, lng)
|
||||||
|
Olympus.debug("Olympus.moveSpot " .. spotID .. " -> (" .. lat .. ", " .. lng .. ")", 2)
|
||||||
local spot = Olympus.spots[spotID]
|
local spot = Olympus.spots[spotID]
|
||||||
if spot ~= nil then
|
if spot ~= nil then
|
||||||
spot.object:setPoint(coord.LLtoLO(lat, lng, 0))
|
spot.object:setPoint(mist.utils.makeVec3GL(coord.LLtoLO(lat, lng, 0)))
|
||||||
spot.targetPosition = {lat = lat, lng = lng}
|
spot.targetPosition = {lat = lat, lng = lng}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove the spot
|
-- Remove the spot
|
||||||
function Olympus.deleteSpot(spotID)
|
function Olympus.deleteSpot(spotID)
|
||||||
|
Olympus.debug("Olympus.deleteSpot " .. spotID, 2)
|
||||||
local spot = Olympus.spots[spotID]
|
local spot = Olympus.spots[spotID]
|
||||||
if spot ~= nil then
|
if spot ~= nil then
|
||||||
spot.object:destroy()
|
spot.object:destroy()
|
||||||
Olympus.spots[spotID] = nil
|
Olympus.spots[spotID]["active"] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1415,8 +1420,8 @@ function Olympus.setWeaponsData(arg, time)
|
|||||||
table["category"] = "Missile"
|
table["category"] = "Missile"
|
||||||
elseif weapon:getDesc().category == Weapon.Category.BOMB then
|
elseif weapon:getDesc().category == Weapon.Category.BOMB then
|
||||||
table["category"] = "Bomb"
|
table["category"] = "Bomb"
|
||||||
elseif weapon:getDesc().category == Weapon.Category.SHELL then
|
--elseif weapon:getDesc().category == Weapon.Category.SHELL then
|
||||||
table["category"] = "Shell"
|
-- table["category"] = "Shell" -- Useful for debugging but has no real use and has big impact on performance
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
weapons[ID] = {isAlive = false}
|
weapons[ID] = {isAlive = false}
|
||||||
@@ -1527,6 +1532,7 @@ function Olympus.setMissionData(arg, time)
|
|||||||
type = spot.type,
|
type = spot.type,
|
||||||
sourceUnitID = spot.sourceUnitID,
|
sourceUnitID = spot.sourceUnitID,
|
||||||
targetPosition = spot.targetPosition,
|
targetPosition = spot.targetPosition,
|
||||||
|
active = spot.active,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- If the spot type is "laser", add the code to the spot entry
|
-- If the spot type is "laser", add the code to the spot entry
|
||||||
@@ -1542,7 +1548,7 @@ function Olympus.setMissionData(arg, time)
|
|||||||
Olympus.missionData["spots"] = spots
|
Olympus.missionData["spots"] = spots
|
||||||
|
|
||||||
Olympus.OlympusDLL.setMissionData()
|
Olympus.OlympusDLL.setMissionData()
|
||||||
return time + 1 -- For perfomance reasons weapons are updated once every second
|
return time + 1 -- For perfomance reasons mission data is updated once every second
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Initializes the units table with all the existing ME units
|
-- Initializes the units table with all the existing ME units
|
||||||
|
|||||||
Reference in New Issue
Block a user