updated airbase
This commit is contained in:
Binary file not shown.
@@ -116,6 +116,8 @@ function CapGroup:new(groupName, airbaseId, logger, database, capConfig)
|
|||||||
|
|
||||||
local RESPAWN_AFTER_TOUCHDOWN_SECONDS = 180
|
local RESPAWN_AFTER_TOUCHDOWN_SECONDS = 180
|
||||||
|
|
||||||
|
Spearhead.DcsUtil.DestroyGroup(groupName)
|
||||||
|
|
||||||
-- initials
|
-- initials
|
||||||
o.groupName = groupName
|
o.groupName = groupName
|
||||||
o.airbaseId = airbaseId
|
o.airbaseId = airbaseId
|
||||||
|
|||||||
@@ -53,4 +53,5 @@ function CapConfig:new()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not Spearhead.internal then Spearhead.internal = {} end
|
if not Spearhead.internal then Spearhead.internal = {} end
|
||||||
|
if not Spearhead.internal.configuration then Spearhead.internal.configuration = {} end
|
||||||
Spearhead.internal.configuration.CapConfig = CapConfig;
|
Spearhead.internal.configuration.CapConfig = CapConfig;
|
||||||
@@ -20,11 +20,12 @@ function StageConfig:new()
|
|||||||
o.isAutoStages = function(self) return autoStages end
|
o.isAutoStages = function(self) return autoStages end
|
||||||
|
|
||||||
local maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage
|
local maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage
|
||||||
o.getMaxMissionPerStage = function(self) return maxMissionsPerStage end
|
o.getMaxMissionsPerStage = function(self) return maxMissionsPerStage end
|
||||||
|
|
||||||
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO
|
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO
|
||||||
return o;
|
return o;
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Spearhead.internal then Spearhead.internal = {} end
|
if not Spearhead.internal then Spearhead.internal = {} end
|
||||||
|
if not Spearhead.internal.configuration then Spearhead.internal.configuration = {} end
|
||||||
Spearhead.internal.configuration.StageConfig = StageConfig;
|
Spearhead.internal.configuration.StageConfig = StageConfig;
|
||||||
+155
-858
File diff suppressed because it is too large
Load Diff
+126
-101
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
local SpearheadDB = {}
|
local SpearheadDB = {}
|
||||||
do -- DB
|
do -- DB
|
||||||
|
|
||||||
local singleton = nil
|
local singleton = nil
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param Logger table
|
---@param Logger table
|
||||||
---@return table
|
---@return table
|
||||||
function SpearheadDB:new(Logger)
|
function SpearheadDB:new(Logger, debug)
|
||||||
|
if not debug then debug = false end
|
||||||
if singleton ~= nil then
|
if singleton ~= nil then
|
||||||
Logger:info("Returning an already initiated instance of SpearheadDB")
|
Logger:info("Returning an already initiated instance of SpearheadDB")
|
||||||
return singleton
|
return singleton
|
||||||
@@ -21,7 +21,7 @@ do -- DB
|
|||||||
o.tables = {}
|
o.tables = {}
|
||||||
do --INIT ALL TABLES
|
do --INIT ALL TABLES
|
||||||
Logger:debug("Initiating tables")
|
Logger:debug("Initiating tables")
|
||||||
|
|
||||||
o.tables.all_zones = {}
|
o.tables.all_zones = {}
|
||||||
o.tables.stage_zones = {}
|
o.tables.stage_zones = {}
|
||||||
o.tables.mission_zones = {}
|
o.tables.mission_zones = {}
|
||||||
@@ -34,43 +34,41 @@ do -- DB
|
|||||||
o.tables.stage_numberPerzone = {}
|
o.tables.stage_numberPerzone = {}
|
||||||
|
|
||||||
do -- INIT ZONE TABLES
|
do -- INIT ZONE TABLES
|
||||||
if env.mission.triggers and env.mission.triggers.zones then
|
for zone_ind, zone_data in pairs(Spearhead.DcsUtil.__trigger_zones) do
|
||||||
for zone_ind, zone_data in pairs(env.mission.triggers.zones) do
|
local zone_name = zone_data.name
|
||||||
local zone_name = zone_data.name
|
local split_string = Spearhead.Util.split_string(zone_name, "_")
|
||||||
local split_string = Spearhead.Util.split_string(zone_name, "_")
|
table.insert(o.tables.all_zones, zone_name)
|
||||||
table.insert(o.tables.all_zones, zone_name)
|
|
||||||
|
|
||||||
if string.lower(split_string[1]) == "missionstage" then
|
if string.lower(split_string[1]) == "missionstage" then
|
||||||
table.insert(o.tables.stage_zones, zone_name)
|
table.insert(o.tables.stage_zones, zone_name)
|
||||||
if split_string[2] then
|
if split_string[2] then
|
||||||
local stringified = tostring(split_string[2]) or "unknown"
|
local stringified = tostring(split_string[2]) or "unknown"
|
||||||
if o.tables.stage_zonesByNumer[stringified] == nil then
|
if o.tables.stage_zonesByNumer[stringified] == nil then
|
||||||
o.tables.stage_zonesByNumer[stringified] = {}
|
o.tables.stage_zonesByNumer[stringified] = {}
|
||||||
end
|
|
||||||
table.insert(o.tables.stage_zonesByNumer[stringified], zone_name)
|
|
||||||
o.tables.stage_numberPerzone[zone_name] = stringified
|
|
||||||
end
|
end
|
||||||
|
table.insert(o.tables.stage_zonesByNumer[stringified], zone_name)
|
||||||
|
o.tables.stage_numberPerzone[zone_name] = stringified
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if string.lower(split_string[1]) == "mission" then
|
if string.lower(split_string[1]) == "mission" then
|
||||||
table.insert(o.tables.mission_zones, zone_name)
|
table.insert(o.tables.mission_zones, zone_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if string.lower(split_string[1]) == "randommission" then
|
if string.lower(split_string[1]) == "randommission" then
|
||||||
table.insert(o.tables.random_mission_zones, zone_name)
|
table.insert(o.tables.random_mission_zones, zone_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if string.lower(split_string[1]) == "farp" then
|
if string.lower(split_string[1]) == "farp" then
|
||||||
table.insert(o.tables.farp_zones, zone_name)
|
table.insert(o.tables.farp_zones, zone_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if string.lower(split_string[1]) == "caproute" then
|
if string.lower(split_string[1]) == "caproute" then
|
||||||
table.insert(o.tables.cap_route_zones, zone_name)
|
table.insert(o.tables.cap_route_zones, zone_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if string.lower(split_string[1]) == "carrierroute" then
|
if string.lower(split_string[1]) == "carrierroute" then
|
||||||
table.insert(o.tables.carrier_route_zones, zone_name)
|
table.insert(o.tables.carrier_route_zones, zone_name)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -82,7 +80,8 @@ do -- DB
|
|||||||
for i, layer in pairs(env.mission.drawings.layers) do
|
for i, layer in pairs(env.mission.drawings.layers) do
|
||||||
if string.lower(layer.name) == "author" then
|
if string.lower(layer.name) == "author" then
|
||||||
for key, layer_object in pairs(layer.objects) do
|
for key, layer_object in pairs(layer.objects) do
|
||||||
local inZone = Spearhead.DcsUtil.isPositionInZones(layer_object.mapX, layer_object.mapY, o.tables.mission_zones)
|
local inZone = Spearhead.DcsUtil.isPositionInZones(layer_object.mapX, layer_object.mapY,
|
||||||
|
o.tables.mission_zones)
|
||||||
if Spearhead.Util.tableLength(inZone) >= 1 then
|
if Spearhead.Util.tableLength(inZone) >= 1 then
|
||||||
local name = inZone[1]
|
local name = inZone[1]
|
||||||
if name ~= nil then
|
if name ~= nil then
|
||||||
@@ -90,7 +89,8 @@ do -- DB
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local inZone = Spearhead.DcsUtil.isPositionInZones(layer_object.mapX, layer_object.mapY, o.tables.random_mission_zones)
|
local inZone = Spearhead.DcsUtil.isPositionInZones(layer_object.mapX, layer_object.mapY,
|
||||||
|
o.tables.random_mission_zones)
|
||||||
if Spearhead.Util.tableLength(inZone) >= 1 then
|
if Spearhead.Util.tableLength(inZone) >= 1 then
|
||||||
local name = inZone[1]
|
local name = inZone[1]
|
||||||
if name ~= nil then
|
if name ~= nil then
|
||||||
@@ -151,7 +151,7 @@ do -- DB
|
|||||||
isAirbaseInZone[baseIdString] = true
|
isAirbaseInZone[baseIdString] = true
|
||||||
|
|
||||||
if airbase:getDesc().category == 0 then
|
if airbase:getDesc().category == 0 then
|
||||||
--Airbase
|
--Airbase
|
||||||
if Spearhead.DcsUtil.getStartingCoalition(baseId) == 2 then
|
if Spearhead.DcsUtil.getStartingCoalition(baseId) == 2 then
|
||||||
airbase:setCoalition(1)
|
airbase:setCoalition(1)
|
||||||
airbase:autoCapture(false)
|
airbase:autoCapture(false)
|
||||||
@@ -179,19 +179,19 @@ do -- DB
|
|||||||
airbase:autoCapture(false)
|
airbase:autoCapture(false)
|
||||||
table.insert(o.tables.farpIdsInFarpZones[farpZoneName], baseIdString)
|
table.insert(o.tables.farpIdsInFarpZones[farpZoneName], baseIdString)
|
||||||
end
|
end
|
||||||
i = i +1
|
i = i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
o.tables.farpZonesPerStage = {}
|
o.tables.farpZonesPerStage = {}
|
||||||
for _, farpZoneName in pairs(o.tables.farp_zones) do
|
for _, farpZoneName in pairs(o.tables.farp_zones) do
|
||||||
local findFirst = function (farpZoneName)
|
local findFirst = function(farpZoneName)
|
||||||
for _, stage_zone in pairs(o.tables.stage_zones) do
|
for _, stage_zone in pairs(o.tables.stage_zones) do
|
||||||
if Spearhead.DcsUtil.isZoneInZone(farpZoneName, stage_zone) then
|
if Spearhead.DcsUtil.isZoneInZone(farpZoneName, stage_zone) then
|
||||||
return stage_zone
|
return stage_zone
|
||||||
@@ -202,7 +202,6 @@ do -- DB
|
|||||||
|
|
||||||
local found = findFirst(farpZoneName)
|
local found = findFirst(farpZoneName)
|
||||||
if found then
|
if found then
|
||||||
|
|
||||||
if o.tables.farpZonesPerStage[found] == nil then
|
if o.tables.farpZonesPerStage[found] == nil then
|
||||||
o.tables.farpZonesPerStage[found] = {}
|
o.tables.farpZonesPerStage[found] = {}
|
||||||
end
|
end
|
||||||
@@ -248,10 +247,10 @@ do -- DB
|
|||||||
for _, airbase in pairs(airbases) do
|
for _, airbase in pairs(airbases) do
|
||||||
local baseId = airbase:getID()
|
local baseId = airbase:getID()
|
||||||
local point = airbase:getPoint()
|
local point = airbase:getPoint()
|
||||||
|
local zone = Spearhead.DcsUtil.getAirbaseZoneById(baseId) or
|
||||||
|
{ x = point.x, z = point.z, radius = 4000 }
|
||||||
o.tables.capGroupsOnAirbase[baseId] = {}
|
o.tables.capGroupsOnAirbase[baseId] = {}
|
||||||
local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups,
|
local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups, zone)
|
||||||
{ x = point.x, z = point.z, radius = 2048 })
|
|
||||||
for _, groupName in pairs(groups) do
|
for _, groupName in pairs(groups) do
|
||||||
is_group_taken[groupName] = true
|
is_group_taken[groupName] = true
|
||||||
table.insert(o.tables.capGroupsOnAirbase[baseId], groupName)
|
table.insert(o.tables.capGroupsOnAirbase[baseId], groupName)
|
||||||
@@ -273,19 +272,19 @@ do -- DB
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- missionZoneName <> groupname[]
|
--- missionZoneName <> groupname[]
|
||||||
o.tables.groupsInRandomMissions = {}
|
o.tables.groupsInRandomMissions = {}
|
||||||
local loadRandomMissionzoneUnits = function()
|
local loadRandomMissionzoneUnits = function()
|
||||||
local all_groups = getAvailableGroups()
|
local all_groups = getAvailableGroups()
|
||||||
for _, missionZoneName in pairs(o.tables.random_mission_zones) do
|
for _, missionZoneName in pairs(o.tables.random_mission_zones) do
|
||||||
o.tables.groupsInRandomMissions[missionZoneName] = {}
|
o.tables.groupsInRandomMissions[missionZoneName] = {}
|
||||||
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
|
local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, missionZoneName)
|
||||||
for _, groupName in pairs(groups) do
|
for _, groupName in pairs(groups) do
|
||||||
is_group_taken[groupName] = true
|
is_group_taken[groupName] = true
|
||||||
table.insert(o.tables.groupsInRandomMissions[missionZoneName], groupName)
|
table.insert(o.tables.groupsInRandomMissions[missionZoneName], groupName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- farpZoneName <> groupname[]
|
--- farpZoneName <> groupname[]
|
||||||
o.tables.groupsInFarpZone = {}
|
o.tables.groupsInFarpZone = {}
|
||||||
@@ -310,13 +309,37 @@ do -- DB
|
|||||||
for _, airbase in pairs(airbases) do
|
for _, airbase in pairs(airbases) do
|
||||||
local baseId = tostring(airbase:getID())
|
local baseId = tostring(airbase:getID())
|
||||||
local point = airbase:getPoint()
|
local point = airbase:getPoint()
|
||||||
|
local airbaseZone = Spearhead.DcsUtil.getAirbaseZoneById(baseId) or
|
||||||
|
{ x = point.x, z = point.z, radius = 4000 }
|
||||||
|
|
||||||
|
if isAirbaseInZone[tostring(baseId) or "something"] == true and airbaseZone and airbase:getDesc().category == Airbase.Category.AIRDROME then
|
||||||
|
if debug then
|
||||||
|
if airbaseZone.zone_type == Spearhead.DcsUtil.ZoneType.Polygon then
|
||||||
|
local functionString = "trigger.action.markupToAll(7, -1, " .. baseId + 300 .. ","
|
||||||
|
for _, vecpoint in pairs(airbaseZone.verts) do
|
||||||
|
functionString = functionString .. " { x=" .. vecpoint.x .. ", y=0,z=" .. vecpoint.z ..
|
||||||
|
"},"
|
||||||
|
end
|
||||||
|
functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, 1)"
|
||||||
|
|
||||||
|
env.info(functionString)
|
||||||
|
local f, err = loadstring(functionString)
|
||||||
|
if f then
|
||||||
|
f()
|
||||||
|
else
|
||||||
|
env.info(err)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
trigger.action.circleToAll(-1, baseId, { x = point.x, y = 0, z = point.z }, 2048,
|
||||||
|
{ 1, 0, 0, 1 }, { 1, 0, 0, 0 }, 1, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
if isAirbaseInZone[tostring(baseId) or "something" ] == true and airbase:getDesc().category == Airbase.Category.AIRDROME then
|
|
||||||
o.tables.redAirbaseGroupsPerAirbase[baseId] = {}
|
o.tables.redAirbaseGroupsPerAirbase[baseId] = {}
|
||||||
o.tables.blueAirbaseGroupsPerAirbase[baseId] = {}
|
o.tables.blueAirbaseGroupsPerAirbase[baseId] = {}
|
||||||
local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups, { x = point.x, z = point.z, radius = 2048 })
|
local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups, airbaseZone)
|
||||||
for _, groupName in pairs(groups) do
|
for _, groupName in pairs(groups) do
|
||||||
|
|
||||||
if Spearhead.DcsUtil.IsGroupStatic(groupName) == true then
|
if Spearhead.DcsUtil.IsGroupStatic(groupName) == true then
|
||||||
local object = StaticObject.getByName(groupName)
|
local object = StaticObject.getByName(groupName)
|
||||||
if object then
|
if object then
|
||||||
@@ -346,7 +369,7 @@ do -- DB
|
|||||||
end
|
end
|
||||||
|
|
||||||
o.tables.miscGroupsInStages = {}
|
o.tables.miscGroupsInStages = {}
|
||||||
local loadMiscGroupsInStages = function ()
|
local loadMiscGroupsInStages = function()
|
||||||
local all_groups = getAvailableGroups()
|
local all_groups = getAvailableGroups()
|
||||||
for _, stage_zone in pairs(o.tables.stage_zones) do
|
for _, stage_zone in pairs(o.tables.stage_zones) do
|
||||||
o.tables.miscGroupsInStages[stage_zone] = {}
|
o.tables.miscGroupsInStages[stage_zone] = {}
|
||||||
@@ -376,8 +399,8 @@ do -- DB
|
|||||||
loadAirbaseGroups()
|
loadAirbaseGroups()
|
||||||
loadMiscGroupsInStages()
|
loadMiscGroupsInStages()
|
||||||
|
|
||||||
-- local cleanup = function () --CLean up all groups that are now managed inside zones by spearhead
|
-- local cleanup = function () --CLean up all groups that are now managed inside zones by spearhead
|
||||||
|
|
||||||
-- local count = 0
|
-- local count = 0
|
||||||
-- for name, taken in pairs(is_group_taken) do
|
-- for name, taken in pairs(is_group_taken) do
|
||||||
-- if taken == true then
|
-- if taken == true then
|
||||||
@@ -406,7 +429,8 @@ do -- DB
|
|||||||
local zone = Spearhead.DcsUtil.getZoneByName(cap_route_zone)
|
local zone = Spearhead.DcsUtil.getZoneByName(cap_route_zone)
|
||||||
if zone then
|
if zone then
|
||||||
if zone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
if zone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
||||||
table.insert(o.tables.capRoutesPerStageNumber[number].routes, { point1 = { x = zone.x , z = zone.z }, point2 = nil } )
|
table.insert(o.tables.capRoutesPerStageNumber[number].routes,
|
||||||
|
{ point1 = { x = zone.x, z = zone.z }, point2 = nil })
|
||||||
else
|
else
|
||||||
local function getDist(a, b)
|
local function getDist(a, b)
|
||||||
return math.sqrt((b.x - a.x) ^ 2 + (b.z - a.z) ^ 2)
|
return math.sqrt((b.x - a.x) ^ 2 + (b.z - a.z) ^ 2)
|
||||||
@@ -416,12 +440,11 @@ do -- DB
|
|||||||
local biggestA = nil
|
local biggestA = nil
|
||||||
local biggestB = nil
|
local biggestB = nil
|
||||||
|
|
||||||
for i=1, 3 do
|
for i = 1, 3 do
|
||||||
for ii = i + 1, 4 do
|
for ii = i + 1, 4 do
|
||||||
|
|
||||||
local a = zone.verts[i]
|
local a = zone.verts[i]
|
||||||
local b = zone.verts[ii]
|
local b = zone.verts[ii]
|
||||||
local dist = getDist(a,b)
|
local dist = getDist(a, b)
|
||||||
|
|
||||||
if biggest == nil or dist > biggest then
|
if biggest == nil or dist > biggest then
|
||||||
biggestA = a
|
biggestA = a
|
||||||
@@ -432,11 +455,11 @@ do -- DB
|
|||||||
end
|
end
|
||||||
|
|
||||||
if biggestA and biggestB then
|
if biggestA and biggestB then
|
||||||
table.insert(o.tables.capRoutesPerStageNumber[number].routes,
|
table.insert(o.tables.capRoutesPerStageNumber[number].routes,
|
||||||
{
|
{
|
||||||
point1 = { x = biggestA.x , z = biggestA.z },
|
point1 = { x = biggestA.x, z = biggestA.z },
|
||||||
point2 = { x = biggestB.x , z = biggestB.z }
|
point2 = { x = biggestB.x, z = biggestB.z }
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -445,7 +468,7 @@ do -- DB
|
|||||||
end
|
end
|
||||||
|
|
||||||
o.Logger:debug(o.tables.capRoutesPerStageNumber)
|
o.Logger:debug(o.tables.capRoutesPerStageNumber)
|
||||||
|
|
||||||
o.tables.missionCodes = {}
|
o.tables.missionCodes = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -456,7 +479,7 @@ do -- DB
|
|||||||
o.getCapRouteInZone = function(self, stageNumber, baseId)
|
o.getCapRouteInZone = function(self, stageNumber, baseId)
|
||||||
local stageNumber = tostring(stageNumber) or "nothing"
|
local stageNumber = tostring(stageNumber) or "nothing"
|
||||||
local routeData = self.tables.capRoutesPerStageNumber[stageNumber]
|
local routeData = self.tables.capRoutesPerStageNumber[stageNumber]
|
||||||
if routeData then
|
if routeData then
|
||||||
local count = Spearhead.Util.tableLength(routeData.routes)
|
local count = Spearhead.Util.tableLength(routeData.routes)
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
routeData.current = routeData.current + 1
|
routeData.current = routeData.current + 1
|
||||||
@@ -470,49 +493,50 @@ do -- DB
|
|||||||
local function GetClosestPointOnCircle(pC, radius, p)
|
local function GetClosestPointOnCircle(pC, radius, p)
|
||||||
local vX = p.x - pC.x;
|
local vX = p.x - pC.x;
|
||||||
local vY = p.z - pC.z;
|
local vY = p.z - pC.z;
|
||||||
local magV = math.sqrt(vX*vX + vY*vY);
|
local magV = math.sqrt(vX * vX + vY * vY);
|
||||||
local aX = pC.x + vX / magV * radius;
|
local aX = pC.x + vX / magV * radius;
|
||||||
local aY = pC.z + vY / magV * radius;
|
local aY = pC.z + vY / magV * radius;
|
||||||
return { x = aX, z = aY }
|
return { x = aX, z = aY }
|
||||||
end
|
end
|
||||||
local stageZoneName = Spearhead.Util.randomFromList(self.tables.stage_zonesByNumer[stageNumber]) or "none"
|
local stageZoneName = Spearhead.Util.randomFromList(self.tables.stage_zonesByNumer[stageNumber]) or
|
||||||
|
"none"
|
||||||
local stagezone = Spearhead.DcsUtil.getZoneByName(stageZoneName)
|
local stagezone = Spearhead.DcsUtil.getZoneByName(stageZoneName)
|
||||||
if stagezone then
|
if stagezone then
|
||||||
local base = Spearhead.DcsUtil.getAirbaseById(baseId)
|
local base = Spearhead.DcsUtil.getAirbaseById(baseId)
|
||||||
if base then
|
if base then
|
||||||
local closest = nil
|
local closest = nil
|
||||||
if stagezone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
if stagezone.zone_type == Spearhead.DcsUtil.ZoneType.Cilinder then
|
||||||
closest = GetClosestPointOnCircle({x = stagezone.x, z = stagezone.z}, stagezone.radius, base:getPoint())
|
closest = GetClosestPointOnCircle({ x = stagezone.x, z = stagezone.z }, stagezone.radius,
|
||||||
|
base:getPoint())
|
||||||
else
|
else
|
||||||
local function getDist(a, b)
|
local function getDist(a, b)
|
||||||
return math.sqrt((b.x - a.x) ^ 2 + (b.z - a.z) ^ 2)
|
return math.sqrt((b.x - a.x) ^ 2 + (b.z - a.z) ^ 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local closestDistance = -1
|
local closestDistance = -1
|
||||||
for _, vert in pairs(stagezone.verts) do
|
for _, vert in pairs(stagezone.verts) do
|
||||||
local distance = getDist(vert, base:getPoint())
|
local distance = getDist(vert, base:getPoint())
|
||||||
if closestDistance == -1 or distance < closestDistance then
|
if closestDistance == -1 or distance < closestDistance then
|
||||||
closestDistance = distance
|
closestDistance = distance
|
||||||
closest = vert
|
closest = vert
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if math.random(1,2)%2 == 0 then
|
if math.random(1, 2) % 2 == 0 then
|
||||||
return { point1 = closest, point2 = {x = stagezone.x, z = stagezone.z} }
|
return { point1 = closest, point2 = { x = stagezone.x, z = stagezone.z } }
|
||||||
else
|
else
|
||||||
return { point1 = {x = stagezone.x, z = stagezone.z}, point2 = closest }
|
return { point1 = { x = stagezone.x, z = stagezone.z }, point2 = closest }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
---comment
|
---comment
|
||||||
---@param self table
|
---@param self table
|
||||||
---@param number number
|
---@param number number
|
||||||
---@return string zoneName
|
---@return string zoneName
|
||||||
o.getStageZonesByStageNumber = function (self, number)
|
o.getStageZonesByStageNumber = function(self, number)
|
||||||
local numberString = tostring(number)
|
local numberString = tostring(number)
|
||||||
return self.tables.stage_zonesByNumer[numberString]
|
return self.tables.stage_zonesByNumer[numberString]
|
||||||
end
|
end
|
||||||
@@ -520,15 +544,15 @@ do -- DB
|
|||||||
---comment
|
---comment
|
||||||
---@param self table
|
---@param self table
|
||||||
---@return table result a list of stage zone names
|
---@return table result a list of stage zone names
|
||||||
o.getStagezoneNames = function (self)
|
o.getStagezoneNames = function(self)
|
||||||
return self.tables.stage_zones
|
return self.tables.stage_zones
|
||||||
end
|
end
|
||||||
|
|
||||||
o.getCarrierRouteZones = function (self)
|
o.getCarrierRouteZones = function(self)
|
||||||
return self.tables.carrier_route_zones
|
return self.tables.carrier_route_zones
|
||||||
end
|
end
|
||||||
|
|
||||||
o.getMissionsForStage = function (self, stagename)
|
o.getMissionsForStage = function(self, stagename)
|
||||||
return self.tables.missionZonesPerStage[stagename] or {}
|
return self.tables.missionZonesPerStage[stagename] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -536,14 +560,14 @@ do -- DB
|
|||||||
return self.tables.randomMissionZonesPerStage[stagename] or {}
|
return self.tables.randomMissionZonesPerStage[stagename] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
o.getGroupsForMissionZone = function (self, missionZoneName)
|
o.getGroupsForMissionZone = function(self, missionZoneName)
|
||||||
if Spearhead.Util.startswith(missionZoneName, "RANDOMMISSION") == true then
|
if Spearhead.Util.startswith(missionZoneName, "RANDOMMISSION") == true then
|
||||||
return self.tables.groupsInRandomMissions[missionZoneName] or {}
|
return self.tables.groupsInRandomMissions[missionZoneName] or {}
|
||||||
end
|
end
|
||||||
return self.tables.groupsInMissionZone[missionZoneName] or {}
|
return self.tables.groupsInMissionZone[missionZoneName] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
o.getMissionBriefingForMissionZone = function (self, missionZoneName)
|
o.getMissionBriefingForMissionZone = function(self, missionZoneName)
|
||||||
return self.tables.descriptions[missionZoneName] or ""
|
return self.tables.descriptions[missionZoneName] or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -551,11 +575,11 @@ do -- DB
|
|||||||
---@param self table
|
---@param self table
|
||||||
---@param stageName string
|
---@param stageName string
|
||||||
---@return table result airbase IDs. Use Spearhead.DcsUtil.getAirbaseById
|
---@return table result airbase IDs. Use Spearhead.DcsUtil.getAirbaseById
|
||||||
o.getAirbaseIdsInStage = function (self, stageName)
|
o.getAirbaseIdsInStage = function(self, stageName)
|
||||||
return self.tables.airbasesPerStage[stageName] or {}
|
return self.tables.airbasesPerStage[stageName] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
o.getFarpZonesInStage = function (self, stageName)
|
o.getFarpZonesInStage = function(self, stageName)
|
||||||
return self.tables.farpZonesPerStage[stageName]
|
return self.tables.farpZonesPerStage[stageName]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -566,13 +590,13 @@ do -- DB
|
|||||||
o.getCapGroupsAtAirbase = function(self, airbaseId)
|
o.getCapGroupsAtAirbase = function(self, airbaseId)
|
||||||
return self.tables.capGroupsOnAirbase[airbaseId] or {}
|
return self.tables.capGroupsOnAirbase[airbaseId] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
o.getRedGroupsAtAirbase = function (self, airbaseId)
|
o.getRedGroupsAtAirbase = function(self, airbaseId)
|
||||||
local baseId = tostring(airbaseId)
|
local baseId = tostring(airbaseId)
|
||||||
return self.tables.redAirbaseGroupsPerAirbase[baseId] or {}
|
return self.tables.redAirbaseGroupsPerAirbase[baseId] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
o.getBlueGroupsAtAirbase = function (self, airbaseId)
|
o.getBlueGroupsAtAirbase = function(self, airbaseId)
|
||||||
local baseId = tostring(airbaseId)
|
local baseId = tostring(airbaseId)
|
||||||
return self.tables.blueAirbaseGroupsPerAirbase[baseId] or {}
|
return self.tables.blueAirbaseGroupsPerAirbase[baseId] or {}
|
||||||
end
|
end
|
||||||
@@ -581,7 +605,7 @@ do -- DB
|
|||||||
return self.tables.miscGroupsInStages[stageName] or {}
|
return self.tables.miscGroupsInStages[stageName] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
o.GetNewMissionCode = function (self)
|
o.GetNewMissionCode = function(self)
|
||||||
local code = nil
|
local code = nil
|
||||||
local tries = 0
|
local tries = 0
|
||||||
while code == nil and tries < 10 do
|
while code == nil and tries < 10 do
|
||||||
@@ -610,16 +634,17 @@ do -- DB
|
|||||||
|
|
||||||
for _, missionZone in pairs(o.tables.mission_zones) do
|
for _, missionZone in pairs(o.tables.mission_zones) do
|
||||||
if o.tables.descriptions[missionZone] == nil then
|
if o.tables.descriptions[missionZone] == nil then
|
||||||
Spearhead.AddMissionEditorWarning("Mission with zonename: " .. missionZone .. " does not have a briefing")
|
Spearhead.AddMissionEditorWarning("Mission with zonename: " ..
|
||||||
|
missionZone .. " does not have a briefing")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, randomMission in pairs(o.tables.random_mission_zones) do
|
for _, randomMission in pairs(o.tables.random_mission_zones) do
|
||||||
if o.tables.descriptions[randomMission] == nil then
|
if o.tables.descriptions[randomMission] == nil then
|
||||||
Spearhead.AddMissionEditorWarning("Mission with zonename: " .. randomMission .. " does not have a briefing")
|
Spearhead.AddMissionEditorWarning("Mission with zonename: " ..
|
||||||
|
randomMission .. " does not have a briefing")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
singleton = o
|
singleton = o
|
||||||
return o
|
return o
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ GlobalStageManager.start = function (database, stageConfig)
|
|||||||
for _, stageName in pairs(database:getStagezoneNames()) do
|
for _, stageName in pairs(database:getStagezoneNames()) do
|
||||||
|
|
||||||
local logger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
local logger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
||||||
local stage = Spearhead.internal.Stage:new(stageName, database, logger)
|
local stage = Spearhead.internal.Stage:new(stageName, database, logger, stageConfig)
|
||||||
|
|
||||||
StagesByName[stageName] = stage
|
StagesByName[stageName] = stage
|
||||||
|
|
||||||
|
|||||||
@@ -353,6 +353,7 @@ do -- INIT Mission Class
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Spearhead.DcsUtil.DestroyGroup(group_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if Spearhead.Util.tableLength(self.targetAliveStates) > 0 then
|
if Spearhead.Util.tableLength(self.targetAliveStates) > 0 then
|
||||||
|
|||||||
@@ -94,14 +94,21 @@ do --init STAGE DIRECTOR
|
|||||||
|
|
||||||
for _, groupName in pairs(database:getRedGroupsAtAirbase(airbaseId)) do
|
for _, groupName in pairs(database:getRedGroupsAtAirbase(airbaseId)) do
|
||||||
table.insert(o.db.redAirbasegroups, groupName)
|
table.insert(o.db.redAirbasegroups, groupName)
|
||||||
|
Spearhead.DcsUtil.DestroyGroup(groupName)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, groupName in pairs(database:getBlueGroupsAtAirbase(airbaseId)) do
|
for _, groupName in pairs(database:getBlueGroupsAtAirbase(airbaseId)) do
|
||||||
table.insert(o.db.blueAirbasegroups, groupName)
|
table.insert(o.db.blueAirbasegroups, groupName)
|
||||||
|
Spearhead.DcsUtil.DestroyGroup(groupName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local miscGroups = database:getMiscGroupsAtStage(o.zoneName)
|
||||||
|
for _, groupName in pairs(miscGroups) do
|
||||||
|
Spearhead.DcsUtil.DestroyGroup(groupName)
|
||||||
|
end
|
||||||
|
|
||||||
local farps = database:getFarpZonesInStage(o.zoneName)
|
local farps = database:getFarpZonesInStage(o.zoneName)
|
||||||
if farps ~= nil and type(farps) == "table" then o.db.farps = farps end
|
if farps ~= nil and type(farps) == "table" then o.db.farps = farps end
|
||||||
end
|
end
|
||||||
@@ -178,7 +185,7 @@ do --init STAGE DIRECTOR
|
|||||||
trigger.action.circleToAll(-1, self.stageDrawingId, {x = zone.x, y = 0 , z = zone.z}, zone.radius, {0,0,0,0}, {0,0,0,0},4, true)
|
trigger.action.circleToAll(-1, self.stageDrawingId, {x = zone.x, y = 0 , z = zone.z}, zone.radius, {0,0,0,0}, {0,0,0,0},4, true)
|
||||||
else
|
else
|
||||||
--trigger.action.circleToAll(-1, self.stageDrawingId, {x = zone.x, y = 0 , z = zone.z}, zone.radius, { 1, 0,0, 1 }, {1,0,0,1},4, true)
|
--trigger.action.circleToAll(-1, self.stageDrawingId, {x = zone.x, y = 0 , z = zone.z}, zone.radius, { 1, 0,0, 1 }, {1,0,0,1},4, true)
|
||||||
trigger.action.quadToAll( -1, self.stageDrawingId, zone.verts[2], zone.verts[1], zone.verts[4], zone.verts[3], {0,0,0,0}, {0,0,0,0}, 4, true)
|
trigger.action.quadToAll( -1, self.stageDrawingId, zone.verts[1], zone.verts[2], zone.verts[3], zone.verts[4], {0,0,0,0}, {0,0,0,0}, 4, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
trigger.action.setMarkupColorFill(self.stageDrawingId, fillColor)
|
trigger.action.setMarkupColorFill(self.stageDrawingId, fillColor)
|
||||||
@@ -222,7 +229,7 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local max = self.stageConfig:getMaxMissionPerStage() or 10
|
local max = self.stageConfig:getMaxMissionsPerStage() or 10
|
||||||
|
|
||||||
local availableMissionsCount = Spearhead.Util.tableLength(availableMissions)
|
local availableMissionsCount = Spearhead.Util.tableLength(availableMissions)
|
||||||
if activeCount < max and availableMissionsCount > 0 then
|
if activeCount < max and availableMissionsCount > 0 then
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
|
|
||||||
|
--Single player purpose
|
||||||
|
|
||||||
|
local debug = false
|
||||||
|
local id = net.get_my_player_id()
|
||||||
|
if id == 0 then
|
||||||
|
debug = true
|
||||||
|
end
|
||||||
|
|
||||||
local dbLogger = Spearhead.LoggerTemplate:new("database", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
local dbLogger = Spearhead.LoggerTemplate:new("database", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
||||||
local databaseManager = Spearhead.DB:new(dbLogger)
|
local databaseManager = Spearhead.DB:new(dbLogger, debug)
|
||||||
|
|
||||||
local capConfig = Spearhead.internal.configuration.CapConfig:new();
|
local capConfig = Spearhead.internal.configuration.CapConfig:new();
|
||||||
local stageConfig = Spearhead.internal.configuration.StageConfig:new();
|
local stageConfig = Spearhead.internal.configuration.StageConfig:new();
|
||||||
@@ -21,3 +29,25 @@ Spearhead.LoadingDone()
|
|||||||
-- Get-ChildItem . -Include *.lua -Recurse | foreach {""+(Get-Content $_).Count + " => " + $_.name }; && GCI . -Include *.lua* -Recurse | foreach{(GC $_).Count} | measure-object -sum | % Sum
|
-- Get-ChildItem . -Include *.lua -Recurse | foreach {""+(Get-Content $_).Count + " => " + $_.name }; && GCI . -Include *.lua* -Recurse | foreach{(GC $_).Count} | measure-object -sum | % Sum
|
||||||
-- find . -name '*.lua' | xargs wc -l
|
-- find . -name '*.lua' | xargs wc -l
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- ==================== DEBUG ORDER OR ZONE VEC ===========================
|
||||||
|
-- local zone = Spearhead.DcsUtil.getZoneByName("MISSIONSTAGE_99")
|
||||||
|
|
||||||
|
-- local count = Spearhead.Util.tableLength(zone.verts)
|
||||||
|
|
||||||
|
-- for i = 1, count - 1 do
|
||||||
|
|
||||||
|
-- local a = zone.verts[i]
|
||||||
|
-- local b = zone.verts[i+1]
|
||||||
|
|
||||||
|
-- local color = {0,0,0,1}
|
||||||
|
|
||||||
|
-- color[i] = 1
|
||||||
|
|
||||||
|
-- trigger.action.textToAll(-1, 46+i , { x= a.x, y = 0, z = a.z } , color, {0,0,0}, 24 , true , "" .. i )
|
||||||
|
-- trigger.action.lineToAll(-1 , 56+i , { x= a.x, y = 0, z = a.z } , { x = b.x, y = 0, z = b.z } , color , 1, true)
|
||||||
|
|
||||||
|
-- end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user