mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Stratego
This commit is contained in:
@@ -176,7 +176,7 @@ STRATEGO = {
|
|||||||
debug = false,
|
debug = false,
|
||||||
drawzone = false,
|
drawzone = false,
|
||||||
markzone = false,
|
markzone = false,
|
||||||
version = "0.2.3",
|
version = "0.2.4",
|
||||||
portweight = 3,
|
portweight = 3,
|
||||||
POIweight = 1,
|
POIweight = 1,
|
||||||
maxrunways = 3,
|
maxrunways = 3,
|
||||||
@@ -948,22 +948,22 @@ function STRATEGO:FindClosestConsolidationTarget(Startpoint,BaseWeight)
|
|||||||
return shortest,target, weight, coa
|
return shortest,target, weight, coa
|
||||||
end
|
end
|
||||||
|
|
||||||
--- [USER] Get the next best strategic target node with same or higher BaseWeight.
|
--- [USER] Get the next best strategic target node with same or higher Consolidated Weight.
|
||||||
-- @param #STRATEGO self
|
-- @param #STRATEGO self
|
||||||
-- @param #string Startpoint Name of start point.
|
-- @param #string Startpoint Name of start point.
|
||||||
-- @param #number BaseWeight Base weight of the node, e.g. the number of runways of an airbase or the weight of ports or POIs.
|
-- @param #number Weight Consolidated Weight of the node, i.e. the calculated weight of the node based on number of runways, connections and a weight factor.
|
||||||
-- @return #number ShortestDist Shortest distance found.
|
-- @return #number ShortestDist Shortest distance found.
|
||||||
-- @return #string Name Name of the target node.
|
-- @return #string Name Name of the target node.
|
||||||
-- @return #number Weight Consolidated weight of the target node, zero if none found.
|
-- @return #number Weight Consolidated weight of the target node, zero if none found.
|
||||||
-- @return #number Coalition Coaltion of the target.
|
-- @return #number Coalition Coaltion of the target.
|
||||||
function STRATEGO:FindClosestStrategicTarget(Startpoint,BaseWeight)
|
function STRATEGO:FindClosestStrategicTarget(Startpoint,Weight)
|
||||||
self:T(self.lid.."FindClosestStrategicTarget")
|
self:T(self.lid.."FindClosestStrategicTarget for "..Startpoint.." Weight "..Weight or 0)
|
||||||
-- find existing routes
|
-- find existing routes
|
||||||
local shortest = 1000*1000
|
local shortest = 1000*1000
|
||||||
local target = nil
|
local target = nil
|
||||||
local weight = 0
|
local weight = 0
|
||||||
local coa = nil
|
local coa = nil
|
||||||
if not BaseWeight then BaseWeight = self.maxrunways end
|
if not Weight then Weight = self.maxrunways end
|
||||||
local startpoint = string.gsub(Startpoint,"[%p%s]",".")
|
local startpoint = string.gsub(Startpoint,"[%p%s]",".")
|
||||||
for _,_route in pairs(self.routexists) do
|
for _,_route in pairs(self.routexists) do
|
||||||
if string.find(_route,startpoint,1,true) then
|
if string.find(_route,startpoint,1,true) then
|
||||||
@@ -971,7 +971,11 @@ function STRATEGO:FindClosestStrategicTarget(Startpoint,BaseWeight)
|
|||||||
local tname = string.gsub(_route,startpoint,"")
|
local tname = string.gsub(_route,startpoint,"")
|
||||||
local tname = string.gsub(tname,";","")
|
local tname = string.gsub(tname,";","")
|
||||||
local cname = self.easynames[tname]
|
local cname = self.easynames[tname]
|
||||||
if dist < shortest and self.airbasetable[cname].coalition ~= self.coalition and self.airbasetable[cname].baseweight >= BaseWeight then
|
local coa = self.airbasetable[cname].coalition
|
||||||
|
local tweight = self.airbasetable[cname].baseweight
|
||||||
|
local ttweight = self.airbasetable[cname].weight
|
||||||
|
self:T("Start -> End: "..startpoint.." -> "..cname)
|
||||||
|
if (dist < shortest) and (coa ~= self.coalition) and (tweight >= Weight) then
|
||||||
shortest = dist
|
shortest = dist
|
||||||
target = cname
|
target = cname
|
||||||
weight = self.airbasetable[cname].weight
|
weight = self.airbasetable[cname].weight
|
||||||
@@ -991,7 +995,7 @@ function STRATEGO:FindStrategicTargets()
|
|||||||
for _,_data in pairs(self.airbasetable) do
|
for _,_data in pairs(self.airbasetable) do
|
||||||
local data = _data -- #STRATEGO.Data
|
local data = _data -- #STRATEGO.Data
|
||||||
if data.coalition == self.coalition then
|
if data.coalition == self.coalition then
|
||||||
local dist, name, points, coa = self:FindClosestStrategicTarget(data.name,self.maxrunways)
|
local dist, name, points, coa = self:FindClosestStrategicTarget(data.name,data.weight)
|
||||||
if coa == coalition.side.NEUTRAL and points ~= 0 then
|
if coa == coalition.side.NEUTRAL and points ~= 0 then
|
||||||
local fpoints = points + self.NeutralBenefit
|
local fpoints = points + self.NeutralBenefit
|
||||||
local tries = 1
|
local tries = 1
|
||||||
|
|||||||
@@ -3414,7 +3414,7 @@ end
|
|||||||
-- FSM states
|
-- FSM states
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
--- On after Start event. Starts the warehouse. Addes event handlers and schedules status updates of reqests and queue.
|
--- On after Start event. Starts the warehouse. Adds event handlers and schedules status updates of reqests and queue.
|
||||||
-- @param #WAREHOUSE self
|
-- @param #WAREHOUSE self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
@@ -3595,6 +3595,7 @@ function WAREHOUSE:onafterStatus(From, Event, To)
|
|||||||
local Trepair=self:GetRunwayRepairtime()
|
local Trepair=self:GetRunwayRepairtime()
|
||||||
self:I(self.lid..string.format("Runway destroyed! Will be repaired in %d sec", Trepair))
|
self:I(self.lid..string.format("Runway destroyed! Will be repaired in %d sec", Trepair))
|
||||||
if Trepair==0 then
|
if Trepair==0 then
|
||||||
|
self.runwaydestroyed = nil
|
||||||
self:RunwayRepaired()
|
self:RunwayRepaired()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -5393,6 +5394,7 @@ function WAREHOUSE:onafterRunwayDestroyed(From, Event, To)
|
|||||||
|
|
||||||
self.runwaydestroyed=timer.getAbsTime()
|
self.runwaydestroyed=timer.getAbsTime()
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "RunwayRepaired" event.
|
--- On after "RunwayRepaired" event.
|
||||||
@@ -5408,6 +5410,7 @@ function WAREHOUSE:onafterRunwayRepaired(From, Event, To)
|
|||||||
|
|
||||||
self.runwaydestroyed=nil
|
self.runwaydestroyed=nil
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user