Completed transition to weapons handler

This commit is contained in:
Pax1601
2023-07-27 19:21:34 +02:00
parent 6d434e48a1
commit 80ed675cbc
6 changed files with 20 additions and 24 deletions

View File

@@ -664,28 +664,28 @@ export class UnitsManager {
spawnUnits(category: string, units: any, coalition: string = "blue", immediate: boolean = true, airbase: string = "") { spawnUnits(category: string, units: any, coalition: string = "blue", immediate: boolean = true, airbase: string = "") {
var spawnPoints = 0; var spawnPoints = 0;
if (category === "Aircraft") { if (category === "Aircraft") {
if (airbase == "" && getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) { if (airbase == "" && getMissionHandler().getCommandModeOptions().restrictSpawns && getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) {
getInfoPopup().setText("Aircrafts can be air spawned during the SETUP phase only"); getInfoPopup().setText("Aircrafts can be air spawned during the SETUP phase only");
return false; return false;
} }
spawnPoints = units.reduce((points: number, unit: any) => {return points + aircraftDatabase.getSpawnPointsByName(unit.unitType)}, 0); spawnPoints = units.reduce((points: number, unit: any) => {return points + aircraftDatabase.getSpawnPointsByName(unit.unitType)}, 0);
spawnAircrafts(units, coalition, airbase, immediate, spawnPoints); spawnAircrafts(units, coalition, airbase, immediate, spawnPoints);
} else if (category === "Helicopter") { } else if (category === "Helicopter") {
if (airbase == "" && getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) { if (airbase == "" && getMissionHandler().getCommandModeOptions().restrictSpawns && getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) {
getInfoPopup().setText("Helicopters can be air spawned during the SETUP phase only"); getInfoPopup().setText("Helicopters can be air spawned during the SETUP phase only");
return false; return false;
} }
spawnPoints = units.reduce((points: number, unit: any) => {return points + helicopterDatabase.getSpawnPointsByName(unit.unitType)}, 0); spawnPoints = units.reduce((points: number, unit: any) => {return points + helicopterDatabase.getSpawnPointsByName(unit.unitType)}, 0);
spawnHelicopters(units, coalition, airbase, immediate, spawnPoints); spawnHelicopters(units, coalition, airbase, immediate, spawnPoints);
} else if (category === "GroundUnit") { } else if (category === "GroundUnit") {
if (getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) { if (getMissionHandler().getCommandModeOptions().restrictSpawns && getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) {
getInfoPopup().setText("Ground units can be spawned during the SETUP phase only"); getInfoPopup().setText("Ground units can be spawned during the SETUP phase only");
return false; return false;
} }
spawnPoints = units.reduce((points: number, unit: any) => {return points + groundUnitDatabase.getSpawnPointsByName(unit.unitType)}, 0); spawnPoints = units.reduce((points: number, unit: any) => {return points + groundUnitDatabase.getSpawnPointsByName(unit.unitType)}, 0);
spawnGroundUnits(units, coalition, immediate, spawnPoints); spawnGroundUnits(units, coalition, immediate, spawnPoints);
} else if (category === "NavyUnit") { } else if (category === "NavyUnit") {
if (getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) { if (getMissionHandler().getCommandModeOptions().restrictSpawns && getMissionHandler().getRemainingSetupTime() < 0 && getMissionHandler().getCommandModeOptions().commandMode !== GAME_MASTER) {
getInfoPopup().setText("Navy units can be spawned during the SETUP phase only"); getInfoPopup().setText("Navy units can be spawned during the SETUP phase only");
return false; return false;
} }

View File

@@ -704,11 +704,12 @@ function Olympus.setUnitsData(arg, time)
-- Get the targets detected by the group controller -- Get the targets detected by the group controller
local group = unit:getGroup() local group = unit:getGroup()
local controller = group:getController() local controller = group:getController()
local controllerTargets = controller:getDetectedTargets()
local contacts = {} local contacts = {}
for i, target in ipairs(controllerTargets) do for det, enum in pairs(Controller.Detection) do
for det, enum in pairs(Controller.Detection) do local controllerTargets = unit:getController():getDetectedTargets(enum)
if target.object ~= nil then for i, target in ipairs(controllerTargets) do
if target.object ~= nil and target.visible then
target["detectionMethod"] = det target["detectionMethod"] = det
contacts[#contacts + 1] = target contacts[#contacts + 1] = target
end end
@@ -756,7 +757,7 @@ function Olympus.setWeaponsData(arg, time)
local startIndex = Olympus.weaponIndex local startIndex = Olympus.weaponIndex
local endIndex = startIndex + Olympus.weaponStep local endIndex = startIndex + Olympus.weaponStep
local index = 0 local index = 0
for ID, unit in pairs(Olympus.weapons) do for ID, weapon in pairs(Olympus.weapons) do
index = index + 1 index = index + 1
if index > startIndex then if index > startIndex then
if weapon ~= nil then if weapon ~= nil then
@@ -817,7 +818,7 @@ function Olympus.setWeaponsData(arg, time)
Olympus.weaponsData["weapons"] = weapons Olympus.weaponsData["weapons"] = weapons
Olympus.OlympusDLL.setWeaponsData() Olympus.OlympusDLL.setWeaponsData()
return time + 0.05 return time + 0.25
end end
function Olympus.setMissionData(arg, time) function Olympus.setMissionData(arg, time)
@@ -875,7 +876,7 @@ function Olympus.initializeUnits()
Olympus.units[unit["id_"]] = unit Olympus.units[unit["id_"]] = unit
end end
end end
Olympus.debug("Olympus units table initialized", 2) Olympus.notify("Olympus units table initialized", 2)
else else
Olympus.debug("MIST DBs not ready", 2) Olympus.debug("MIST DBs not ready", 2)
timer.scheduleFunction(Olympus.initializeUnits, {}, timer.getTime() + 1) timer.scheduleFunction(Olympus.initializeUnits, {}, timer.getTime() + 1)
@@ -946,7 +947,6 @@ end
------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------
-- Olympus startup script -- Olympus startup script
------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------
local OlympusName = 'Olympus ' .. version .. ' C++ module'; local OlympusName = 'Olympus ' .. version .. ' C++ module';
Olympus.DLLsloaded = Olympus.loadDLLs() Olympus.DLLsloaded = Olympus.loadDLLs()
if Olympus.DLLsloaded then if Olympus.DLLsloaded then
@@ -962,7 +962,6 @@ if handler ~= nil then
end end
handler = {} handler = {}
function handler:onEvent(event) function handler:onEvent(event)
Olympus.debug(Olympus.serializeTable(event), 2)
if event.id == 1 then if event.id == 1 then
local weapon = event.weapon local weapon = event.weapon
Olympus.weapons[weapon["id_"]] = weapon Olympus.weapons[weapon["id_"]] = weapon
@@ -977,6 +976,7 @@ world.addEventHandler(handler)
-- Start the periodic functions -- Start the periodic functions
timer.scheduleFunction(Olympus.setUnitsData, {}, timer.getTime() + 0.05) timer.scheduleFunction(Olympus.setUnitsData, {}, timer.getTime() + 0.05)
timer.scheduleFunction(Olympus.setWeaponsData, {}, timer.getTime() + 0.25)
timer.scheduleFunction(Olympus.setMissionData, {}, timer.getTime() + 1) timer.scheduleFunction(Olympus.setMissionData, {}, timer.getTime() + 1)
-- Initialize the ME units -- Initialize the ME units

View File

@@ -115,7 +115,7 @@ extern "C" DllExport int coreUnitsData(lua_State * L)
return(0); return(0);
} }
extern "C" DllExport int coreWeaponssData(lua_State * L) extern "C" DllExport int coreWeaponsData(lua_State * L)
{ {
if (!initialized) if (!initialized)
return (0); return (0);

View File

@@ -72,7 +72,7 @@ void Unit::update(json::value json, double dt)
if (json.has_boolean_field(L"isAlive")) if (json.has_boolean_field(L"isAlive"))
setAlive(json[L"isAlive"].as_bool()); setAlive(json[L"isAlive"].as_bool());
if (json.has_object_field(L"isHuman")) if (json.has_boolean_field(L"isHuman"))
setHuman(json[L"isHuman"].as_bool()); setHuman(json[L"isHuman"].as_bool());
if (json.has_number_field(L"fuel")) { if (json.has_number_field(L"fuel")) {
@@ -109,7 +109,7 @@ void Unit::update(json::value json, double dt)
contactItem.ID = contactJson[L"object"][L"id_"].as_number().to_uint32(); contactItem.ID = contactJson[L"object"][L"id_"].as_number().to_uint32();
string detectionMethod = to_string(contactJson[L"detectionMethod"]); string detectionMethod = to_string(contactJson[L"detectionMethod"]);
if (detectionMethod.compare("VISUAL") == 0) contactItem.detectionMethod = 1; if (detectionMethod.compare("VISUAL") == 0) contactItem.detectionMethod = 1;
else if (detectionMethod.compare("OPTIC") == 0) contactItem.detectionMethod = 2; else if (detectionMethod.compare("OPTIC") == 0) contactItem.detectionMethod = 2;
else if (detectionMethod.compare("RADAR") == 0) contactItem.detectionMethod = 4; else if (detectionMethod.compare("RADAR") == 0) contactItem.detectionMethod = 4;
else if (detectionMethod.compare("IRST") == 0) contactItem.detectionMethod = 8; else if (detectionMethod.compare("IRST") == 0) contactItem.detectionMethod = 8;

View File

@@ -110,10 +110,6 @@ void UnitsManager::update(json::value& json, double dt)
units[ID] = dynamic_cast<Unit*>(new GroundUnit(p.second, ID)); units[ID] = dynamic_cast<Unit*>(new GroundUnit(p.second, ID));
else if (category.compare("NavyUnit") == 0) else if (category.compare("NavyUnit") == 0)
units[ID] = dynamic_cast<Unit*>(new NavyUnit(p.second, ID)); units[ID] = dynamic_cast<Unit*>(new NavyUnit(p.second, ID));
else if (category.compare("Missile") == 0)
units[ID] = dynamic_cast<Unit*>(new Missile(p.second, ID));
else if (category.compare("Bomb") == 0)
units[ID] = dynamic_cast<Unit*>(new Bomb(p.second, ID));
/* Initialize the unit if creation was successfull */ /* Initialize the unit if creation was successfull */
if (units.count(ID) != 0) { if (units.count(ID) != 0) {

View File

@@ -69,21 +69,21 @@ static int onSimulationStart(lua_State* L)
goto error; goto error;
} }
coreUnitsData = (f_coreFrame)GetProcAddress(hGetProcIDDLL, "coreUnitsData"); coreUnitsData = (f_coreUnitsData)GetProcAddress(hGetProcIDDLL, "coreUnitsData");
if (!coreUnitsData) if (!coreUnitsData)
{ {
LogError(L, "Error getting coreUnitsData ProcAddress from DLL"); LogError(L, "Error getting coreUnitsData ProcAddress from DLL");
goto error; goto error;
} }
coreWeaponsData = (f_coreFrame)GetProcAddress(hGetProcIDDLL, "coreWeaponsData"); coreWeaponsData = (f_coreWeaponsData)GetProcAddress(hGetProcIDDLL, "coreWeaponsData");
if (!coreWeaponsData) if (!coreWeaponsData)
{ {
LogError(L, "Error getting coreWeaponsData ProcAddress from DLL"); LogError(L, "Error getting coreWeaponsData ProcAddress from DLL");
goto error; goto error;
} }
coreMissionData = (f_coreFrame)GetProcAddress(hGetProcIDDLL, "coreMissionData"); coreMissionData = (f_coreMissionData)GetProcAddress(hGetProcIDDLL, "coreMissionData");
if (!coreMissionData) if (!coreMissionData)
{ {
LogError(L, "Error getting coreMissionData ProcAddress from DLL"); LogError(L, "Error getting coreMissionData ProcAddress from DLL");