mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OPS Transport
This commit is contained in:
parent
4ffdf9e536
commit
65e852f341
@ -3149,8 +3149,9 @@ end
|
|||||||
--- Get coordinate of target. First unit/group of the set is used.
|
--- Get coordinate of target. First unit/group of the set is used.
|
||||||
-- @param #AUFTRAG self
|
-- @param #AUFTRAG self
|
||||||
-- @param Wrapper.Group#GROUP group Group.
|
-- @param Wrapper.Group#GROUP group Group.
|
||||||
|
-- @param #number randomradius Random radius in meters.
|
||||||
-- @return Core.Point#COORDINATE Coordinate where the mission is executed.
|
-- @return Core.Point#COORDINATE Coordinate where the mission is executed.
|
||||||
function AUFTRAG:GetMissionWaypointCoord(group)
|
function AUFTRAG:GetMissionWaypointCoord(group, randomradius)
|
||||||
|
|
||||||
-- Check if a coord has been explicitly set.
|
-- Check if a coord has been explicitly set.
|
||||||
if self.missionWaypointCoord then
|
if self.missionWaypointCoord then
|
||||||
@ -3166,7 +3167,9 @@ function AUFTRAG:GetMissionWaypointCoord(group)
|
|||||||
local alt=waypointcoord.y
|
local alt=waypointcoord.y
|
||||||
|
|
||||||
-- Add some randomization.
|
-- Add some randomization.
|
||||||
waypointcoord=ZONE_RADIUS:New("Temp", waypointcoord:GetVec2(), 1000):GetRandomCoordinate():SetAltitude(alt, false)
|
if randomradius then
|
||||||
|
waypointcoord=ZONE_RADIUS:New("Temp", waypointcoord:GetVec2(), randomradius):GetRandomCoordinate():SetAltitude(alt, false)
|
||||||
|
end
|
||||||
|
|
||||||
-- Set altitude of mission waypoint.
|
-- Set altitude of mission waypoint.
|
||||||
if self.missionAltitude then
|
if self.missionAltitude then
|
||||||
|
|||||||
@ -3009,6 +3009,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task)
|
|||||||
-- Parameters.
|
-- Parameters.
|
||||||
local zone=Task.dcstask.params.zone --Core.Zone#ZONE
|
local zone=Task.dcstask.params.zone --Core.Zone#ZONE
|
||||||
local Coordinate=zone:GetRandomCoordinate()
|
local Coordinate=zone:GetRandomCoordinate()
|
||||||
|
Coordinate:MarkToAll("Random Patrol Zone Coordinate")
|
||||||
local Speed=UTILS.KmphToKnots(Task.dcstask.params.speed or self.speedCruise)
|
local Speed=UTILS.KmphToKnots(Task.dcstask.params.speed or self.speedCruise)
|
||||||
local Altitude=Task.dcstask.params.altitude and UTILS.MetersToFeet(Task.dcstask.params.altitude) or nil
|
local Altitude=Task.dcstask.params.altitude and UTILS.MetersToFeet(Task.dcstask.params.altitude) or nil
|
||||||
|
|
||||||
@ -3695,15 +3696,21 @@ function OPSGROUP:RouteToMission(mission, delay)
|
|||||||
self:ScheduleOnce(delay, OPSGROUP.RouteToMission, self, mission)
|
self:ScheduleOnce(delay, OPSGROUP.RouteToMission, self, mission)
|
||||||
else
|
else
|
||||||
|
|
||||||
if self:IsDead() then
|
if self:IsDead() or self:IsStopped() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ID of current waypoint.
|
-- ID of current waypoint.
|
||||||
local uid=self:GetWaypointCurrent().uid
|
local uid=self:GetWaypointCurrent().uid
|
||||||
|
|
||||||
|
-- Random radius.
|
||||||
|
local randomradius=1000
|
||||||
|
if mission.type==AUFTRAG.Type.PATROLZONE then
|
||||||
|
randomradius=nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Get coordinate where the mission is executed.
|
-- Get coordinate where the mission is executed.
|
||||||
local waypointcoord=mission:GetMissionWaypointCoord(self.group)
|
local waypointcoord=mission:GetMissionWaypointCoord(self.group, randomradius)
|
||||||
|
|
||||||
-- Add enroute tasks.
|
-- Add enroute tasks.
|
||||||
for _,task in pairs(mission.enrouteTasks) do
|
for _,task in pairs(mission.enrouteTasks) do
|
||||||
@ -5423,6 +5430,39 @@ function OPSGROUP:_CheckDelivered(CargoTransport)
|
|||||||
return done
|
return done
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if all cargo of this transport assignment was delivered.
|
||||||
|
-- @param #OPSGROUP self
|
||||||
|
-- @param Ops.OpsTransport#OPSTRANSPORT CargoTransport The next due cargo transport or `nil`.
|
||||||
|
-- @return #boolean If true, all cargo was delivered.
|
||||||
|
function OPSGROUP:_CheckGoPickup(CargoTransport)
|
||||||
|
|
||||||
|
local done=true
|
||||||
|
for _,_cargo in pairs(CargoTransport.cargos) do
|
||||||
|
local cargo=_cargo --Ops.OpsGroup#OPSGROUP.CargoGroup
|
||||||
|
|
||||||
|
if self:CanCargo(cargo.opsgroup) then
|
||||||
|
|
||||||
|
if cargo.delivered then
|
||||||
|
-- This one is delivered.
|
||||||
|
elseif cargo.opsgroup==nil or cargo.opsgroup:IsDead() or cargo.opsgroup:IsStopped() then
|
||||||
|
-- This one is dead.
|
||||||
|
elseif cargo.opsgroup:IsLoaded() then
|
||||||
|
-- This one is loaded into a(nother) carrier.
|
||||||
|
else
|
||||||
|
done=false --Someone is not done!
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:T(self.lid..string.format("Cargotransport UID=%d Status=%s: delivered=%s", CargoTransport.uid, CargoTransport:GetState(), tostring(done)))
|
||||||
|
|
||||||
|
return done
|
||||||
|
end
|
||||||
|
|
||||||
--- Create a cargo transport assignment.
|
--- Create a cargo transport assignment.
|
||||||
-- @param #OPSGROUP self
|
-- @param #OPSGROUP self
|
||||||
-- @param Ops.OpsTransport#OPSTRANSPORT OpsTransport The troop transport assignment.
|
-- @param Ops.OpsTransport#OPSTRANSPORT OpsTransport The troop transport assignment.
|
||||||
@ -5517,6 +5557,32 @@ function OPSGROUP:GetFreeCargobay(UnitName, IncludeReserved)
|
|||||||
return Free
|
return Free
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get relative free cargo bay in percent.
|
||||||
|
-- @param #OPSGROUP self
|
||||||
|
-- @param #string UnitName Name of the unit. Default is of the whole group.
|
||||||
|
-- @param #boolean IncludeReserved If `false`, cargo weight that is only *reserved* is **not** counted. By default (`true` or `nil`), the reserved cargo is included.
|
||||||
|
-- @return #number Free cargo bay in percent.
|
||||||
|
function OPSGROUP:GetFreeCargobayRelative(UnitName, IncludeReserved)
|
||||||
|
|
||||||
|
local free=self:GetFreeCargobay(UnitName, IncludeReserved)
|
||||||
|
|
||||||
|
local total=self:GetWeightCargoMax(UnitName)
|
||||||
|
|
||||||
|
local percent=free/total*100
|
||||||
|
|
||||||
|
return percent
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get relative used (loaded) cargo bay in percent.
|
||||||
|
-- @param #OPSGROUP self
|
||||||
|
-- @param #string UnitName Name of the unit. Default is of the whole group.
|
||||||
|
-- @param #boolean IncludeReserved If `false`, cargo weight that is only *reserved* is **not** counted. By default (`true` or `nil`), the reserved cargo is included.
|
||||||
|
-- @return #number Used cargo bay in percent.
|
||||||
|
function OPSGROUP:GetUsedCargobayRelative(UnitName, IncludeReserved)
|
||||||
|
local free=self:GetFreeCargobayRelative(UnitName, IncludeReserved)
|
||||||
|
return 100-free
|
||||||
|
end
|
||||||
|
|
||||||
--- Get max weight of cargo (group) this group can load. This is the largest free cargo bay of any (not dead) element of the group.
|
--- Get max weight of cargo (group) this group can load. This is the largest free cargo bay of any (not dead) element of the group.
|
||||||
-- Optionally, you can calculate the current max weight possible, which accounts for currently loaded cargo.
|
-- Optionally, you can calculate the current max weight possible, which accounts for currently loaded cargo.
|
||||||
-- @param #OPSGROUP self
|
-- @param #OPSGROUP self
|
||||||
@ -6563,7 +6629,7 @@ function OPSGROUP:onafterUnloaded(From, Event, To)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Check everything was delivered (or is dead).
|
-- Check everything was delivered (or is dead).
|
||||||
local delivered=self:_CheckDelivered(self.cargoTransport)
|
local delivered=self:_CheckGoPickup(self.cargoTransport)
|
||||||
|
|
||||||
if not delivered then
|
if not delivered then
|
||||||
|
|
||||||
@ -9295,9 +9361,11 @@ end
|
|||||||
-- @return #OPSGROUP self
|
-- @return #OPSGROUP self
|
||||||
function OPSGROUP:_SetTemplate(Template)
|
function OPSGROUP:_SetTemplate(Template)
|
||||||
|
|
||||||
|
-- Set the template.
|
||||||
self.template=Template or self.group:GetTemplate()
|
self.template=Template or self.group:GetTemplate()
|
||||||
|
|
||||||
self:I(self.lid.."Setting group template")
|
-- Debug info.
|
||||||
|
self:T3(self.lid.."Setting group template")
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user