mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
RAT
- Uncontrolled
This commit is contained in:
parent
21412e0061
commit
833206a3b5
@ -292,9 +292,10 @@ SPAWN = {
|
|||||||
|
|
||||||
--- Enumerator for spawns at airbases
|
--- Enumerator for spawns at airbases
|
||||||
-- @type SPAWN.Takeoff
|
-- @type SPAWN.Takeoff
|
||||||
-- @extends Wrapper.Group#GROUP.Takeoff
|
-- @field #number Air Take off happens in air.
|
||||||
|
-- @field #number Runway Spawn on runway. Does not work in MP!
|
||||||
-- @field #SPAWN.Takeoff Takeoff
|
-- @field #number Hot Spawn at parking with engines on.
|
||||||
|
-- @field #number Cold Spawn at parking with engines off.
|
||||||
SPAWN.Takeoff = {
|
SPAWN.Takeoff = {
|
||||||
Air = 1,
|
Air = 1,
|
||||||
Runway = 2,
|
Runway = 2,
|
||||||
|
|||||||
@ -432,7 +432,7 @@ RAT={
|
|||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
--- Categories of the RAT class.
|
--- Categories of the RAT class.
|
||||||
-- @list cat
|
-- @type RAT.cat
|
||||||
-- @field #string plane Plane.
|
-- @field #string plane Plane.
|
||||||
-- @field #string heli Heli.
|
-- @field #string heli Heli.
|
||||||
RAT.cat={
|
RAT.cat={
|
||||||
@ -441,7 +441,7 @@ RAT.cat={
|
|||||||
}
|
}
|
||||||
|
|
||||||
--- RAT waypoint type.
|
--- RAT waypoint type.
|
||||||
-- @list wp
|
-- @type RAT.wp
|
||||||
RAT.wp={
|
RAT.wp={
|
||||||
coldorhot=0,
|
coldorhot=0,
|
||||||
air=1,
|
air=1,
|
||||||
@ -457,7 +457,7 @@ RAT.wp={
|
|||||||
}
|
}
|
||||||
|
|
||||||
--- RAT aircraft status.
|
--- RAT aircraft status.
|
||||||
-- @list status
|
-- @type RAT.status
|
||||||
RAT.status={
|
RAT.status={
|
||||||
-- Waypoint states.
|
-- Waypoint states.
|
||||||
Departure="At departure point",
|
Departure="At departure point",
|
||||||
@ -506,7 +506,7 @@ RAT.status={
|
|||||||
-- @field #number nrespawn Number of respawns.
|
-- @field #number nrespawn Number of respawns.
|
||||||
|
|
||||||
--- RAT friendly coalitions.
|
--- RAT friendly coalitions.
|
||||||
-- @list coal
|
-- @type RAT.coal
|
||||||
RAT.coal={
|
RAT.coal={
|
||||||
same="same",
|
same="same",
|
||||||
sameonly="sameonly",
|
sameonly="sameonly",
|
||||||
@ -514,7 +514,7 @@ RAT.coal={
|
|||||||
}
|
}
|
||||||
|
|
||||||
--- RAT unit conversions.
|
--- RAT unit conversions.
|
||||||
-- @list unit
|
-- @type RAT.unit
|
||||||
RAT.unit={
|
RAT.unit={
|
||||||
ft2meter=0.305,
|
ft2meter=0.305,
|
||||||
kmh2ms=0.278,
|
kmh2ms=0.278,
|
||||||
@ -524,7 +524,7 @@ RAT.unit={
|
|||||||
}
|
}
|
||||||
|
|
||||||
--- RAT rules of engagement.
|
--- RAT rules of engagement.
|
||||||
-- @list ROE
|
-- @type RAT.ROE
|
||||||
RAT.ROE={
|
RAT.ROE={
|
||||||
weaponhold="hold",
|
weaponhold="hold",
|
||||||
weaponfree="free",
|
weaponfree="free",
|
||||||
@ -532,7 +532,7 @@ RAT.ROE={
|
|||||||
}
|
}
|
||||||
|
|
||||||
--- RAT reaction to threat.
|
--- RAT reaction to threat.
|
||||||
-- @list ROT
|
-- @type RAT.ROT
|
||||||
RAT.ROT={
|
RAT.ROT={
|
||||||
evade="evade",
|
evade="evade",
|
||||||
passive="passive",
|
passive="passive",
|
||||||
@ -1523,6 +1523,15 @@ function RAT:SetSpawnInterval(interval)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Set max number of groups that will be spawned. When this limit is reached, no more RAT groups are spawned.
|
||||||
|
-- @param #RAT self
|
||||||
|
-- @param #number Nmax Max number of groups. Default `nil`=unlimited.
|
||||||
|
-- @return #RAT RAT self object.
|
||||||
|
function RAT:SetSpawnLimit(Nmax)
|
||||||
|
self.NspawnMax=Nmax
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- Make aircraft respawn the moment they land rather than at engine shut down.
|
--- Make aircraft respawn the moment they land rather than at engine shut down.
|
||||||
-- @param #RAT self
|
-- @param #RAT self
|
||||||
-- @param #number delay (Optional) Delay in seconds until respawn happens after landing. Default is 1 second. Minimum is 1 second.
|
-- @param #number delay (Optional) Delay in seconds until respawn happens after landing. Default is 1 second. Minimum is 1 second.
|
||||||
@ -2225,8 +2234,16 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
|||||||
livery=nil
|
livery=nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- We set the aircraft to uncontrolled if the departure airbase has a FLIGHTCONTROL.
|
||||||
|
local uncontrolled=self.uncontrolled
|
||||||
|
local isFlightcontrol=self:_IsFlightControlAirbase(departure)
|
||||||
|
if takeoff~=RAT.wp.air and departure and isFlightcontrol then
|
||||||
|
takeoff=RAT.wp.cold
|
||||||
|
uncontrolled=true
|
||||||
|
end
|
||||||
|
|
||||||
-- Modify the spawn template to follow the flight plan.
|
-- Modify the spawn template to follow the flight plan.
|
||||||
local successful=self:_ModifySpawnTemplate(waypoints, livery, _lastpos, departure, takeoff, parkingdata)
|
local successful=self:_ModifySpawnTemplate(waypoints, livery, _lastpos, departure, takeoff, parkingdata, uncontrolled)
|
||||||
if not successful then
|
if not successful then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -2263,7 +2280,7 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Add flight (if there is no FC at the airbase)
|
-- Add flight (if there is no FC at the airbase)
|
||||||
if not _DATABASE:GetFlightControl(airbasename) then
|
if not self:_IsFlightControlAirbase(airbasename) then
|
||||||
self:_ATCAddFlight(groupname, airbasename)
|
self:_ATCAddFlight(groupname, airbasename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2273,6 +2290,13 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
|||||||
self:_PlaceMarkers(waypoints, wpdesc, self.SpawnIndex)
|
self:_PlaceMarkers(waypoints, wpdesc, self.SpawnIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Set group ready for takeoff at the FLIGHTCONTROL (if we do not do via a scheduler).
|
||||||
|
if isFlightcontrol and not self.activate_uncontrolled then
|
||||||
|
local N=math.random(120)
|
||||||
|
self:T(self.lid..string.format("Flight will be ready for takeoff in %d seconds", N))
|
||||||
|
flightgroup:SetReadyForTakeoff(true, N)
|
||||||
|
end
|
||||||
|
|
||||||
-- Set group to be invisible.
|
-- Set group to be invisible.
|
||||||
if self.invisible then
|
if self.invisible then
|
||||||
flightgroup:SetDefaultInvisible(true)
|
flightgroup:SetDefaultInvisible(true)
|
||||||
@ -2319,7 +2343,7 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
|||||||
ratcraft.wpstatus=wpstatus
|
ratcraft.wpstatus=wpstatus
|
||||||
|
|
||||||
-- Aircraft is active or spawned in uncontrolled state.
|
-- Aircraft is active or spawned in uncontrolled state.
|
||||||
ratcraft.active=not self.uncontrolled
|
ratcraft.active=not uncontrolled
|
||||||
|
|
||||||
-- Set status to spawned. This will be overwritten in birth event.
|
-- Set status to spawned. This will be overwritten in birth event.
|
||||||
ratcraft.status=RAT.status.Spawned
|
ratcraft.status=RAT.status.Spawned
|
||||||
@ -2466,6 +2490,31 @@ function RAT:_SpawnWithRoute(_departure, _destination, _takeoff, _landing, _live
|
|||||||
return self.SpawnIndex
|
return self.SpawnIndex
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if a given airbase has a FLIGHTCONTROL.
|
||||||
|
-- @param #RAT self
|
||||||
|
-- @param Wrapper.Airbase#AIRBASE airbase The airbase.
|
||||||
|
-- @return #boolean `true` if the airbase has a FLIGHTCONTROL.
|
||||||
|
function RAT:_IsFlightControlAirbase(airbase)
|
||||||
|
|
||||||
|
if type(airbase)=="table" then
|
||||||
|
airbase=airbase:GetName()
|
||||||
|
end
|
||||||
|
|
||||||
|
if airbase then
|
||||||
|
|
||||||
|
local fc=_DATABASE:GetFlightControl(airbase)
|
||||||
|
|
||||||
|
if fc then
|
||||||
|
self:T(self.lid..string.format("Airbase %s has a FLIGHTCONTROL running", airbase))
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
--- Clear flight for landing. Sets tigger value to 1.
|
--- Clear flight for landing. Sets tigger value to 1.
|
||||||
-- @param #RAT self
|
-- @param #RAT self
|
||||||
@ -3693,22 +3742,12 @@ function RAT:_GetAirportsOfCoalition()
|
|||||||
local airport=_airport --Wrapper.Airbase#AIRBASE
|
local airport=_airport --Wrapper.Airbase#AIRBASE
|
||||||
local category=airport:GetAirbaseCategory()
|
local category=airport:GetAirbaseCategory()
|
||||||
if airport:GetCoalition()==coalition then
|
if airport:GetCoalition()==coalition then
|
||||||
-- Planes cannot land on FARPs.
|
|
||||||
--local condition1=self.category==RAT.cat.plane and airport:GetTypeName()=="FARP"
|
|
||||||
local condition1=self.category==RAT.cat.plane and category==Airbase.Category.HELIPAD
|
|
||||||
-- Planes cannot land on ships.
|
|
||||||
--local condition2=self.category==RAT.cat.plane and airport:GetCategory()==1
|
|
||||||
local condition2=self.category==RAT.cat.plane and category==Airbase.Category.SHIP
|
|
||||||
|
|
||||||
-- Check that airport has the requested terminal types.
|
-- Planes cannot land on FARPs.
|
||||||
-- NOT good here because we would also not allow any airport zones!
|
local condition1=self.category==RAT.cat.plane and category==Airbase.Category.HELIPAD
|
||||||
--[[
|
|
||||||
local nspots=1
|
-- Planes cannot land on ships.
|
||||||
if self.termtype then
|
local condition2=self.category==RAT.cat.plane and category==Airbase.Category.SHIP
|
||||||
nspots=airport:GetParkingSpotsNumber(self.termtype)
|
|
||||||
end
|
|
||||||
local condition3 = nspots==0
|
|
||||||
]]
|
|
||||||
|
|
||||||
if not (condition1 or condition2) then
|
if not (condition1 or condition2) then
|
||||||
table.insert(self.airports, airport)
|
table.insert(self.airports, airport)
|
||||||
@ -5108,8 +5147,9 @@ end
|
|||||||
-- @param Wrapper.Airbase#AIRBASE departure Departure airbase or zone.
|
-- @param Wrapper.Airbase#AIRBASE departure Departure airbase or zone.
|
||||||
-- @param #number takeoff Takeoff type.
|
-- @param #number takeoff Takeoff type.
|
||||||
-- @param #table parkingdata Parking data, i.e. parking spot coordinates and terminal ids for all units of the group.
|
-- @param #table parkingdata Parking data, i.e. parking spot coordinates and terminal ids for all units of the group.
|
||||||
|
-- @param #boolean uncontrolled If `true`, group is spawned uncontrolled.
|
||||||
-- @return #boolean True if modification was successful or nil if not, e.g. when no parking space was found and spawn in air is disabled.
|
-- @return #boolean True if modification was successful or nil if not, e.g. when no parking space was found and spawn in air is disabled.
|
||||||
function RAT:_ModifySpawnTemplate(waypoints, livery, spawnplace, departure, takeoff, parkingdata)
|
function RAT:_ModifySpawnTemplate(waypoints, livery, spawnplace, departure, takeoff, parkingdata, uncontrolled)
|
||||||
self:F2({waypoints=waypoints, livery=livery, spawnplace=spawnplace, departure=departure, takeoff=takeoff, parking=parkingdata})
|
self:F2({waypoints=waypoints, livery=livery, spawnplace=spawnplace, departure=departure, takeoff=takeoff, parking=parkingdata})
|
||||||
|
|
||||||
-- The 3D vector of the first waypoint, i.e. where we actually spawn the template group.
|
-- The 3D vector of the first waypoint, i.e. where we actually spawn the template group.
|
||||||
@ -5160,9 +5200,9 @@ function RAT:_ModifySpawnTemplate(waypoints, livery, spawnplace, departure, take
|
|||||||
self:T(SpawnTemplate)
|
self:T(SpawnTemplate)
|
||||||
|
|
||||||
-- Spawn aircraft in uncontrolled state.
|
-- Spawn aircraft in uncontrolled state.
|
||||||
if self.uncontrolled then
|
if self.uncontrolled or uncontrolled then
|
||||||
-- This is used in the SPAWN:SpawnWithIndex() function. Some values are overwritten there!
|
-- This is used in the SPAWN:SpawnWithIndex() function. Some values are overwritten there!
|
||||||
self.SpawnUnControlled=true
|
--self.SpawnUnControlled=true
|
||||||
SpawnTemplate.uncontrolled=true
|
SpawnTemplate.uncontrolled=true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -5348,9 +5388,6 @@ function RAT:_ModifySpawnTemplate(waypoints, livery, spawnplace, departure, take
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- new
|
|
||||||
|
|
||||||
-- Translate the position of the Group Template to the Vec3.
|
-- Translate the position of the Group Template to the Vec3.
|
||||||
for UnitID = 1, nunits do
|
for UnitID = 1, nunits do
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user