diff --git a/client/public/databases/units/groundunitdatabase.json b/client/public/databases/units/groundunitdatabase.json index 08e24921..263e32f5 100644 --- a/client/public/databases/units/groundunitdatabase.json +++ b/client/public/databases/units/groundunitdatabase.json @@ -2074,7 +2074,9 @@ "shortLabel": "Infantry AK", "filename": "", "type": "Infantry", - "enabled": true + "enabled": true, + "muzzleVelocity": 860, + "barrelHeight": 0.9 }, "KAMAZ Truck": { "name": "KAMAZ Truck", diff --git a/client/src/server/server.ts b/client/src/server/server.ts deleted file mode 100644 index 9938d026..00000000 --- a/client/src/server/server.ts +++ /dev/null @@ -1,495 +0,0 @@ -import { LatLng } from 'leaflet'; -import { getConnectionStatusPanel, getInfoPopup, getLogPanel, getMissionHandler, getServerStatusPanel, getUnitsManager, getWeaponsManager, setLoginStatus } from '..'; -import { GeneralSettings, Radio, TACAN } from '../@types/unit'; -import { AIRBASES_URI, BULLSEYE_URI, COMMANDS_URI, LOGS_URI, MISSION_URI, NONE, ROEs, UNITS_URI, WEAPONS_URI, emissionsCountermeasures, reactionsToThreat } from '../constants/constants'; - -var connected: boolean = false; -var paused: boolean = false; - -var REST_ADDRESS = "http://localhost:30000/olympus"; -var DEMO_ADDRESS = window.location.href + "demo"; - -var username = ""; -var password = ""; - -var sessionHash: string | null = null; -var lastUpdateTimes: {[key: string]: number} = {} -lastUpdateTimes[UNITS_URI] = Date.now(); -lastUpdateTimes[WEAPONS_URI] = Date.now(); -lastUpdateTimes[LOGS_URI] = Date.now(); -lastUpdateTimes[AIRBASES_URI] = Date.now(); -lastUpdateTimes[BULLSEYE_URI] = Date.now(); -lastUpdateTimes[MISSION_URI] = Date.now(); - -var demoEnabled = false; - -export function toggleDemoEnabled() { - demoEnabled = !demoEnabled; -} - -export function setCredentials(newUsername: string, newPassword: string) { - username = newUsername; - password = newPassword; -} - -export function GET(callback: CallableFunction, uri: string, options?: ServerRequestOptions, responseType?: string) { - var xmlHttp = new XMLHttpRequest(); - - /* Assemble the request options string */ - var optionsString = ''; - if (options?.time != undefined) - optionsString = `time=${options.time}`; - if (options?.commandHash != undefined) - optionsString = `commandHash=${options.commandHash}`; - - /* On the connection */ - xmlHttp.open("GET", `${demoEnabled ? DEMO_ADDRESS : REST_ADDRESS}/${uri}${optionsString ? `?${optionsString}` : ''}`, true); - - /* If provided, set the credentials */ - if (username && password) - xmlHttp.setRequestHeader("Authorization", "Basic " + btoa(`${username}:${password}`)); - - /* If specified, set the response type */ - if (responseType) - xmlHttp.responseType = responseType as XMLHttpRequestResponseType; - - xmlHttp.onload = function (e) { - if (xmlHttp.status == 200) { - /* Success */ - setConnected(true); - if (xmlHttp.responseType == 'arraybuffer') - lastUpdateTimes[uri] = callback(xmlHttp.response); - else { - const result = JSON.parse(xmlHttp.responseText); - lastUpdateTimes[uri] = callback(result); - - if (result.frameRate !== undefined && result.load !== undefined) - getServerStatusPanel().update(result.frameRate, result.load); - } - } else if (xmlHttp.status == 401) { - /* Bad credentials */ - console.error("Incorrect username/password"); - setLoginStatus("failed"); - } else { - /* Failure, probably disconnected */ - setConnected(false); - } - }; - xmlHttp.onerror = function (res) { - console.error("An error occurred during the XMLHttpRequest"); - setConnected(false); - }; - xmlHttp.send(null); -} - -export function POST(request: object, callback: CallableFunction) { - var xmlHttp = new XMLHttpRequest(); - xmlHttp.open("PUT", demoEnabled ? DEMO_ADDRESS : REST_ADDRESS); - xmlHttp.setRequestHeader("Content-Type", "application/json"); - if (username && password) - xmlHttp.setRequestHeader("Authorization", "Basic " + btoa(`${username}:${password}`)); - xmlHttp.onload = (res: any) => { - var res = JSON.parse(xmlHttp.responseText); - callback(res); - }; - xmlHttp.send(JSON.stringify(request)); -} - -export function getConfig(callback: CallableFunction) { - var xmlHttp = new XMLHttpRequest(); - xmlHttp.open("GET", window.location.href + "config", true); - xmlHttp.onload = function (e) { - var data = JSON.parse(xmlHttp.responseText); - callback(data); - }; - xmlHttp.onerror = function () { - console.error("An error occurred during the XMLHttpRequest, could not retrieve configuration file"); - }; - xmlHttp.send(null); -} - -export function setAddress(address: string, port: number) { - REST_ADDRESS = `http://${address}:${port}/olympus` - console.log(`Setting REST address to ${REST_ADDRESS}`) -} - -export function getAirbases(callback: CallableFunction) { - GET(callback, AIRBASES_URI); -} - -export function getBullseye(callback: CallableFunction) { - GET(callback, BULLSEYE_URI); -} - -export function getLogs(callback: CallableFunction, refresh: boolean = false) { - GET(callback, LOGS_URI, { time: refresh ? 0 : lastUpdateTimes[LOGS_URI]}); -} - -export function getMission(callback: CallableFunction) { - GET(callback, MISSION_URI); -} - -export function getUnits(callback: CallableFunction, refresh: boolean = false) { - GET(callback, UNITS_URI, { time: refresh ? 0 : lastUpdateTimes[UNITS_URI] }, 'arraybuffer'); -} - -export function getWeapons(callback: CallableFunction, refresh: boolean = false) { - GET(callback, WEAPONS_URI, { time: refresh ? 0 : lastUpdateTimes[WEAPONS_URI] }, 'arraybuffer'); -} - -export function isCommandExecuted(callback: CallableFunction, commandHash: string) { - GET(callback, COMMANDS_URI, { commandHash: commandHash}); -} - -export function addDestination(ID: number, path: any, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "path": path } - var data = { "setPath": command } - POST(data, callback); -} - -export function spawnSmoke(color: string, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "color": color, "location": latlng }; - var data = { "smoke": command } - POST(data, callback); -} - -export function spawnExplosion(intensity: number, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "intensity": intensity, "location": latlng }; - var data = { "explosion": command } - POST(data, callback); -} - -export function spawnAircrafts(units: any, coalition: string, airbaseName: string, country: string, immediate: boolean, spawnPoints: number, callback: CallableFunction = () => {}) { - var command = { "units": units, "coalition": coalition, "airbaseName": airbaseName, "country": country, "immediate": immediate, "spawnPoints": spawnPoints }; - var data = { "spawnAircrafts": command } - POST(data, callback); -} - -export function spawnHelicopters(units: any, coalition: string, airbaseName: string, country: string, immediate: boolean, spawnPoints: number, callback: CallableFunction = () => {}) { - var command = { "units": units, "coalition": coalition, "airbaseName": airbaseName, "country": country, "immediate": immediate, "spawnPoints": spawnPoints }; - var data = { "spawnHelicopters": command } - POST(data, callback); -} - -export function spawnGroundUnits(units: any, coalition: string, country: string, immediate: boolean, spawnPoints: number, callback: CallableFunction = () => {}) { - var command = { "units": units, "coalition": coalition, "country": country, "immediate": immediate, "spawnPoints": spawnPoints };; - var data = { "spawnGroundUnits": command } - POST(data, callback); -} - -export function spawnNavyUnits(units: any, coalition: string, country: string, immediate: boolean, spawnPoints: number, callback: CallableFunction = () => {}) { - var command = { "units": units, "coalition": coalition, "country": country, "immediate": immediate, "spawnPoints": spawnPoints }; - var data = { "spawnNavyUnits": command } - POST(data, callback); -} - -export function attackUnit(ID: number, targetID: number, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "targetID": targetID }; - var data = { "attackUnit": command } - POST(data, callback); -} - -export function followUnit(ID: number, targetID: number, offset: { "x": number, "y": number, "z": number }, callback: CallableFunction = () => {}) { - // X: front-rear, positive front - // Y: top-bottom, positive bottom - // Z: left-right, positive right - - var command = { "ID": ID, "targetID": targetID, "offsetX": offset["x"], "offsetY": offset["y"], "offsetZ": offset["z"] }; - var data = { "followUnit": command } - POST(data, callback); -} - -export function cloneUnits(units: {ID: number, location: LatLng}[], deleteOriginal: boolean, spawnPoints: number, callback: CallableFunction = () => {}) { - var command = { "units": units, "deleteOriginal": deleteOriginal, "spawnPoints": spawnPoints }; - var data = { "cloneUnits": command } - POST(data, callback); -} - -export function deleteUnit(ID: number, explosion: boolean, immediate: boolean, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "explosion": explosion, "immediate": immediate }; - var data = { "deleteUnit": command } - POST(data, callback); -} - -export function landAt(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "location": latlng }; - var data = { "landAt": command } - POST(data, callback); -} - -export function changeSpeed(ID: number, speedChange: string, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "change": speedChange } - var data = { "changeSpeed": command } - POST(data, callback); -} - -export function setSpeed(ID: number, speed: number, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "speed": speed } - var data = { "setSpeed": command } - POST(data, callback); -} - -export function setSpeedType(ID: number, speedType: string, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "speedType": speedType } - var data = { "setSpeedType": command } - POST(data, callback); -} - -export function changeAltitude(ID: number, altitudeChange: string, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "change": altitudeChange } - var data = { "changeAltitude": command } - POST(data, callback); -} - -export function setAltitudeType(ID: number, altitudeType: string, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "altitudeType": altitudeType } - var data = { "setAltitudeType": command } - POST(data, callback); -} - -export function setAltitude(ID: number, altitude: number, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "altitude": altitude } - var data = { "setAltitude": command } - POST(data, callback); -} - -export function createFormation(ID: number, isLeader: boolean, wingmenIDs: number[], callback: CallableFunction = () => {}) { - var command = { "ID": ID, "wingmenIDs": wingmenIDs, "isLeader": isLeader } - var data = { "setLeader": command } - POST(data, callback); -} - -export function setROE(ID: number, ROE: string, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "ROE": ROEs.indexOf(ROE) } - var data = { "setROE": command } - POST(data, callback); -} - -export function setReactionToThreat(ID: number, reactionToThreat: string, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "reactionToThreat": reactionsToThreat.indexOf(reactionToThreat) } - var data = { "setReactionToThreat": command } - POST(data, callback); -} - -export function setEmissionsCountermeasures(ID: number, emissionCountermeasure: string, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "emissionsCountermeasures": emissionsCountermeasures.indexOf(emissionCountermeasure) } - var data = { "setEmissionsCountermeasures": command } - POST(data, callback); -} - -export function setOnOff(ID: number, onOff: boolean, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "onOff": onOff } - var data = { "setOnOff": command } - POST(data, callback); -} - -export function setFollowRoads(ID: number, followRoads: boolean, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "followRoads": followRoads } - var data = { "setFollowRoads": command } - POST(data, callback); -} - -export function refuel(ID: number, callback: CallableFunction = () => {}) { - var command = { "ID": ID }; - var data = { "refuel": command } - POST(data, callback); -} - -export function bombPoint(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "location": latlng } - var data = { "bombPoint": command } - POST(data, callback); -} - -export function carpetBomb(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "location": latlng } - var data = { "carpetBomb": command } - POST(data, callback); -} - -export function bombBuilding(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "location": latlng } - var data = { "bombBuilding": command } - POST(data, callback); -} - -export function fireAtArea(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "location": latlng } - var data = { "fireAtArea": command } - POST(data, callback); -} - -export function simulateFireFight(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) { - var command = { "ID": ID, "location": latlng } - var data = { "simulateFireFight": command } - POST(data, callback); -} - -export function setAdvacedOptions(ID: number, isTanker: boolean, isAWACS: boolean, TACAN: TACAN, radio: Radio, generalSettings: GeneralSettings, callback: CallableFunction = () => {}) { - var command = { - "ID": ID, - "isTanker": isTanker, - "isAWACS": isAWACS, - "TACAN": TACAN, - "radio": radio, - "generalSettings": generalSettings - }; - - var data = { "setAdvancedOptions": command }; - POST(data, callback); -} - -export function setCommandModeOptions(restrictSpawns: boolean, restrictToCoalition: boolean, spawnPoints: {blue: number, red: number}, eras: string[], setupTime: number, callback: CallableFunction = () => {}) { - var command = { - "restrictSpawns": restrictSpawns, - "restrictToCoalition": restrictToCoalition, - "spawnPoints": spawnPoints, - "eras": eras, - "setupTime": setupTime - }; - - var data = { "setCommandModeOptions": command }; - POST(data, callback); -} - -export function startUpdate() { - window.setInterval(() => { - if (!getPaused()) { - getMission((data: MissionData) => { - checkSessionHash(data.sessionHash); - getMissionHandler()?.updateMission(data); - return data.time; - }); - } - }, 1000); - - window.setInterval(() => { - if (!getPaused() && getMissionHandler().getCommandModeOptions().commandMode != NONE) { - getAirbases((data: AirbasesData) => { - checkSessionHash(data.sessionHash); - getMissionHandler()?.updateAirbases(data); - return data.time; - }); - } - }, 10000); - - window.setInterval(() => { - if (!getPaused() && getMissionHandler().getCommandModeOptions().commandMode != NONE){ - getBullseye((data: BullseyesData) => { - checkSessionHash(data.sessionHash); - getMissionHandler()?.updateBullseyes(data); - return data.time; - }); - } - }, 10000); - - window.setInterval(() => { - if (!getPaused() && getMissionHandler().getCommandModeOptions().commandMode != NONE) { - getLogs((data: any) => { - checkSessionHash(data.sessionHash); - getLogPanel().appendLogs(data.logs) - return data.time; - }); - } - }, 1000); - - window.setInterval(() => { - if (!getPaused() && getMissionHandler().getCommandModeOptions().commandMode != NONE) { - getUnits((buffer: ArrayBuffer) => { - var time = getUnitsManager()?.update(buffer); - return time; - }, false); - } - }, 250); - - window.setInterval(() => { - if (!getPaused() && getMissionHandler().getCommandModeOptions().commandMode != NONE) { - getWeapons((buffer: ArrayBuffer) => { - var time = getWeaponsManager()?.update(buffer); - return time; - }, false); - } - }, 250); - - window.setInterval(() => { - if (!getPaused() && getMissionHandler().getCommandModeOptions().commandMode != NONE) { - getUnits((buffer: ArrayBuffer) => { - var time = getUnitsManager()?.update(buffer); - return time; - }, true); - getConnectionStatusPanel()?.update(getConnected()); - } - }, 5000); - - window.setInterval(() => { - if (!getPaused() && getMissionHandler().getCommandModeOptions().commandMode != NONE) { - getWeapons((buffer: ArrayBuffer) => { - var time = getWeaponsManager()?.update(buffer); - return time; - }, true); - } - }, 5000); -} - -export function refreshAll() { - getAirbases((data: AirbasesData) => { - checkSessionHash(data.sessionHash); - getMissionHandler()?.updateAirbases(data); - return data.time; - }); - - getBullseye((data: BullseyesData) => { - checkSessionHash(data.sessionHash); - getMissionHandler()?.updateBullseyes(data); - return data.time; - }); - - getLogs((data: any) => { - checkSessionHash(data.sessionHash); - getLogPanel().appendLogs(data.logs) - return data.time; - }); - - getWeapons((buffer: ArrayBuffer) => { - var time = getWeaponsManager()?.update(buffer); - return time; - }, true); - - getUnits((buffer: ArrayBuffer) => { - var time = getUnitsManager()?.update(buffer); - return time; - }, true); -} - -export function checkSessionHash(newSessionHash: string) { - if (sessionHash != null) { - if (newSessionHash !== sessionHash) - location.reload(); - } - else - sessionHash = newSessionHash; -} - -export function setConnected(newConnected: boolean) { - if (connected != newConnected) - newConnected ? getInfoPopup().setText("Connected to DCS Olympus server") : getInfoPopup().setText("Disconnected from DCS Olympus server"); - connected = newConnected; - - if (connected) { - document.querySelector("#splash-screen")?.classList.add("hide"); - document.querySelector("#gray-out")?.classList.add("hide"); - } -} - -export function getConnected() { - return connected; -} - -export function setPaused(newPaused: boolean) { - paused = newPaused; - paused ? getInfoPopup().setText("View paused") : getInfoPopup().setText("View unpaused"); -} - -export function getPaused() { - return paused; -} \ No newline at end of file diff --git a/client/src/server/servermanager.ts b/client/src/server/servermanager.ts index d2747e69..8df86f62 100644 --- a/client/src/server/servermanager.ts +++ b/client/src/server/servermanager.ts @@ -322,6 +322,12 @@ export class ServerManager { this.POST(data, callback); } + simulateFireFight(ID: number, latlng: LatLng, callback: CallableFunction = () => {}) { + var command = { "ID": ID, "location": latlng } + var data = { "simulateFireFight": command } + this.POST(data, callback); + } + setAdvacedOptions(ID: number, isTanker: boolean, isAWACS: boolean, TACAN: TACAN, radio: Radio, generalSettings: GeneralSettings, callback: CallableFunction = () => {}) { var command = { "ID": ID, diff --git a/client/src/unit/unit.ts b/client/src/unit/unit.ts index e9cb4084..bd8cb3d3 100644 --- a/client/src/unit/unit.ts +++ b/client/src/unit/unit.ts @@ -723,7 +723,7 @@ export class Unit extends CustomMarker { } simulateFireFight(latlng: LatLng) { - simulateFireFight(this.ID, latlng); + getApp().getServerManager().simulateFireFight(this.ID, latlng); } /***********************************************/ diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index da1d2d5e..7c46020d 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -37,7 +37,6 @@ - diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index cfb10c59..56fade36 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -54,9 +54,6 @@ Header Files - - Header Files - diff --git a/src/core/include/aircraft.h b/src/core/include/aircraft.h index be27e35b..a3fa2b2a 100644 --- a/src/core/include/aircraft.h +++ b/src/core/include/aircraft.h @@ -6,6 +6,11 @@ class Aircraft : public AirUnit public: Aircraft(json::value json, unsigned int ID); + static void loadDatabase(string path); + virtual void changeSpeed(string change); virtual void changeAltitude(string change); + +protected: + static json::value database; }; \ No newline at end of file diff --git a/src/core/include/datatypes.h b/src/core/include/datatypes.h index f8be70fa..207b72ee 100644 --- a/src/core/include/datatypes.h +++ b/src/core/include/datatypes.h @@ -127,8 +127,3 @@ struct CloneOptions { unsigned int ID; Coords location; }; - -struct GunDataItem { - double barrelHeight; - double muzzleVelocity; -}; \ No newline at end of file diff --git a/src/core/include/groundunit.h b/src/core/include/groundunit.h index 46e1b78d..8ef0fb35 100644 --- a/src/core/include/groundunit.h +++ b/src/core/include/groundunit.h @@ -8,6 +8,8 @@ class GroundUnit : public Unit public: GroundUnit(json::value json, unsigned int ID); + static void loadDatabase(string path); + virtual void setState(unsigned char newState); virtual void setDefaults(bool force = false); @@ -17,4 +19,5 @@ public: protected: virtual void AIloop(); + static json::value database; }; \ No newline at end of file diff --git a/src/core/include/gundata.h b/src/core/include/gundata.h deleted file mode 100644 index b463f423..00000000 --- a/src/core/include/gundata.h +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once - -#include "framework.h" -#include "datatypes.h" - -map gunData = { -{"2B11 mortar", {0.9, 860}}, -{"SAU Gvozdika", {0.9, 860}}, -{"SAU Msta", {0.9, 860}}, -{"SAU Akatsia", {0.9, 860}}, -{"SAU 2-C9", {0.9, 860}}, -{"M-109", {0.9, 860}}, -{"SpGH_Dana", {0.9, 860}}, -{"AAV7", {0.9, 860}}, -{"BMD-1", {0.9, 860}}, -{"BMP-1", {0.9, 860}}, -{"BMP-2", {0.9, 860}}, -{"BMP-3", {0.9, 860}}, -{"BRDM-2", {0.9, 860}}, -{"BTR_D", {0.9, 860}}, -{"Cobra", {0.9, 860}}, -{"LAV-25", {0.9, 860}}, -{"M1043 HMMWV Armament", {0.9, 860}}, -{"M1045 HMMWV TOW", {0.9, 860}}, -{"M1126 Stryker ICV", {0.9, 860}}, -{"M-113", {0.9, 860}}, -{"M1134 Stryker ATGM", {0.9, 860}}, -{"M-2 Bradley", {0.9, 860}}, -{"MCV-80", {0.9, 860}}, -{"MTLB", {0.9, 860}}, -{"Marder", {0.9, 860}}, -{"TPZ", {0.9, 860}}, -{"Grad_FDDM", {0.9, 860}}, -{"Paratrooper RPG-16", {0.9, 860}}, -{"Paratrooper AKS-74", {0.9, 860}}, -{"Infantry AK Ins", {0.9, 860}}, -{"Soldier AK", {0.4, 860}}, -{"Infantry AK", {0.9, 860}}, -{"Soldier M249", {0.9, 860}}, -{"Soldier M4", {0.9, 860}}, -{"Soldier M4 GRG", {0.9, 860}}, -{"Soldier RPG", {0.9, 860}}, -{"MLRS FDDM", {0.9, 860}}, -{"Infantry AK ver2", {0.9, 860}}, -{"Infantry AK ver3", {0.9, 860}}, -{"Grad-URAL", {0.9, 860}}, -{"Uragan_BM-27", {0.9, 860}}, -{"Smerch", {0.9, 860}}, -{"Smerch_HE", {0.9, 860}}, -{"MLRS", {0.9, 860}}, -{"Challenger2", {0.9, 860}}, -{"Leclerc", {0.9, 860}}, -{"M-60", {0.9, 860}}, -{"M1128 Stryker MGS", {0.9, 860}}, -{"M-1 Abrams", {0.9, 860}}, -{"T-55", {0.9, 860}}, -{"T-72B", {0.9, 860}}, -{"T-80UD", {0.9, 860}}, -{"T-90", {0.9, 860}}, -{"Leopard1A3", {0.9, 860}}, -{"Merkava_Mk4", {0.9, 860}}, -{"JTAC", {0.9, 860}}, -{"Infantry Animated", {0.9, 860}}, -{"HL_DSHK", {0.9, 860}}, -{"HL_KORD", {0.9, 860}}, -{"tt_DSHK", {0.9, 860}}, -{"tt_KORD", {0.9, 860}}, -{"HL_B8M1", {0.9, 860}}, -{"tt_B8M1", {0.9, 860}}, -{"M4_Sherman", {0.9, 860}}, -{"M2A1_halftrack", {0.9, 860}}, -{"BTR-80", {0.9, 860}}, -{"T-72B3", {0.9, 860}}, -{"PT_76", {0.9, 860}}, -{"BTR-82A", {0.9, 860}}, -{"Chieftain_mk3", {0.9, 860}}, -{"Pz_IV_H", {0.9, 860}}, -{"Leopard-2A5", {0.9, 860}}, -{"Leopard-2", {0.9, 860}}, -{"leopard-2A4", {0.9, 860}}, -{"leopard-2A4_trs", {0.9, 860}}, -{"Sd_Kfz_251", {0.9, 860}}, -{"T155_Firtina", {0.9, 860}}, -{"VAB_Mephisto", {0.9, 860}}, -{"ZTZ96B", {0.9, 860}}, -{"ZBD04A", {0.9, 860}}, -{"PLZ05", {0.9, 860}}, -{"TYPE-59", {0.9, 860}}, -{"Tiger_I", {0.9, 860}}, -{"Tiger_II_H", {0.9, 860}}, -{"Pz_V_Panther_G", {0.9, 860}}, -{"Jagdpanther_G1", {0.9, 860}}, -{"JagdPz_IV", {0.9, 860}}, -{"Stug_IV", {0.9, 860}}, -{"SturmPzIV", {0.9, 860}}, -{"Wespe124", {0.9, 860}}, -{"Sd_Kfz_234_2_Puma", {0.9, 860}}, -{"soldier_mauser98", {0.9, 860}}, -{"Stug_III", {0.9, 860}}, -{"Elefant_SdKfz_184", {0.9, 860}}, -{"Pak40", {0.9, 860}}, -{"LeFH_18-40-105", {0.9, 860}}, -{"Cromwell_IV", {0.9, 860}}, -{"M4A4_Sherman_FF", {0.9, 860}}, -{"soldier_wwii_br_01", {0.9, 860}}, -{"Centaur_IV", {0.9, 860}}, -{"Churchill_VII", {0.9, 860}}, -{"Daimler_AC", {0.9, 860}}, -{"Tetrarch", {0.9, 860}}, -{"M12_GMC", {0.9, 860}}, -{"soldier_wwii_us", {0.9, 860}}, -{"M10_GMC", {0.9, 860}}, -{"M8_Greyhound", {0.9, 860}}, -{"M2A1-105", {0.9, 860}}, -{"M4_Tractor", {0.9, 860}}, -}; \ No newline at end of file diff --git a/src/core/include/helicopter.h b/src/core/include/helicopter.h index 3c72693b..5c0246ae 100644 --- a/src/core/include/helicopter.h +++ b/src/core/include/helicopter.h @@ -6,6 +6,11 @@ class Helicopter : public AirUnit public: Helicopter(json::value json, unsigned int ID); + static void loadDatabase(string path); + virtual void changeSpeed(string change); virtual void changeAltitude(string change); + +protected: + static json::value database; }; \ No newline at end of file diff --git a/src/core/include/navyunit.h b/src/core/include/navyunit.h index 24ed244d..23f86fe7 100644 --- a/src/core/include/navyunit.h +++ b/src/core/include/navyunit.h @@ -8,6 +8,8 @@ class NavyUnit : public Unit public: NavyUnit(json::value json, unsigned int ID); + static void loadDatabase(string path); + virtual void setState(unsigned char newState); virtual void setDefaults(bool force = false); @@ -16,5 +18,5 @@ public: protected: virtual void AIloop(); - + static json::value database; }; \ No newline at end of file diff --git a/src/core/src/aircraft.cpp b/src/core/src/aircraft.cpp index e8a932dd..be3021f9 100644 --- a/src/core/src/aircraft.cpp +++ b/src/core/src/aircraft.cpp @@ -11,6 +11,26 @@ using namespace GeographicLib; extern Scheduler* scheduler; extern UnitsManager* unitsManager; +json::value Aircraft::database = json::value(); + +void Aircraft::loadDatabase(string path) { + char* buf = nullptr; + size_t sz = 0; + if (_dupenv_s(&buf, &sz, "DCSOLYMPUS_PATH") == 0 && buf != nullptr) + { + std::ifstream ifstream(string(buf) + path); + std::stringstream ss; + ss << ifstream.rdbuf(); + std::error_code errorCode; + database = json::value::parse(ss.str(), errorCode); + if (database.is_object()) + log("Aircrafts database loaded correctly"); + else + log("Error reading Aircrafts database file"); + + free(buf); + } +} /* Aircraft */ Aircraft::Aircraft(json::value json, unsigned int ID) : AirUnit(json, ID) diff --git a/src/core/src/core.cpp b/src/core/src/core.cpp index 3fc42753..e41128e9 100644 --- a/src/core/src/core.cpp +++ b/src/core/src/core.cpp @@ -7,6 +7,10 @@ #include "scheduler.h" #include "scriptLoader.h" #include "luatools.h" +#include "aircraft.h" +#include "helicopter.h" +#include "groundunit.h" +#include "navyunit.h" #include using namespace std::chrono; @@ -59,6 +63,11 @@ 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); diff --git a/src/core/src/groundunit.cpp b/src/core/src/groundunit.cpp index 69e76b83..61aa867f 100644 --- a/src/core/src/groundunit.cpp +++ b/src/core/src/groundunit.cpp @@ -5,13 +5,32 @@ #include "scheduler.h" #include "defines.h" #include "unitsmanager.h" -#include "gundata.h" #include using namespace GeographicLib; extern Scheduler* scheduler; extern UnitsManager* unitsManager; +json::value GroundUnit::database = json::value(); + +void GroundUnit::loadDatabase(string path) { + char* buf = nullptr; + size_t sz = 0; + if (_dupenv_s(&buf, &sz, "DCSOLYMPUS_PATH") == 0 && buf != nullptr) + { + std::ifstream ifstream(string(buf) + path); + std::stringstream ss; + ss << ifstream.rdbuf(); + std::error_code errorCode; + database = json::value::parse(ss.str(), errorCode); + if (database.is_object()) + log("Ground Units database loaded correctly"); + else + log("Error reading Ground Units database file"); + + free(buf); + } +} /* Ground unit */ GroundUnit::GroundUnit(json::value json, unsigned int ID) : Unit(json, ID) @@ -151,16 +170,20 @@ void GroundUnit::AIloop() /* Default gun values */ double barrelHeight = 1.0; /* m */ double muzzleVelocity = 860; /* m/s */ - if (gunData.find(name) != gunData.end()) { - barrelHeight = gunData[name].barrelHeight; - muzzleVelocity = gunData[name].muzzleVelocity; + if (database.has_object_field(to_wstring(name))) { + json::value databaseEntry = database[to_wstring(name)]; + if (databaseEntry.has_number_field(L"barrelHeight") && databaseEntry.has_number_field(L"muzzleVelocity")) { + barrelHeight = databaseEntry[L"barrelHeight"].as_number().to_double(); + muzzleVelocity = databaseEntry[L"muzzleVelocity"].as_number().to_double(); + log(to_string(barrelHeight) + " " + to_string(muzzleVelocity)); + } } double barrelElevation = r * (9.81 * dist / (2 * muzzleVelocity * muzzleVelocity) - barrelHeight / dist); /* m */ double lat = 0; double lng = 0; - double randomBearing = bearing1 + (((double)(rand()) / (double)(RAND_MAX) - 0.5) * 2) * 45; + double randomBearing = bearing1 + (((double)(rand()) / (double)(RAND_MAX) - 0.5) * 2) * 15; Geodesic::WGS84().Direct(position.lat, position.lng, randomBearing, r, lat, lng); std::ostringstream taskSS; diff --git a/src/core/src/helicopter.cpp b/src/core/src/helicopter.cpp index 6d24022e..bfd6caab 100644 --- a/src/core/src/helicopter.cpp +++ b/src/core/src/helicopter.cpp @@ -11,6 +11,26 @@ using namespace GeographicLib; extern Scheduler* scheduler; extern UnitsManager* unitsManager; +json::value Helicopter::database = json::value(); + +void Helicopter::loadDatabase(string path) { + char* buf = nullptr; + size_t sz = 0; + if (_dupenv_s(&buf, &sz, "DCSOLYMPUS_PATH") == 0 && buf != nullptr) + { + std::ifstream ifstream(string(buf) + path); + std::stringstream ss; + ss << ifstream.rdbuf(); + std::error_code errorCode; + database = json::value::parse(ss.str(), errorCode); + if (database.is_object()) + log("Helicopters database loaded correctly"); + else + log("Error reading Helicopters database file"); + + free(buf); + } +} /* Helicopter */ Helicopter::Helicopter(json::value json, unsigned int ID) : AirUnit(json, ID) diff --git a/src/core/src/navyunit.cpp b/src/core/src/navyunit.cpp index d2c68a3d..0c66380d 100644 --- a/src/core/src/navyunit.cpp +++ b/src/core/src/navyunit.cpp @@ -11,6 +11,26 @@ using namespace GeographicLib; extern Scheduler* scheduler; extern UnitsManager* unitsManager; +json::value NavyUnit::database = json::value(); + +void NavyUnit::loadDatabase(string path) { + char* buf = nullptr; + size_t sz = 0; + if (_dupenv_s(&buf, &sz, "DCSOLYMPUS_PATH") == 0 && buf != nullptr) + { + std::ifstream ifstream(string(buf) + path); + std::stringstream ss; + ss << ifstream.rdbuf(); + std::error_code errorCode; + database = json::value::parse(ss.str(), errorCode); + if (database.is_object()) + log("Navy Units database loaded correctly"); + else + log("Error reading Navy Units database file"); + + free(buf); + } +} /* Navy Unit */ NavyUnit::NavyUnit(json::value json, unsigned int ID) : Unit(json, ID) diff --git a/src/core/src/server.cpp b/src/core/src/server.cpp index 2817846a..e3be2f2f 100644 --- a/src/core/src/server.cpp +++ b/src/core/src/server.cpp @@ -291,7 +291,7 @@ void Server::task() size_t sz = 0; if (_dupenv_s(&buf, &sz, "DCSOLYMPUS_PATH") == 0 && buf != nullptr) { - std::ifstream ifstream(string(buf) + "\\olympus.json"); + std::ifstream ifstream(string(buf) + OLYMPUS_JSON_PATH); std::stringstream ss; ss << ifstream.rdbuf(); std::error_code errorCode; diff --git a/src/shared/include/defines.h b/src/shared/include/defines.h index e8f8fc14..fc15746e 100644 --- a/src/shared/include/defines.h +++ b/src/shared/include/defines.h @@ -12,4 +12,10 @@ #define MISSION_URI "mission" #define COMMANDS_URI "commands" -#define FRAMERATE_TIME_INTERVAL 0.05 \ No newline at end of file +#define FRAMERATE_TIME_INTERVAL 0.05 + +#define OLYMPUS_JSON_PATH "\\olympus.json" +#define AIRCRAFT_DATABASE_PATH "\\client\\public\\databases\\units\\aircraftdatabase.json" +#define HELICOPTER_DATABASE_PATH "\\client\\public\\databases\\units\\helicopterdatabase.json" +#define GROUNDUNIT_DATABASE_PATH "\\client\\public\\databases\\units\\groundunitdatabase.json" +#define NAVYUNIT_DATABASE_PATH "\\client\\public\\databases\\units\\navyunitdatabase.json"