From 1060d63808ffcbcf6e55c1b80573c3d766f0c3ba Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 24 Apr 2023 16:44:38 +0200 Subject: [PATCH 1/5] #SET_SCENERY * Added functions to count Life0, Life and RelativeLife points of SET_SCENERY --- Moose Development/Moose/Core/Set.lua | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index a48e917f6..d9b80bee8 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -7797,7 +7797,7 @@ do -- SET_SCENERY end - --- + --- [Internal] Determine if an object is to be included in the SET -- @param #SET_SCENERY self -- @param Wrapper.Scenery#SCENERY MScenery -- @return #SET_SCENERY self @@ -7805,4 +7805,44 @@ do -- SET_SCENERY self:F2( MScenery ) return true end + + --- Count overall initial (Life0) lifepoints of the SET objects. + -- @param #SET_SCENERY self + -- @return #number LIfe0Points + function SET_SCENERY:GetLife0() + local life0 = 0 + self:ForEachScenery( + function(obj) + local Obj = obj -- Wrapper.Scenery#SCENERY + life0 = life0 + Obj:GetLife0() + end + ) + return life0 + end + + --- Count overall current lifepoints of the SET objects. + -- @param #SET_SCENERY self + -- @return #number LifePoints + function SET_SCENERY:GetLife() + local life = 0 + self:ForEachScenery( + function(obj) + local Obj = obj -- Wrapper.Scenery#SCENERY + life = life + Obj:GetLife() + end + ) + return life + end + + --- Calculate current relative lifepoints of the SET objects, i.e. Life divided by Life0 as percentage value, eg 75 meaning 75% alive. + -- **CAVEAT**: Some objects change their life value or "hitpoints" **after** the first hit. Be aware that thus the relative life value might be > 100 after a hit. + -- @param #SET_SCENERY self + -- @return #number LifePoints + function SET_SCENERY:GetRelativeLife() + local life0 = self:GetLife0() + local life = self:GetLife() + local rlife = math.floor((life / life0) * 100) + return rlife + end + end From 6896dc155a610feaf77c3f720bfc2187442a8899 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Tue, 25 Apr 2023 09:12:25 +0200 Subject: [PATCH 2/5] #SCENERY * Added update of Life0 value if `GetLife()`is called #SET_SCENERY * Added Documentation --- Moose Development/Moose/Wrapper/Scenery.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Scenery.lua b/Moose Development/Moose/Wrapper/Scenery.lua index 8fe17ecfe..6a6f70bd9 100644 --- a/Moose Development/Moose/Wrapper/Scenery.lua +++ b/Moose Development/Moose/Wrapper/Scenery.lua @@ -63,12 +63,18 @@ function SCENERY:GetDCSObject() end --- Get current life points from the SCENERY Object. +-- **CAVEAT**: Some objects change their life value or "hitpoints" **after** the first hit. Hence we will adjust the life0 value to 120% +-- of the last life value if life exceeds life0 (initial life) at any point. Thus will will get a smooth percentage decrease, if you use this e.g. as success +-- criteria for a bombing task. --@param #SCENERY self --@return #number life function SCENERY:GetLife() local life = 0 if self.SceneryObject then life = self.SceneryObject:getLife() + if life > self.Life0 then + self.Life0 = math.floor(life * 1.2) + end end return life end @@ -110,11 +116,13 @@ end --@param #number Radius (optional) Search radius around coordinate, defaults to 100 --@return #SCENERY Scenery Object or `nil` if it cannot be found function SCENERY:FindByName(Name, Coordinate, Radius) - + local radius = Radius or 100 local name = Name or "unknown" local scenery = nil + BASE:T({name, radius, Coordinate:GetVec2()}) + --- -- @param Core.Point#COORDINATE coordinate -- @param #number radius @@ -170,6 +178,7 @@ function SCENERY:FindByZoneName( ZoneName ) zone = ZONE:FindByName(ZoneName) end local _id = zone:GetProperty('OBJECT ID') + BASE:T("Object ID ".._id) if not _id then -- this zone has no object ID BASE:E("**** Zone without object ID: "..ZoneName.." | Type: "..tostring(zone.ClassName)) @@ -235,4 +244,4 @@ end --@return #SCENERY self function SCENERY:Destroy() return self -end \ No newline at end of file +end From b96ebc1872abf9987e08ac6408503fb5cf1b14bc Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Tue, 25 Apr 2023 09:12:31 +0200 Subject: [PATCH 3/5] #SCENERY * Added update of Life0 value if `GetLife()`is called #SET_SCENERY * Added Documentation --- Moose Development/Moose/Core/Set.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index d9b80bee8..2ba9d95ac 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -7835,12 +7835,15 @@ do -- SET_SCENERY end --- Calculate current relative lifepoints of the SET objects, i.e. Life divided by Life0 as percentage value, eg 75 meaning 75% alive. - -- **CAVEAT**: Some objects change their life value or "hitpoints" **after** the first hit. Be aware that thus the relative life value might be > 100 after a hit. + -- **CAVEAT**: Some objects change their life value or "hitpoints" **after** the first hit. Hence we will adjust the Life0 value to 120% + -- of the last life value if life exceeds life0 ata any point. + -- Thus will will get a smooth percentage decrease, if you use this e.g. as success criteria for a bombing task. -- @param #SET_SCENERY self -- @return #number LifePoints function SET_SCENERY:GetRelativeLife() - local life0 = self:GetLife0() local life = self:GetLife() + local life0 = self:GetLife0() + self:T3(string.format("Set Lifepoints: %d life0 | %d life",life0,life)) local rlife = math.floor((life / life0) * 100) return rlife end From d8b80aab1ace1d13dfcf006eb05ec0d8c281136a Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 25 Apr 2023 21:20:16 +0200 Subject: [PATCH 4/5] Update Socket.lua - Added `SOCKET:SendTextToSpeech()` function --- Moose Development/Moose/Utilities/Socket.lua | 34 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Utilities/Socket.lua b/Moose Development/Moose/Utilities/Socket.lua index 1970c60a2..93d64e3a0 100644 --- a/Moose Development/Moose/Utilities/Socket.lua +++ b/Moose Development/Moose/Utilities/Socket.lua @@ -49,17 +49,19 @@ SOCKET = { -- @field #string BOMBRESULT Range bombing. -- @field #string STRAFERESULT Range strafeing result. -- @field #string LSOGRADE Airboss LSO grade. +-- @field #string TTS Text-To-Speech. SOCKET.DataType={ TEXT="moose_text", BOMBRESULT="moose_bomb_result", STRAFERESULT="moose_strafe_result", LSOGRADE="moose_lso_grade", + TTS="moose_text2speech" } --- SOCKET class version. -- @field #string version -SOCKET.version="0.2.0" +SOCKET.version="0.3.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -140,7 +142,7 @@ end --- Send a text message. -- @param #SOCKET self --- @param #string Text Test message. +-- @param #string Text Text message. -- @return #SOCKET self function SOCKET:SendText(Text) @@ -154,4 +156,32 @@ function SOCKET:SendText(Text) return self end +--- Send a text-to-speech message. +-- @param #SOCKET self +-- @param #string Text The text message to speek. +-- @param #number Provider The TTS provider: 0=Microsoft (default), 1=Google. +-- @param #string Voice The specific voice to use, e.g. `"Microsoft David Desktop"` or "`en-US-Standard-A`". If not set, the service will choose a voice based on the other parameters such as culture and gender. +-- @param #string Culture The Culture or language code, *e.g.* `"en-US"`. +-- @param #string Gender The Gender, *i.e.* "male", "female". Default "female". +-- @param #number Volume The volume. Microsoft: [0,100] default 50, Google: [-96, 10] default 0. +-- @return #SOCKET self +function SOCKET:SendTextToSpeech(Text, Provider, Voice, Culture, Gender, Volume) + + Text=Text or "Hello World!" + + local message={} + + message.command = SOCKET.DataType.TTS + message.text = Text + message.provider=Provider + message.voice = Voice + message.culture = Culture + message.gender = Gender + message.volume = Volume + + self:SendTable(message) + + return self +end + From 9b8154246f97680a9f616526be769480b240567f Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 5 May 2023 10:31:18 +0200 Subject: [PATCH 5/5] #COORDINATE * Added `IsInSteepArea()`and `IsInFlatArea()` --- Moose Development/Moose/Core/Point.lua | 49 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 18254b033..772de02bf 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -540,7 +540,7 @@ do -- COORDINATE local gotscenery=false local function EvaluateZone(ZoneObject) - BASE:T({ZoneObject}) + if ZoneObject then -- Get category of scanned object. @@ -3283,7 +3283,52 @@ do -- COORDINATE return self:GetTemperatureText( nil, Settings ) end - + + + --- Function to check if a coordinate is in a steep (>8% elevation) area of the map + -- @param #COORDINATE self + -- @param #number Radius (Optional) Radius to check around the coordinate, defaults to 50m (100m diameter) + -- @param #number Minelevation (Optional) Elevation from which on a area is defined as steep, defaults to 8% (8m height gain across 100 meters) + -- @return #boolen IsSteep If true, area is steep + -- @return #number MaxElevation Elevation in meters measured over 100m + function COORDINATE:IsInSteepArea(Radius,Minelevation) + local steep = false + local elev = Minelevation or 8 + local bdelta = 0 + local h0 = self:GetLandHeight() + local radius = Radius or 50 + local diam = radius * 2 + for i=0,150,30 do + local polar = math.fmod(i+180,360) + local c1 = self:Translate(radius,i,false,false) + local c2 = self:Translate(radius,polar,false,false) + local h1 = c1:GetLandHeight() + local h2 = c2:GetLandHeight() + local d1 = math.abs(h1-h2) + local d2 = math.abs(h0-h1) + local d3 = math.abs(h0-h2) + local dm = d1 > d2 and d1 or d2 + local dm1 = dm > d3 and dm or d3 + bdelta = dm1 > bdelta and dm1 or bdelta + self:T(string.format("d1=%d, d2=%d, d3=%d, max delta=%d",d1,d2,d3,bdelta)) + end + local steepness = bdelta / (radius / 100) + if steepness >= elev then steep = true end + return steep, math.floor(steepness) + end + + --- Function to check if a coordinate is in a flat (<8% elevation) area of the map + -- @param #COORDINATE self + -- @param #number Radius (Optional) Radius to check around the coordinate, defaults to 50m (100m diameter) + -- @param #number Minelevation (Optional) Elevation from which on a area is defined as steep, defaults to 8% (8m height gain across 100 meters) + -- @return #boolen IsFlat If true, area is flat + -- @return #number MaxElevation Elevation in meters measured over 100m + function COORDINATE:IsInFlatArea(Radius,Minelevation) + local steep, elev = self:IsInSteepArea(Radius,Minelevation) + local flat = not steep + return flat, elev + end + end do -- POINT_VEC3