Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Fixed crash in concealment, tweaks to player block enforcement, added…
Browse files Browse the repository at this point in the history
… option to turn off physics for concealed grids, tweak to grid groups
  • Loading branch information
rexxar-tc committed Jun 5, 2016
1 parent 3a21403 commit f278876
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 51 deletions.
6 changes: 3 additions & 3 deletions EssentialsPlugin/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//1
//4
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

using System.Reflection;

[assembly: AssemblyFileVersion("1.13.7.1")]
[assembly: AssemblyVersion("1.13.7.1")]
[assembly: AssemblyFileVersion("1.13.7.4")]
[assembly: AssemblyVersion("1.13.7.4")]
59 changes: 17 additions & 42 deletions EssentialsPlugin/EntityManagers/EntityManagement.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,27 @@
using Sandbox.Game.Entities;
using VRage.Game.Entity;

namespace EssentialsPlugin.EntityManagers
namespace EssentialsPlugin.EntityManagers
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using EssentialsPlugin.ProcessHandlers;
using EssentialsPlugin.Utility;
using Sandbox.Common;
using Sandbox.Common.ObjectBuilders;
using Sandbox.ModAPI;
using Sandbox.ModAPI.Ingame;
using SEModAPIInternal.API.Common;
using SEModAPIInternal.API.Entity;
using VRage.ModAPI;
using VRage.ObjectBuilders;
using VRageMath;
using IMyFunctionalBlock = Sandbox.ModAPI.Ingame.IMyFunctionalBlock;
using IMyProductionBlock = Sandbox.ModAPI.Ingame.IMyProductionBlock;
using IMyTerminalBlock = Sandbox.ModAPI.Ingame.IMyTerminalBlock;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Replication;
using Sandbox.Game.Entities;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World;
using VRage.Collections;
using Sandbox.Game.Entities.Blocks;
using Sandbox.Game.Entities.Character;
using Sandbox.Game.Entities.Cube;
using SpaceEngineers.Game.ModAPI.Ingame;
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;

class ConcealItem
{
public ConcealItem( IMyEntity _entity, string _reason )
{
this.entity = _entity;
this.reason = _reason;
}
public ConcealItem( KeyValuePair<IMyEntity, string> kvp )
{
this.entity = kvp.Key;
this.reason = kvp.Value;
}

public IMyEntity entity;
public string reason;
}


public class EntityManagement
{
private static volatile bool _checkReveal;
Expand Down Expand Up @@ -322,7 +291,7 @@ public static void CheckAndRevealEntitiesObsolete()
if (entity.InScene)
continue;

RevealEntityObsolete(new KeyValuePair<IMyEntity, string>(entity, "Obsolete Reveal"));
Wrapper.GameAction( () => RevealEntityObsolete( new KeyValuePair<IMyEntity, string>( entity, "Obsolete Reveal" ) ) );
}

DateTime reStart = DateTime.Now;
Expand Down Expand Up @@ -696,8 +665,12 @@ private static void UnregisterHierarchy( MyEntity entity )
childEntity.RemoveFromGamePruningStructure();

//child.Container.Entity.InScene = false;
//if (child.Container.Entity.Physics != null)
// child.Container.Entity.Physics.Enabled = false;

if ( !PluginSettings.Instance.DynamicConcealPhysics )
continue;

if (child.Container.Entity.Physics != null)
child.Container.Entity.Physics.Enabled = false;
}

UnregisteredEntities.Add( entity );
Expand All @@ -715,14 +688,16 @@ private static void ReregisterHierarchy( MyEntity entity )
MyEntities.RegisterForUpdate(childEntity);
childEntity.AddToGamePruningStructure();

//child.Container.Entity.InScene = false;
//if (child.Container.Entity.Physics != null)
// child.Container.Entity.Physics.Enabled = false;
//child.Container.Entity.InScene = true;

if (!PluginSettings.Instance.DynamicConcealPhysics)
continue;

if (child.Container.Entity.Physics != null)
child.Container.Entity.Physics.Enabled = true;
}

UnregisteredEntities.Remove( entity );
}
}
}

//TODO: command to remove dead owners from grid
}
17 changes: 17 additions & 0 deletions EssentialsPlugin/Essentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,23 @@ public bool DynamicConcealPirates
}
}

[Category("Dynamic Entity Management")]
[DisplayName("ConcealPhysics")]
[Description("Setting this option will turn off physics on concealed grids.")]
[Browsable(true)]
[ReadOnly(false)]
public bool DynamicConcealPhysics
{
get
{
return PluginSettings.Instance.DynamicConcealPhysics;
}
set
{
PluginSettings.Instance.DynamicConcealPhysics = value;
}
}

[Category( "Dynamic Entity Management" )]
[DisplayName( "Conceal Distance" )]
[Description( "The distance a player must be from a grid for it to be revealed due to distance. The smaller this value is, the longer a grid will be hidden from sight. Default is 8000m (max view distance)" )]
Expand Down
14 changes: 14 additions & 0 deletions EssentialsPlugin/Settings/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class PluginSettings
private bool _dynamicConcealIncludeMedBays;
private bool _dynamicShowMessages;
private bool _dynamicConcealPirates;
private bool _dynamicConcealPhysics;
private bool _dynamicTurretManagementEnabled;
private int _dynamicTurretTargetDistance;
private bool _dynamicTurretAllowExemption;
Expand Down Expand Up @@ -622,6 +623,16 @@ public bool DynamicConcealPirates
}
}

public bool DynamicConcealPhysics
{
get {return _dynamicConcealPhysics;}
set
{
_dynamicConcealPhysics = value;
Save();
}
}

public float DynamicConcealDistance
{
get { return _dynamicConcealDistance; }
Expand Down Expand Up @@ -842,6 +853,8 @@ public bool PlayerBlockEnforcementEnabled
set
{
_playerBlockEnforcementEnabled = value;
if(value)
PlayerBlockEnforcement.Init();
Save();
}
}
Expand Down Expand Up @@ -1044,6 +1057,7 @@ public PluginSettings()

_dynamicConcealDistance = 8000;
_dynamicConcealPirates = false;
_dynamicConcealPhysics = false;
_dynamicShowMessages = false;
_dynamicTurretTargetDistance = 2000;
_dynamicTurretManagementEnabled = false;
Expand Down
2 changes: 1 addition & 1 deletion EssentialsPlugin/Utility/Communication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public static void ReceiveMessageParts(byte[] data)
} );
}

private static Dictionary<int, PartialMessage> messages = new Dictionary<int, PartialMessage>();
private static Dictionary<int, PartialMessage> messages = new Dictionary<int, PartialMessage>();
private const int PACKET_SIZE = 4096;
private const int META_SIZE = sizeof(int) * 2;
private const int DATA_LENGTH = PACKET_SIZE - META_SIZE;
Expand Down
5 changes: 3 additions & 2 deletions EssentialsPlugin/Utility/GridGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ public static HashSet<GridGroup> GetGroups( HashSet<MyEntity> entities, GridLink
return;
lock (result)
if (result.Any( x => x.Grids.Contains( grid ) ))
return;
foreach(var item in result)
if ( item._grids.Contains( grid ) )
return;
var newGroup = new GridGroup( grid, linkType );
Expand Down
9 changes: 6 additions & 3 deletions EssentialsPlugin/Utility/PlayerBlockEnforcement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static class PlayerBlockEnforcement

public static void Init()
{
if ( !PluginSettings.Instance.PlayerBlockEnforcementEnabled )
return;

if (_init)
return;

Expand Down Expand Up @@ -168,7 +171,7 @@ private static void ProcessEnforcement( MyCubeBlock newBlock = null)

Task.Run( () =>
{
Essentials.Log.Debug( "process enforcement" );
//Essentials.Log.Debug( "process enforcement" );
foreach ( var item in PluginSettings.Instance.PlayerBlockEnforcementItems )
{
string blockSearch;
Expand Down Expand Up @@ -226,11 +229,11 @@ private static void ProcessEnforcement( MyCubeBlock newBlock = null)
if ( ( searchSubType && cubeBlock.BlockDefinition.Id.SubtypeId.ToString().Contains( blockSearch ) )
|| ( !searchSubType && cubeBlock.BlockDefinition.Id.TypeId.ToString().Contains( blockSearch ) ) )
{
Essentials.Log.Debug( $"found block: {cubeBlock.BlockDefinition.Id.SubtypeName}" );
//Essentials.Log.Debug( $"found block: {cubeBlock.BlockDefinition.Id.SubtypeName}" );
if ( MySession.Static.Players.IdentityIsNpc( cubeBlock.OwnerId ) )
{
Essentials.Log.Debug( "not processing NPC owned block" );
//Essentials.Log.Debug( "not processing NPC owned block" );
continue;
}
Expand Down

0 comments on commit f278876

Please sign in to comment.