function TestSave(bpid, army, e) if string.lower(bpid) == 'uel0307' then return nil end LOG('Saving shield') local id = safecall('SAVE: Bad entity', e.GetEntityId, e) if not id then return end LOG('position') local x, y, z = unpack( e:GetPosition() ) LOG('heading (radians -> degrees)') local heading = e:GetHeading()* 180/math.pi -- join data into table local data = {tonumber(id), x, y, z, heading} -- get unit data if e.IsUnitState ~= nil then -- this is a unit LOG('unit layer (air,land,sea,sub,etc)') local layer = GetLayerId( e:GetCurrentLayer() ) LOG('unit health') local health = e:GetHealth() LOG('unit experience level') local xp = e.VeteranLevel LOG('fire state (how the unit assigns attack priorities)') local fire_state = e:GetFireState() -- state (what the unit is doing) local state = 0 -- focus (entity we are helping, attacking or following or location we move towards) local focus = 0 -- data specific to special units and circumstances local misc = {} LOG('check if paused') if e:IsPaused() then misc.paused=1 end LOG('get factory data') if EntityCategoryContains(categories.FACTORY, e) then misc.rally = e:GetRallyPoint() end LOG('get stored missiles') local nukeammo = e:GetNukeSiloAmmoCount() if nukeammo > 0 then misc.nukeammo = nukeammo end local tacammo = e:GetTacticalSiloAmmoCount() if tacammo > 0 then misc.tacammo = tacammo end LOG('get fuel') if EntityCategoryContains(categories.AIR*categories.MOBILE, e) then misc.fuel = e:GetFuelRatio() end -- get information on what the unit is currently doing -- order is important because for simplicity we only allow one state per unit LOG('check if dead') if e:IsDead() then -- Ignore deadites elseif e:IsUnitState('Enhancing') then LOG('enhancing') state = GetStateId('Enhancing') -- CommandData is put here by custom ScriptTask.OnCreate misc.enhancement = e.commandData.Enhancement misc.progress = e:GetWorkProgress() elseif e:IsUnitState('SiloBuildingAmmo') then LOG('SiloBuildingAmmo') state = GetStateId('SiloBuildingAmmo') misc.progress = e:GetWorkProgress() elseif e:IsUnitState('Upgrading') then LOG('Upgrading') state = GetStateId('Upgrading') focus = e.UnitBeingBuilt:GetEntityId() elseif e:IsUnitState('Guarding') then LOG('Guarding') local guarding = e:GetGuardedUnit() if guarding then LOG('guarding '..DumpUnit(guarding)) state = GetStateId('Guarding') focus = guarding:GetEntityId() end elseif e:IsUnitState('Building') then LOG('Building') local building = e.UnitBeingBuilt if building then LOG('building '..DumpUnit(building)) state = GetStateId('Building') focus = building:GetEntityId() end elseif e:IsUnitState('BeingBuilt') then LOG('beingbuilt') local builder = e:GetParent() if builder then --LOG('built by '..DumpUnit(builder)) state = GetStateId('BeingBuilt') focus = builder:GetEntityId() end elseif e:IsUnitState('Attached') then LOG('attached') local parent = e:GetParent() if parent then --LOG('attached to '..DumpUnit(parent)) state = GetStateId('Attached') focus = parent:GetEntityId() end elseif e:IsUnitState('Patrolling') then LOG('patrolling') local nav = e:GetNavigator() if nav then state = GetStateId('Patrolling') focus = nav:GetGoalPos() end elseif e:IsUnitState('Repairing') then LOG('repairing') local repairee = e:GetFocusUnit() if repairee then --LOG('repairee '..DumpUnit(repairee)) state = GetStateId('Repairing') focus = repairee:GetEntityId() end elseif e:IsUnitState('Attacking') then LOG('repairing') local target = e:GetTargetEntity() if target then LOG('target '..DumpUnit(target)) state = GetStateId('Attacking') focus = target:GetEntityId() end elseif e:IsUnitState('Moving') then LOG('moving') local nav = e:GetNavigator() if nav then state = GetStateId('Moving') focus = nav:GetGoalPos() end end end end