mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#DynamicCargo - fix for FARP/Ship heights
This commit is contained in:
parent
37d321bb5c
commit
e61856197a
@ -857,11 +857,15 @@ end
|
|||||||
-- @return Wrapper.Client#CLIENT The client object.
|
-- @return Wrapper.Client#CLIENT The client object.
|
||||||
function DATABASE:AddClient( ClientName, Force )
|
function DATABASE:AddClient( ClientName, Force )
|
||||||
|
|
||||||
if not self.CLIENTS[ClientName] or Force == true then
|
local DCSUnitName = ClientName
|
||||||
self.CLIENTS[ClientName] = CLIENT:Register( ClientName )
|
|
||||||
|
if type(DCSUnitName) == "number" then DCSUnitName = string.format("%d",ClientName) end
|
||||||
|
|
||||||
|
if not self.CLIENTS[DCSUnitName] or Force == true then
|
||||||
|
self.CLIENTS[DCSUnitName] = CLIENT:Register( DCSUnitName )
|
||||||
end
|
end
|
||||||
|
|
||||||
return self.CLIENTS[ClientName]
|
return self.CLIENTS[DCSUnitName]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -902,8 +906,10 @@ end
|
|||||||
-- @param #DATABASE self
|
-- @param #DATABASE self
|
||||||
function DATABASE:AddPlayer( UnitName, PlayerName )
|
function DATABASE:AddPlayer( UnitName, PlayerName )
|
||||||
|
|
||||||
|
if type(UnitName) == "number" then UnitName = string.format("%d",UnitName) end
|
||||||
|
|
||||||
if PlayerName then
|
if PlayerName then
|
||||||
self:T( { "Add player for unit:", UnitName, PlayerName } )
|
self:I( { "Add player for unit:", UnitName, PlayerName } )
|
||||||
self.PLAYERS[PlayerName] = UnitName
|
self.PLAYERS[PlayerName] = UnitName
|
||||||
self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName )
|
self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName )
|
||||||
self.PLAYERSJOINED[PlayerName] = PlayerName
|
self.PLAYERSJOINED[PlayerName] = PlayerName
|
||||||
@ -911,6 +917,21 @@ function DATABASE:AddPlayer( UnitName, PlayerName )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get a PlayerName by UnitName from PLAYERS in DATABASE.
|
||||||
|
-- @param #DATABASE self
|
||||||
|
-- @return #string PlayerName
|
||||||
|
-- @return Wrapper.Unit#UNIT PlayerUnit
|
||||||
|
function DATABASE:_FindPlayerNameByUnitName(UnitName)
|
||||||
|
if UnitName then
|
||||||
|
for playername,unitname in pairs(self.PLAYERS) do
|
||||||
|
if unitname == UnitName and self.PLAYERUNITS[playername] and self.PLAYERUNITS[playername]:IsAlive() then
|
||||||
|
return playername, self.PLAYERUNITS[playername]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Deletes a player from the DATABASE based on the Player Name.
|
--- Deletes a player from the DATABASE based on the Player Name.
|
||||||
-- @param #DATABASE self
|
-- @param #DATABASE self
|
||||||
function DATABASE:DeletePlayer( UnitName, PlayerName )
|
function DATABASE:DeletePlayer( UnitName, PlayerName )
|
||||||
|
|||||||
@ -49,7 +49,7 @@
|
|||||||
DYNAMICCARGO = {
|
DYNAMICCARGO = {
|
||||||
ClassName = "DYNAMICCARGO",
|
ClassName = "DYNAMICCARGO",
|
||||||
verbose = 0,
|
verbose = 0,
|
||||||
testing = true,
|
testing = false,
|
||||||
Interval = 10,
|
Interval = 10,
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ DYNAMICCARGO.AircraftDimensions = {
|
|||||||
|
|
||||||
--- DYNAMICCARGO class version.
|
--- DYNAMICCARGO class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
DYNAMICCARGO.version="0.0.3"
|
DYNAMICCARGO.version="0.0.4"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- TODO list
|
-- TODO list
|
||||||
@ -171,6 +171,11 @@ function DYNAMICCARGO:Register(CargoName)
|
|||||||
_DYNAMICCARGO_HELOS = SET_CLIENT:New():FilterAlive():FilterFunction(DYNAMICCARGO._FilterHeloTypes):FilterStart()
|
_DYNAMICCARGO_HELOS = SET_CLIENT:New():FilterAlive():FilterFunction(DYNAMICCARGO._FilterHeloTypes):FilterStart()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.testing then
|
||||||
|
BASE:TraceOn()
|
||||||
|
BASE:TraceClass("DYNAMICCARGO")
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -341,11 +346,13 @@ function DYNAMICCARGO:_GetPossibleHeloNearby(pos,loading)
|
|||||||
local Playername = nil
|
local Playername = nil
|
||||||
for _,_helo in pairs (set or {}) do
|
for _,_helo in pairs (set or {}) do
|
||||||
local helo = _helo -- Wrapper.Client#CLIENT
|
local helo = _helo -- Wrapper.Client#CLIENT
|
||||||
local name = helo:GetPlayerName() or "None"
|
local name = helo:GetPlayerName() or _DATABASE:_FindPlayerNameByUnitName(helo:GetName()) or "None"
|
||||||
self:T(self.lid.." Checking: "..name)
|
self:T(self.lid.." Checking: "..name)
|
||||||
local hpos = helo:GetCoordinate()
|
local hpos = helo:GetCoordinate()
|
||||||
-- TODO Unloading via sling load?
|
-- TODO Unloading via sling load?
|
||||||
local inair = hpos.y-hpos:GetLandHeight() > 4 and true or false
|
--local inair = hpos.y-hpos:GetLandHeight() > 4.5 and true or false -- Standard FARP is 4.5m
|
||||||
|
local inair = helo:InAir()
|
||||||
|
self:T(self.lid.." InAir: AGL/InAir: "..hpos.y-hpos:GetLandHeight().."/"..tostring(inair))
|
||||||
local typename = helo:GetTypeName()
|
local typename = helo:GetTypeName()
|
||||||
if hpos and typename and inair == false then
|
if hpos and typename and inair == false then
|
||||||
local dimensions = DYNAMICCARGO.AircraftDimensions[typename]
|
local dimensions = DYNAMICCARGO.AircraftDimensions[typename]
|
||||||
@ -389,7 +396,7 @@ function DYNAMICCARGO:_UpdatePosition()
|
|||||||
---------------
|
---------------
|
||||||
if self.CargoState == DYNAMICCARGO.State.NEW then
|
if self.CargoState == DYNAMICCARGO.State.NEW then
|
||||||
local isloaded, client, playername = self:_GetPossibleHeloNearby(pos,true)
|
local isloaded, client, playername = self:_GetPossibleHeloNearby(pos,true)
|
||||||
self:T(self.lid.." moved! NEW -> LOADED by "..playername)
|
self:T(self.lid.." moved! NEW -> LOADED by "..tostring(playername))
|
||||||
self.CargoState = DYNAMICCARGO.State.LOADED
|
self.CargoState = DYNAMICCARGO.State.LOADED
|
||||||
self.Owner = playername
|
self.Owner = playername
|
||||||
_DATABASE:CreateEventDynamicCargoLoaded(self)
|
_DATABASE:CreateEventDynamicCargoLoaded(self)
|
||||||
@ -414,7 +421,7 @@ function DYNAMICCARGO:_UpdatePosition()
|
|||||||
isunloaded, client, playername = self:_GetPossibleHeloNearby(pos,false)
|
isunloaded, client, playername = self:_GetPossibleHeloNearby(pos,false)
|
||||||
end
|
end
|
||||||
if isunloaded then
|
if isunloaded then
|
||||||
self:T(self.lid.." moved! LOADED -> UNLOADED by "..playername)
|
self:T(self.lid.." moved! LOADED -> UNLOADED by "..tostring(playername))
|
||||||
self.CargoState = DYNAMICCARGO.State.UNLOADED
|
self.CargoState = DYNAMICCARGO.State.UNLOADED
|
||||||
self.Owner = playername
|
self.Owner = playername
|
||||||
_DATABASE:CreateEventDynamicCargoUnloaded(self)
|
_DATABASE:CreateEventDynamicCargoUnloaded(self)
|
||||||
|
|||||||
@ -1500,7 +1500,7 @@ function UNIT:InAir(NoHeloCheck)
|
|||||||
local UnitCategory = DCSUnit:getDesc().category
|
local UnitCategory = DCSUnit:getDesc().category
|
||||||
|
|
||||||
-- If DCS says that it is in air, check if this is really the case, since we might have landed on a building where inAir()=true but actually is not.
|
-- If DCS says that it is in air, check if this is really the case, since we might have landed on a building where inAir()=true but actually is not.
|
||||||
-- This is a workaround since DCS currently does not acknoledge that helos land on buildings.
|
-- This is a workaround since DCS currently does not acknowledge that helos land on buildings.
|
||||||
-- Note however, that the velocity check will fail if the ground is moving, e.g. on an aircraft carrier!
|
-- Note however, that the velocity check will fail if the ground is moving, e.g. on an aircraft carrier!
|
||||||
if UnitInAir==true and UnitCategory == Unit.Category.HELICOPTER and (not NoHeloCheck) then
|
if UnitInAir==true and UnitCategory == Unit.Category.HELICOPTER and (not NoHeloCheck) then
|
||||||
local VelocityVec3 = DCSUnit:getVelocity()
|
local VelocityVec3 = DCSUnit:getVelocity()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user