diff --git a/SPEARHEADDEV.miz b/SPEARHEADDEV.miz deleted file mode 100644 index 0d09e53..0000000 Binary files a/SPEARHEADDEV.miz and /dev/null differ diff --git a/SPEARHEADDEV.zip b/SPEARHEADDEV.zip deleted file mode 100644 index a0f304f..0000000 Binary files a/SPEARHEADDEV.zip and /dev/null differ diff --git a/_miz/SPEARHEADDEV copy.miz b/_miz/SPEARHEADDEV copy.miz new file mode 100644 index 0000000..ea775f6 Binary files /dev/null and b/_miz/SPEARHEADDEV copy.miz differ diff --git a/_miz/SPEARHEADDEV.miz b/_miz/SPEARHEADDEV.miz new file mode 100644 index 0000000..ea775f6 Binary files /dev/null and b/_miz/SPEARHEADDEV.miz differ diff --git a/spearhead_base.lua b/spearhead_base.lua index c70ce18..c21759b 100644 --- a/spearhead_base.lua +++ b/spearhead_base.lua @@ -1491,6 +1491,47 @@ do end end + do --COMMANDS + do -- status updates + + local onStatusRequestReceivedListeners = {} + + ---comment + ---@param listener table object with OnStatusRequestReceived(self, groupId) + SpearheadEvents.AddOnStatusRequestReceivedListener = function(listener) + if type(listener) ~= "table" then + SpearheadLogger:warn("Unit lost Event listener not of type table/object") + return + end + + table.insert(onStatusRequestReceivedListeners, listener) + end + + local triggerStatusRequestReceived = function (groupId) + for _, callable in pairs(onStatusRequestReceivedListeners) do + local succ, err = pcall(function () + callable:OnStatusRequestReceived(groupId) + end) + end + end + + SpearheadEvents.AddCommandsToGroup = function(groupId) + + local base = "MISSIONS" + if groupId then + missionCommands.addCommandForGroup(groupId, "Stage Status", {}, triggerStatusRequestReceived, groupId) + end + end + + --Single player purpose + for i = 1, 2 do + for _, unit in pairs(coalition.getPlayers(i)) do + local groupId = unit:getGroup():getID() + SpearheadEvents.AddCommandsToGroup(groupId) + end + end + end + end local e = {} function e:onEvent(event) @@ -1529,6 +1570,12 @@ do end end end + + if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then + env.info("blaat player entering unit") + local groupId = event.initiator:getGroup():getID() + SpearheadEvents.AddCommandsToGroup(groupId) + end end world.addEventHandler(e) diff --git a/spearhead_db.lua b/spearhead_db.lua index 91923d3..6cd86f5 100644 --- a/spearhead_db.lua +++ b/spearhead_db.lua @@ -298,7 +298,7 @@ do -- DB local baseId = tostring(airbase:getID()) local point = airbase:getPoint() - if isAirbaseInZone[tostring(baseId) or "something" ] == true then + if isAirbaseInZone[tostring(baseId) or "something" ] == true and airbase:getDesc().Category == Airbase.Category.AIRDROME then o.tables.redAirbaseGroupsPerAirbase[baseId] = {} o.tables.blueAirbaseGroupsPerAirbase[baseId] = {} local groups = Spearhead.DcsUtil.areGroupsInCustomZone(all_groups, { x = point.x, z = point.z, radius = 6600 }) @@ -309,8 +309,10 @@ do -- DB if object then if object:getCoalition() == coalition.side.RED then table.insert(o.tables.redAirbaseGroupsPerAirbase[baseId], groupName) + is_group_taken[groupName] = true elseif object:getCoalition() == coalition.side.BLUE then table.insert(o.tables.blueAirbaseGroupsPerAirbase[baseId], groupName) + is_group_taken[groupName] = true end end else @@ -330,25 +332,24 @@ do -- DB end end - o.tables.miscGroupsInStage = {} - local loadMiscGroupsInStage = function () + o.tables.miscGroupsInStages = {} + local loadMiscGroupsInStages = function () local all_groups = getAvailableGroups() for _, stage_zone in pairs(o.tables.stage_zones) do - o.tables.miscGroupsInStage[stage_zone] = {} + o.tables.miscGroupsInStages[stage_zone] = {} local groups = Spearhead.DcsUtil.getGroupsInZone(all_groups, stage_zone) for _, groupName in pairs(groups) do - if Spearhead.DcsUtil.IsGroupStatic(groupName) == true then local object = StaticObject.getByName(groupName) if object and object:getCoalition() ~= coalition.side.NEUTRAL then is_group_taken[groupName] = true - table.insert(o.tables.miscGroupsInStage[stage_zone], groupName) + table.insert(o.tables.miscGroupsInStages[stage_zone], groupName) end else local group = Group.getByName(groupName) if group and group:getCoalition() ~= coalition.side.NEUTRAL then is_group_taken[groupName] = true - table.insert(o.tables.miscGroupsInStage[stage_zone], groupName) + table.insert(o.tables.miscGroupsInStages[stage_zone], groupName) end end end @@ -360,7 +361,9 @@ do -- DB loadRandomMissionzoneUnits() loadFarpGroups() loadAirbaseGroups() - loadMiscGroupsInStage() + loadMiscGroupsInStages() + + Logger:debug(o.tables.miscGroupsInStages) local cleanup = function () --CLean up all groups that are now managed inside zones by spearhead @@ -546,12 +549,16 @@ do -- DB o.getRedGroupsAtAirbase = function (self, airbaseId) local baseId = tostring(airbaseId) - return self.tables.redAirbaseGroupsPerAirbase[baseId] + return self.tables.redAirbaseGroupsPerAirbase[baseId] or {} end o.getBlueGroupsAtAirbase = function (self, airbaseId) local baseId = tostring(airbaseId) - return self.tables.blueAirbaseGroupsPerAirbase[baseId] + return self.tables.blueAirbaseGroupsPerAirbase[baseId] or {} + end + + o.getMiscGroupsAtStage = function(self, stageName) + return self.tables.miscGroupsInStages[stageName] or {} end o.GetNewMissionCode = function (self) diff --git a/stageClasses/Stage.lua b/stageClasses/Stage.lua index 8ab6459..9a2bd4f 100644 --- a/stageClasses/Stage.lua +++ b/stageClasses/Stage.lua @@ -27,7 +27,7 @@ do --init STAGE DIRECTOR o.stageNumber = orderNumber o.database = database - + o.logger = logger o.db = {} o.db.missions = {} o.db.sams = {} @@ -35,6 +35,7 @@ do --init STAGE DIRECTOR o.db.blueAirbasegroups = {} o.db.airbaseIds = {} o.db.farps = {} + o.activeStage = 0 o.preActivated = false do --Init Stage @@ -82,7 +83,6 @@ do --init STAGE DIRECTOR for _, airbaseId in pairs(airbaseIds) do for _, groupName in pairs(database:getRedGroupsAtAirbase(airbaseId)) do - logger:debug("blaat)") table.insert(o.db.redAirbasegroups, groupName) end @@ -117,7 +117,7 @@ do --init STAGE DIRECTOR end end - logger:debug("blaat Pre-activating stage with airbase groups amount: " .. Spearhead.Util.tableLength(self.db.redAirbasegroups)) + self.logger:debug("Pre-activating stage with airbase groups amount: " .. Spearhead.Util.tableLength(self.db.redAirbasegroups)) for _ , groupName in pairs(self.db.redAirbasegroups) do Spearhead.DcsUtil.SpawnGroupTemplate(groupName) @@ -129,6 +129,18 @@ do --init STAGE DIRECTOR self:PreActivate() end + local miscGroups = self.database:getMiscGroupsAtStage(self.zoneName) + self.logger:debug("Activating Misc groups for zone: " .. Spearhead.Util.tableLength(miscGroups)) + for _, groupName in pairs(miscGroups) do + Spearhead.DcsUtil.SpawnGroupTemplate(groupName) + end + + for _, mission in pairs(self.db.missions) do + if mission.missionType == Spearhead.internal.Mission.MissionType.DEAD then + mission:Activate() + end + end + --[[ TODO: Activate Stage ]]-- @@ -221,7 +233,18 @@ do --init STAGE DIRECTOR o.ManageStage = function(self) end + o.OnStatusRequestReceived = function(self, groupId) + trigger.action.outTextForGroup("Status Update incoming... ") + end + o.OnStageNumberChanged = function (self, number) + + if self.activeStage == number then --only activate once for a stage + return + end + + self.activeStage = number + if Spearhead.capInfo.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then self:PreActivate() end