First commit

This commit is contained in:
Greg Burri 2023-09-08 23:45:14 +02:00
commit 1d890b728a
24 changed files with 1814 additions and 0 deletions

View file

@ -0,0 +1,5 @@
R e a d m e
-----------
In this file you can include any instructions or other comments you want to have injected onto the
top of your final script. You can safely delete this file if you do not want any such comments.

View file

@ -0,0 +1,27 @@
using Malware.MDKUtilities;
namespace IngameScript.MDK
{
public class TestBootstrapper
{
// All the files in this folder, as well as all files containing the file ".debug.", will be excluded
// from the build process. You can use this to create utilites for testing your scripts directly in
// Visual Studio.
static TestBootstrapper()
{
// Initialize the MDK utility framework
MDKUtilityFramework.Load();
}
public static void Main()
{
// In order for your program to actually run, you will need to provide a mockup of all the facilities
// your script uses from the game, since they're not available outside of the game.
// Create and configure the desired program.
var program = MDKFactory.CreateProgram<Program>();
MDKFactory.Run(program);
}
}
}

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--
Contains basic settings that should be included in code repositories
-->
<MDKVersion>1.5.17</MDKVersion>
<MDKTrimTypes>
<Enabled>no</Enabled>
</MDKTrimTypes>
<MDKMinify>
<Level>None</Level>
</MDKMinify>
<MDKIgnore>
<Folder>mdk</Folder>
</MDKIgnore>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--
You can safely exclude this file from code repositories and use different
user settings per machine.
-->
<MDKVersion>1.5.17</MDKVersion>
<MDKUseGameBinPath>no</MDKUseGameBinPath>
<MDKGameBinPath>G:\SteamLibrary\SteamApps\common\SpaceEngineers\Bin64</MDKGameBinPath>
<MDKInstallPath>c:\users\lyssmetal\appdata\local\microsoft\visualstudio\17.0_6c02a30d\extensions\bnnd2422.thc</MDKInstallPath>
<MDKOutputPath>C:\Users\LyssMetal\AppData\Roaming\SpaceEngineers\IngameScripts\local</MDKOutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Collections.Immutable">
<HintPath>$(MDKGameBinPath)\System.Collections.Immutable.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Sandbox.Common">
<HintPath>$(MDKGameBinPath)\Sandbox.Common.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sandbox.Game">
<HintPath>$(MDKGameBinPath)\Sandbox.Game.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sandbox.Graphics">
<HintPath>$(MDKGameBinPath)\Sandbox.Graphics.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SpaceEngineers.Game">
<HintPath>$(MDKGameBinPath)\SpaceEngineers.Game.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SpaceEngineers.ObjectBuilders">
<HintPath>$(MDKGameBinPath)\SpaceEngineers.ObjectBuilders.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage">
<HintPath>$(MDKGameBinPath)\VRage.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Audio">
<HintPath>$(MDKGameBinPath)\VRage.Audio.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Game">
<HintPath>$(MDKGameBinPath)\VRage.Game.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Input">
<HintPath>$(MDKGameBinPath)\VRage.Input.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Library">
<HintPath>$(MDKGameBinPath)\VRage.Library.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Math">
<HintPath>$(MDKGameBinPath)\VRage.Math.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Render">
<HintPath>$(MDKGameBinPath)\VRage.Render.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Render11">
<HintPath>$(MDKGameBinPath)\VRage.Render11.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Scripting">
<HintPath>$(MDKGameBinPath)\VRage.Scripting.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MDKUtilities">
<HintPath>$(MDKInstallPath)\MDKUtilities.dll</HintPath>
<Private>True</Private>
</Reference>
<Analyzer Include="$(MDKInstallPath)\Analyzers\MDKAnalyzer.dll" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,85 @@
<?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>{DBCD62FE-F7AA-4A03-9241-0A4BE6952664}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>IngameScript</RootNamespace>
<AssemblyName>MiningRover</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>6</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="netstandard" />
<Reference Include="System" />
<Reference Include="System.Core" />
<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" />
</ItemGroup>
<Import Project="MDK/MDK.options.props" />
<Import Project="MDK/MDK.paths.props" Condition="exists('MDK/MDK.paths.props')" />
<ItemGroup>
<Compile Include="MDK\Bootstrapper.cs" />
<AdditionalFiles Include="MDK\MDK.options.props">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
<AdditionalFiles Include="MDK\MDK.paths.props">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
<Compile Include="Program.cs" />
<AdditionalFiles Include="Instructions.readme" />
<AdditionalFiles Include="thumb.png" />
<AdditionalFiles Include="MDK\whitelist.cache" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<Copy SourceFiles="MDK\MDK.options.props" DestinationFolder="$(TargetDir)\MDK" />
<Copy SourceFiles="MDK\MDK.paths.props" DestinationFolder="$(TargetDir)\MDK" />
</Target>
</Project>

445
MiningRover/Program.cs Normal file
View file

@ -0,0 +1,445 @@
using Sandbox.Game.EntityComponents;
using Sandbox.ModAPI.Ingame;
using Sandbox.ModAPI.Interfaces;
using SpaceEngineers.Game.ModAPI.Ingame;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using VRage;
using VRage.Collections;
using VRage.Game;
using VRage.Game.Components;
using VRage.Game.GUI.TextPanel;
using VRage.Game.ModAPI.Ingame;
using VRage.Game.ModAPI.Ingame.Utilities;
using VRage.Game.ObjectBuilders.Definitions;
using VRageMath;
namespace IngameScript
{
partial class Program : MyGridProgram
{
enum State
{
DEFAULT,
PACKING,
UNPACKING,
}
const float EPSILON = 0.05f;
const float EPSILON_RAD = (float)(Math.PI / 64);
State currentState = State.DEFAULT;
IMyMotorAdvancedStator rotor01;
IMyMotorAdvancedStator rotor02;
IMyMotorAdvancedStator hinge01;
IMyMotorAdvancedStator hinge02;
IMyMotorAdvancedStator hinge03;
IMyExtendedPistonBase piston01;
List<IMyExtendedPistonBase> pistons = new List<IMyExtendedPistonBase>();
List<string> pistonsNames = new List<string> { "Piston 02", "Piston 03", "Piston 04", "Piston 05", "Piston 06", "Piston 07", };
IMyLandingGear magneticPlateArm;
IMyLandingGear lockPlate;
IMyExtendedPistonBase lockPiston;
IMyTextSurface output;
public void Print(string text)
{
this.output.WriteText((this.output.GetText() != "" ? Environment.NewLine : "") + text, true);
}
public void PrintError(string text)
{
this.Print($"Error: {text}");
}
public Program()
{
this.output = this.Me.GetSurface(0);
this.output.ContentType = ContentType.TEXT_AND_IMAGE;
this.output.WriteText("");
this.Me.CustomData = "Packing";
this.Print("Mining rover system starting...");
var stators = new List<IMyMotorAdvancedStator>();
GridTerminalSystem.GetBlocksOfType(stators);
foreach (var s in stators)
{
if (s.DisplayNameText.Contains("Rotor 01"))
this.rotor01 = s;
else if (s.DisplayNameText.Contains("Rotor 02"))
this.rotor02 = s;
else if (s.DisplayNameText.Contains("Hinge 01"))
this.hinge01 = s;
else if (s.DisplayNameText.Contains("Hinge 02"))
this.hinge02 = s;
else if (s.DisplayNameText.Contains("Hinge 03"))
this.hinge03 = s;
}
var pistons = new List<IMyExtendedPistonBase>();
GridTerminalSystem.GetBlocksOfType(pistons);
foreach (var p in pistons)
{
if (p.DisplayNameText.Contains("Piston 01"))
{
this.piston01 = p;
}
else if (p.DisplayNameText.Contains("Lock Piston"))
{
this.lockPiston = p;
}
else
{
foreach (var name in pistonsNames)
{
if (p.DisplayNameText.Contains(name))
{
this.pistons.Add(p);
break;
}
}
}
}
var magneticPlates = new List<IMyLandingGear>();
GridTerminalSystem.GetBlocksOfType(magneticPlates);
foreach (var magneticPlate in magneticPlates)
{
if (magneticPlate.DisplayNameText.Contains("Magnetic Plate arm"))
{
this.magneticPlateArm = magneticPlate;
}
else if (magneticPlate.DisplayNameText.Contains("Lock Plate"))
{
this.lockPlate = magneticPlate;
}
}
if (this.rotor01 == null)
{
this.PrintError("Can't find 'Rotor 01'");
return;
}
if (this.rotor02 == null)
{
this.PrintError("Can't find 'Rotor 02'");
return;
}
if (this.hinge01 == null)
{
this.PrintError("Can't find 'Hinge 01'");
return;
}
if (this.hinge02 == null)
{
this.PrintError("Can't find 'Hinge 02'");
return;
}
if (this.magneticPlateArm == null)
{
this.PrintError("Can't find 'Magnetic Plate arm'");
return;
}
if (this.lockPlate == null)
{
this.PrintError("Can't find 'Lock Plate'");
return;
}
if (this.piston01 == null)
{
this.PrintError("Can't find 'Piston 01'");
return;
}
if (this.lockPiston == null)
{
this.PrintError("Can't find 'Lock Piston'");
return;
}
this.Runtime.UpdateFrequency = UpdateFrequency.Update100;
this.Print("Mining rover system has started");
}
public void Save()
{
}
/// <summary>
/// Always returns an angle between 0 and pi/2.
/// </summary>
/// <param name="a1"></param>
/// <param name="a2"></param>
/// <returns></returns>
float SumAngles(float a1, float a2)
{
var r = (float)((a1 + a2) % (2 * Math.PI));
if (r < 0)
return (float)(r + 2 * Math.PI);
else
return r;
}
// Return 'true' if the rotor is in place.
bool SetRotorVelocity(float targetAngle, IMyMotorAdvancedStator rotor, float tolerance = (float)(Math.PI / 64))
{
//if (rotor.Angle)
return false;
}
void UpdateState()
{
if (this.currentState == State.UNPACKING)
{
if (!this.piston01.Enabled)
{
this.piston01.Enabled = true;
foreach (var p in this.pistons)
p.Enabled = true;
}
bool finished = true;
//bool roverLocked = false;
if (this.magneticPlateArm.IsLocked)
this.magneticPlateArm.Unlock();
this.rotor01.TargetVelocityRPM = 0.0f;
if (this.lockPiston.CurrentPosition <= EPSILON)
{
finished = false;
this.lockPiston.Velocity = 0.5f;
}
else if (this.lockPiston.CurrentPosition >= this.lockPiston.MaxLimit - EPSILON)
{
//roverLocked = true;
if (!this.lockPlate.IsLocked)
this.lockPlate.Lock();
this.lockPiston.Velocity = 0.0f;
}
if (this.hinge01.Angle <= -Math.PI / 8)
{
this.hinge01.TargetVelocityRPM = 0.0f;
}
else // if (roverLocked)
{
this.hinge01.TargetVelocityRPM = -1.5f;
finished = false;
}
if (this.hinge02.Angle <= -Math.PI / 3)
{
this.hinge02.TargetVelocityRPM = 0.0f;
}
else // if (roverLocked)
{
this.hinge02.TargetVelocityRPM = -1.5f;
finished = false;
}
if (this.piston01.CurrentPosition <= this.piston01.MaxLimit - EPSILON /*&& roverLocked*/)
{
this.piston01.Velocity = 1.0f;
finished = false;
}
else
{
this.piston01.Velocity = 0.0f;
}
if (finished)
{
this.rotor01.RotorLock = false;
this.currentState = State.DEFAULT;
this.Print("Unpacking terminated");
}
}
else if (this.currentState == State.PACKING)
{
bool finished = true;
var rotor01InPlace = this.rotor01.Angle >= 2 * Math.PI - EPSILON_RAD || this.rotor01.Angle <= EPSILON_RAD;
if (rotor01InPlace)
{
this.rotor01.RotorLock = true;
this.rotor01.TargetVelocityRPM = 0.0f;
}
else if (this.rotor01.Angle >= Math.PI)
{
this.rotor01.TargetVelocityRPM = 1.0f;
finished = false;
}
else // if (this.rotor01.Angle <= Math.PI)
{
this.rotor01.TargetVelocityRPM = -1.0f;
finished = false;
}
//this.Print($"Hinge 01 angle: {this.hinge01.Angle}");
if (this.hinge01.Angle <= Math.PI / 4.0 || rotor01InPlace && this.hinge01.Angle <= Math.PI / 2.0 - Math.PI / 32.0)
{
this.hinge01.TargetVelocityRPM = 1.5f;
finished = false;
}
else
{
this.hinge01.TargetVelocityRPM = 0f;
}
if (this.hinge02.Angle <= -Math.PI / 32.0)
{
this.hinge02.TargetVelocityRPM = 1.5f;
finished = false;
}
else
{
this.hinge02.TargetVelocityRPM = 0f;
}
if (this.piston01.CurrentPosition >= EPSILON)
{
this.piston01.Velocity = -1.0f;
finished = false;
}
else
{
this.piston01.Velocity = 0.0f;
}
//var rotor2TargetAngle = 2 * Math.PI - Math.PI / 4; // 315°.
if (finished)
{
if (!this.magneticPlateArm.IsLocked)
this.magneticPlateArm.Lock();
if (this.lockPlate.IsLocked)
{
this.lockPlate.Unlock();
this.lockPiston.Velocity = -0.5f;
}
this.piston01.Enabled = false;
foreach (var p in this.pistons)
p.Enabled = false;
this.currentState = State.DEFAULT;
this.Print("Packing terminated");
}
}
}
/*
enum RotateDirection
{
RIGHT,
LEFT,
}
enum ElevationDirection
{
UP,
DOWN,
}
const double SPEED_ROTATION = 1.0;
const double SPEED_HINGE = 1.0;
const double SPEED_EXTEND_1 = 1.0;
const double SPEED_EXTEND_2 = 1.0;
void Rotate(RotateDirection direction)
{
//if (this.rotor01.)
}
void ChangeElevation(ElevationDirection direction)
{
}
void LockUnlock()
{
if (rotor01.Base)
}*/
public void Main(string argument, UpdateType updateSource)
{
if ((updateSource & UpdateType.Update100) != 0)
{
this.UpdateState();
}
else if ((updateSource & (UpdateType.Terminal | UpdateType.Trigger)) != 0)
{
switch (argument)
{
case "UNPACK":
this.Print("Unpacking...");
this.currentState = State.UNPACKING;
break;
case "PACK":
this.Print("Packing...");
this.currentState = State.PACKING;
break;
case "STOP":
this.currentState = State.DEFAULT;
break;
/*
case "LOCK OR UNLOCK":
LockUnlock();
break;
case "DOWN":
ChangeElevation(ElevationDirection.DOWN);
break;
case "UP":
ChangeElevation(ElevationDirection.UP);
break;
case "LEFT":
Rotate(RotateDirection.LEFT);
break;
case "RIGHT":
Rotate(RotateDirection.RIGHT);
break;*/
default:
Echo($"Uknown command: {argument}");
break;
}
}
}
}
}

BIN
MiningRover/thumb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 KiB