From b5d1cee96b73b59b0cba14c6b2cfc587c455f290 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sun, 14 Jul 2024 19:15:19 +0200 Subject: [PATCH 1/3] #documentation --- Moose Development/Moose/Core/Event.lua | 2 +- Moose Development/Moose/DCS.lua | 94 +++++++++++++++++--------- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/Moose Development/Moose/Core/Event.lua b/Moose Development/Moose/Core/Event.lua index 6df0cd70e..54813f39c 100644 --- a/Moose Development/Moose/Core/Event.lua +++ b/Moose Development/Moose/Core/Event.lua @@ -1382,7 +1382,7 @@ function EVENT:onEvent( Event ) end -- Weapon. - if Event.weapon then + if Event.weapon and type(Event.weapon) == "table" then Event.Weapon = Event.weapon Event.WeaponName = Event.weapon:isExist() and Event.weapon:getTypeName() or "Unknown Weapon" Event.WeaponUNIT = CLIENT:Find( Event.Weapon, '', true ) -- Sometimes, the weapon is a player unit! diff --git a/Moose Development/Moose/DCS.lua b/Moose Development/Moose/DCS.lua index 26a0a99e7..c9af9b5b7 100644 --- a/Moose Development/Moose/DCS.lua +++ b/Moose Development/Moose/DCS.lua @@ -25,38 +25,68 @@ do -- world --- [https://wiki.hoggitworld.com/view/DCS_enum_world](https://wiki.hoggitworld.com/view/DCS_enum_world) -- @type world.event - -- @field S_EVENT_INVALID - -- @field S_EVENT_SHOT [https://wiki.hoggitworld.com/view/DCS_event_shot](https://wiki.hoggitworld.com/view/DCS_event_shot) - -- @field S_EVENT_HIT [https://wiki.hoggitworld.com/view/DCS_event_hit](https://wiki.hoggitworld.com/view/DCS_event_hit) - -- @field S_EVENT_TAKEOFF [https://wiki.hoggitworld.com/view/DCS_event_takeoff](https://wiki.hoggitworld.com/view/DCS_event_takeoff) - -- @field S_EVENT_LAND [https://wiki.hoggitworld.com/view/DCS_event_land](https://wiki.hoggitworld.com/view/DCS_event_land) - -- @field S_EVENT_CRASH [https://wiki.hoggitworld.com/view/DCS_event_crash](https://wiki.hoggitworld.com/view/DCS_event_crash) - -- @field S_EVENT_EJECTION [https://wiki.hoggitworld.com/view/DCS_event_ejection](https://wiki.hoggitworld.com/view/DCS_event_ejection) - -- @field S_EVENT_REFUELING [https://wiki.hoggitworld.com/view/DCS_event_refueling](https://wiki.hoggitworld.com/view/DCS_event_refueling) - -- @field S_EVENT_DEAD [https://wiki.hoggitworld.com/view/DCS_event_dead](https://wiki.hoggitworld.com/view/DCS_event_dead) - -- @field S_EVENT_PILOT_DEAD [https://wiki.hoggitworld.com/view/DCS_event_pilot_dead](https://wiki.hoggitworld.com/view/DCS_event_pilot_dead) - -- @field S_EVENT_BASE_CAPTURED [https://wiki.hoggitworld.com/view/DCS_event_base_captured](https://wiki.hoggitworld.com/view/DCS_event_base_captured) - -- @field S_EVENT_MISSION_START [https://wiki.hoggitworld.com/view/DCS_event_mission_start](https://wiki.hoggitworld.com/view/DCS_event_mission_start) - -- @field S_EVENT_MISSION_END [https://wiki.hoggitworld.com/view/DCS_event_mission_end](https://wiki.hoggitworld.com/view/DCS_event_mission_end) - -- @field S_EVENT_TOOK_CONTROL - -- @field S_EVENT_REFUELING_STOP [https://wiki.hoggitworld.com/view/DCS_event_refueling_stop](https://wiki.hoggitworld.com/view/DCS_event_refueling_stop) - -- @field S_EVENT_BIRTH [https://wiki.hoggitworld.com/view/DCS_event_birth](https://wiki.hoggitworld.com/view/DCS_event_birth) - -- @field S_EVENT_HUMAN_FAILURE [https://wiki.hoggitworld.com/view/DCS_event_human_failure](https://wiki.hoggitworld.com/view/DCS_event_human_failure) - -- @field S_EVENT_ENGINE_STARTUP [https://wiki.hoggitworld.com/view/DCS_event_engine_startup](https://wiki.hoggitworld.com/view/DCS_event_engine_startup) - -- @field S_EVENT_ENGINE_SHUTDOWN [https://wiki.hoggitworld.com/view/DCS_event_engine_shutdown](https://wiki.hoggitworld.com/view/DCS_event_engine_shutdown) - -- @field S_EVENT_PLAYER_ENTER_UNIT [https://wiki.hoggitworld.com/view/DCS_event_player_enter_unit](https://wiki.hoggitworld.com/view/DCS_event_player_enter_unit) - -- @field S_EVENT_PLAYER_LEAVE_UNIT [https://wiki.hoggitworld.com/view/DCS_event_player_leave_unit](https://wiki.hoggitworld.com/view/DCS_event_player_leave_unit) - -- @field S_EVENT_PLAYER_COMMENT - -- @field S_EVENT_SHOOTING_START [https://wiki.hoggitworld.com/view/DCS_event_shooting_start](https://wiki.hoggitworld.com/view/DCS_event_shooting_start) - -- @field S_EVENT_SHOOTING_END [https://wiki.hoggitworld.com/view/DCS_event_shooting_end](https://wiki.hoggitworld.com/view/DCS_event_shooting_end) - -- @field S_EVENT_MARK ADDED [https://wiki.hoggitworld.com/view/DCS_event_mark_added](https://wiki.hoggitworld.com/view/DCS_event_mark_added) DCS>=2.5.1 - -- @field S_EVENT_MARK CHANGE [https://wiki.hoggitworld.com/view/DCS_event_mark_change](https://wiki.hoggitworld.com/view/DCS_event_mark_change) DCS>=2.5.1 - -- @field S_EVENT_MARK REMOVE [https://wiki.hoggitworld.com/view/DCS_event_mark_remove](https://wiki.hoggitworld.com/view/DCS_event_mark_remove) DCS>=2.5.1 - -- @field S_EVENT_KILL [https://wiki.hoggitworld.com/view/DCS_event_kill](https://wiki.hoggitworld.com/view/DCS_event_kill) DCS>=2.5.6 - -- @field S_EVENT_SCORE [https://wiki.hoggitworld.com/view/DCS_event_score](https://wiki.hoggitworld.com/view/DCS_event_score) DCS>=2.5.6 - -- @field S_EVENT_UNIT_LOST [https://wiki.hoggitworld.com/view/DCS_event_unit_lost](https://wiki.hoggitworld.com/view/DCS_event_unit_lost) DCS>=2.5.6 - -- @field S_EVENT_LANDING_AFTER_EJECTION [https://wiki.hoggitworld.com/view/DCS_event_landing_after_ejection](https://wiki.hoggitworld.com/view/DCS_event_landing_after_ejection) DCS>=2.5.6 - -- @field S_EVENT_MAX + -- @field S_EVENT_INVALID = 0 + -- @field S_EVENT_SHOT = 1 + -- @field S_EVENT_HIT = 2 + -- @field S_EVENT_TAKEOFF = 3 + -- @field S_EVENT_LAND = 4 + -- @field S_EVENT_CRASH = 5 + -- @field S_EVENT_EJECTION = 6 + -- @field S_EVENT_REFUELING = 7 + -- @field S_EVENT_DEAD = 8 + -- @field S_EVENT_PILOT_DEAD = 9 + -- @field S_EVENT_BASE_CAPTURED = 10 + -- @field S_EVENT_MISSION_START = 11 + -- @field S_EVENT_MISSION_END = 12 + -- @field S_EVENT_TOOK_CONTROL = 13 + -- @field S_EVENT_REFUELING_STOP = 14 + -- @field S_EVENT_BIRTH = 15 + -- @field S_EVENT_HUMAN_FAILURE = 16 + -- @field S_EVENT_DETAILED_FAILURE = 17 + -- @field S_EVENT_ENGINE_STARTUP = 18 + -- @field S_EVENT_ENGINE_SHUTDOWN = 19 + -- @field S_EVENT_PLAYER_ENTER_UNIT = 20 + -- @field S_EVENT_PLAYER_LEAVE_UNIT = 21 + -- @field S_EVENT_PLAYER_COMMENT = 22 + -- @field S_EVENT_SHOOTING_START = 23 + -- @field S_EVENT_SHOOTING_END = 24 + -- @field S_EVENT_MARK_ADDED = 25 + -- @field S_EVENT_MARK_CHANGE = 26 + -- @field S_EVENT_MARK_REMOVED = 27 + -- @field S_EVENT_KILL = 28 + -- @field S_EVENT_SCORE = 29 + -- @field S_EVENT_UNIT_LOST = 30 + -- @field S_EVENT_LANDING_AFTER_EJECTION = 31 + -- @field S_EVENT_PARATROOPER_LENDING = 32 -- who's lending whom what? ;) + -- @field S_EVENT_DISCARD_CHAIR_AFTER_EJECTION = 33 + -- @field S_EVENT_WEAPON_ADD = 34 + -- @field S_EVENT_TRIGGER_ZONE = 35 + -- @field S_EVENT_LANDING_QUALITY_MARK = 36 + -- @field S_EVENT_BDA = 37 -- battle damage assessment + -- @field S_EVENT_AI_ABORT_MISSION = 38 + -- @field S_EVENT_DAYNIGHT = 39 + -- @field S_EVENT_FLIGHT_TIME = 40 + -- @field S_EVENT_PLAYER_SELF_KILL_PILOT = 41 + -- @field S_EVENT_PLAYER_CAPTURE_AIRFIELD = 42 + -- @field S_EVENT_EMERGENCY_LANDING = 43 + -- @field S_EVENT_UNIT_CREATE_TASK = 44 + -- @field S_EVENT_UNIT_DELETE_TASK = 45 + -- @field S_EVENT_SIMULATION_START = 46 + -- @field S_EVENT_WEAPON_REARM = 47 + -- @field S_EVENT_WEAPON_DROP = 48 + -- @field S_EVENT_UNIT_TASK_COMPLETE = 49 + -- @field S_EVENT_UNIT_TASK_STAGE = 50 + -- @field S_EVENT_MAC_EXTRA_SCORE= 51 -- not sure what this is + -- @field S_EVENT_MISSION_RESTART= 52 + -- @field S_EVENT_MISSION_WINNER = 53 + -- @field S_EVENT_RUNWAY_TAKEOFF= 54 + -- @field S_EVENT_RUNWAY_TOUCH= 55 + -- @field S_EVENT_MAC_LMS_RESTART= 56 -- not sure what this is + -- @field S_EVENT_SIMULATION_FREEZE = 57 + -- @field S_EVENT_SIMULATION_UNFREEZE = 58 + -- @field S_EVENT_HUMAN_AIRCRAFT_REPAIR_START = 59 + -- @field S_EVENT_HUMAN_AIRCRAFT_REPAIR_FINISH = 60 + -- @field S_EVENT_MAX = 61 --- The birthplace enumerator is used to define where an aircraft or helicopter has spawned in association with birth events. -- @type world.BirthPlace From 6fb931a05516064431113ba4dd02253789b9e60b Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 15 Jul 2024 14:31:54 +0200 Subject: [PATCH 2/3] #SPAWN - couple of fixes for SPAWN, planes scheduler --- Moose Development/Moose/Core/Spawn.lua | 48 +++++++++++++++++--------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index ad430a33a..b5fddf5c0 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -1540,11 +1540,11 @@ function SPAWN:ReSpawn( SpawnIndex ) SpawnGroup:WayPointExecute( 1, 5 ) end - if SpawnGroup.ReSpawnFunction then + if SpawnGroup and SpawnGroup.ReSpawnFunction then SpawnGroup:ReSpawnFunction() end - SpawnGroup:ResetEvents() + if SpawnGroup then SpawnGroup:ResetEvents() end return SpawnGroup end @@ -1565,8 +1565,24 @@ end -- @param #string SpawnIndex The index of the group to be spawned. -- @return Wrapper.Group#GROUP The group that was spawned. You can use this group for further actions. function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth ) - self:F2( { SpawnTemplatePrefix = self.SpawnTemplatePrefix, SpawnIndex = SpawnIndex, AliveUnits = self.AliveUnits, SpawnMaxGroups = self.SpawnMaxGroups } ) - + + local set = SET_GROUP:New():FilterAlive():FilterPrefixes({self.SpawnTemplatePrefix, self.SpawnAliasPrefix}):FilterOnce() + local aliveunits = 0 + set:ForEachGroupAlive( + function(grp) + aliveunits = aliveunits + grp:CountAliveUnits() + end + ) + + if aliveunits ~= self.AliveUnits then + self.AliveUnits = aliveunits + self:T("***** self.AliveUnits accounting failure! Corrected! *****") + end + + set= nil + + self:T( { SpawnTemplatePrefix = self.SpawnTemplatePrefix, SpawnIndex = SpawnIndex, AliveUnits = self.AliveUnits, SpawnMaxGroups = self.SpawnMaxGroups } ) + if self:_GetSpawnIndex( SpawnIndex ) then if self.SpawnFromNewPosition then @@ -1613,12 +1629,12 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth ) RandomVec2 = PointVec3:GetRandomVec2InRadius( self.SpawnOuterRadius, self.SpawnInnerRadius ) numTries = numTries + 1 inZone = SpawnZone:IsVec2InZone(RandomVec2) - --self:I("Retrying " .. numTries .. "spawn " .. SpawnTemplate.name .. " in Zone " .. SpawnZone:GetName() .. "!") - --self:I(SpawnZone) + --self:T("Retrying " .. numTries .. "spawn " .. SpawnTemplate.name .. " in Zone " .. SpawnZone:GetName() .. "!") + --self:T(SpawnZone) end end if (not inZone) then - self:I("Could not place unit within zone and within radius!") + self:T("Could not place unit within zone and within radius!") RandomVec2 = SpawnZone:GetRandomVec2() end end @@ -3905,9 +3921,9 @@ end -- @param Core.Event#EVENTDATA EventData function SPAWN:_OnDeadOrCrash( EventData ) self:T( "Dead or crash event ID "..EventData.id) - self:T( "Dead or crash event for "..self.SpawnTemplatePrefix ) + self:T( "Dead or crash event for "..EventData.IniUnitName ) - if EventData.id == EVENTS.Dead then return end + --if EventData.id == EVENTS.Dead then return end local unit=UNIT:FindByName(EventData.IniUnitName) --local group=GROUP:FindByName(EventData.IniGroupName) @@ -3918,14 +3934,11 @@ function SPAWN:_OnDeadOrCrash( EventData ) if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group! self:T( { "Dead event: " .. EventPrefix } ) - - if EventPrefix == self.SpawnTemplatePrefix or ( self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix ) then - - self.AliveUnits = self.AliveUnits - 1 - - self:T( "Alive Units: " .. self.AliveUnits ) + self:T(string.format("EventPrefix = %s | SpawnAliasPrefix = %s | Old AliveUnits = %d",EventPrefix,self.SpawnAliasPrefix,self.AliveUnits)) + if EventPrefix == self.SpawnTemplatePrefix or ( self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix ) and self.AliveUnits > 0 then + self.AliveUnits = self.AliveUnits - 1 end - + self:T( "New Alive Units: " .. self.AliveUnits ) end end end @@ -4051,7 +4064,8 @@ function SPAWN:_SpawnCleanUpScheduler() -- If the plane is not moving or dead , and is on the ground, assign it with a timestamp... if Stamp.Time + self.SpawnCleanUpInterval < timer.getTime() then self:T( { "CleanUp Scheduler:", "ReSpawning:", SpawnGroup:GetName() } ) - self:ReSpawn( SpawnCursor ) + --self:ReSpawn( SpawnCursor ) + SCHEDULER:New( nil, self.ReSpawn, { self, SpawnCursor }, 3 ) Stamp.Vec2 = nil Stamp.Time = nil end From 214cd3748cb577248c17c5fa6103c21d88789bcb Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 15 Jul 2024 17:23:30 +0200 Subject: [PATCH 3/3] #SET - dynamic slot fixes for SET_CLIENT and SET_PLAYER --- Moose Development/Moose/Core/Set.lua | 24 ++++++++++++------- .../Moose/Wrapper/Identifiable.lua | 18 ++++++++++---- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 798f4c4cd..9023297f6 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -4748,11 +4748,12 @@ do -- SET_CLIENT local MClientCategory = false for CategoryID, CategoryName in pairs( self.Filter.Categories ) do local ClientCategoryID = _DATABASE:GetCategoryFromClientTemplate( MClientName ) + local UnitCategory if ClientCategoryID==nil and MClient:IsAlive()~=nil then - ClientCategoryID=MClient:GetCategory() + ClientCategoryID,UnitCategory=MClient:GetCategory() end - self:T3( { "Category:", ClientCategoryID, self.FilterMeta.Categories[CategoryName], CategoryName } ) - if self.FilterMeta.Categories[CategoryName] and ClientCategoryID and self.FilterMeta.Categories[CategoryName] == ClientCategoryID then + self:T3( { "Category:", UnitCategory, self.FilterMeta.Categories[CategoryName], CategoryName } ) + if self.FilterMeta.Categories[CategoryName] and UnitCategory and self.FilterMeta.Categories[CategoryName] == UnitCategory then MClientCategory = true end end @@ -5196,12 +5197,15 @@ do -- SET_PLAYER if MClient then local MClientName = MClient.UnitName - if self.Filter.Coalitions then + if self.Filter.Coalitions and MClientInclude then local MClientCoalition = false for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do local ClientCoalitionID = _DATABASE:GetCoalitionFromClientTemplate( MClientName ) + if ClientCoalitionID==nil and MClient:IsAlive()~=nil then + ClientCoalitionID=MClient:GetCoalition() + end self:T3( { "Coalition:", ClientCoalitionID, self.FilterMeta.Coalitions[CoalitionName], CoalitionName } ) - if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == ClientCoalitionID then + if self.FilterMeta.Coalitions[CoalitionName] and ClientCoalitionID and self.FilterMeta.Coalitions[CoalitionName] == ClientCoalitionID then MClientCoalition = true end end @@ -5209,12 +5213,16 @@ do -- SET_PLAYER MClientInclude = MClientInclude and MClientCoalition end - if self.Filter.Categories then + if self.Filter.Categories and MClientInclude then local MClientCategory = false for CategoryID, CategoryName in pairs( self.Filter.Categories ) do local ClientCategoryID = _DATABASE:GetCategoryFromClientTemplate( MClientName ) - self:T3( { "Category:", ClientCategoryID, self.FilterMeta.Categories[CategoryName], CategoryName } ) - if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == ClientCategoryID then + local UnitCategory + if ClientCategoryID==nil and MClient:IsAlive()~=nil then + ClientCategoryID,UnitCategory=MClient:GetCategory() + end + self:T3( { "Category:", UnitCategory, self.FilterMeta.Categories[CategoryName], CategoryName } ) + if self.FilterMeta.Categories[CategoryName] and UnitCategory and self.FilterMeta.Categories[CategoryName] == UnitCategory then MClientCategory = true end end diff --git a/Moose Development/Moose/Wrapper/Identifiable.lua b/Moose Development/Moose/Wrapper/Identifiable.lua index 1710289d7..8561d5b2b 100644 --- a/Moose Development/Moose/Wrapper/Identifiable.lua +++ b/Moose Development/Moose/Wrapper/Identifiable.lua @@ -11,7 +11,8 @@ -- @module Wrapper.Identifiable -- @image MOOSE.JPG ---- @type IDENTIFIABLE +--- +-- @type IDENTIFIABLE -- @extends Wrapper.Object#OBJECT -- @field #string IdentifiableName The name of the identifiable. @@ -111,19 +112,28 @@ end -- * Object.Category.SCENERY = 5 -- * Object.Category.Cargo = 6 -- +-- For UNITs this returns a second value, one of +-- +-- Unit.Category.AIRPLANE = 0 +-- Unit.Category.HELICOPTER = 1 +-- Unit.Category.GROUND_UNIT = 2 +-- Unit.Category.SHIP = 3 +-- Unit.Category.STRUCTURE = 4 +-- -- @param #IDENTIFIABLE self -- @return DCS#Object.Category The category ID, i.e. a number. +-- @return DCS#Unit.Category The unit category ID, i.e. a number. For units only. function IDENTIFIABLE:GetCategory() self:F2( self.ObjectName ) local DCSObject = self:GetDCSObject() if DCSObject then - local ObjectCategory = DCSObject:getCategory() + local ObjectCategory, UnitCategory = DCSObject:getCategory() self:T3( ObjectCategory ) - return ObjectCategory + return ObjectCategory, UnitCategory end - return nil + return nil,nil end