2727using VRage . Game . ModAPI ;
2828using VRage . Game . ObjectBuilders . ComponentSystem ;
2929using VRage . ModAPI ;
30- using VRage . ObjectBuilders ;
31- using VRage . Utils ;
3230using VRageMath ;
3331
3432namespace Concealment
3533{
36- [ Plugin ( "Concealment" , "1.1" , "17f44521-b77a-4e85-810f-ee73311cf75d" ) ]
37- public class ConcealmentPlugin : TorchPluginBase , IWpfPlugin
34+ [ Plugin ( "Concealment" , "1.1.2 " , "17f44521-b77a-4e85-810f-ee73311cf75d" ) ]
35+ public sealed class ConcealmentPlugin : TorchPluginBase , IWpfPlugin
3836 {
3937 public Persistent < Settings > Settings { get ; private set ; }
4038 public MTObservableCollection < ConcealGroup > ConcealGroups { get ; } = new MTObservableCollection < ConcealGroup > ( ) ;
@@ -52,7 +50,7 @@ public ConcealmentPlugin()
5250 _intersectGroups = new List < ConcealGroup > ( ) ;
5351 }
5452
55- public UserControl GetControl ( )
53+ UserControl IWpfPlugin . GetControl ( )
5654 {
5755 return _control ?? ( _control = new ConcealmentControl { DataContext = this } ) ;
5856 }
@@ -87,7 +85,7 @@ public override void Update()
8785 return ;
8886
8987 if ( _counter % Settings . Data . ConcealInterval == 0 )
90- ConcealDistantGrids ( Settings . Data . ConcealDistance ) ;
88+ ConcealGrids ( Settings . Data . ConcealDistance ) ;
9189 if ( _counter % Settings . Data . RevealInterval == 0 )
9290 RevealNearbyGrids ( Settings . Data . RevealDistance ) ;
9391 _counter += 1 ;
@@ -168,7 +166,7 @@ void UnregisterRecursive(IMyEntity e)
168166 return ;
169167
170168 foreach ( var child in e . Hierarchy . Children )
171- UnregisterRecursive ( child . Entity ) ;
169+ UnregisterRecursive ( child . Container . Entity ) ;
172170 }
173171 }
174172
@@ -191,7 +189,7 @@ void RegisterRecursive(IMyEntity e)
191189 return ;
192190
193191 foreach ( var child in e . Hierarchy . Children )
194- RegisterRecursive ( child . Entity ) ;
192+ RegisterRecursive ( child . Container . Entity ) ;
195193 }
196194 }
197195
@@ -203,6 +201,7 @@ private int ConcealGroup(ConcealGroup group)
203201 Log . Debug ( $ "Concealing grids: { group . GridNames } ") ;
204202 group . Grids . ForEach ( ConcealEntity ) ;
205203#if ! NOPHYS
204+ group . UpdateAABB ( ) ;
206205 var aabb = group . WorldAABB ;
207206 group . ProxyId = _concealedAabbTree . AddProxy ( ref aabb , group , 0 ) ;
208207#endif
@@ -230,18 +229,19 @@ public int RevealGroup(ConcealGroup group)
230229 Log . Warn ( new StackTrace ( ) ) ;
231230 return 0 ;
232231 }
232+
233+ var count = group . Grids . Count ;
233234 Log . Debug ( $ "Revealing grids: { group . GridNames } ") ;
234235 group . Grids . ForEach ( RevealEntity ) ;
235236#if ! NOPHYS
236237 _concealGroups . Remove ( group ) ;
237238 _concealedAabbTree . RemoveProxy ( group . ProxyId ) ;
238239#endif
239- return group . Grids . Count ;
240+ return count ;
240241 }
241242
242243 public int RevealGridsInSphere ( BoundingSphereD sphere )
243244 {
244- Log . Debug ( $ "reveal in sphere { sphere . Center } | { sphere . Radius } ") ;
245245 var revealed = 0 ;
246246#if ! NOPHYS
247247 _concealedAabbTree . OverlapAllBoundingSphere ( ref sphere , _intersectGroups ) ;
@@ -253,6 +253,7 @@ public int RevealGridsInSphere(BoundingSphereD sphere)
253253 _intersectGroups . Add ( group ) ;
254254 }
255255#endif
256+ Log . Trace ( $ "{ _intersectGroups . Count } groups") ;
256257 foreach ( var group in _intersectGroups )
257258 revealed += RevealGroup ( group ) ;
258259
@@ -262,23 +263,24 @@ public int RevealGridsInSphere(BoundingSphereD sphere)
262263
263264 public int RevealNearbyGrids ( double distanceFromPlayers )
264265 {
265- Log . Debug ( "Revealing nearby grids" ) ;
266266 var revealed = 0 ;
267- var playerSpheres = GetPlayerBoundingSpheres ( distanceFromPlayers ) ;
268- Log . Debug ( playerSpheres . Count ) ;
267+ var playerSpheres = GetPlayerViewSpheres ( distanceFromPlayers ) ;
269268 foreach ( var sphere in playerSpheres )
269+ {
270+ Log . Trace ( $ "{ sphere . Center } : { sphere . Radius } ") ;
270271 revealed += RevealGridsInSphere ( sphere ) ;
272+ }
271273
272274 if ( revealed != 0 )
273275 Log . Info ( $ "Revealed { revealed } grids near players.") ;
274276 return revealed ;
275277 }
276278
277- public int ConcealDistantGrids ( double distanceFromPlayers )
279+ public int ConcealGrids ( double distanceFromPlayers )
278280 {
279- Log . Debug ( "Concealing distant grids" ) ;
281+ Log . Debug ( "Concealing grids" ) ;
280282 int concealed = 0 ;
281- var playerSpheres = GetPlayerBoundingSpheres ( distanceFromPlayers ) ;
283+ var playerSpheres = GetPlayerViewSpheres ( distanceFromPlayers ) ;
282284
283285 ConcurrentBag < ConcealGroup > groups = new ConcurrentBag < ConcealGroup > ( ) ;
284286 //Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group =>
@@ -288,10 +290,16 @@ public int ConcealDistantGrids(double distanceFromPlayers)
288290
289291 var volume = group . GetWorldAABB ( ) ;
290292 if ( playerSpheres . Any ( s => s . Contains ( volume ) != ContainmentType . Disjoint ) )
293+ {
294+ Log . Trace ( "group near player" ) ;
291295 continue ;
296+ }
292297
293- //if (IsExcluded(concealGroup))
294- // return;
298+ if ( IsExcluded ( concealGroup ) )
299+ {
300+ Log . Trace ( "group excluded" ) ;
301+ continue ;
302+ }
295303
296304 groups . Add ( concealGroup ) ;
297305 }
@@ -312,11 +320,21 @@ public bool IsExcluded(ConcealGroup group)
312320 {
313321 if ( block == null )
314322 continue ;
323+
324+ if ( block is IMyProductionBlock p && Settings . Data . ExemptProduction && p . IsProducing )
325+ {
326+ Log . Trace ( $ "{ group . GridNames } exempted production ({ p . CustomName } active)") ;
327+ return true ;
328+ }
329+
315330 if ( Settings . Data . ExcludedSubtypes . Contains ( block . BlockDefinition . Id . SubtypeName ) )
316- return false ;
331+ {
332+ Log . Trace ( $ "{ group . GridNames } exempted subtype { block . BlockDefinition . Id . SubtypeName } ") ;
333+ return true ;
334+ }
317335 }
318336
319- return true ;
337+ return false ;
320338 }
321339
322340 public int RevealAll ( )
@@ -330,9 +348,9 @@ public int RevealAll()
330348 return revealed ;
331349 }
332350
333- private List < BoundingSphereD > GetPlayerBoundingSpheres ( double distance )
351+ private List < BoundingSphereD > GetPlayerViewSpheres ( double distance )
334352 {
335- return ( ( MyPlayerCollection ) MyAPIGateway . Multiplayer . Players ) . GetOnlinePlayers ( ) . Where ( p => p . Controller ? . ControlledEntity != null ) . Select ( p => new BoundingSphereD ( p . Controller . ControlledEntity . Entity . PositionComp . GetPosition ( ) , distance ) ) . ToList ( ) ;
353+ return ( ( MyPlayerCollection ) MyAPIGateway . Multiplayer . Players ) . GetOnlinePlayers ( ) . Select ( p => new BoundingSphereD ( p . GetPosition ( ) , distance ) ) . ToList ( ) ;
336354 }
337355 }
338356
0 commit comments