本文整理汇总了C#中BoundingSphereD.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingSphereD.Contains方法的具体用法?C# BoundingSphereD.Contains怎么用?C# BoundingSphereD.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingSphereD
的用法示例。
在下文中一共展示了BoundingSphereD.Contains方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleCommand
public override bool HandleCommand( ulong userId, string[] words )
{
Essentials.Log.Info( "Asteroid cleanup" );
HashSet<IMyEntity> entities = new HashSet<IMyEntity>( );
Wrapper.GameAction( ( ) =>
{
MyAPIGateway.Entities.GetEntities( entities );
foreach ( IMyEntity entity in entities )
{
if ( entity == null )
continue;
if ( entity is IMyVoxelMap )
asteroidPositions.Add( entity.PositionComp.GetPosition( ), (IMyVoxelMap)entity );
else
entityPositions.Add( entity.PositionComp.GetPosition( ) );
}
} );
//TODO: Use a thread pool to speed this up?
DateTime profile = DateTime.Now;
Communication.SendPrivateInformation( userId, $"Found {asteroidPositions.Count} asteroids." );
foreach ( var asteroid in asteroidPositions )
{
bool found = false;
BoundingSphereD bound = new BoundingSphereD( asteroid.Key, 1000 );
foreach ( Vector3D checkPosition in entityPositions )
{
if ( bound.Contains( checkPosition ) == ContainmentType.Contains )
{
found = true;
break;
}
}
if ( !found )
toRemove.Add( asteroid.Value );
}
Communication.SendPrivateInformation( userId, $"Found {toRemove.Count} asteroids to remove." );
int count = 0;
foreach ( IMyVoxelMap asteroid in toRemove )
{
if ( asteroid == null || asteroid.Closed )
continue;
count++;
Wrapper.GameAction( ( ) => asteroid.Close( ) );
}
Communication.SendPrivateInformation( userId, $"Removed {count} asteroids." );
Essentials.Log.Info( "Asteroid cleanup elapsed time: " + (DateTime.Now - profile) );
return true;
}
示例2: HandleCommand
public override bool HandleCommand(ulong userId, string[] words)
{
var entities = MyEntities.GetEntities( ).ToArray( );
var planets = new HashSet<MyPlanet>( );
int count = 0;
foreach (var entity in entities)
{
MyPlanet item = entity as MyPlanet;
if (item != null)
planets.Add( item );
}
foreach (var planet in planets)
{
var sphere25 = new BoundingSphereD(planet.PositionComp.GetPosition(), planet.MinimumRadius * 0.25);
var sphere75 = new BoundingSphereD(planet.PositionComp.GetPosition(), planet.MinimumRadius * 0.75);
foreach (var entity in entities)
{
if (entity.MarkedForClose || entity.Physics == null || entity is MyCharacter)
continue;
if (sphere25.Contains(entity.PositionComp.GetPosition()) != ContainmentType.Disjoint)
{
count++;
Wrapper.BeginGameAction( entity.Close, null, null );
continue;
}
if (Vector3.IsZero(entity.Physics.LinearVelocity))
continue;
if (sphere75.Contains(entity.PositionComp.GetPosition()) == ContainmentType.Disjoint)
continue;
count++;
Wrapper.BeginGameAction(entity.Close, null, null);
}
}
Communication.SendPrivateInformation( userId, $"Deleted {count} entities trapped in planets." );
return true;
}
示例3: GenerateObjectSeeds
private void GenerateObjectSeeds(BoundingSphereD sphere)
{
ProfilerShort.Begin("GenerateObjectSeedsInBox");
BoundingBoxD box = new BoundingBoxD(sphere.Center - sphere.Radius, sphere.Center + sphere.Radius);
Vector3I cellId = Vector3I.Floor(box.Min / CELL_SIZE);
for (var iter = GetCellsIterator(sphere); iter.IsValid(); iter.GetNext(out cellId))
{
if (!m_cells.ContainsKey(cellId))
{
var cellBox = new BoundingBoxD(cellId * CELL_SIZE, (cellId + 1) * CELL_SIZE);
if (sphere.Contains(cellBox) == ContainmentType.Disjoint)
{
continue;
}
var cell = GenerateObjectSeedsCell(ref cellId);
if (cell != null)
{
m_cells.Add(cellId, cell);
var cellBBox = cell.BoundingVolume;
cell.proxyId = m_cellsTree.AddProxy(ref cellBBox, cell, 0);
}
}
}
ProfilerShort.End();
}
示例4: MarkCellsDirty
private void MarkCellsDirty(BoundingSphereD toMark, BoundingSphereD toExclude)
{
ProfilerShort.Begin("Mark dirty cells");
Vector3I cellId = Vector3I.Floor((toMark.Center - toMark.Radius) / CELL_SIZE);
for (var iter = GetCellsIterator(toMark); iter.IsValid(); iter.GetNext(out cellId))
{
MyProceduralCell cell;
if (m_cells.TryGetValue(cellId, out cell))
{
if (toExclude.Contains(cell.BoundingVolume) == ContainmentType.Disjoint)
{
m_dirtyCellsToAdd.Add(cell);
}
}
}
ProfilerShort.End();
}
示例5: AvoidCollisions
private Vector3D AvoidCollisions(Vector3D delta, ref float autopilotSpeedLimit)
{
if (m_collisionCtr <= 0)
{
m_collisionCtr = 0;
}
else
{
m_collisionCtr--;
return m_oldCollisionDelta;
}
bool drawDebug = MyDebugDrawSettings.ENABLE_DEBUG_DRAW;// && MyDebugDrawSettings.DEBUG_DRAW_DRONES;
Vector3D originalDelta = delta;
Vector3D origin = this.CubeGrid.Physics.CenterOfMassWorld;
double shipRadius = this.CubeGrid.PositionComp.WorldVolume.Radius * 1.3f;
if (MyFakes.ENABLE_VR_DRONE_COLLISIONS) //TODO VR: this MyFake should be enabled in VR but disabled in SE
shipRadius = this.CubeGrid.PositionComp.WorldVolume.Radius * 1f;
Vector3D linVel = this.CubeGrid.Physics.LinearVelocity;
double vel = linVel.Length();
double detectionRadius = this.CubeGrid.PositionComp.WorldVolume.Radius * 10.0f + (vel * vel) * 0.05;
if (MyFakes.ENABLE_VR_DRONE_COLLISIONS)
detectionRadius = this.CubeGrid.PositionComp.WorldVolume.Radius + (vel * vel) * 0.05;
BoundingSphereD sphere = new BoundingSphereD(origin, detectionRadius);
Vector3D testPoint = sphere.Center + linVel * 2.0f;
if (MyFakes.ENABLE_VR_DRONE_COLLISIONS)
testPoint = sphere.Center + linVel;
if (drawDebug)
{
MyRenderProxy.DebugDrawSphere(sphere.Center, (float)shipRadius, Color.HotPink, 1.0f, false);
MyRenderProxy.DebugDrawSphere(sphere.Center + linVel, 1.0f, Color.HotPink, 1.0f, false);
MyRenderProxy.DebugDrawSphere(sphere.Center, (float)detectionRadius, Color.White, 1.0f, false);
}
Vector3D steeringVector = Vector3D.Zero;
Vector3D avoidanceVector = Vector3D.Zero;
int n = 0;
double maxAvCoeff = 0.0f;
var entities = MyEntities.GetTopMostEntitiesInSphere(ref sphere);
IMyGravityProvider well;
if (MyGravityProviderSystem.GetStrongestNaturalGravityWell(origin, out well) > 0 && well is MyGravityProviderComponent)
{
MyEntity e = (MyEntity)((MyGravityProviderComponent)well).Entity;
if (!entities.Contains(e)) entities.Add(e);
}
for (int i = 0; i < entities.Count; ++i)
{
var entity = entities[i];
if (entity == this.Parent) continue;
Vector3D steeringDelta = Vector3D.Zero;
Vector3D avoidanceDelta = Vector3D.Zero;
if ((entity is MyCubeGrid) || (entity is MyVoxelMap) || (entity is MySkinnedEntity))
{
if (MyFakes.ENABLE_VR_DRONE_COLLISIONS && (entity is MyCubeGrid))
{
var grid = entity as MyCubeGrid;
if (grid.IsStatic)
{
continue;
}
}
if (entity is MyCubeGrid)
{
var grid = entity as MyCubeGrid;
if(MyCubeGridGroups.Static.Physical.GetGroup(CubeGrid) == MyCubeGridGroups.Static.Physical.GetGroup(grid))
{
continue;
}
}
var otherSphere = entity.PositionComp.WorldVolume;
otherSphere.Radius += shipRadius;
Vector3D offset = otherSphere.Center - sphere.Center;
if (this.CubeGrid.Physics.LinearVelocity.LengthSquared() > 5.0f && Vector3D.Dot(delta, this.CubeGrid.Physics.LinearVelocity) < 0) continue;
// Collision avoidance
double dist = offset.Length();
BoundingSphereD forbiddenSphere = new BoundingSphereD(otherSphere.Center + linVel, otherSphere.Radius + vel);
if (forbiddenSphere.Contains(testPoint) == ContainmentType.Contains)
{
autopilotSpeedLimit = 2.0f;
if (drawDebug)
{
MyRenderProxy.DebugDrawSphere(forbiddenSphere.Center, (float)forbiddenSphere.Radius, Color.Red, 1.0f, false);
}
}
//.........这里部分代码省略.........
示例6: TestClipSpheres
private static void TestClipSpheres(ref MyCellCoord cell, ref BoundingSphereD nearClipSphere, ref BoundingSphereD farClipSphere, out ContainmentType nearClipRes, out ContainmentType farClipRes)
{
BoundingBoxD localAabb;
MyVoxelCoordSystems.RenderCellCoordToLocalAABB(ref cell, out localAabb);
localAabb.Inflate(MyVoxelConstants.VOXEL_SIZE_IN_METRES * (1 << cell.Lod));
nearClipSphere.Contains(ref localAabb, out nearClipRes);
farClipSphere.Contains(ref localAabb, out farClipRes);
}
示例7: MarkCellsDirty
public void MarkCellsDirty(BoundingSphereD toMark, BoundingSphereD? toExclude = null)
{
BoundingSphereD toMarkScaled = new BoundingSphereD(toMark.Center, toMark.Radius * RADIUS_MULTIPLIER);
BoundingSphereD toExcludeScaled = new BoundingSphereD();
if (toExclude.HasValue)
{
toExcludeScaled = toExclude.Value;
toExcludeScaled.Radius *= RADIUS_MULTIPLIER;
}
ProfilerShort.Begin("Mark dirty cells");
Vector3I cellId = Vector3I.Floor((toMark.Center - toMark.Radius) / CELL_SIZE);
for (var iter = GetCellsIterator(toMark); iter.IsValid(); iter.GetNext(out cellId))
{
MyProceduralCell cell;
if (m_cells.TryGetValue(cellId, out cell))
{
if (!toExclude.HasValue || toExcludeScaled.Contains(cell.BoundingVolume) == ContainmentType.Disjoint)
{
m_dirtyCells.Add(cell);
}
}
}
ProfilerShort.End();
}
示例8: UpdateDroneSpawning
private void UpdateDroneSpawning()
{
int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
m_iteratingAntennas = true;
foreach (var antennaEntry in m_pirateAntennas)
{
PirateAntennaInfo antennaInfo = antennaEntry.Value;
if (!antennaInfo.IsActive) continue;
if (currentTime - antennaInfo.LastGenerationGameTime <= antennaInfo.AntennaDefinition.SpawnTimeMs) continue;
MyRadioAntenna antenna = null;
MyEntities.TryGetEntityById(antennaEntry.Key, out antenna);
Debug.Assert(antenna != null, "Could not find antenna for spawning enemy drones!");
var spawnGroup = antennaInfo.AntennaDefinition.SpawnGroupSampler.Sample();
Debug.Assert(spawnGroup != null, "Could not find spawnGroup for spawning enemy drones!");
if
(
!MySession.Static.Settings.EnableDrones ||
antennaInfo.SpawnedDrones >= antennaInfo.AntennaDefinition.MaxDrones ||
antenna == null ||
spawnGroup == null ||
m_droneInfos.Reader.Count() >= MySession.Static.Settings.MaxDrones
)
{
antennaInfo.LastGenerationGameTime = currentTime;
continue;
}
spawnGroup.ReloadPrefabs();
BoundingSphereD antennaSphere = new BoundingSphereD(antenna.WorldMatrix.Translation, antenna.GetRadius());
var players = MySession.Static.Players.GetOnlinePlayers();
bool successfulSpawn = false;
foreach (var player in players)
{
if (antennaSphere.Contains(player.GetPosition()) == ContainmentType.Contains)
{
Vector3D? spawnPosition = null;
for (int i = 0; i < 10; ++i)
{
Vector3D position = antenna.WorldMatrix.Translation + MyUtils.GetRandomVector3Normalized() * antennaInfo.AntennaDefinition.SpawnDistance;
spawnPosition = MyEntities.FindFreePlace(position, spawnGroup.SpawnRadius);
if (spawnPosition.HasValue) break;
}
if (spawnPosition.HasValue)
{
successfulSpawn = SpawnDrone(antenna.EntityId, antenna.OwnerId, spawnPosition.Value, spawnGroup);
break;
}
break;
}
}
// Don't reschedule if there was no player inside
if (successfulSpawn)
{
antennaInfo.LastGenerationGameTime = currentTime;
}
}
m_pirateAntennas.ApplyChanges();
m_iteratingAntennas = false;
}
示例9: ProjectileIsThreat
private bool ProjectileIsThreat(IMyEntity projectile, TargetType tType)
{
if (projectile.Closed)
return false;
Vector3D projectilePosition = projectile.GetPosition();
BoundingSphereD ignoreArea = new BoundingSphereD(ProjectilePosition(), Options.TargetingRange / 10f);
if (ignoreArea.Contains(projectilePosition) == ContainmentType.Contains)
return false;
Vector3D weaponPosition = ProjectilePosition();
Vector3D nextPosition = projectilePosition + projectile.GetLinearVelocity() / 60f;
if (Vector3D.DistanceSquared(weaponPosition, nextPosition) < Vector3D.DistanceSquared(weaponPosition, projectilePosition))
{
myLogger.debugLog("projectile: " + projectile.getBestName() + ", is moving towards weapon. D0 = " + Vector3D.DistanceSquared(weaponPosition, nextPosition) + ", D1 = " + Vector3D.DistanceSquared(weaponPosition, projectilePosition), "ProjectileIsThreat()");
return true;
}
else
{
myLogger.debugLog("projectile: " + projectile.getBestName() + ", is moving away from weapon. D0 = " + Vector3D.DistanceSquared(weaponPosition, nextPosition) + ", D1 = " + Vector3D.DistanceSquared(weaponPosition, projectilePosition), "ProjectileIsThreat()");
return false;
}
}
示例10: FindMarketsFromLocation
public static List<MarketStruct> FindMarketsFromLocation(Vector3D position)
{
var list = new List<MarketStruct>();
foreach (var market in EconomyScript.Instance.Data.Markets)
{
switch (market.MarketZoneType)
{
case MarketZoneType.EntitySphere:
if (market.EntityId == 0 || !MyAPIGateway.Entities.EntityExists(market.EntityId))
continue;
if (!market.MarketZoneSphere.HasValue)
continue;
IMyEntity entity;
if (!MyAPIGateway.Entities.TryGetEntityById(market.EntityId, out entity))
continue;
if (entity.Closed || entity.MarkedForClose)
continue;
var sphere = new BoundingSphereD(entity.WorldMatrix.Translation, market.MarketZoneSphere.Value.Radius);
if (sphere.Contains(position) == ContainmentType.Contains)
list.Add(market);
break;
case MarketZoneType.FixedSphere:
if (!market.MarketZoneSphere.HasValue)
continue;
if (market.MarketZoneSphere.Value.Contains(position) == ContainmentType.Contains)
list.Add(market);
break;
case MarketZoneType.FixedBox:
if (!market.MarketZoneBox.HasValue)
continue;
if (market.MarketZoneBox.Value.Contains(position) == ContainmentType.Contains)
list.Add(market);
break;
}
}
return list;
}
示例11: AvoidCollisions
private Vector3D AvoidCollisions(Vector3D delta)
{
if (m_collisionCtr <= 0)
{
m_collisionCtr = 0;
}
else
{
m_collisionCtr--;
return m_oldCollisionDelta;
}
bool drawDebug = MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_DRONES;
Vector3D originalDelta = delta;
Vector3D origin = this.CubeGrid.Physics.CenterOfMassWorld;
double shipRadius = this.CubeGrid.PositionComp.WorldVolume.Radius * 1.3f;
Vector3D linVel = this.CubeGrid.Physics.LinearVelocity;
double vel = linVel.Length();
double detectionRadius = this.CubeGrid.PositionComp.WorldVolume.Radius * 10.0f + (vel * vel) * 0.05;
BoundingSphereD sphere = new BoundingSphereD(origin, detectionRadius);
if (drawDebug)
{
MyRenderProxy.DebugDrawSphere(sphere.Center, (float)shipRadius, Color.HotPink, 1.0f, false);
MyRenderProxy.DebugDrawSphere(sphere.Center + linVel, 1.0f, Color.HotPink, 1.0f, false);
MyRenderProxy.DebugDrawSphere(sphere.Center, (float)detectionRadius, Color.White, 1.0f, false);
}
Vector3D steeringVector = Vector3D.Zero;
Vector3D avoidanceVector = Vector3D.Zero;
int n = 0;
double maxAvCoeff = 0.0f;
var entities = MyEntities.GetTopMostEntitiesInSphere(ref sphere);
for (int i = 0; i < entities.Count; ++i)
{
var entity = entities[i];
if (!(entity is MyCubeGrid) && !(entity is MyVoxelMap)) continue;
if (entity == this.Parent) continue;
var otherSphere = entity.PositionComp.WorldVolume;
otherSphere.Radius += shipRadius;
Vector3D offset = otherSphere.Center - sphere.Center;
if (Vector3D.Dot(delta, this.CubeGrid.Physics.LinearVelocity) < 0) continue;
// Collision avoidance
double dist = offset.Length();
BoundingSphereD forbiddenSphere = new BoundingSphereD(otherSphere.Center + linVel, otherSphere.Radius + vel);
Vector3D testPoint = sphere.Center + linVel * 2.0f;
if (forbiddenSphere.Contains(testPoint) == ContainmentType.Contains)
{
m_autopilotSpeedLimit = 2.0f;
if (drawDebug)
{
MyRenderProxy.DebugDrawSphere(forbiddenSphere.Center, (float)forbiddenSphere.Radius, Color.Red, 1.0f, false);
}
}
else
{
if (Vector3D.Dot(offset, linVel) < 0)
{
if (drawDebug)
{
MyRenderProxy.DebugDrawSphere(forbiddenSphere.Center, (float)forbiddenSphere.Radius, Color.Red, 1.0f, false);
}
}
else if (drawDebug)
{
MyRenderProxy.DebugDrawSphere(forbiddenSphere.Center, (float)forbiddenSphere.Radius, Color.DarkOrange, 1.0f, false);
}
}
// 0.693 is log(2), because we want svLength(otherSphere.radius) -> 1 and svLength(0) -> 2
double exponent = -0.693 * dist / (otherSphere.Radius + this.CubeGrid.PositionComp.WorldVolume.Radius + vel);
double svLength = 2 * Math.Exp(exponent);
double avCoeff = Math.Min(1.0f, Math.Max(0.0f, -(forbiddenSphere.Center - sphere.Center).Length() / forbiddenSphere.Radius + 2));
maxAvCoeff = Math.Max(maxAvCoeff, avCoeff);
Vector3D normOffset = offset / dist;
steeringVector -= normOffset * svLength;
avoidanceVector -= normOffset * avCoeff;
n++;
}
entities.Clear();
/*if (minTmin < vel)
{
delta = origin + minTmin * vel;
}*/
if (n > 0)
{
double l = delta.Length();
//.........这里部分代码省略.........
示例12: FindMarketsFromLocation
/// <summary>
/// Finds all available markets that are within range that can be traded with.
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public static List<MarketStruct> FindMarketsFromLocation(Vector3D position)
{
var list = new List<MarketStruct>();
foreach (var market in EconomyScript.Instance.Data.Markets)
{
if (!market.Open)
continue;
switch (market.MarketZoneType)
{
case MarketZoneType.EntitySphere:
if (!EconomyScript.Instance.ServerConfig.EnablePlayerTradezones)
continue;
if (market.EntityId == 0 || !MyAPIGateway.Entities.EntityExists(market.EntityId))
continue;
IMyEntity entity;
if (!MyAPIGateway.Entities.TryGetEntityById(market.EntityId, out entity))
{
// Close the market, because the cube no longer exists.
market.Open = false;
continue;
}
if (entity.Closed || entity.MarkedForClose)
{
// Close the market, because the cube no longer exists.
market.Open = false;
continue;
}
IMyBeacon beacon = entity as IMyBeacon;
if (beacon == null)
continue;
if (!beacon.IsWorking)
continue;
// TODO: I'm not sure if these two commands will impact perfomance.
// player will be null if the player is not online.
// I'm not sure if there is a way to may a steamId to a playerId without them been online.
var player = MyAPIGateway.Players.FindPlayerBySteamId(market.MarketId);
if (player != null && beacon.GetUserRelationToOwner(player.PlayerID) != MyRelationsBetweenPlayerAndBlock.Owner)
{
// Close the market, because it's no longer owner by the player.
market.Open = false;
continue;
}
var sphere = new BoundingSphereD(entity.WorldMatrix.Translation, market.MarketZoneSphere.HasValue ? market.MarketZoneSphere.Value.Radius : 1);
if (sphere.Contains(position) == ContainmentType.Contains)
list.Add(market);
break;
case MarketZoneType.FixedSphere:
if (!EconomyScript.Instance.ServerConfig.EnableNpcTradezones)
continue;
if (!market.MarketZoneSphere.HasValue)
continue;
if (market.MarketZoneSphere.Value.Contains(position) == ContainmentType.Contains)
list.Add(market);
break;
case MarketZoneType.FixedBox:
if (!EconomyScript.Instance.ServerConfig.EnableNpcTradezones)
continue;
if (!market.MarketZoneBox.HasValue)
continue;
if (market.MarketZoneBox.Value.Contains(position) == ContainmentType.Contains)
list.Add(market);
break;
}
}
return list;
}
示例13: UpdateBeforeSimulation10
//.........这里部分代码省略.........
IsMoving = false;
Logger.Log.Debug(" * set last not moving state at NOW");
}
}
else
{
Logger.Log.Error("BeaconSecurity: BS {0} no GRID FOUND!!!", Entity.EntityId);
}
} // if flag is off, check that IsMoving must be false all time
else
IsMoving = false;
// Check the owner's presence near the beacon.
// Check the search of all the players in relation to the current beacon.
// one BS - all players.
// preset owner sphere
BoundingSphereD SphereOwner = new BoundingSphereD(GetPosition(), Core.Settings.DistanceBeforeTurningOn);
List<IMyPlayer> players = new List<IMyPlayer>();
MyAPIGateway.Players.GetPlayers(players, x => x.Controller != null && x.Controller.ControlledEntity != null);
foreach (IMyPlayer player in players)
{
// get relations between player and beacon
MyRelationsBetweenPlayerAndBlock relation = m_block.GetUserRelationToOwner(player.PlayerID);
if (relation != MyRelationsBetweenPlayerAndBlock.Owner && relation != MyRelationsBetweenPlayerAndBlock.FactionShare)
continue;
// if player has rights to this beacon, check in radius
if (Core.Settings.DistanceBeforeTurningOn <= 0)
{ // we need just check if player online, any of group
m_lastOwnerSeen = DTNow;
break;
}
// spaceman or ship, get world boundingbox
BoundingBoxD playerObject = (player.Controller.ControlledEntity is IMyCharacter) ? player.Controller.ControlledEntity.Entity.WorldAABB : player.Controller.ControlledEntity.Entity.GetTopMostParent().WorldAABB;
if (SphereOwner.Contains(playerObject) != ContainmentType.Disjoint)
{ // user is in sphere, set last seen date
m_lastOwnerSeen = DTNow;
break;
}
}
// Next part - Check the switching conditions
// 1 - owner away by DistanceBeforeTurningOn meters
// 2 - delay before turning on DelayBeforeTurningOn seconds
// 3 - IsMoving must be false
// 4 - if set OnlyForStations, check grid isStatic
// 5 - if not exceed sizes
bool chkOnlyForStations = true;
bool chkSizes = true;
if (Core.Settings.OnlyForStations && grid != null) // check grid istatic property
chkOnlyForStations = grid.IsStatic;
IMyEntity entGrid = grid as IMyEntity;
if (entGrid != null)
{
Vector3 size = entGrid.LocalAABB.Size;
long limit = Core.Settings.LimitGridSizes;
if (limit > 0)
{
Logger.Log.Debug("Limitation for sizes: {0} {1}x{2}x{3}", limit, size.X, size.Y, size.Z);
if (size.X > limit || size.Y > limit || size.Z > limit)
{
chkSizes = false;
}
}
}
TimeSpan diff = DTNow - m_lastOwnerSeen;
if (diff.TotalSeconds > Core.Settings.DelayBeforeTurningOn && !IsMoving && chkOnlyForStations && chkSizes && m_block.IsFunctional && IsPowered)
{ // BeaconSecurity must be ON
if (!m_block.Enabled)
{
Logger.Log.Debug("BeaconSecurity is activated {0} ownerid {1}, sync date info to others...", m_block.EntityId, m_block.OwnerId);
RequestEnable(true);
}
else if (!m_block.IsWorking)
{ // if enabled, but still don't working...
Logger.Log.Debug("BeaconSecurity is deactivated NOPOWER {0} ownerid {1}, sync date info to others...", m_block.EntityId, m_block.OwnerId);
RequestEnable(false);
m_lastOwnerSeen = DTNow.AddSeconds(10); // shift a power on by time;
}
}
else
{
// must be off
if (m_block.Enabled)
{
Logger.Log.Debug("BeaconSecurity is deactivated {0} ownerid {1}, sync date info to others...", m_block.EntityId, m_block.OwnerId);
RequestEnable(false);
}
}
}
catch (Exception ex)
{
Logger.Log.Error("Exception in BeaconSecurity: {0}", ex.Message);
}
}