Skip to content

Commit 09f99b9

Browse files
Merge branch 'develop' of https://github.com/FlightControl-Master/MOOSE into develop
2 parents ca7d3a4 + ff5205e commit 09f99b9

5 files changed

Lines changed: 425 additions & 33 deletions

File tree

Moose Development/Moose/Core/Set.lua

Lines changed: 145 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ do -- SET_BASE
6262
-- @field #table List Unused table.
6363
-- @field Core.Scheduler#SCHEDULER CallScheduler
6464
-- @field #SET_BASE.Filters Filter Filters
65-
-- @field #booleaen filterNoRegex If true, FilterPrefix ignores special characters and evaluates plain string.
65+
-- @field #boolean filterNoRegex If true, FilterPrefix ignores special characters and evaluates plain string. Defaults to false.
66+
-- @field #boolean filterReplaceDash If true then if filterNoRegex is false, replace dashes with regex pattern friendly pattern. Defaults to true
6667
-- @extends Core.Base#BASE
6768

6869
--- The @{Core.Set#SET_BASE} class defines the core functions that define a collection of objects.
@@ -102,6 +103,7 @@ do -- SET_BASE
102103
},
103104
},
104105
filterNoRegex=false,
106+
filterReplaceDash=true,
105107
}
106108

107109
--- Filters
@@ -256,7 +258,8 @@ do -- SET_BASE
256258
-- @return #boolean Returns `true`, if the pattern is contained in the name and false otherwise.
257259
function SET_BASE:_SearchPattern(Name, Pattern, NoRegex, ReplaceDash)
258260
NoRegex=NoRegex or self.filterNoRegex
259-
if ReplaceDash==true then
261+
ReplaceDash=ReplaceDash or self.filterReplaceDash
262+
if ReplaceDash==true and NoRegex ~= true then
260263
-- Not sure why "-" is replaced by "%-" ?! - So we can still match group names with a dash in them
261264
-- reason is that the string is interpreted as a pattern and "-" is a special character then. For interpreting it as a string, fourth parameter needs to be set to true.
262265
Pattern=Pattern:gsub("-", "%%-")
@@ -265,6 +268,16 @@ do -- SET_BASE
265268
return contain
266269
end
267270

271+
---Set Regex Options for FilterPrefix function.
272+
-- @param #SET_BASE self
273+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
274+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
275+
-- @return #SET_BASE self
276+
function SET_BASE:FilterSetRegex(NoRegex,ReplaceDash)
277+
if NoRegex ~= nil then self.filterNoRegex = NoRegex end
278+
self.filterReplaceDash = ReplaceDash or true
279+
return self
280+
end
268281

269282
--- Gets the Set.
270283
-- @param #SET_BASE self
@@ -1198,7 +1211,21 @@ do
11981211
-- @param #SET_GROUP self
11991212
-- @return #SET_GROUP self
12001213

1201-
1214+
---Set Regex Options for FilterPrefix function.
1215+
-- @function [parent=#SET_GROUP] FilterSetRegex
1216+
-- @param #SET_GROUP self
1217+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
1218+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
1219+
-- @return #SET_GROUP self
1220+
1221+
--- Builds a set of objects of same coalitions.
1222+
-- Possible current coalitions are red, blue and neutral.
1223+
-- @function [parent=#SET_GROUP] FilterCoalitions
1224+
-- @param #SET_GROUP self
1225+
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral" and coalition.side.RED, coalition.side.BLUE,coalition.side.NEUTRAL
1226+
-- @param #boolean Clear If `true`, clear any previously defined filters.
1227+
-- @return #SET_GROUP self
1228+
12021229
end
12031230

12041231
--- Get a *new* set table that only contains alive groups.
@@ -2116,7 +2143,7 @@ do
21162143
if self.Filter.GroupPrefixes and MGroupInclude then
21172144
local MGroupPrefix = false
21182145
for GroupPrefixId, GroupPrefix in pairs(self.Filter.GroupPrefixes) do
2119-
if self:_SearchPattern(MGroup:GetName(), GroupPrefix, false, true) then
2146+
if self:_SearchPattern(MGroup:GetName(), GroupPrefix, self.filterNoRegex, self.filterReplaceDash) then
21202147
MGroupPrefix = true
21212148
end
21222149
end
@@ -2337,6 +2364,26 @@ do -- SET_UNIT
23372364
-- @param #SET_UNIT self
23382365
-- @return #SET_UNIT self
23392366

2367+
--- Filter the set once
2368+
-- @function [parent=#SET_UNIT] FilterOnce
2369+
-- @param #SET_UNIT self
2370+
-- @return #SET_UNIT self
2371+
2372+
---Set Regex Options for FilterPrefix function.
2373+
-- @function [parent=#SET_UNIT] FilterSetRegex
2374+
-- @param #SET_UNIT self
2375+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
2376+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
2377+
-- @return #SET_UNIT self
2378+
2379+
--- Builds a set of objects of same coalitions.
2380+
-- Possible current coalitions are red, blue and neutral.
2381+
-- @function [parent=#SET_UNIT] FilterCoalitions
2382+
-- @param #SET_UNIT self
2383+
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral" and coalition.side.RED, coalition.side.BLUE,coalition.side.NEUTRAL
2384+
-- @param #boolean Clear If `true`, clear any previously defined filters.
2385+
-- @return #SET_UNIT self
2386+
23402387
return self
23412388
end
23422389

@@ -3348,7 +3395,7 @@ do -- SET_UNIT
33483395
if self.Filter.UnitPrefixes and MUnitInclude then
33493396
local MUnitPrefix = false
33503397
for UnitPrefixId, UnitPrefix in pairs(self.Filter.UnitPrefixes) do
3351-
if self:_SearchPattern(MUnit:GetName(), UnitPrefix, false, true) then
3398+
if self:_SearchPattern(MUnit:GetName(), UnitPrefix, self.filterNoRegex, self.filterReplaceDash) then
33523399
MUnitPrefix = true
33533400
end
33543401
end
@@ -3544,7 +3591,27 @@ do -- SET_STATIC
35443591

35453592
-- Inherits from BASE
35463593
local self = BASE:Inherit(self, SET_BASE:New(_DATABASE.STATICS)) -- Core.Set#SET_STATIC
3547-
3594+
3595+
--- Filter the set once
3596+
-- @function [parent=#SET_STATIC] FilterOnce
3597+
-- @param #SET_STATIC self
3598+
-- @return #SET_STATIC self
3599+
3600+
---Set Regex Options for FilterPrefix function.
3601+
-- @function [parent=#SET_STATIC] FilterSetRegex
3602+
-- @param #SET_STATIC self
3603+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
3604+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
3605+
-- @return #SET_STATIC self
3606+
3607+
--- Builds a set of objects of same coalitions.
3608+
-- Possible current coalitions are red, blue and neutral.
3609+
-- @function [parent=#SET_STATIC] FilterCoalitions
3610+
-- @param #SET_STATIC self
3611+
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral" and coalition.side.RED, coalition.side.BLUE,coalition.side.NEUTRAL
3612+
-- @param #boolean Clear If `true`, clear any previously defined filters.
3613+
-- @return #SET_STATIC self
3614+
35483615
return self
35493616
end
35503617

@@ -4119,7 +4186,7 @@ do -- SET_STATIC
41194186
if self.Filter.StaticPrefixes then
41204187
local MStaticPrefix = false
41214188
for StaticPrefixId, StaticPrefix in pairs(self.Filter.StaticPrefixes) do
4122-
if self:_SearchPattern(MStatic:GetName(), StaticPrefix, false, true) then
4189+
if self:_SearchPattern(MStatic:GetName(), StaticPrefix, self.filterNoRegex, self.filterReplaceDash) then
41234190
MStaticPrefix = true
41244191
end
41254192
end
@@ -4303,7 +4370,27 @@ do -- SET_CLIENT
43034370
local self = BASE:Inherit(self, SET_BASE:New(_DATABASE.CLIENTS)) -- #SET_CLIENT
43044371

43054372
self:FilterActive(false)
4306-
4373+
4374+
--- Filter the set once
4375+
-- @function [parent=#SET_CLIENT] FilterOnce
4376+
-- @param #SET_CLIENT self
4377+
-- @return #SET_CLIENT self
4378+
4379+
---Set Regex Options for FilterPrefix function.
4380+
-- @function [parent=#SET_CLIENT] FilterSetRegex
4381+
-- @param #SET_CLIENT self
4382+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
4383+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
4384+
-- @return #SET_CLIENT self
4385+
4386+
--- Builds a set of objects of same coalitions.
4387+
-- Possible current coalitions are red, blue and neutral.
4388+
-- @function [parent=#SET_CLIENT] FilterCoalitions
4389+
-- @param #SET_CLIENT self
4390+
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral" and coalition.side.RED, coalition.side.BLUE,coalition.side.NEUTRAL
4391+
-- @param #boolean Clear If `true`, clear any previously defined filters.
4392+
-- @return #SET_CLIENT self
4393+
43074394
return self
43084395
end
43094396

@@ -4902,7 +4989,7 @@ do -- SET_CLIENT
49024989
if self.Filter.ClientPrefixes and MClientInclude then
49034990
local MClientPrefix = false
49044991
for ClientPrefixId, ClientPrefix in pairs(self.Filter.ClientPrefixes) do
4905-
if self:_SearchPattern(MClient.UnitName, ClientPrefix) then
4992+
if self:_SearchPattern(MClient.UnitName, ClientPrefix, self.filterNoRegex, self.filterReplaceDash) then
49064993
MClientPrefix = true
49074994
end
49084995
end
@@ -4926,7 +5013,7 @@ do -- SET_CLIENT
49265013
local playername = MClient:GetPlayerName() or "Unknown"
49275014
--self:T(playername)
49285015
for _,_Playername in pairs(self.Filter.Playernames) do
4929-
if playername and self:_SearchPattern(playername,_Playername) then
5016+
if playername and self:_SearchPattern(playername,_Playername,self.filterNoRegex, self.filterReplaceDash) then
49305017
MClientPlayername = true
49315018
end
49325019
end
@@ -4939,7 +5026,7 @@ do -- SET_CLIENT
49395026
local callsign = MClient:GetCallsign()
49405027
--self:I(callsign)
49415028
for _,_Callsign in pairs(self.Filter.Callsigns) do
4942-
if callsign and self:_SearchPattern(callsign,_Callsign, true) then
5029+
if callsign and self:_SearchPattern(callsign,_Callsign, self.filterNoRegex, self.filterReplaceDash) then
49435030
MClientCallsigns = true
49445031
end
49455032
end
@@ -5360,7 +5447,7 @@ do -- SET_PLAYER
53605447
if self.Filter.ClientPrefixes then
53615448
local MClientPrefix = false
53625449
for ClientPrefixId, ClientPrefix in pairs(self.Filter.ClientPrefixes) do
5363-
if self:_SearchPattern(MClient.UnitName,ClientPrefix) then
5450+
if self:_SearchPattern(MClient.UnitName,ClientPrefix,self.filterNoRegex, self.filterReplaceDash) then
53645451
MClientPrefix = true
53655452
end
53665453
end
@@ -5830,7 +5917,19 @@ do -- SET_ZONE
58305917
function SET_ZONE:New()
58315918
-- Inherits from BASE
58325919
local self = BASE:Inherit(self, SET_BASE:New(_DATABASE.ZONES))
5833-
5920+
5921+
--- Filter the set once
5922+
-- @function [parent=#SET_ZONE] FilterOnce
5923+
-- @param #SET_ZONE self
5924+
-- @return #SET_ZONE self
5925+
5926+
---Set Regex Options for FilterPrefix function.
5927+
-- @function [parent=#SET_ZONE] FilterSetRegex
5928+
-- @param #SET_ZONE self
5929+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
5930+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
5931+
-- @return #SET_ZONE self
5932+
58345933
return self
58355934
end
58365935

@@ -6068,7 +6167,7 @@ do -- SET_ZONE
60686167
if self.Filter.Prefixes then
60696168
local MZonePrefix = false
60706169
for ZonePrefixId, ZonePrefix in pairs(self.Filter.Prefixes) do
6071-
if self:_SearchPattern(MZoneName, ZonePrefix, false, true) then
6170+
if self:_SearchPattern(MZoneName, ZonePrefix, self.filterNoRegex, self.filterReplaceDash) then
60726171
MZonePrefix = true
60736172
end
60746173
end
@@ -6577,7 +6676,7 @@ do -- SET_ZONE_GOAL
65776676
if self.Filter.Prefixes then
65786677
local MZonePrefix = false
65796678
for ZonePrefixId, ZonePrefix in pairs(self.Filter.Prefixes) do
6580-
if self:_SearchPattern(MZoneName, ZonePrefix, false, true) then
6679+
if self:_SearchPattern(MZoneName, ZonePrefix, self.filterNoRegex, self.filterReplaceDash) then
65816680
MZonePrefix = true
65826681
end
65836682
end
@@ -6713,7 +6812,19 @@ do -- SET_OPSZONE
67136812

67146813
-- Inherits from BASE
67156814
local self = BASE:Inherit(self, SET_BASE:New(_DATABASE.OPSZONES))
6716-
6815+
6816+
--- Filter the set once
6817+
-- @function [parent=#SET_OPSZONE] FilterOnce
6818+
-- @param #SET_OPSZONE self
6819+
-- @return #SET_OPSZONE self
6820+
6821+
---Set Regex Options for FilterPrefix function.
6822+
-- @function [parent=#SET_OPSZONE] FilterSetRegex
6823+
-- @param #SET_OPSZONE self
6824+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
6825+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
6826+
-- @return #SET_OPSZONE self
6827+
67176828
return self
67186829
end
67196830

@@ -6938,7 +7049,7 @@ do -- SET_OPSZONE
69387049
for ZonePrefixId, ZonePrefix in pairs(self.Filter.Prefixes) do
69397050

69407051
-- Prefix
6941-
if self:_SearchPattern(MZoneName, ZonePrefix, false, true) then
7052+
if self:_SearchPattern(MZoneName, ZonePrefix, self.filterNoRegex, self.filterReplaceDash) then
69427053
MZonePrefix = true
69437054
break --Break the loop as we found the prefix.
69447055
end
@@ -7732,7 +7843,7 @@ function SET_OPSGROUP:_EventOnBirth(Event)
77327843
local MGroupPrefix = false
77337844

77347845
for GroupPrefixId, GroupPrefix in pairs(self.Filter.GroupPrefixes) do
7735-
if self:_SearchPattern(MGroup:GetName(), GroupPrefix, false, true) then
7846+
if self:_SearchPattern(MGroup:GetName(), GroupPrefix, self.filterNoRegex, self.filterReplaceDash) then
77367847
MGroupPrefix = true
77377848
end
77387849
end
@@ -8066,7 +8177,7 @@ do -- SET_SCENERY
80668177
if self.Filter.Prefixes then
80678178
local MSceneryPrefix = false
80688179
for ZonePrefixId, ZonePrefix in pairs(self.Filter.Prefixes) do
8069-
if self:_SearchPattern(MSceneryName, ZonePrefix, false, true) then
8180+
if self:_SearchPattern(MSceneryName, ZonePrefix, self.filterNoRegex, self.filterReplaceDash) then
80708181
MSceneryPrefix = true
80718182
end
80728183
end
@@ -8289,7 +8400,19 @@ do -- SET_DYNAMICCARGO
82898400

82908401
--- Inherits from BASE
82918402
local self = BASE:Inherit(self, SET_BASE:New(_DATABASE.DYNAMICCARGO)) -- Core.Set#SET_DYNAMICCARGO
8292-
8403+
8404+
--- Filter the set once
8405+
-- @function [parent=#SET_DYNAMICCARGO] FilterOnce
8406+
-- @param #SET_DYNAMICCARGO self
8407+
-- @return #SET_DYNAMICCARGO self
8408+
8409+
---Set Regex Options for FilterPrefix function.
8410+
-- @function [parent=#SET_DYNAMICCARGO] FilterSetRegex
8411+
-- @param #SET_DYNAMICCARGO self
8412+
-- @param #boolean NoRegex If true, switch off Regex pattern matching for FilterPrefixes.
8413+
-- @param #boolean ReplaceDash If false, switch off dash "-" replacement in strings for FilterPrefixes.
8414+
-- @return #SET_DYNAMICCARGO self
8415+
82938416
return self
82948417
end
82958418

@@ -8337,7 +8460,7 @@ do -- SET_DYNAMICCARGO
83378460
if self.Filter.StaticPrefixes then
83388461
local DCargoPrefix = false
83398462
for StaticPrefixId, StaticPrefix in pairs(self.Filter.StaticPrefixes) do
8340-
if self:_SearchPattern(DCargo:GetName(), StaticPrefix, false, true) then
8463+
if self:_SearchPattern(DCargo:GetName(), StaticPrefix, self.filterNoRegex, self.filterReplaceDash) then
83418464
DCargoPrefix = true
83428465
end
83438466
end
@@ -8505,7 +8628,7 @@ do -- SET_DYNAMICCARGO
85058628
function SET_DYNAMICCARGO:FilterCurrentOwner(PlayerName)
85068629
self:FilterFunction(
85078630
function(cargo)
8508-
if cargo and cargo.Owner and self:_SearchPattern(cargo.Owner, PlayerName, true) then
8631+
if cargo and cargo.Owner and self:_SearchPattern(cargo.Owner, PlayerName, self.filterNoRegex, self.filterReplaceDash) then
85098632
return true
85108633
else
85118634
return false

Moose Development/Moose/Functional/Shorad.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,20 @@ do
795795
local tgtgrp1 = self.Samset:FindNearestGroupFromPointVec2(tgtcoord)
796796
local tgtcoord1 = tgtgrp1:GetCoordinate()
797797
local tgtgrp2 = self.Groupset:FindNearestGroupFromPointVec2(tgtcoord)
798-
local tgtcoord2 = tgtgrp2:GetCoordinate()
799-
local dist1 = tgtcoord:Get2DDistance(tgtcoord1)
800-
local dist2 = tgtcoord:Get2DDistance(tgtcoord2)
801-
802-
if dist1 < dist2 then
803-
targetunit = tgtgrp1
804-
targetcat = Object.Category.UNIT
798+
if tgtgrp2 then
799+
local tgtcoord2 = tgtgrp2:GetCoordinate()
800+
local dist1 = tgtcoord:Get2DDistance(tgtcoord1)
801+
local dist2 = tgtcoord:Get2DDistance(tgtcoord2)
802+
803+
if dist1 < dist2 then
804+
targetunit = tgtgrp1
805+
targetcat = Object.Category.UNIT
806+
else
807+
targetunit = tgtgrp2
808+
targetcat = Object.Category.UNIT
809+
end
805810
else
806-
targetunit = tgtgrp2
811+
targetunit = tgtgrp1
807812
targetcat = Object.Category.UNIT
808813
end
809814
end

Moose Development/Moose/Functional/Suppression.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ function SUPPRESSION:onafterStop(Controllable, From, Event, To)
14851485

14861486
local text=string.format("Stopping SUPPRESSION for group %s", self.Controllable:GetName())
14871487
MESSAGE:New(text, 10):ToAllIf(self.Debug)
1488-
sefl:T(self.lid..text)
1488+
self:T(self.lid..text)
14891489

14901490
-- Clear all pending schedules
14911491
self.CallScheduler:Clear()

0 commit comments

Comments
 (0)