Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmacle committed Apr 16, 2017
1 parent 2cfb6a8 commit 66eddee
Show file tree
Hide file tree
Showing 9 changed files with 771 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Concealment/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Torch.Commands;
using Torch.Commands.Permissions;
using VRage.Game.ModAPI;
using VRageMath;

namespace Concealment
{
public class Commands : CommandModule
{
public ConcealmentPlugin Plugin => (ConcealmentPlugin)Context.Plugin;

[Command("conceal", "Conceal grids x distance from players."), Permission(MyPromoteLevel.SpaceMaster)]
public void Conceal(double distance = 0)
{
if (distance == 0)
{
distance = Plugin.Settings.ConcealDistance;
}
var num = Plugin.ConcealDistantGrids(distance);
Context.Respond($"{num} grids concealed.");
}

[Command("reveal", "Reveal all grids within the given distance"), Permission(MyPromoteLevel.SpaceMaster)]
public void Reveal(double distance = 1000)
{
var pos = Context.Player.Controller.ControlledEntity?.Entity.GetPosition();
if (!pos.HasValue)
{
Context.Respond("You must be controlling an entity");
return;
}

var sphere = new BoundingSphereD(pos.Value, distance);
var num = Plugin.RevealGridsInSphere(sphere);
Context.Respond($"{num} grids revealed.");
}

[Command("all", "Reveal all grids", null, "reveal"), Permission(MyPromoteLevel.SpaceMaster)]
public void RevealAll()
{
int num = Plugin.RevealAll();
Context.Respond($"{num} grids revealed.");
}
}
}
95 changes: 95 additions & 0 deletions Concealment/ConcealGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Sandbox.Game.Entities;
using Sandbox.Game.Entities.Blocks;
using Sandbox.Game.World;
using SpaceEngineers.Game.Entities.Blocks;
using VRage.Groups;
using VRageMath;

namespace Concealment
{
public class ConcealGroup
{
/// <summary>
/// Entity ID of the first grid in the group.
/// </summary>
public long Id { get; }
public DateTime ConcealTime { get; set; }
public BoundingBoxD WorldAABB { get; private set; }
public List<MyCubeGrid> Grids { get; }
public List<MyMedicalRoom> MedicalRooms { get; } = new List<MyMedicalRoom>();
public List<MyCryoChamber> CryoChambers { get; } = new List<MyCryoChamber>();
internal volatile int ProxyId = -1;

public ConcealGroup(MyGroups<MyCubeGrid, MyGridPhysicalGroupData>.Group group)
{
Grids = group.Nodes.Select(n => n.NodeData).ToList();
Id = Grids.First().EntityId;
}

public string GridNames
{
get { return string.Join(", ", Grids.Select(g => g.DisplayName)); }
}

public void UpdatePostConceal()
{
UpdateAABB();
CacheSpawns();
}

private void UpdateAABB()
{
var startPos = Grids.First().PositionComp.GetPosition();
var box = new BoundingBoxD(startPos, startPos);

foreach (var aabb in Grids.Select(g => g.PositionComp.WorldAABB))
box.Include(aabb);

WorldAABB = box;
}

private void CacheSpawns()
{
MedicalRooms.Clear();
CryoChambers.Clear();

foreach (var block in Grids.SelectMany(x => x.GetFatBlocks()))
{
if (block is MyMedicalRoom medical)
MedicalRooms.Add(medical);
else if (block is MyCryoChamber cryo)
CryoChambers.Add(cryo);
}
}

public bool IsMedicalRoomAvailable(long identityId)
{
foreach (var room in MedicalRooms)
{
if (room.HasPlayerAccess(identityId) && room.IsWorking)
return true;
}

return false;
}

public bool IsCryoOccupied(ulong steamId)
{
var currentIdField = typeof(MyCryoChamber).GetField("m_currentPlayerId", BindingFlags.NonPublic | BindingFlags.Instance);

foreach (var chamber in CryoChambers)
{
var value = (MyPlayer.PlayerId?)currentIdField.GetValue(chamber);
if (value?.SteamId == steamId)
return true;
}

return false;
}
}

}
155 changes: 155 additions & 0 deletions Concealment/Concealment.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E5C0184B-7DC4-43D8-872E-2F71162748AA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Concealment</RootNamespace>
<AssemblyName>Concealment</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="HavokWrapper">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\HavokWrapper.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\NLog.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Sandbox.Common">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Common.dll</HintPath>
</Reference>
<Reference Include="Sandbox.Game">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Game.dll</HintPath>
</Reference>
<Reference Include="Sandbox.Graphics">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\Sandbox.Graphics.dll</HintPath>
</Reference>
<Reference Include="SpaceEngineers.Game">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.Game.dll</HintPath>
</Reference>
<Reference Include="SpaceEngineers.ObjectBuilders">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.dll</HintPath>
</Reference>
<Reference Include="SpaceEngineers.ObjectBuilders.XmlSerializers">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SpaceEngineers.ObjectBuilders.XmlSerializers.dll</HintPath>
</Reference>
<Reference Include="SteamSDK">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\SteamSDK.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Torch, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Torch\Torch.Server\bin\x64\Release\Torch.dll</HintPath>
</Reference>
<Reference Include="Torch.API, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Torch\Torch.Server\bin\x64\Release\Torch.API.dll</HintPath>
</Reference>
<Reference Include="VRage">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.dll</HintPath>
</Reference>
<Reference Include="VRage.Audio">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Audio.dll</HintPath>
</Reference>
<Reference Include="VRage.Dedicated">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Dedicated.dll</HintPath>
</Reference>
<Reference Include="VRage.Game">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.dll</HintPath>
</Reference>
<Reference Include="VRage.Game.XmlSerializers">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Game.XmlSerializers.dll</HintPath>
</Reference>
<Reference Include="VRage.Input">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Input.dll</HintPath>
</Reference>
<Reference Include="VRage.Library">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Library.dll</HintPath>
</Reference>
<Reference Include="VRage.Math">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Math.dll</HintPath>
</Reference>
<Reference Include="VRage.Native">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Native.dll</HintPath>
</Reference>
<Reference Include="VRage.OpenVRWrapper">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.OpenVRWrapper.dll</HintPath>
</Reference>
<Reference Include="VRage.Render">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render.dll</HintPath>
</Reference>
<Reference Include="VRage.Render11">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Render11.dll</HintPath>
</Reference>
<Reference Include="VRage.Scripting">
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Scripting.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands.cs" />
<Compile Include="ConcealGroup.cs" />
<Compile Include="ConcealmentControl.xaml.cs">
<DependentUpon>ConcealmentControl.xaml</DependentUpon>
</Compile>
<Compile Include="ConcealmentPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="ConcealmentControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
28 changes: 28 additions & 0 deletions Concealment/Concealment.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|x64.ActiveCfg = Release|x64
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|x64.Build.0 = Release|x64
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|Any CPU.Build.0 = Release|Any CPU
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.ActiveCfg = Release|x64
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
47 changes: 47 additions & 0 deletions Concealment/ConcealmentControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<UserControl x:Class="Concealment.ConcealmentControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Concealment"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<StackPanel DataContext="{Binding Settings}">
<CheckBox Content="Enable Concealment" Margin="3" IsChecked="{Binding Enabled}" />
<StackPanel Orientation="Horizontal">
<TextBox Margin="3" Width="150" Text="{Binding ConcealDistance}" />
<Label Content="Conceal Distance (meters)" Margin="3" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Margin="3" Width="150" Text="{Binding RevealDistance}" />
<Label Content="Reveal Distance (meters)" Margin="3" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Margin="3" Width="150" Text="{Binding ConcealInterval}" />
<Label Content="Conceal Interval (ticks, 1/60 s)" Margin="3" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Margin="3" Width="150" Text="{Binding RevealInterval}" />
<Label Content="Reveal Interval (ticks, 1/60 s)" Margin="3" />
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="Manual Conceal" Margin="3" Click="Conceal_OnClick" />
<Button Content="Manual Reveal" Margin="3" Click="Reveal_OnClick" />
</StackPanel>
</StackPanel>
<Button Content="Reveal Selected" Margin="3" DockPanel.Dock="Bottom" Click="ButtonBase_OnClick" />
<ListView Name="Concealed" Margin="3" DockPanel.Dock="Bottom" ItemsSource="{Binding ConcealGroups}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding GridNames}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListView>
</DockPanel>

</UserControl>
Loading

0 comments on commit 66eddee

Please sign in to comment.