Add missile launcher and missile controller projects
This commit is contained in:
parent
1d890b728a
commit
6b3ee666d6
18 changed files with 992 additions and 195 deletions
27
MissileLauncher/MDK/Bootstrapper.cs
Normal file
27
MissileLauncher/MDK/Bootstrapper.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
MissileLauncher/MDK/MDK.options.props
Normal file
18
MissileLauncher/MDK/MDK.options.props
Normal 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>
|
||||
81
MissileLauncher/MDK/MDK.paths.props
Normal file
81
MissileLauncher/MDK/MDK.paths.props
Normal 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.4.14</MDKVersion>
|
||||
<MDKUseGameBinPath>no</MDKUseGameBinPath>
|
||||
<MDKGameBinPath>G:\SteamLibrary\SteamApps\common\SpaceEngineers\Bin64</MDKGameBinPath>
|
||||
<MDKInstallPath>c:\users\lyssmetal\appdata\local\microsoft\visualstudio\17.0_6c02a30d\extensions\twejjmj5.r1e</MDKInstallPath>
|
||||
<MDKOutputPath>C:\Users\LyssMetal\AppData\Roaming\SpaceEngineers\IngameScripts\local</MDKOutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<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>
|
||||
<Reference Include="System.Collections.Immutable">
|
||||
<HintPath>$(MDKGameBinPath)\System.Collections.Immutable.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Analyzer Include="$(MDKInstallPath)\Analyzers\MDKAnalyzer.dll" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
59
MissileLauncher/MissileLauncher.csproj
Normal file
59
MissileLauncher/MissileLauncher.csproj
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?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>{761F968E-CE71-404B-A20A-7C1458D6C014}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>IngameScript</RootNamespace>
|
||||
<AssemblyName>MissileLauncher</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</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>
|
||||
<Import Project="..\SECommon\SECommon.projitems" Label="Shared" />
|
||||
<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>
|
||||
193
MissileLauncher/Program.cs
Normal file
193
MissileLauncher/Program.cs
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
using Sandbox.Game.Entities.Cube;
|
||||
using Sandbox.Game.EntityComponents;
|
||||
using Sandbox.Game.GameSystems;
|
||||
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;
|
||||
|
||||
using static VRageRender.Utils.MyWingedEdgeMesh;
|
||||
|
||||
namespace IngameScript
|
||||
{
|
||||
enum State
|
||||
{
|
||||
NORMAL,
|
||||
STARTING_SEQUENCE,
|
||||
FILLING_TANK,
|
||||
LAUNCHING,
|
||||
}
|
||||
|
||||
class Missile
|
||||
{
|
||||
string prefix;
|
||||
readonly string tankName = "Hydrogen Tank";
|
||||
readonly string connectorName = "Connector";
|
||||
readonly string mergeBlockName = "Merge Block";
|
||||
readonly string programmableBlockName = "Programmable Block";
|
||||
|
||||
State currentState = State.NORMAL;
|
||||
|
||||
IMyGridTerminalSystem gridTerminalSystem;
|
||||
|
||||
IMyGasTank tank = null;
|
||||
IMyShipConnector connector = null;
|
||||
IMyShipMergeBlock mergeBlock = null;
|
||||
IMyProgrammableBlock programmableBlock = null;
|
||||
|
||||
// bool loop = false; // Not used for the moment.
|
||||
public Missile(string prefix, IMyGridTerminalSystem gridTerminalSystem)
|
||||
{
|
||||
this.prefix = prefix;
|
||||
this.gridTerminalSystem = gridTerminalSystem;
|
||||
}
|
||||
}
|
||||
|
||||
partial class Program : MyGridProgram
|
||||
{
|
||||
const string GRID_PREFIX = "[PML]";
|
||||
const string MISSILE_GRID_PREFIX = "[PM]";
|
||||
const double HYDRO_TANK_FILLED_PERCENT = 20;
|
||||
|
||||
const float EPSILON = 0.05f;
|
||||
|
||||
readonly Output output;
|
||||
|
||||
public Program()
|
||||
{
|
||||
var output = this.Me.GetSurface(0);
|
||||
this.output = new Output(output);
|
||||
this.output.Print("Missile launcher system starting...");
|
||||
|
||||
this.Runtime.UpdateFrequency = UpdateFrequency.Update100;
|
||||
|
||||
this.output.Print("Missile launcher system started");
|
||||
}
|
||||
|
||||
void UpdateState()
|
||||
{
|
||||
switch (this.currentState)
|
||||
{
|
||||
case State.STARTING_SEQUENCE:
|
||||
this.tank = this.GridTerminalSystem.GetBlockWithName("[PM] Hydrogen Tank") as IMyGasTank;
|
||||
if (this.tank == null)
|
||||
{
|
||||
this.output.Print("Cannot find the missile hydrogen tank");
|
||||
break;
|
||||
}
|
||||
|
||||
this.connector = this.GridTerminalSystem.GetBlockWithName("[PM] Connector") as IMyShipConnector;
|
||||
if (this.connector == null)
|
||||
{
|
||||
this.output.Print("Cannot find the missile connector");
|
||||
break;
|
||||
}
|
||||
|
||||
this.mergeBlock = this.GridTerminalSystem.GetBlockWithName("[PM] Merge Block") as IMyShipMergeBlock;
|
||||
if (this.mergeBlock == null)
|
||||
{
|
||||
this.output.Print("Cannot find the missile merge block");
|
||||
break;
|
||||
}
|
||||
|
||||
this.programmableBlock = this.GridTerminalSystem.GetBlockWithName("[PM] Programmable Block") as IMyProgrammableBlock;
|
||||
if (this.programmableBlock == null)
|
||||
{
|
||||
this.output.Print("Cannot find the missile programmable block");
|
||||
break;
|
||||
}
|
||||
|
||||
this.tank.Stockpile = true;
|
||||
this.connector.Connect();
|
||||
|
||||
this.currentState = State.FILLING_TANK;
|
||||
break; ;
|
||||
|
||||
case State.FILLING_TANK:
|
||||
this.output.Print("Waiting missile tank filled...");
|
||||
if (this.tank.FilledRatio >= HYDRO_TANK_FILLED_PERCENT / 100)
|
||||
{
|
||||
this.tank.Stockpile = false;
|
||||
this.currentState = State.LAUNCHING;
|
||||
}
|
||||
break;
|
||||
|
||||
case State.LAUNCHING:
|
||||
this.output.Print("Launching missile...");
|
||||
|
||||
if (this.programmableBlock.TryRun("START"))
|
||||
this.output.Print("Missile launched!");
|
||||
else
|
||||
this.output.Print("ERROR: Can't send START command to missile");
|
||||
|
||||
this.mergeBlock.Enabled = false;
|
||||
this.connector.Disconnect();
|
||||
|
||||
if (this.loop)
|
||||
this.currentState = State.STARTING_SEQUENCE;
|
||||
else
|
||||
this.currentState = State.NORMAL;
|
||||
|
||||
break;
|
||||
|
||||
case State.NORMAL:
|
||||
break; // Nothing;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
}
|
||||
|
||||
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 "LAUNCH ONE":
|
||||
this.loop = false;
|
||||
this.currentState = State.STARTING_SEQUENCE;
|
||||
break;
|
||||
|
||||
case "LAUNCH SOME":
|
||||
this.loop = true;
|
||||
this.currentState = State.STARTING_SEQUENCE;
|
||||
break;
|
||||
|
||||
case "STOP":
|
||||
this.loop = false;
|
||||
this.currentState = State.NORMAL;
|
||||
break;
|
||||
|
||||
default:
|
||||
this.output.Print($"Uknown command: {argument}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
MissileLauncher/thumb.png
Normal file
BIN
MissileLauncher/thumb.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 385 KiB |
Loading…
Add table
Add a link
Reference in a new issue