Fix/cas mission (#40)

* fixes

* fixed and made weapons more random

---------

Co-authored-by: dutchie032 <dutchie032>
This commit is contained in:
2025-05-25 22:12:16 +02:00
committed by GitHub
co-authored by dutchie032 <dutchie032>
parent f61c7b5657
commit c2121d0e70
3 changed files with 69 additions and 18 deletions
Binary file not shown.
+32 -11
View File
@@ -659,11 +659,22 @@ function Database:loadMissionzoneUnits()
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
for _, groupName in pairs(groups) do
local group = Group.getByName(groupName)
if group and group:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif group and group:getCoalition() == coalition.side.BLUE then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
if Spearhead.DcsUtil.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName)
if object and object:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif object then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
else
local group = Group.getByName(groupName)
if group and group:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif group then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
end
is_group_taken[groupName] = true
end
@@ -680,13 +691,23 @@ function Database:loadRandomMissionzoneUnits()
}
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
for _, groupName in pairs(groups) do
local group = Group.getByName(groupName)
if group and group:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif group and group:getCoalition() == coalition.side.BLUE then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
if Spearhead.DcsUtil.IsGroupStatic(groupName) == true then
local object = StaticObject.getByName(groupName)
if object and object:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif object then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
else
local group = Group.getByName(groupName)
if group and group:getCoalition() == coalition.side.RED then
table.insert(self._tables.MissionZoneData[missionZoneName].RedGroups, groupName)
elseif group then
table.insert(self._tables.MissionZoneData[missionZoneName].BlueGroups, groupName)
end
end
is_group_taken[groupName] = true
end
end
+37 -7
View File
@@ -153,19 +153,14 @@ function BattleManager:LetUnitsShoot(groups, targetGroups)
local point = self:GetRandomPoint({x = unitPos.x, y = unitPos.z }, targetGroups)
if point then
local qty = 1
local ammo = unit:getAmmo()
if ammo and ammo[1] then
qty = math.ceil((ammo[1].count or 1) / 50)
end
local ammo, qty = self:getBestAmmo(unit)
local shootTask = {
id = "FireAtPoint",
params = {
point = point,
radius = 1,
expendQty = qty,
weaponType = ammo,
expendQtyEnabled = true,
counterbattaryRadius = math.random(5, 10)
}
@@ -182,6 +177,41 @@ function BattleManager:LetUnitsShoot(groups, targetGroups)
end
end
end
end
---@param unit Unit
---@return number
---@return number
function BattleManager:getBestAmmo(unit)
if unit:getName() == "Ground-32-1" then
env.info(Spearhead.Util.toString(unit:getAmmo()))
end
local ammo = unit:getAmmo()
if not ammo then return 3221225470, 1 end -- Default ammo if no ammo is found
local shells = {}
for _, entry in pairs(ammo) do
if entry.count and entry.count > 0 then
if entry.desc.category == Weapon.Category.SHELL then
table.insert(shells, entry)
end
end
end
local entry = Spearhead.Util.randomFromList(shells)
if entry.desc.warhead then
local caliber = entry.desc.warhead.caliber
if caliber > 50 then
return 258503344128, 1
else
return 258503344129, 25
end
end
return 3221225470, 1
end
---@private