Fixed elevation calculations

This commit is contained in:
Pax1601 2023-09-30 18:53:32 +02:00
parent 0954bf2923
commit 48d4ff97a0
13 changed files with 3682 additions and 1827 deletions

View File

@ -1957,6 +1957,7 @@ declare module "server/servermanager" {
blue: number;
red: number;
}, eras: string[], setupTime: number, callback?: CallableFunction): void;
reloadDatabases(callback?: CallableFunction): void;
startUpdate(): void;
refreshAll(): void;
checkSessionHash(newSessionHash: string): void;

5420
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -258,6 +258,10 @@ export class DatabaseManagerPlugin implements OlympusPlugin {
this.#app?.getHelicopterDatabase().load(() => {});
this.#app?.getGroundUnitDatabase().load(() => {});
this.#app?.getNavyUnitDatabase().load(() => {});
this.#app?.getServerManager().reloadDatabases(() => {
this.#app?.getPopupsManager().get("infoPopup")?.setText("Olympus core databases reloaded");
})
});
}
});
@ -282,6 +286,10 @@ export class DatabaseManagerPlugin implements OlympusPlugin {
this.#app?.getNavyUnitDatabase().load(() => {
this.#loadDatabases();
this.#app?.getServerManager().reloadDatabases(() => {
this.#app?.getPopupsManager().get("infoPopup")?.setText("Olympus core databases reloaded");
})
this.#hideAll();
this.#aircraftEditor.show();
this.#button1.classList.add("selected");
@ -309,6 +317,10 @@ export class DatabaseManagerPlugin implements OlympusPlugin {
this.#app?.getNavyUnitDatabase().load(() => {
this.#loadDatabases();
this.#app?.getServerManager().reloadDatabases(() => {
this.#app?.getPopupsManager().get("infoPopup")?.setText("Olympus core databases reloaded");
})
this.#hideAll();
this.#aircraftEditor.show();
this.#button1.classList.add("selected");

View File

@ -275,7 +275,9 @@
"name": "Desert",
"countries": "All"
}
}
},
"barrelHeight": 1.25,
"muzzleVelocity": 900
},
"BMP-1": {
"name": "BMP-1",
@ -451,7 +453,9 @@
"name": "Desert",
"countries": "All"
}
}
},
"barrelHeight": 1.95,
"muzzleVelocity": 970
},
"BMP-3": {
"name": "BMP-3",
@ -901,7 +905,9 @@
"name": "Desert",
"countries": "All"
}
}
},
"barrelHeight": 2.35,
"muzzleVelocity": 1440
},
"Grad-URAL": {
"name": "Grad-URAL",
@ -2075,7 +2081,7 @@
"filename": "",
"type": "Infantry",
"enabled": true,
"muzzleVelocity": 860,
"muzzleVelocity": 900,
"barrelHeight": 0.9
},
"KAMAZ Truck": {
@ -4521,7 +4527,9 @@
"name": "GRC_Winter",
"countries": "All"
}
}
},
"muzzleVelocity": 900,
"barrelHeight": 0.9
},
"Soldier M249": {
"name": "Soldier M249",

View File

@ -605,7 +605,7 @@ export class Map extends L.Map {
}
}
else if (selectedUnitTypes.length === 1 && ["GroundUnit", "NavyUnit"].includes(selectedUnitTypes[0])) {
if (selectedUnits.every((unit: Unit) => { return ["Gun Artillery", "Rocket Artillery", "Infantry", "IFV", "Tank", "Cruiser", "Destroyer", "Frigate"].includes(unit.getType()) })) {
if (selectedUnits.every((unit: Unit) => { return ["AAA", "Gun Artillery", "Rocket Artillery", "Infantry", "IFV", "Tank", "Cruiser", "Destroyer", "Frigate"].includes(unit.getType()) })) {
options["fire-at-area"] = { text: "Fire at area", tooltip: "Fire at a large area" };
options["simulate-fire-fight"] = { text: "Simulate fire fight", tooltip: "Simulate a fire fight by shooting randomly in a certain large area" };
}

View File

@ -356,6 +356,11 @@ export class ServerManager {
this.PUT(data, callback);
}
reloadDatabases(callback: CallableFunction = () => {}) {
var data = { "reloadDatabases": {} };
this.PUT(data, callback);
}
startUpdate() {
window.setInterval(() => {
if (!this.getPaused()) {

View File

@ -1,6 +1,6 @@
import { Marker, LatLng, Polyline, Icon, DivIcon, CircleMarker, Map, Point } from 'leaflet';
import { getApp } from '..';
import { enumToCoalition, enumToEmissioNCountermeasure, getMarkerCategoryByName, enumToROE, enumToReactionToThreat, enumToState, getUnitDatabaseByCategory, mToFt, msToKnots, rad2deg, bearing, deg2rad, ftToM } from '../other/utils';
import { enumToCoalition, enumToEmissioNCountermeasure, getMarkerCategoryByName, enumToROE, enumToReactionToThreat, enumToState, getUnitDatabaseByCategory, mToFt, msToKnots, rad2deg, bearing, deg2rad, ftToM, getGroundElevation } from '../other/utils';
import { CustomMarker } from '../map/markers/custommarker';
import { SVGInjector } from '@tanem/svg-injector';
import { UnitDatabase } from './databases/unitdatabase';
@ -723,8 +723,20 @@ export class Unit extends CustomMarker {
getApp().getServerManager().fireAtArea(this.ID, latlng);
}
simulateFireFight(latlng: LatLng, groundElevation: number | null) {
getApp().getServerManager().simulateFireFight(this.ID, latlng, groundElevation?? 0);
simulateFireFight(latlng: LatLng, targetGroundElevation: number | null) {
getGroundElevation(this.getPosition(), (response: string) => {
var unitGroundElevation: number | null = null;
try {
unitGroundElevation = parseFloat(response);
} catch {
console.log("Simulate fire fight: could not retrieve ground elevation")
}
/* DCS and SRTM altitude data is not exactly the same so to minimize error we use SRTM only to compute relative elevation difference */
var altitude = this.getPosition().alt;
if (altitude !== undefined && targetGroundElevation !== null && unitGroundElevation !== null)
getApp().getServerManager().simulateFireFight(this.ID, latlng, altitude + targetGroundElevation - unitGroundElevation);
});
}
/***********************************************/

View File

@ -235,7 +235,8 @@ function Olympus.buildTask(groupName, options)
params = {
point = {x = point.x, y = point.z},
radius = options['radius'],
altitude = options['alt']
altitude = options['alt'],
alt_type = 0 -- ASL
}
}
else

View File

@ -22,6 +22,7 @@ public:
void getUnitData(stringstream &ss, unsigned long long time);
void deleteUnit(unsigned int ID, bool explosion, bool immediate);
void acquireControl(unsigned int ID);
void loadDatabases();
private:
map<unsigned int, Unit*> units;

View File

@ -7,10 +7,6 @@
#include "scheduler.h"
#include "scriptLoader.h"
#include "luatools.h"
#include "aircraft.h"
#include "helicopter.h"
#include "groundunit.h"
#include "navyunit.h"
#include <chrono>
using namespace std::chrono;
@ -63,15 +59,12 @@ extern "C" DllExport int coreInit(lua_State* L)
server = new Server(L);
scheduler = new Scheduler(L);
Aircraft::loadDatabase(AIRCRAFT_DATABASE_PATH);
Helicopter::loadDatabase(HELICOPTER_DATABASE_PATH);
GroundUnit::loadDatabase(GROUNDUNIT_DATABASE_PATH);
NavyUnit::loadDatabase(NAVYUNIT_DATABASE_PATH);
registerLuaFunctions(L);
server->start(L);
unitsManager->loadDatabases();
initialized = true;
return(0);
}

View File

@ -160,13 +160,13 @@ void GroundUnit::AIloop()
case State::SIMULATE_FIRE_FIGHT: {
setTask("Simulating fire fight");
if (!getHasTask() || ((double)(rand()) / (double)(RAND_MAX)) < 0.01) {
if (!getHasTask() || 0 * (((double)(rand()) / (double)(RAND_MAX)) < 0.01)) {
double dist;
double bearing1;
double bearing2;
Geodesic::WGS84().Inverse(position.lat, position.lng, targetPosition.lat, targetPosition.lng, dist, bearing1, bearing2);
double r = 5; /* m */
double r = 15; /* m */
/* Default gun values */
double barrelHeight = 1.0; /* m */
double muzzleVelocity = 860; /* m/s */
@ -183,12 +183,12 @@ void GroundUnit::AIloop()
double lat = 0;
double lng = 0;
double randomBearing = bearing1 + (((double)(rand()) / (double)(RAND_MAX) - 0.5) * 2) * 15;
double randomBearing = bearing1 + 0 * (((double)(rand()) / (double)(RAND_MAX) - 0.5) * 2) * 15;
Geodesic::WGS84().Direct(position.lat, position.lng, randomBearing, r, lat, lng);
std::ostringstream taskSS;
taskSS.precision(10);
taskSS << "{id = 'FireAtPoint', lat = " << lat << ", lng = " << lng << ", alt = " << barrelElevation + barrelHeight << ", radius = 0.001}";
taskSS << "{id = 'FireAtPoint', lat = " << lat << ", lng = " << lng << ", alt = " << position.alt + barrelElevation + barrelHeight << ", radius = 0.001}";
Command* command = dynamic_cast<Command*>(new SetTask(groupName, taskSS.str(), [this]() { this->setHasTaskAssigned(true); }));
scheduler->appendCommand(command);
setHasTask(true);

View File

@ -579,6 +579,9 @@ void Scheduler::handleRequest(string key, json::value value, string username, js
setCommandModeOptions(value);
log(username + " updated the Command Mode Options", true);
}
else if (key.compare("reloadDatabases") == 0) {
unitsManager->loadDatabases();
}
else
{
log("Unknown command: " + key);

View File

@ -9,6 +9,7 @@
#include "weapon.h"
#include "commands.h"
#include "scheduler.h"
#include "defines.h"
#include "base64.hpp"
using namespace base64;
@ -157,3 +158,9 @@ void UnitsManager::acquireControl(unsigned int ID) {
}
}
void UnitsManager::loadDatabases() {
Aircraft::loadDatabase(AIRCRAFT_DATABASE_PATH);
Helicopter::loadDatabase(HELICOPTER_DATABASE_PATH);
GroundUnit::loadDatabase(GROUNDUNIT_DATABASE_PATH);
NavyUnit::loadDatabase(NAVYUNIT_DATABASE_PATH);
}