mirror of
https://github.com/weyne85/DML.git
synced 2025-10-29 16:57:49 +00:00
2.3.6
Yeller Model, The Debugger -x !, heloTroops' dropZones
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
cfxCargoReceiver = {}
|
||||
cfxCargoReceiver.version = "2.0.0"
|
||||
cfxCargoReceiver.version = "2.1.0"
|
||||
cfxCargoReceiver.ups = 1 -- once a second
|
||||
cfxCargoReceiver.maxDirectionRange = 500 -- in m. distance when cargo manager starts talking to pilots who are carrying that cargo
|
||||
cfxCargoReceiver.requiredLibs = {
|
||||
@@ -12,7 +12,10 @@ cfxCargoReceiver.requiredLibs = {
|
||||
- 2.0.0 no more cfxPlayer Dependency
|
||||
dmlZones, OOP
|
||||
clean-up
|
||||
|
||||
- 2.1.0 code maintenance
|
||||
cargo gets removed from mgr when touching ground
|
||||
switch to cargoReceiver!
|
||||
noBounce attribute
|
||||
|
||||
CargoReceiver is a zone enhancement you use to be automatically
|
||||
notified if a cargo was delivered inside the zone.
|
||||
@@ -25,26 +28,30 @@ cfxCargoReceiver.receiverZones = {}
|
||||
function cfxCargoReceiver.processReceiverZone(aZone) -- process attribute and add to zone
|
||||
-- since the attribute is there, simply set the zones
|
||||
-- isCargoReceiver flag and we are good
|
||||
aZone.isCargoReceiver = true
|
||||
-- we can add additional processing here
|
||||
aZone.autoRemove = aZone:getBoolFromZoneProperty("autoRemove", false) -- maybe add a removeDelay
|
||||
aZone.isCargoReceiver = true -- so all zones can detect this. Necessary?
|
||||
aZone.autoRemove = aZone:getBoolFromZoneProperty("autoRemove", false)
|
||||
aZone.removeDelay = aZone:getNumberFromZoneProperty("removeDelay", 1)
|
||||
if aZone.removeDelay < 1 then aZone.removeDelay = 1 end
|
||||
aZone.silent = aZone:getBoolFromZoneProperty("silent", false)
|
||||
|
||||
|
||||
-- new method support
|
||||
aZone.cargoMethod = aZone:getStringFromZoneProperty("method", "inc")
|
||||
if aZone:hasProperty("cargoMethod") then
|
||||
aZone.cargoMethod = aZone:getStringFromZoneProperty("cargoMethod", "inc")
|
||||
end
|
||||
|
||||
if aZone:hasProperty("f!") then
|
||||
-- save the names of cargos delivered to prevent 'bounce'
|
||||
aZone.cargosDelivered = {} -- by cargo name
|
||||
aZone.noBounce = aZone:getBoolFromZoneProperty("noBounce", true)
|
||||
if aZone:hasProperty("cargoReceiver!") then
|
||||
aZone.outReceiveFlag = aZone:getStringFromZoneProperty("cargoReceiver!", "*<none>")
|
||||
elseif aZone:hasProperty("f!") then
|
||||
aZone.outReceiveFlag = aZone:getStringFromZoneProperty("f!", "*<none>")
|
||||
elseif aZone:hasProperty("cargoReceived!") then
|
||||
aZone.outReceiveFlag = aZone:getStringFromZoneProperty( "cargoReceived!", "*<none>")
|
||||
end
|
||||
|
||||
if not aZone.outReceiveFlag then
|
||||
trigger.action.outText("+++crgR: receiver <" .. aZone.name .. "> has no output!", 30)
|
||||
end
|
||||
end
|
||||
|
||||
function cfxCargoReceiver.addReceiverZone(aZone)
|
||||
@@ -94,7 +101,7 @@ function cfxCargoReceiver.cargoEvent(event, object, name)
|
||||
|
||||
if not event then return end
|
||||
if event == "grounded" then
|
||||
-- this is actually the only one that interests us
|
||||
-- this is the only one that interests us
|
||||
if not object then
|
||||
return
|
||||
end
|
||||
@@ -106,21 +113,28 @@ function cfxCargoReceiver.cargoEvent(event, object, name)
|
||||
-- now invoke callbacks for all zones
|
||||
-- this is in
|
||||
for name, aZone in pairs(cfxCargoReceiver.receiverZones) do
|
||||
if cfxZones.pointInZone(loc, aZone) then
|
||||
if aZone:pointInZone(loc) then
|
||||
cfxCargoReceiver.invokeCallback("deliver", object, name, aZone)
|
||||
|
||||
-- set flags as indicated
|
||||
if aZone.outReceiveFlag then
|
||||
cfxZones.pollFlag(aZone.outReceiveFlag, aZone.cargoMethod, aZone)
|
||||
if aZone.noBounce then
|
||||
-- we only do this once for every named object
|
||||
if not aZone.cargosDelivered[name] then
|
||||
aZone.cargosDelivered[name] = true
|
||||
aZone:pollFlag(aZone.outReceiveFlag, aZone.cargoMethod)
|
||||
end
|
||||
else
|
||||
aZone:pollFlag(aZone.outReceiveFlag, aZone.cargoMethod)
|
||||
end
|
||||
end
|
||||
|
||||
if aZone.autoRemove then
|
||||
-- schedule this for in a few seconds?
|
||||
-- schedule this for in a few seconds
|
||||
local args = {}
|
||||
args.theObject = object
|
||||
args.theZone = aZone
|
||||
timer.scheduleFunction(cfxCargoReceiver.removeCargo, args, timer.getTime() + aZone.removeDelay)
|
||||
--object:destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -139,17 +153,13 @@ function cfxCargoReceiver.update()
|
||||
-- new we see if any of these are close to a delivery zone
|
||||
for idx, aCargo in pairs(liftedCargos) do
|
||||
local thePoint = aCargo:getPoint()
|
||||
local receiver = cfxZones.getClosestZone(
|
||||
thePoint,
|
||||
cfxCargoReceiver.receiverZones -- must be indexed by name
|
||||
)
|
||||
local receiver = cfxZones.getClosestZone(thePoint, cfxCargoReceiver.receiverZones) -- must be indexed by name
|
||||
-- we now check if we are in 'speaking range' and receiver can talk
|
||||
-- modify delta by distance to boundary, not
|
||||
-- center
|
||||
-- modify delta by distance to boundary, not center
|
||||
local delta = dcsCommon.distFlat(thePoint, cfxZones.getPoint(receiver))
|
||||
delta = delta - receiver.radius
|
||||
|
||||
if (receiver.silent == false) and
|
||||
if (not receiver.silent) and
|
||||
(delta < cfxCargoReceiver.maxDirectionRange) then
|
||||
-- this cargo can be talked down.
|
||||
-- find the player unit that is closest to in in hopes
|
||||
@@ -214,10 +224,14 @@ function cfxCargoReceiver.start()
|
||||
end
|
||||
|
||||
-- scan all zones for cargoReceiver flag
|
||||
local attrZones = cfxZones.getZonesWithAttributeNamed("cargoReceiver!")
|
||||
for k, aZone in pairs(attrZones) do
|
||||
cfxCargoReceiver.processReceiverZone(aZone)
|
||||
cfxCargoReceiver.addReceiverZone(aZone)
|
||||
end
|
||||
|
||||
-- old version, LEGACY
|
||||
local attrZones = cfxZones.getZonesWithAttributeNamed("cargoReceiver")
|
||||
|
||||
-- now create a spawner for all, add them to the spawner updater, and spawn for all zones that are not
|
||||
-- paused
|
||||
for k, aZone in pairs(attrZones) do
|
||||
cfxCargoReceiver.processReceiverZone(aZone) -- process attribute and add to zone
|
||||
cfxCargoReceiver.addReceiverZone(aZone) -- remember it so we can smoke it
|
||||
|
||||
Reference in New Issue
Block a user