From d6363d0f8005c8a78e815a677875fc8bd3ff908a Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 12 Oct 2022 09:33:57 +0200 Subject: [PATCH] Misc --- Moose Development/Moose/Ops/CTLD.lua | 52 +++++++++++++-- Moose Development/Moose/Ops/PlayerTask.lua | 73 +++++++++++++++++++--- Moose Development/Moose/Ops/Target.lua | 6 +- Moose Development/Moose/Wrapper/Static.lua | 24 +++++++ 4 files changed, 139 insertions(+), 16 deletions(-) diff --git a/Moose Development/Moose/Ops/CTLD.lua b/Moose Development/Moose/Ops/CTLD.lua index 6ec93761c..a25f01a5e 100644 --- a/Moose Development/Moose/Ops/CTLD.lua +++ b/Moose Development/Moose/Ops/CTLD.lua @@ -23,7 +23,7 @@ -- @image OPS_CTLD.jpg -- Date: Feb 2022 --- Last Update Sep 2022 +-- Last Update October 2022 do @@ -343,7 +343,7 @@ CTLD_CARGO = { CRATE = "Crate", -- #string crate REPAIR = "Repair", -- #string repair ENGINEERS = "Engineers", -- #string engineers - STATIC = "Static", -- #string engineers + STATIC = "Static", -- #string statics } --- Function to create new CTLD_CARGO object. @@ -574,6 +574,10 @@ CTLD_CARGO = { end do +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +-- TODO CTLD +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + ------------------------------------------------------------------------- --- **CTLD** class, extends Core.Base#BASE, Core.Fsm#FSM -- @type CTLD @@ -1068,7 +1072,7 @@ CTLD.UnitTypes = { --- CTLD class version. -- @field #string version -CTLD.version="1.0.11" +CTLD.version="1.0.12" --- Instantiate a new CTLD. -- @param #CTLD self @@ -1476,6 +1480,19 @@ function CTLD:SetTroopDropZoneRadius(Radius) return self end +--- (User) Add a PLAYERTASK - FSM events will check success +-- @param #CTLD self +-- @param Ops.PlayerTask#PLAYERTASK PlayerTask +-- @return #CTLD self +function CTLD:AddPlayerTask(PlayerTask) + self:T(self.lid .. " AddPlayerTask") + if not self.PlayerTaskQueue then + self.PlayerTaskQueue = FIFO:New() + end + self.PlayerTaskQueue:Push(PlayerTask,PlayerTask.PlayerTaskNr) + return self +end + --- (Internal) Event handler function -- @param #CTLD self -- @param Core.Event#EVENTDATA EventData @@ -4244,7 +4261,7 @@ end end ------------------------------------------------------------------- --- FSM functions +-- TODO FSM functions ------------------------------------------------------------------- --- (Internal) FSM Function onafterStart. @@ -4445,9 +4462,30 @@ end -- @return #CTLD self function CTLD:onbeforeCratesBuild(From, Event, To, Group, Unit, Vehicle) self:T({From, Event, To}) + if Unit and Unit:IsPlayer() and self.PlayerTaskQueue then + local playername = Unit:GetPlayerName() + local dropcoord = Vehicle:GetCoordinate() or COORDINATE:New(0,0,0) + local dropvec2 = dropcoord:GetVec2() + self.PlayerTaskQueue:ForEach( + function (Task) + local task = Task -- Ops.PlayerTask#PLAYERTASK + local subtype = task:GetSubType() + -- right subtype? + if Event == subtype and not task:IsDone() then + local targetzone = task.Target:GetObject() -- Core.Zone#ZONE should be a zone in this case .... + if targetzone and targetzone.ClassName and string.match(targetzone.ClassName,"ZONE") and targetzone:IsVec2InZone(dropvec2) then + if task.Clients:HasUniqueID(playername) then + -- success + task:__Success(-1) + end + end + end + end + ) + end return self end - + --- (Internal) FSM Function onbeforeTroopsRTB. -- @param #CTLD self -- @param #string From State. @@ -4802,7 +4840,9 @@ end -- end do do --- **Hercules Cargo AIR Drop Events** by Anubis Yinepu -- Moose CTLD OO refactoring by Applevangelist --- +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +-- TODO CTLD_HERCULES +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -- This script will only work for the Herculus mod by Anubis, and only for **Air Dropping** cargo from the Hercules. -- Use the standard Moose CTLD if you want to unload on the ground. -- Payloads carried by pylons 11, 12 and 13 need to be declared in the Herculus_Loadout.lua file diff --git a/Moose Development/Moose/Ops/PlayerTask.lua b/Moose Development/Moose/Ops/PlayerTask.lua index 60eacc0dd..af4a207d0 100644 --- a/Moose Development/Moose/Ops/PlayerTask.lua +++ b/Moose Development/Moose/Ops/PlayerTask.lua @@ -1,11 +1,11 @@ ---- **Ops** - PlayerTask (mission) for Players. +---- **Ops** - PlayerTask (mission) for Players. -- -- ## Main Features: -- -- * Simplifies defining and executing Player tasks -- * FSM events when a mission is added, done, successful or failed, replanned -- * Ready to use SRS and localization --- * Mission locations can be smoked, flared and marked on the map +-- * Mission locations can be smoked, flared, illuminated and marked on the map -- -- === -- @@ -53,6 +53,7 @@ do -- @field #number coalition -- @field #string Freetext -- @field #string FreetextTTS +-- @field #string TaskSubType -- @extends Core.Fsm#FSM @@ -81,13 +82,14 @@ PLAYERTASK = { TaskController = nil, timestamp = 0, lastsmoketime = 0, - Freetext = nil, - FreetextTTS = nil, + Freetext = nil, + FreetextTTS = nil, + TaskSubType = nil, } --- PLAYERTASK class version. -- @field #string version -PLAYERTASK.version="0.1.5" +PLAYERTASK.version="0.1.6" --- Generic task condition. -- @type PLAYERTASK.Condition @@ -100,6 +102,7 @@ PLAYERTASK.version="0.1.5" -- @param Ops.Target#TARGET Target Target for this task -- @param #boolean Repeat Repeat this task if true (default = false) -- @param #number Times Repeat on failure this many times if Repeat is true (default = 1) +-- @param #string TTSType TTS friendly task type name -- @return #PLAYERTASK self function PLAYERTASK:New(Type, Target, Repeat, Times, TTSType) @@ -285,6 +288,24 @@ function PLAYERTASK:AddFreetext(Text) return self end +--- [USER] Set a task sub type description to this task. +-- @param #PLAYERTASK self +-- @param #string Type +-- @return #PLAYERTASK self +function PLAYERTASK:SetSubType(Type) + self:T(self.lid.."AddSubType") + self.TaskSubType = Type + return self +end + +--- [USER] Get task sub type description from this task. +-- @param #PLAYERTASK self +-- @return #string Type or nil +function PLAYERTASK:GetSubType() + self:T(self.lid.."GetSubType") + return self.TaskSubType +end + --- [USER] Get the free text description from this task. -- @param #PLAYERTASK self -- @return #string Text @@ -842,6 +863,7 @@ do -- @field #boolean TransmitOnlyWithPlayers -- @field #boolean buddylasing -- @field Ops.PlayerRecce#PLAYERRECCE PlayerRecce +-- @field #number Coalition -- @extends Core.Fsm#FSM --- @@ -1147,7 +1169,8 @@ PLAYERTASKCONTROLLER = { noflaresmokemenu = false, TransmitOnlyWithPlayers = true, buddylasing = false, - PlayerRecce = nil, + PlayerRecce = nil, + Coalition = nil, } --- @@ -1166,7 +1189,7 @@ PLAYERTASKCONTROLLER.Type = { --- Define new AUFTRAG Types AUFTRAG.Type.PRECISIONBOMBING = "Precision Bombing" AUFTRAG.Type.CTLD = "Combat Transport" -AUFTRAG.Type.CSAR "Combat Rescue" +AUFTRAG.Type.CSAR = "Combat Rescue" --- -- @type SeadAttributes @@ -2425,6 +2448,42 @@ function PLAYERTASKCONTROLLER:_AddTask(Target) return self end +--- [User] Add a PLAYERTASK object to the list of (open) tasks +-- @param #PLAYERTASKCONTROLLER self +-- @param Ops.PlayerTask#PLAYERTASK PlayerTask +-- @return #PLAYERTASKCONTROLLER self +-- @usage +-- Example to create a PLAYERTASK of type CTLD and give Players 10 minutes to complete: +-- +-- local newtask = PLAYERTASK:New(AUFTRAG.Type.CTLD,ZONE:Find("Unloading"),false,0,"Combat Transport") +-- newtask.Time0 = timer.getAbsTime() -- inject a timestamp for T0 +-- newtask:AddFreetext("Transport crates to the drop zone and build a vehicle in the next 10 minutes!") +-- +-- -- add a condition for failure - fail after 10 minutes +-- newtask:AddConditionFailure( +-- function() +-- local Time = timer.getAbsTime() +-- if Time - newtask.Time0 > 600 then +-- return true +-- end +-- return false +-- end +-- ) +-- +-- taskmanager:AddPlayerTaskToQueue(PlayerTask) +function PLAYERTASKCONTROLLER:AddPlayerTaskToQueue(PlayerTask) + self:T(self.lid.."AddPlayerTaskToQueue") + if PlayerTask and PlayerTask.ClassName and PlayerTask.ClassName == "PLAYERTASK" then + PlayerTask:_SetController(self) + PlayerTask:SetCoalition(self.Coalition) + self.TaskQueue:Push(PlayerTask) + self:__TaskAdded(-1,PlayerTask) + else + self:E(self.lid.."***** NO valid PAYERTASK object sent!") + end + return self +end + --- [Internal] Join a player to a task -- @param #PLAYERTASKCONTROLLER self -- @param Wrapper.Group#GROUP Group diff --git a/Moose Development/Moose/Ops/Target.lua b/Moose Development/Moose/Ops/Target.lua index 167c042f9..901dcb5e4 100644 --- a/Moose Development/Moose/Ops/Target.lua +++ b/Moose Development/Moose/Ops/Target.lua @@ -147,7 +147,7 @@ _TARGETID=0 --- TARGET class version. -- @field #string version -TARGET.version="0.5.3" +TARGET.version="0.5.4" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -830,8 +830,8 @@ function TARGET:_AddObject(Object) if static and static:IsAlive() then - target.Life0=1 - target.Life=1 + target.Life0=static:GetLife0() + target.Life=static:GetLife() target.N0=target.N0+1 table.insert(self.elements, target.Name) diff --git a/Moose Development/Moose/Wrapper/Static.lua b/Moose Development/Moose/Wrapper/Static.lua index 08c9a0bce..fef0b098d 100644 --- a/Moose Development/Moose/Wrapper/Static.lua +++ b/Moose Development/Moose/Wrapper/Static.lua @@ -55,9 +55,33 @@ STATIC = { function STATIC:Register( StaticName ) local self = BASE:Inherit( self, POSITIONABLE:New( StaticName ) ) self.StaticName = StaticName + + local DCSStatic = StaticObject.getByName( self.StaticName ) + if DCSStatic then + local Life0 = DCSStatic:getLife() or 1 + self.Life0 = Life0 + end + return self end +--- Get initial life points +-- @param #STATIC self +-- @return #number lifepoints +function STATIC:GetLife0() + return self.Life0 or 1 +end + +--- Get current life points +-- @param #STATIC self +-- @return #number lifepoints or nil +function STATIC:GetLife() + local DCSStatic = StaticObject.getByName( self.StaticName ) + if DCSStatic then + return DCSStatic:getLife() or 1 + end + return nil +end --- Finds a STATIC from the _DATABASE using a DCSStatic object. -- @param #STATIC self