Page 1 of 1

Targets Under Targets

Posted: Fri Nov 10, 2023 10:24 pm
by SeaQueen
Sometimes facilities are buried. Sometimes facilities are buried UNDER other facilities. For example, one might bury a C3 bunker underneath a SATCOM facility. It might or might not be desirable to strike the surface target, but regardless, you care enough about the thing underneath that it's worth the trouble of digging through the thing on top of it to get to the thing underneath it. How might one represent this in CMO using a combination of LUA and triggers? It's actually not very difficult.

Code: Select all

-- at scenario start
-- record the position of all the relevant surface level targets

aboveGroundBuilding = 'Z32OYR-0HMUR6J0UQ4E4'
satcomFacility = 'Z32OYR-0HMUU2TRG92A8'

surfaceTargetList = { aboveGroundBuilding,  satcomFacility }
surfaceTargetPositionList = {}

function recordSurfaceTargetPosition(targetGuid)
    surfaceTargetPosition = {latitude=99999, longitude=99999}  -- initialize to somewhere non-physical for easy error detection
    if(ScenEdit_GetUnit({guid=targetGuid}) ~= nil) then
        surfaceTarget = ScenEdit_GetUnit({guid=targetGuid})
        surfaceTargetPosition = {latitude=surfaceTarget.latitude, longitude=surfaceTarget.longitude}
        
    end
    return surfaceTargetPosition
end

for i, g in ipairs( surfaceTargetList ) do
    surfaceTargetPositionList[g] = recordSurfaceTargetPosition(g)
end

-- on destruction of the surface level facility run this
-- it "exposes" the target underneath the original target

targetPosition = surfaceTargetPositionList[ satcomFacility  ]

ScenEdit_AddUnit({side='RED', type='FACILITY', dbid=5, name="C3 Bunker A", latitude=targetPosition.latitude, longitude=targetPosition.longitude})

Re: Targets Under Targets

Posted: Tue Nov 14, 2023 10:20 am
by blu3s
Very nice, but I think you don't need to create/initialize the positions of what is underneath from the beginning, you can save the relations between surface/underneath facilities in a table, and when a unit is destroyed, search in this table if the facility destroyed has a record in the table, if there is, you create it in the same place where your destroyed unit was.

The table could look like this:

Code: Select all

bunkers = {
['GUID-SURFACE-FACILITY-1'] = {name='Name_underneath_facility1', dbid=134},
['GUID-SURFACE-FACILITY-2'] = {name='Name_underneath_facility2', dbid=135},

So when unit is destroyed you can do

Code: Select all

local unit_destroyed = ScenEdit_UnitX()
...

if bunkers[unit_destroyed.guid] then
local bunker_info = bunkers[unit_destroyed.guid]
ScenEdit_AddUnit({type='Faciltiy', side=unit_destroyed.side, name=bunker_info.name, dbid=bunker_info.dbid, latitude=unit_destroyed.latitude, longitude=unit_destroyed.longitude ... })
end