From ffcc46cb2d7b1c66ef545587f098ef3750c708e7 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 17 May 2023 09:34:50 +0200 Subject: [PATCH 1/5] #CTLD * Changed VHF modulation to AM * Added option to have a different sound file for UHF, in case you want to silent FC3 radios * Thanks to Streakeagle --- Moose Development/Moose/Ops/CTLD.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/Ops/CTLD.lua b/Moose Development/Moose/Ops/CTLD.lua index c623b2c58..04e84ee7d 100644 --- a/Moose Development/Moose/Ops/CTLD.lua +++ b/Moose Development/Moose/Ops/CTLD.lua @@ -725,6 +725,8 @@ do -- my_ctld.movecratesbeforebuild = true -- crates must be moved once before they can be build. Set to false for direct builds. -- my_ctld.surfacetypes = {land.SurfaceType.LAND,land.SurfaceType.ROAD,land.SurfaceType.RUNWAY,land.SurfaceType.SHALLOW_WATER} -- surfaces for loading back objects. -- my_ctld.nobuildmenu = false -- if set to true effectively enforces to have engineers build/repair stuff for you. +-- my_ctld.RadioSound = "beacon.ogg" -- -- this sound will be hearable if you tune in the beacon frequency. Add the sound file to your miz. +-- my_ctld.RadioSoundFC3 = "beacon.ogg" -- this sound will be hearable by FC3 users (actually all UHF radios); change to something like "beaconsilent.ogg" and add the sound file to your miz if you don't want to annoy FC3 pilots. -- -- ## 2.1 User functions -- @@ -1219,7 +1221,7 @@ CTLD.UnitTypes = { --- CTLD class version. -- @field #string version -CTLD.version="1.0.36" +CTLD.version="1.0.37" --- Instantiate a new CTLD. -- @param #CTLD self @@ -1302,6 +1304,7 @@ function CTLD:New(Coalition, Prefixes, Alias) -- radio beacons self.RadioSound = "beacon.ogg" + self.RadioSoundFC3 = "beacon.ogg" self.RadioPath = "l10n/DEFAULT/" -- zones stuff @@ -4023,7 +4026,7 @@ function CTLD:_AddRadioBeacon(Name, Sound, Mhz, Modulation, IsShip, IsDropped) local Sound = self.RadioPath..Sound trigger.action.radioTransmission(Sound, ZoneVec3, Modulation, false, Frequency, 1000, Name..math.random(1,10000)) -- Beacon in MP only runs for 30secs straight self:T2(string.format("Beacon added | Name = %s | Sound = %s | Vec3 = %d %d %d | Freq = %f | Modulation = %d (0=AM/1=FM)",Name,Sound,ZoneVec3.x,ZoneVec3.y,ZoneVec3.z,Mhz,Modulation)) - else + else local ZoneCoord = Zone:GetCoordinate() local ZoneVec3 = ZoneCoord:GetVec3() or {x=0,y=0,z=0} local Frequency = Mhz * 1000000 -- Freq in Hert @@ -4077,6 +4080,7 @@ function CTLD:_RefreshRadioBeacons() -- Get Beacon object from zone local czone = cargozone -- #CTLD.CargoZone local Sound = self.RadioSound + local Silent = self.RadioSoundFC3 or self.RadioSound if czone.active and czone.hasbeacon then local FMbeacon = czone.fmbeacon -- #CTLD.ZoneBeacon local VHFbeacon = czone.vhfbeacon -- #CTLD.ZoneBeacon @@ -4086,8 +4090,8 @@ function CTLD:_RefreshRadioBeacons() local VHF = VHFbeacon.frequency -- KHz local UHF = UHFbeacon.frequency -- MHz self:_AddRadioBeacon(Name,Sound,FM, CTLD.RadioModulation.FM, IsShip, IsDropped) - self:_AddRadioBeacon(Name,Sound,VHF,CTLD.RadioModulation.FM, IsShip, IsDropped) - self:_AddRadioBeacon(Name,Sound,UHF,CTLD.RadioModulation.AM, IsShip, IsDropped) + self:_AddRadioBeacon(Name,Sound,VHF,CTLD.RadioModulation.AM, IsShip, IsDropped) + self:_AddRadioBeacon(Name,Silent,UHF,CTLD.RadioModulation.AM, IsShip, IsDropped) end end end From 0868286f27de7afbcf2817a8aa0d5ac6559d7572 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 17 May 2023 10:26:29 +0200 Subject: [PATCH 2/5] #WAREHOUSE * Fixed one omission for SHIP transport types --- .../Moose/Functional/Warehouse.lua | 110 +++++++++--------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 8a1dfcd95..93239b913 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -1798,7 +1798,7 @@ _WAREHOUSEDB = { --- Warehouse class version. -- @field #string version -WAREHOUSE.version="1.0.2" +WAREHOUSE.version="1.0.2a" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO: Warehouse todo list. @@ -4561,7 +4561,8 @@ function WAREHOUSE:onafterRequest(From, Event, To, Request) self:_ErrorMessage("ERROR: Cargo transport by train not supported yet!") return - elseif Request.transporttype==WAREHOUSE.TransportType.SHIP or Request.transporttype==WAREHOUSE.TransportType.NAVALCARRIER then + elseif Request.transporttype==WAREHOUSE.TransportType.SHIP or Request.transporttype==WAREHOUSE.TransportType.NAVALCARRIER + or Request.transporttype==WAREHOUSE.TransportType.ARMEDSHIP or Request.transporttype==WAREHOUSE.TransportType.WARSHIP then -- Spawn Ship in port zone spawngroup=self:_SpawnAssetGroundNaval(_alias, _assetitem, Request, self.portzone) @@ -5829,62 +5830,65 @@ function WAREHOUSE:_SpawnAssetRequest(Request) -- Get stock item. local asset=cargoassets[i] --#WAREHOUSE.Assetitem + + if not asset.spawned then - -- Set asset status to not spawned until we capture its birth event. - asset.spawned=false - asset.iscargo=true - - -- Set request ID. - asset.rid=Request.uid - - -- Spawn group name. - local _alias=asset.spawngroupname - - --Request add asset by id. - Request.assets[asset.uid]=asset - - -- Spawn an asset group. - local _group=nil --Wrapper.Group#GROUP - if asset.category==Group.Category.GROUND then - - -- Spawn ground troops. - _group=self:_SpawnAssetGroundNaval(_alias, asset, Request, self.spawnzone, Request.lateActivation) - - elseif asset.category==Group.Category.AIRPLANE or asset.category==Group.Category.HELICOPTER then - - -- Spawn air units. - if Parking[asset.uid] then - _group=self:_SpawnAssetAircraft(_alias, asset, Request, Parking[asset.uid], UnControlled, Request.lateActivation) - else - _group=self:_SpawnAssetAircraft(_alias, asset, Request, nil, UnControlled, Request.lateActivation) - end - - elseif asset.category==Group.Category.TRAIN then - - -- Spawn train. - if self.rail then - --TODO: Rail should only get one asset because they would spawn on top! - - -- Spawn naval assets. + -- Set asset status to not spawned until we capture its birth event. + asset.iscargo=true + + -- Set request ID. + asset.rid=Request.uid + + -- Spawn group name. + local _alias=asset.spawngroupname + + --Request add asset by id. + Request.assets[asset.uid]=asset + + -- Spawn an asset group. + local _group=nil --Wrapper.Group#GROUP + if asset.category==Group.Category.GROUND then + + -- Spawn ground troops. _group=self:_SpawnAssetGroundNaval(_alias, asset, Request, self.spawnzone, Request.lateActivation) + + elseif asset.category==Group.Category.AIRPLANE or asset.category==Group.Category.HELICOPTER then + + -- Spawn air units. + if Parking[asset.uid] then + _group=self:_SpawnAssetAircraft(_alias, asset, Request, Parking[asset.uid], UnControlled, Request.lateActivation) + else + _group=self:_SpawnAssetAircraft(_alias, asset, Request, nil, UnControlled, Request.lateActivation) + end + + elseif asset.category==Group.Category.TRAIN then + + -- Spawn train. + if self.rail then + --TODO: Rail should only get one asset because they would spawn on top! + + -- Spawn naval assets. + _group=self:_SpawnAssetGroundNaval(_alias, asset, Request, self.spawnzone, Request.lateActivation) + end + + --self:E(self.lid.."ERROR: Spawning of TRAIN assets not possible yet!") + + elseif asset.category==Group.Category.SHIP then + + -- Spawn naval assets. + _group=self:_SpawnAssetGroundNaval(_alias, asset, Request, self.portzone, Request.lateActivation) + + else + self:E(self.lid.."ERROR: Unknown asset category!") end - - --self:E(self.lid.."ERROR: Spawning of TRAIN assets not possible yet!") - - elseif asset.category==Group.Category.SHIP then - - -- Spawn naval assets. - _group=self:_SpawnAssetGroundNaval(_alias, asset, Request, self.portzone, Request.lateActivation) - - else - self:E(self.lid.."ERROR: Unknown asset category!") + + -- Trigger event. + if _group then + self:__AssetSpawned(0.01, _group, asset, Request) + end + end - -- Trigger event. - if _group then - self:__AssetSpawned(0.01, _group, asset, Request) - end - end end From 60b75a4c8fb17ef3be818cd089f54d0c7e5319cb Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 19 May 2023 17:11:54 +0200 Subject: [PATCH 3/5] #POINT * Added FindClosestStatic() --- Moose Development/Moose/Core/Point.lua | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 772de02bf..fb18c6f6b 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -603,6 +603,46 @@ do -- COORDINATE return set end + + --- Scan/find STATICS within a certain radius around the coordinate using the world.searchObjects() DCS API function. + -- @param #COORDINATE self + -- @param #number radius (Optional) Scan radius in meters. Default 100 m. + -- @return Core.Set#SET_UNIT Set of units. + function COORDINATE:ScanStatics(radius) + + local _,_,_,_,statics=self:ScanObjects(radius, false, true, false) + + local set=SET_STATIC:New() + + for _,unit in pairs(statics) do + set:AddUnit(unit) + end + + return set + end + + --- Find the closest static to the COORDINATE within a certain radius. + -- @param #COORDINATE self + -- @param #number radius Scan radius in meters. Default 100 m. + -- @return Wrapper.Static#STATIC The closest static or #nil if no unit is inside the given radius. + function COORDINATE:FindClosestStatic(radius) + + local units=self:ScanStatics(radius) + + local umin=nil --Wrapper.Unit#UNIT + local dmin=math.huge + for _,_unit in pairs(units.Set) do + local unit=_unit --Wrapper.Static#STATIC + local coordinate=unit:GetCoordinate() + local d=self:Get2DDistance(coordinate) + if d Date: Sat, 20 May 2023 12:12:18 +0200 Subject: [PATCH 4/5] Small Fix --- Moose Development/Moose/Core/Point.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index fb18c6f6b..d942e49ba 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -614,8 +614,8 @@ do -- COORDINATE local set=SET_STATIC:New() - for _,unit in pairs(statics) do - set:AddUnit(unit) + for _,stat in pairs(statics) do + set:AddStatic(STATIC:Find(stat)) end return set From 905d29b2797d2ccf0d703c84bb2c6cd5ef97dd53 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 22 May 2023 17:57:03 +0200 Subject: [PATCH 5/5] #SPAWN * Tweaked NewFromTemplate, and gave a better example --- Moose Development/Moose/Core/Spawn.lua | 141 +++++++++++++++++++++---- 1 file changed, 121 insertions(+), 20 deletions(-) diff --git a/Moose Development/Moose/Core/Spawn.lua b/Moose Development/Moose/Core/Spawn.lua index 6b5e9bb55..b170501bc 100644 --- a/Moose Development/Moose/Core/Spawn.lua +++ b/Moose Development/Moose/Core/Spawn.lua @@ -335,7 +335,7 @@ end -- @param #SPAWN self -- @param #string SpawnTemplatePrefix is the name of the Group in the ME that defines the Template. -- @param #string SpawnAliasPrefix is the name that will be given to the Group at runtime. --- @return #SPAWN +-- @return #SPAWN self -- @usage -- -- NATO helicopters engaging in the battle field. -- Spawn_BE_KA50 = SPAWN:NewWithAlias( 'BE KA-50@RAMP-Ground Defense', 'Helicopter Attacking a City' ) @@ -385,32 +385,129 @@ function SPAWN:NewWithAlias( SpawnTemplatePrefix, SpawnAliasPrefix ) return self end ---- Creates a new SPAWN instance to create new groups based on the provided template. +--- Creates a new SPAWN instance to create new groups based on the provided template. This will also register the template for future use. -- @param #SPAWN self --- @param #table SpawnTemplate is the Template of the Group. This must be a valid Group Template structure! --- @param #string SpawnTemplatePrefix is the name of the Group that will be given at each spawn. --- @param #string SpawnAliasPrefix is the name that will be given to the Group at runtime. --- @return #SPAWN +-- @param #table SpawnTemplate is the Template of the Group. This must be a valid Group Template structure - see [Hoggit Wiki](https://wiki.hoggitworld.com/view/DCS_func_addGroup)! +-- @param #string SpawnTemplatePrefix [Mandatory] is the name of the template and the prefix of the GROUP on spawn. +-- @param #string SpawnAliasPrefix [Optional] is the prefix that will be given to the GROUP on spawn. +-- @param #boolean MooseNaming [Optional] If false, skip the Moose naming additions (like groupname#001-01) - you need to ensure yourself no duplicate group names exist! +-- @return #SPAWN self -- @usage --- -- Create a new SPAWN object based on a Group Template defined from scratch. --- Spawn_BE_KA50 = SPAWN:NewWithAlias( 'BE KA-50@RAMP-Ground Defense', 'Helicopter Attacking a City' ) --- @usage --- --- -- Create a new CSAR_Spawn object based on a normal Group Template to spawn a soldier. --- local CSAR_Spawn = SPAWN:NewWithFromTemplate( Template, "CSAR", "Pilot" ) --- -function SPAWN:NewFromTemplate( SpawnTemplate, SpawnTemplatePrefix, SpawnAliasPrefix ) - local self = BASE:Inherit( self, BASE:New() ) - self:F( { SpawnTemplate, SpawnTemplatePrefix, SpawnAliasPrefix } ) - if SpawnAliasPrefix == nil or SpawnAliasPrefix == "" then - BASE:I( "ERROR: in function NewFromTemplate, required parameter SpawnAliasPrefix is not set" ) +-- -- Spawn a P51 Mustang from scratch +-- local ttemp = +-- { +-- ["modulation"] = 0, +-- ["tasks"] = +-- { +-- }, -- end of ["tasks"] +-- ["task"] = "Reconnaissance", +-- ["uncontrolled"] = false, +-- ["route"] = +-- { +-- ["points"] = +-- { +-- [1] = +-- { +-- ["alt"] = 2000, +-- ["action"] = "Turning Point", +-- ["alt_type"] = "BARO", +-- ["speed"] = 125, +-- ["task"] = +-- { +-- ["id"] = "ComboTask", +-- ["params"] = +-- { +-- ["tasks"] = +-- { +-- }, -- end of ["tasks"] +-- }, -- end of ["params"] +-- }, -- end of ["task"] +-- ["type"] = "Turning Point", +-- ["ETA"] = 0, +-- ["ETA_locked"] = true, +-- ["y"] = 666285.71428571, +-- ["x"] = -312000, +-- ["formation_template"] = "", +-- ["speed_locked"] = true, +-- }, -- end of [1] +-- }, -- end of ["points"] +-- }, -- end of ["route"] +-- ["groupId"] = 1, +-- ["hidden"] = false, +-- ["units"] = +-- { +-- [1] = +-- { +-- ["alt"] = 2000, +-- ["alt_type"] = "BARO", +-- ["livery_id"] = "USAF 364th FS", +-- ["skill"] = "High", +-- ["speed"] = 125, +-- ["type"] = "TF-51D", +-- ["unitId"] = 1, +-- ["psi"] = 0, +-- ["y"] = 666285.71428571, +-- ["x"] = -312000, +-- ["name"] = "P51-1-1", +-- ["payload"] = +-- { +-- ["pylons"] = +-- { +-- }, -- end of ["pylons"] +-- ["fuel"] = 340.68, +-- ["flare"] = 0, +-- ["chaff"] = 0, +-- ["gun"] = 100, +-- }, -- end of ["payload"] +-- ["heading"] = 0, +-- ["callsign"] = +-- { +-- [1] = 1, +-- [2] = 1, +-- ["name"] = "Enfield11", +-- [3] = 1, +-- }, -- end of ["callsign"] +-- ["onboard_num"] = "010", +-- }, -- end of [1] +-- }, -- end of ["units"] +-- ["y"] = 666285.71428571, +-- ["x"] = -312000, +-- ["name"] = "P51", +-- ["communication"] = true, +-- ["start_time"] = 0, +-- ["frequency"] = 124, +-- } +-- +-- +-- local mustang = SPAWN:NewFromTemplate(ttemp,"P51D") +-- -- you MUST set the next three: +-- mustang:InitCountry(country.id.FRANCE) +-- mustang:InitCategory(Group.Category.AIRPLANE) +-- mustang:InitCoalition(coalition.side.BLUE) +-- mustang:OnSpawnGroup( +-- function(grp) +-- MESSAGE:New("Group Spawned: "..grp:GetName(),15,"SPAWN"):ToAll() +-- end +-- ) +-- mustang:Spawn() +-- +function SPAWN:NewFromTemplate( SpawnTemplate, SpawnTemplatePrefix, SpawnAliasPrefix, MooseNaming ) + local self = BASE:Inherit( self, BASE:New() ) + self:F( { SpawnTemplate, SpawnTemplatePrefix, SpawnAliasPrefix } ) + --if SpawnAliasPrefix == nil or SpawnAliasPrefix == "" then + --BASE:I( "ERROR: in function NewFromTemplate, required parameter SpawnAliasPrefix is not set" ) + --return nil + --end + if SpawnTemplatePrefix == nil or SpawnTemplatePrefix == "" then + BASE:I( "ERROR: in function NewFromTemplate, required parameter SpawnTemplatePrefix is not set" ) return nil end if SpawnTemplate then self.SpawnTemplate = SpawnTemplate -- Contains the template structure for a Group Spawn from the Mission Editor. Note that this group must have lateActivation always on!!! self.SpawnTemplatePrefix = SpawnTemplatePrefix - self.SpawnAliasPrefix = SpawnAliasPrefix + self.SpawnAliasPrefix = SpawnAliasPrefix or SpawnTemplatePrefix + self.SpawnTemplate.name = SpawnTemplatePrefix self.SpawnIndex = 0 self.SpawnCount = 0 -- The internal counter of the amount of spawning the has happened since SpawnStart. self.AliveUnits = 0 -- Contains the counter how many units are currently alive @@ -435,7 +532,8 @@ function SPAWN:NewFromTemplate( SpawnTemplate, SpawnTemplatePrefix, SpawnAliasPr self.SpawnInitModex = nil self.SpawnInitAirbase = nil self.TweakedTemplate = true -- Check if the user is using self made template. - + self.MooseNameing = MooseNaming or true + self.SpawnGroups = {} -- Array containing the descriptions of each Group to be Spawned. else error( "There is no template provided for SpawnTemplatePrefix = '" .. SpawnTemplatePrefix .. "'" ) @@ -3060,6 +3158,9 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex ) -- R2.2 if self.TweakedTemplate ~= nil and self.TweakedTemplate == true then BASE:I( "WARNING: You are using a tweaked template." ) SpawnTemplate = self.SpawnTemplate + if self.MooseNameing then + SpawnTemplate.name = self:SpawnGroupName( SpawnIndex ) + end else SpawnTemplate = self:_GetTemplate( SpawnTemplatePrefix ) SpawnTemplate.name = self:SpawnGroupName( SpawnIndex )