Compare commits
No commits in common. "169719ba4b3df289041ad1469c145c2c148eb166" and "d0be374ca8b05410512064dfb69e5e6a4aa321ea" have entirely different histories.
169719ba4b
...
d0be374ca8
17 changed files with 125 additions and 1253 deletions
|
|
@ -1,127 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Sandbox.ModAPI.Ingame;
|
|
||||||
|
|
||||||
using VRage;
|
|
||||||
using VRage.Game;
|
|
||||||
using VRage.Game.ModAPI.Ingame;
|
|
||||||
|
|
||||||
namespace IngameScript
|
|
||||||
{
|
|
||||||
internal class AmmoManager
|
|
||||||
{
|
|
||||||
readonly IMyGridTerminalSystem gridTerminal;
|
|
||||||
readonly IMyCubeGrid grid;
|
|
||||||
readonly Output output;
|
|
||||||
readonly IList<IMyAssembler> assemblers;
|
|
||||||
|
|
||||||
public AmmoManager(IMyGridTerminalSystem gridTerminal, IMyCubeGrid grid, Output output, IList<IMyAssembler> assemblers)
|
|
||||||
{
|
|
||||||
this.gridTerminal = gridTerminal;
|
|
||||||
this.grid = grid;
|
|
||||||
this.output = output;
|
|
||||||
this.assemblers = assemblers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AmmoStatus
|
|
||||||
{
|
|
||||||
public MyFixedPoint NbOfCannonShell { get; set; }
|
|
||||||
public MyFixedPoint NbOfArtilleryShell { get; set; }
|
|
||||||
public MyFixedPoint NbOfGatlingAmmo { get; set; }
|
|
||||||
|
|
||||||
public AmmoStatus Copy()
|
|
||||||
{
|
|
||||||
return this.MemberwiseClone() as AmmoStatus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BuildAmmo(AmmoStatus status)
|
|
||||||
{
|
|
||||||
if (this.assemblers.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var mainAssembler = this.assemblers[0];
|
|
||||||
|
|
||||||
var statusWithAssemblerQueues = status.Copy();
|
|
||||||
|
|
||||||
// Add the current Queue.
|
|
||||||
foreach (var assembler in this.gridTerminal.GetBlocks<IMyAssembler>(grid: this.grid))
|
|
||||||
{
|
|
||||||
var queue = new List<MyProductionItem>();
|
|
||||||
assembler.GetQueue(queue);
|
|
||||||
|
|
||||||
foreach (var item in queue)
|
|
||||||
{
|
|
||||||
if (item.BlueprintId == Constants.CANNON_SHELL_BLUEPRINT_ID)
|
|
||||||
statusWithAssemblerQueues.NbOfCannonShell += item.Amount;
|
|
||||||
else if (item.BlueprintId == Constants.ARTILLERY_SHELL_BLUEPRINT_ID)
|
|
||||||
statusWithAssemblerQueues.NbOfArtilleryShell += item.Amount;
|
|
||||||
else if (item.BlueprintId == Constants.GATLING_AMMO_BLUEPRINT_ID)
|
|
||||||
statusWithAssemblerQueues.NbOfGatlingAmmo += item.Amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statusWithAssemblerQueues.NbOfCannonShell < Constants.NUMBER_OF_CANNON_SHELL)
|
|
||||||
{
|
|
||||||
var toBuild = Constants.NUMBER_OF_CANNON_SHELL - statusWithAssemblerQueues.NbOfCannonShell;
|
|
||||||
this.output.Print($"Requesting {toBuild} of {Constants.CANNON_SHELL_BLUEPRINT_ID.SubtypeName}");
|
|
||||||
mainAssembler.AddQueueItem(Constants.CANNON_SHELL_BLUEPRINT_ID, toBuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statusWithAssemblerQueues.NbOfArtilleryShell < Constants.NUMBER_OF_ARTILLERY_SHELL)
|
|
||||||
{
|
|
||||||
var toBuild = Constants.NUMBER_OF_ARTILLERY_SHELL - statusWithAssemblerQueues.NbOfArtilleryShell;
|
|
||||||
this.output.Print($"Requesting {toBuild} of {Constants.ARTILLERY_SHELL_BLUEPRINT_ID.SubtypeName}");
|
|
||||||
mainAssembler.AddQueueItem(Constants.ARTILLERY_SHELL_BLUEPRINT_ID, toBuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statusWithAssemblerQueues.NbOfGatlingAmmo < Constants.NUMBER_OF_GATLING_AMMO)
|
|
||||||
{
|
|
||||||
var toBuild = Constants.NUMBER_OF_GATLING_AMMO - statusWithAssemblerQueues.NbOfGatlingAmmo;
|
|
||||||
this.output.Print($"Requesting {toBuild} of {Constants.GATLING_AMMO_BLUEPRINT_ID.SubtypeName}");
|
|
||||||
mainAssembler.AddQueueItem(Constants.GATLING_AMMO_BLUEPRINT_ID, toBuild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DisplayAmmoStatus(StringBuilder sb, AmmoStatus status)
|
|
||||||
{
|
|
||||||
var assaultConnonShell = "Assault Cannon Shell:";
|
|
||||||
sb.Append(assaultConnonShell);
|
|
||||||
sb.AppendLine($"{status.NbOfCannonShell}".PadLeft(Constants.CONSOLE_LINE_LENGTH - assaultConnonShell.Length));
|
|
||||||
|
|
||||||
var artilleryShell = "Artillery Shell:";
|
|
||||||
sb.Append(artilleryShell);
|
|
||||||
sb.AppendLine($"{status.NbOfArtilleryShell}".PadLeft(Constants.CONSOLE_LINE_LENGTH - artilleryShell.Length));
|
|
||||||
|
|
||||||
var gatlingAmmo = "Gatling Ammo Box";
|
|
||||||
sb.Append(gatlingAmmo);
|
|
||||||
sb.AppendLine($"{status.NbOfGatlingAmmo}".PadLeft(Constants.CONSOLE_LINE_LENGTH - gatlingAmmo.Length));
|
|
||||||
}
|
|
||||||
|
|
||||||
public AmmoStatus GetAmmoStatus()
|
|
||||||
{
|
|
||||||
var status = new AmmoStatus();
|
|
||||||
|
|
||||||
foreach (var inventory in this.gridTerminal.GetAllInventories(grid))
|
|
||||||
{
|
|
||||||
var items = new List<MyInventoryItem>();
|
|
||||||
inventory.GetItems(items);
|
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
if (item.Type.SubtypeId == "MediumCalibreAmmo")
|
|
||||||
status.NbOfCannonShell += item.Amount;
|
|
||||||
else if (item.Type.SubtypeId == "LargeCalibreAmmo")
|
|
||||||
status.NbOfArtilleryShell += item.Amount;
|
|
||||||
else if (item.Type.SubtypeId == "NATO_25x184mm")
|
|
||||||
status.NbOfGatlingAmmo += item.Amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using VRage;
|
|
||||||
using VRage.Game;
|
|
||||||
using VRage.Game.ModAPI.Ingame;
|
|
||||||
|
|
||||||
namespace IngameScript
|
|
||||||
{
|
|
||||||
class ComponentType
|
|
||||||
{
|
|
||||||
public readonly MyItemType ItemType;
|
|
||||||
public readonly MyDefinitionId BlueprintId;
|
|
||||||
|
|
||||||
public ComponentType(MyItemType itemType, MyDefinitionId blueprintId)
|
|
||||||
{
|
|
||||||
this.ItemType = itemType;
|
|
||||||
this.BlueprintId = blueprintId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ComponentQuantity
|
|
||||||
{
|
|
||||||
public readonly ComponentType ComponentType;
|
|
||||||
public readonly MyFixedPoint Quantity;
|
|
||||||
|
|
||||||
public ComponentQuantity(MyItemType itemType, MyDefinitionId blueprintId, MyFixedPoint quantity)
|
|
||||||
{
|
|
||||||
|
|
||||||
this.ComponentType = new ComponentType(itemType, blueprintId);
|
|
||||||
this.Quantity = quantity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using VRage.Game;
|
|
||||||
|
|
||||||
namespace IngameScript
|
|
||||||
{
|
|
||||||
internal static class Constants
|
|
||||||
{
|
|
||||||
public const int NUMBER_OF_MISSILES = 3; // The quantity of components will be created to build this quantity of missiles.
|
|
||||||
|
|
||||||
public const int NUMBER_OF_CANNON_SHELL = 200;
|
|
||||||
public const int NUMBER_OF_ARTILLERY_SHELL = 50;
|
|
||||||
public const int NUMBER_OF_GATLING_AMMO = 500;
|
|
||||||
|
|
||||||
public const int CONSOLE_NB_LINES = 14;
|
|
||||||
public const int CONSOLE_LINE_LENGTH = 50;
|
|
||||||
public const string GRID_PREFIX = "[Mimine]";
|
|
||||||
|
|
||||||
public static readonly MyDefinitionId CANNON_SHELL_BLUEPRINT_ID = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/Position0110_MediumCalibreAmmo");
|
|
||||||
public static readonly MyDefinitionId ARTILLERY_SHELL_BLUEPRINT_ID = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/Position0120_LargeCalibreAmmo");
|
|
||||||
public static readonly MyDefinitionId GATLING_AMMO_BLUEPRINT_ID = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/Position0080_NATO_25x184mmMagazine");
|
|
||||||
|
|
||||||
public const float EPSILON = 0.05f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
144
Mimine/Ingots.cs
144
Mimine/Ingots.cs
|
|
@ -1,144 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.CodeDom;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Sandbox.ModAPI.Ingame;
|
|
||||||
|
|
||||||
using VRage;
|
|
||||||
using VRage.Game;
|
|
||||||
using VRage.Game.ModAPI.Ingame;
|
|
||||||
|
|
||||||
namespace IngameScript
|
|
||||||
{
|
|
||||||
enum IngotsEnum
|
|
||||||
{
|
|
||||||
Iron = 0,
|
|
||||||
Nickel = 1,
|
|
||||||
Cobalt = 2,
|
|
||||||
Magnesium = 3,
|
|
||||||
Silicon = 4,
|
|
||||||
Silver = 5,
|
|
||||||
Gold = 6,
|
|
||||||
Platinum = 7,
|
|
||||||
Uranium = 8,
|
|
||||||
Gravel = 9, // Named 'Stone' in the API.
|
|
||||||
}
|
|
||||||
|
|
||||||
class IngotException : Exception
|
|
||||||
{
|
|
||||||
public IngotException(string mess) :
|
|
||||||
base(mess)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Ingot
|
|
||||||
{
|
|
||||||
public static MyItemType FromEnum(IngotsEnum ingot)
|
|
||||||
{
|
|
||||||
var name = "";
|
|
||||||
switch (ingot)
|
|
||||||
{
|
|
||||||
case IngotsEnum.Iron: name = "Iron"; break;
|
|
||||||
case IngotsEnum.Nickel: name = "Nickel"; break;
|
|
||||||
case IngotsEnum.Cobalt: name = "Cobalt"; break;
|
|
||||||
case IngotsEnum.Magnesium: name = "Magnesium"; break;
|
|
||||||
case IngotsEnum.Silicon: name = "Silicon"; break;
|
|
||||||
case IngotsEnum.Silver: name = "Silver"; break;
|
|
||||||
case IngotsEnum.Gold: name = "Gold"; break;
|
|
||||||
case IngotsEnum.Platinum: name = "Platinum"; break;
|
|
||||||
case IngotsEnum.Uranium: name = "Uranium"; break;
|
|
||||||
case IngotsEnum.Gravel: name = "Stone"; break;
|
|
||||||
}
|
|
||||||
return MyItemType.MakeIngot(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IngotsEnum FromSubTypeId(string id)
|
|
||||||
{
|
|
||||||
IngotsEnum enumValue = IngotsEnum.Iron;
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case "Iron": enumValue = IngotsEnum.Iron; break;
|
|
||||||
case "Nickel": enumValue = IngotsEnum.Nickel; break;
|
|
||||||
case "Cobalt": enumValue = IngotsEnum.Cobalt; break;
|
|
||||||
case "Magnesium": enumValue = IngotsEnum.Magnesium; break;
|
|
||||||
case "Silicon": enumValue = IngotsEnum.Silicon; break;
|
|
||||||
case "Silver": enumValue = IngotsEnum.Silver; break;
|
|
||||||
case "Gold": enumValue = IngotsEnum.Gold; break;
|
|
||||||
case "Platinum": enumValue = IngotsEnum.Platinum; break;
|
|
||||||
case "Uranium": enumValue = IngotsEnum.Uranium; break;
|
|
||||||
case "Stone": enumValue = IngotsEnum.Gravel; break;
|
|
||||||
default: throw new IngotException($"Unknown ingot id: {id}");
|
|
||||||
}
|
|
||||||
return enumValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class Ingots
|
|
||||||
{
|
|
||||||
readonly float[] ingots = new float[10];
|
|
||||||
|
|
||||||
public Ingots(float iron = 0, float nickel = 0, float cobalt = 0, float magnesium = 0, float silicon = 0, float silver = 0, float gold = 0, float platinum = 0, float uranium = 0, float gravel = 0)
|
|
||||||
{
|
|
||||||
ingots[(int)IngotsEnum.Iron] = iron;
|
|
||||||
ingots[(int)IngotsEnum.Nickel] = nickel;
|
|
||||||
ingots[(int)IngotsEnum.Cobalt] = cobalt;
|
|
||||||
ingots[(int)IngotsEnum.Magnesium] = magnesium;
|
|
||||||
ingots[(int)IngotsEnum.Silicon] = silicon;
|
|
||||||
ingots[(int)IngotsEnum.Silver] = silver;
|
|
||||||
ingots[(int)IngotsEnum.Gold] = gold;
|
|
||||||
ingots[(int)IngotsEnum.Platinum] = platinum;
|
|
||||||
ingots[(int)IngotsEnum.Uranium] = uranium;
|
|
||||||
ingots[(int)IngotsEnum.Gravel] = gravel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float this[IngotsEnum ingot]
|
|
||||||
{
|
|
||||||
get { return ingots[(int)ingot]; }
|
|
||||||
set { ingots[(int)ingot] = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Ingots operator +(Ingots a, Ingots b)
|
|
||||||
{
|
|
||||||
var result = new Ingots();
|
|
||||||
for (int i = 0; i < result.ingots.Length; i++)
|
|
||||||
result.ingots[i] = a.ingots[i] + b.ingots[i];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
foreach (var ingot in Enum.GetValues(typeof(IngotsEnum)).Cast<IngotsEnum>())
|
|
||||||
{
|
|
||||||
sb.AppendLine($"{ingot}: {this[ingot]}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class IngotsUtils
|
|
||||||
{
|
|
||||||
public static Ingots IngotsFromGridContainers(this IMyGridTerminalSystem gridTerminal, IMyCubeGrid grid)
|
|
||||||
{
|
|
||||||
var ingots = new Ingots();
|
|
||||||
|
|
||||||
foreach (var inventory in gridTerminal.GetAllInventories(grid))
|
|
||||||
{
|
|
||||||
var items = new List<MyInventoryItem>();
|
|
||||||
inventory.GetItems(items);
|
|
||||||
|
|
||||||
foreach (var item in items)
|
|
||||||
if (item.Type.TypeId == "MyObjectBuilder_Ingot")
|
|
||||||
ingots[Ingot.FromSubTypeId(item.Type.SubtypeId)] += (float)item.Amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ingots;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netframework48</TargetFramework>
|
|
||||||
<RootNamespace>IngameScript</RootNamespace>
|
|
||||||
<LangVersion>6</LangVersion>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
|
||||||
<Configurations>Release;Debug</Configurations>
|
|
||||||
<Platforms>x64</Platforms>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Mal.Mdk2.PbAnalyzers" Version="2.1.13">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Mal.Mdk2.PbPackager" Version="2.1.5">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Mal.Mdk2.References" Version="2.2.4">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="Instructions.readme" />
|
|
||||||
<AdditionalFiles Include="Instructions.readme" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Import Project="..\SECommon\SECommon.projitems" Label="Shared" />
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
; This file is project specific and should be checked in to source control.
|
|
||||||
|
|
||||||
[mdk]
|
|
||||||
; This is a programmable block script project.
|
|
||||||
; You should not change this.
|
|
||||||
type=programmableblock
|
|
||||||
|
|
||||||
; Toggle trace (on|off) (verbose output)
|
|
||||||
trace=off
|
|
||||||
|
|
||||||
; What type of minification to use (none|trim|stripcomments|lite|full)
|
|
||||||
; none: No minification
|
|
||||||
; trim: Removes unused types (NOT members).
|
|
||||||
; stripcomments: trim + removes comments.
|
|
||||||
; lite: stripcomments + removes leading/trailing whitespace.
|
|
||||||
; full: lite + renames identifiers to shorter names.
|
|
||||||
minify=none
|
|
||||||
|
|
||||||
; A list of files and folder to ignore when creating the script.
|
|
||||||
; This is a comma separated list of glob patterns.
|
|
||||||
; See https://code.visualstudio.com/docs/editor/glob-patterns
|
|
||||||
ignores=obj/**/*,MDK/**/*,**/*.debug.cs
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
; This file is _local_ to your machine and should not be checked in to source control.
|
|
||||||
|
|
||||||
[mdk]
|
|
||||||
; Where to output the script to (auto|specific path)
|
|
||||||
output=auto
|
|
||||||
; Override the default binary path (auto|specific path)
|
|
||||||
binarypath=auto
|
|
||||||
|
|
@ -1,209 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Sandbox.ModAPI.Ingame;
|
|
||||||
|
|
||||||
using VRage;
|
|
||||||
using VRage.Game;
|
|
||||||
using VRage.Game.ModAPI.Ingame;
|
|
||||||
|
|
||||||
namespace IngameScript
|
|
||||||
{
|
|
||||||
internal class MissileManager
|
|
||||||
{
|
|
||||||
readonly IMyGridTerminalSystem gridTerminal;
|
|
||||||
readonly IMyCubeGrid grid;
|
|
||||||
readonly Output output;
|
|
||||||
readonly IList<IMyAssembler> assemblers;
|
|
||||||
|
|
||||||
static readonly List<ComponentQuantity> MISSILE_COMPONENTS = new List<ComponentQuantity>{
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("SteelPlate"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/SteelPlate"), 254),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("Construction"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/ConstructionComponent"), 172),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("Motor"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/MotorComponent"), 18),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("InteriorPlate"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/InteriorPlate"), 43),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("Computer"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/ComputerComponent"), 53),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("PowerCell"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/PowerCell"), 2),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("Display"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/Display"), 1),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("SmallTube"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/SmallTube"), 27),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("MetalGrid"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/MetalGrid"), 48),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("LargeTube"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/LargeTube"), 16),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("Detector"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/DetectorComponent"), 14),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("RadioCommunication"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/RadioCommunicationComponent"), 22),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("Girder"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/GirderComponent"), 11),
|
|
||||||
new ComponentQuantity(MyItemType.MakeComponent("Explosives"), MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/ExplosivesComponent"), 22),
|
|
||||||
};
|
|
||||||
|
|
||||||
// In kg.
|
|
||||||
static readonly Dictionary<string, Ingots> INGOTS_PER_COMPONENT = new Dictionary<string, Ingots>
|
|
||||||
{
|
|
||||||
["SteelPlate"] = new Ingots(iron: 21),
|
|
||||||
["Construction"] = new Ingots(iron: 8),
|
|
||||||
["Motor"] = new Ingots(iron: 20, nickel: 5),
|
|
||||||
["InteriorPlate"] = new Ingots(iron: 3),
|
|
||||||
["Computer"] = new Ingots(iron: 0.5f, silicon: 0.2f),
|
|
||||||
["PowerCell"] = new Ingots(iron: 10, nickel: 2, silicon: 1),
|
|
||||||
["Display"] = new Ingots(iron: 1, silicon: 5),
|
|
||||||
["SmallTube"] = new Ingots(iron: 5),
|
|
||||||
["MetalGrid"] = new Ingots(iron: 12, nickel: 5, cobalt: 3),
|
|
||||||
["LargeTube"] = new Ingots(iron: 30),
|
|
||||||
["Detector"] = new Ingots(iron: 5, nickel: 15),
|
|
||||||
["RadioCommunication"] = new Ingots(iron: 8, silicon: 1),
|
|
||||||
["Girder"] = new Ingots(iron: 6),
|
|
||||||
["Explosives"] = new Ingots(silicon: 0.5f, magnesium: 2),
|
|
||||||
};
|
|
||||||
|
|
||||||
static readonly Ingots INGOTS_PER_MISSILE;
|
|
||||||
|
|
||||||
static MissileManager()
|
|
||||||
{
|
|
||||||
INGOTS_PER_MISSILE = new Ingots();
|
|
||||||
foreach (var component in MISSILE_COMPONENTS)
|
|
||||||
{
|
|
||||||
INGOTS_PER_MISSILE += INGOTS_PER_COMPONENT[component.ComponentType.ItemType.SubtypeId];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MissileManager(IMyGridTerminalSystem gridTerminal, IMyCubeGrid grid, Output output, IList<IMyAssembler> assemblers)
|
|
||||||
{
|
|
||||||
this.gridTerminal = gridTerminal;
|
|
||||||
this.grid = grid;
|
|
||||||
this.output = output;
|
|
||||||
this.assemblers = assemblers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BuildComponentForMissiles()
|
|
||||||
{
|
|
||||||
if (this.assemblers.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var existingAmounts = this.GetCurrentItemQuantity(MISSILE_COMPONENTS.Select(quantity => quantity.ComponentType));
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
foreach (var missileComponent in MISSILE_COMPONENTS)
|
|
||||||
{
|
|
||||||
var existing = existingAmounts[i];
|
|
||||||
//this.output.Print($"{missileComponent.ItemType}: {existing}");
|
|
||||||
|
|
||||||
var desired = missileComponent.Quantity * Constants.NUMBER_OF_MISSILES;
|
|
||||||
|
|
||||||
if (existing < desired)
|
|
||||||
{
|
|
||||||
var toBuild = desired - existing;
|
|
||||||
this.output.Print($"Requesting {toBuild} of {missileComponent.ComponentType.BlueprintId.SubtypeName}");
|
|
||||||
this.assemblers[0].AddQueueItem(missileComponent.ComponentType.BlueprintId, toBuild);
|
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IngotsMissileStatus
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public float Amount { get; set; }
|
|
||||||
|
|
||||||
public float NbOfMissiles { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IngotsStatus
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public float Amount { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Display how many missile can be build with the current ingot stock.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="output"></param>
|
|
||||||
public void DisplayIngotsStatus(StringBuilder sb)
|
|
||||||
{
|
|
||||||
var ingots = this.gridTerminal.IngotsFromGridContainers(this.grid);
|
|
||||||
|
|
||||||
var ingotsMissileStatus = new List<IngotsMissileStatus>();
|
|
||||||
var ingotsStatusRest = new List<IngotsStatus>(); // For ingots not needed by missiles.
|
|
||||||
|
|
||||||
foreach (var ingot in Enum.GetValues(typeof(IngotsEnum)).Cast<IngotsEnum>())
|
|
||||||
{
|
|
||||||
var amount = ingots[ingot];
|
|
||||||
var amountNeeded = INGOTS_PER_MISSILE[ingot];
|
|
||||||
|
|
||||||
if (amountNeeded != 0f)
|
|
||||||
ingotsMissileStatus.Add(new IngotsMissileStatus { Name = ingot.ToString(), Amount = amount, NbOfMissiles = amount / amountNeeded });
|
|
||||||
else
|
|
||||||
ingotsStatusRest.Add(new IngotsStatus { Name = ingot.ToString(), Amount = amount });
|
|
||||||
}
|
|
||||||
|
|
||||||
ingotsMissileStatus.Sort((a, b) => b.NbOfMissiles.CompareTo(a.NbOfMissiles));
|
|
||||||
|
|
||||||
sb.AppendLine();
|
|
||||||
sb.AppendLine($"Nb of missiles buildable: {(int)ingotsMissileStatus.Last().NbOfMissiles}");
|
|
||||||
sb.AppendLine(new string('-', Constants.CONSOLE_LINE_LENGTH));
|
|
||||||
|
|
||||||
foreach (var ingotMissileStatus in ingotsMissileStatus)
|
|
||||||
{
|
|
||||||
var name = $"{ingotMissileStatus.Name} ({(int)ingotMissileStatus.NbOfMissiles}):";
|
|
||||||
sb.Append(name);
|
|
||||||
var value = $"{ingotMissileStatus.Amount:N2} kg";
|
|
||||||
sb.AppendLine(value.PadLeft(Constants.CONSOLE_LINE_LENGTH - name.Length));
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.AppendLine(new string('-', Constants.CONSOLE_LINE_LENGTH));
|
|
||||||
|
|
||||||
foreach (var ingotStatus in ingotsStatusRest)
|
|
||||||
{
|
|
||||||
var name = $"{ingotStatus.Name}:";
|
|
||||||
sb.Append(name);
|
|
||||||
var value = $"{ingotStatus.Amount:N2} kg";
|
|
||||||
sb.AppendLine(value.PadLeft(Constants.CONSOLE_LINE_LENGTH - name.Length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// It counts elements in queue in assemblers too.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="componentTypes"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
List<MyFixedPoint> GetCurrentItemQuantity(IEnumerable<ComponentType> componentTypes)
|
|
||||||
{
|
|
||||||
var total = new List<MyFixedPoint>(new MyFixedPoint[componentTypes.Count()]);
|
|
||||||
|
|
||||||
foreach (var inventory in this.gridTerminal.GetAllInventories(grid))
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
foreach (var componentType in componentTypes)
|
|
||||||
{
|
|
||||||
var items = inventory.FindItem(componentType.ItemType);
|
|
||||||
if (items.HasValue)
|
|
||||||
total[i] += items.Value.Amount;
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special case for assemblers: check the current queue.
|
|
||||||
foreach (var assembler in this.gridTerminal.GetBlocks<IMyAssembler>(grid: this.grid))
|
|
||||||
{
|
|
||||||
var queue = new List<MyProductionItem>();
|
|
||||||
assembler.GetQueue(queue);
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
foreach (var componentType in componentTypes)
|
|
||||||
{
|
|
||||||
foreach (var item in queue)
|
|
||||||
{
|
|
||||||
if (item.BlueprintId == componentType.BlueprintId)
|
|
||||||
total[i] += item.Amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,260 +0,0 @@
|
||||||
using Sandbox.Game;
|
|
||||||
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.ComponentModel;
|
|
||||||
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 VRage.Game.VisualScripting;
|
|
||||||
using VRage.GameServices;
|
|
||||||
using VRage.ObjectBuilders;
|
|
||||||
|
|
||||||
using VRageMath;
|
|
||||||
|
|
||||||
namespace IngameScript
|
|
||||||
{
|
|
||||||
partial class Program : MyGridProgram
|
|
||||||
{
|
|
||||||
enum State
|
|
||||||
{
|
|
||||||
IDLE,
|
|
||||||
BUILD_COMPONENTS_MISSILES,
|
|
||||||
}
|
|
||||||
|
|
||||||
State currentState = State.IDLE;
|
|
||||||
|
|
||||||
readonly IMyCubeGrid grid;
|
|
||||||
|
|
||||||
readonly Output output;
|
|
||||||
|
|
||||||
readonly Output leftPanel;
|
|
||||||
readonly Output rightPanel;
|
|
||||||
|
|
||||||
readonly List<IMyAssembler> assemblers = new List<IMyAssembler>(); // First one is the main assembler.
|
|
||||||
|
|
||||||
readonly MissileManager missileManager;
|
|
||||||
readonly AmmoManager ammoManager;
|
|
||||||
|
|
||||||
public Program()
|
|
||||||
{
|
|
||||||
this.grid = this.Me.CubeGrid;
|
|
||||||
|
|
||||||
var cockpitPilot = this.GridTerminalSystem.GetBlock<IMyCockpit>("[Mimine] Control Seat Main");
|
|
||||||
var cockpitCopilot = this.GridTerminalSystem.GetBlock<IMyCockpit>("[Mimine] Control Seat Copilot");
|
|
||||||
|
|
||||||
var output = this.Me.GetSurface(0);
|
|
||||||
this.output = new Output(output, Constants.CONSOLE_NB_LINES);
|
|
||||||
|
|
||||||
this.output.Print("Mimine system starting...");
|
|
||||||
|
|
||||||
this.leftPanel = new Output(new List<IMyTextSurface> { this.GridTerminalSystem.GetBlock<IMyTextPanel>("[Mimine] LCD Panel 01", this.grid), cockpitCopilot.GetSurface(1), cockpitPilot.GetSurface(1) });
|
|
||||||
this.rightPanel = new Output(new List<IMyTextSurface> { this.GridTerminalSystem.GetBlock<IMyTextPanel>("[Mimine] LCD Panel 02", this.grid), cockpitCopilot.GetSurface(0), cockpitPilot.GetSurface(0) });
|
|
||||||
|
|
||||||
foreach (var assembler in this.GridTerminalSystem.GetBlocks<IMyAssembler>(grid: this.grid))
|
|
||||||
{
|
|
||||||
if (assembler.BlockDefinition.SubtypeName == "LargeAssembler")
|
|
||||||
{
|
|
||||||
if (assembler.CooperativeMode)
|
|
||||||
this.assemblers.Add(assembler);
|
|
||||||
else
|
|
||||||
this.assemblers.Insert(0, assembler);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Not very useful to inform about ignored assemblers -> commented out.
|
|
||||||
//this.output.Print($"Assembler Ignored, not a large assembler:");
|
|
||||||
//this.output.Print($" {assembler.CustomName}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.assemblers.Count == 0)
|
|
||||||
this.output.PrintError("No assembler found");
|
|
||||||
else
|
|
||||||
this.output.Print($"Main assembler: {this.assemblers[0].CustomName}");
|
|
||||||
|
|
||||||
this.missileManager = new MissileManager(this.GridTerminalSystem, this.grid, this.output, this.assemblers);
|
|
||||||
this.ammoManager = new AmmoManager(this.GridTerminalSystem, this.grid, this.output, this.assemblers);
|
|
||||||
|
|
||||||
Runtime.UpdateFrequency = UpdateFrequency.Update100;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 "BUILD":
|
|
||||||
this.currentState = State.BUILD_COMPONENTS_MISSILES;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "STOP":
|
|
||||||
this.currentState = State.IDLE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
this.output.Print($"Uknown command: {argument}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateState()
|
|
||||||
{
|
|
||||||
var ammoStatus = this.ammoManager.GetAmmoStatus();
|
|
||||||
|
|
||||||
if (this.currentState == State.BUILD_COMPONENTS_MISSILES)
|
|
||||||
{
|
|
||||||
this.missileManager.BuildComponentForMissiles();
|
|
||||||
this.ammoManager.BuildAmmo(ammoStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.DisplayStatus();
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
this.missileManager.DisplayIngotsStatus(sb);
|
|
||||||
sb.AppendLine(new string('-', Constants.CONSOLE_LINE_LENGTH));
|
|
||||||
this.ammoManager.DisplayAmmoStatus(sb, ammoStatus);
|
|
||||||
this.rightPanel.Display(sb.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DisplayStatus()
|
|
||||||
{
|
|
||||||
var cargoSpace = this.GetCargoSpace();
|
|
||||||
var energyState = this.GetEnergyState();
|
|
||||||
var hydrogenVolume = this.GetHydrogenVolume();
|
|
||||||
var oxygenVolume = this.GetOxygenVolume();
|
|
||||||
|
|
||||||
this.leftPanel.Display(
|
|
||||||
$@"
|
|
||||||
{cargoSpace.ToString("Cargo volume", "kL")}
|
|
||||||
|
|
||||||
{energyState.ToString("Energy", "MWh")}
|
|
||||||
|
|
||||||
{hydrogenVolume.ToString("Hydrogen", "L")}
|
|
||||||
|
|
||||||
{oxygenVolume.ToString("Oxygen", "L")}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Quantity
|
|
||||||
{
|
|
||||||
public Quantity(double current, double total)
|
|
||||||
{
|
|
||||||
this.Current = current;
|
|
||||||
this.Total = total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public readonly double Current;
|
|
||||||
public readonly double Total;
|
|
||||||
|
|
||||||
public string ToString(string name, string unit)
|
|
||||||
{
|
|
||||||
var firstLine = new StringBuilder();
|
|
||||||
firstLine.Append(name).Append(": ");
|
|
||||||
var values = $"{this.Current:N1} {unit} / {this.Total:N1} {unit}";
|
|
||||||
firstLine.Append(values.PadLeft(Constants.CONSOLE_LINE_LENGTH - firstLine.Length));
|
|
||||||
|
|
||||||
var secondLine = new StringBuilder();
|
|
||||||
secondLine.Append("[");
|
|
||||||
var ratio = this.Current / this.Total;
|
|
||||||
var percentStr = $"{ratio * 100.0,8:N1}%";
|
|
||||||
// "-2" because of the starting and ending characters: '[', ']'.
|
|
||||||
var gaugeSize = Constants.CONSOLE_LINE_LENGTH - percentStr.Length - 2;
|
|
||||||
var n = (int)((double)gaugeSize * ratio);
|
|
||||||
secondLine.Append(new string('|', n));
|
|
||||||
secondLine.Append(new string(' ', gaugeSize - n)).Append("]");
|
|
||||||
secondLine.Append(percentStr);
|
|
||||||
|
|
||||||
return $"{firstLine}\n{secondLine}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Quantity GetCargoSpace()
|
|
||||||
{
|
|
||||||
var containers = this.GridTerminalSystem.GetBlocks<IMyCargoContainer>(grid: this.grid);
|
|
||||||
|
|
||||||
double currentVolume = 0;
|
|
||||||
double totalVolume = 0;
|
|
||||||
|
|
||||||
foreach (var container in containers)
|
|
||||||
{
|
|
||||||
var inventory = container.GetInventory();
|
|
||||||
currentVolume += (double)inventory.CurrentVolume;
|
|
||||||
totalVolume += (double)inventory.MaxVolume;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Quantity(currentVolume, totalVolume);
|
|
||||||
}
|
|
||||||
|
|
||||||
Quantity GetEnergyState()
|
|
||||||
{
|
|
||||||
double currentkWh = 0;
|
|
||||||
double maxkWh = 0;
|
|
||||||
var batteries = this.GridTerminalSystem.GetBlocks<IMyBatteryBlock>(grid: this.grid);
|
|
||||||
|
|
||||||
foreach (var battery in batteries)
|
|
||||||
{
|
|
||||||
currentkWh += (double)battery.CurrentStoredPower;
|
|
||||||
maxkWh += (double)battery.MaxStoredPower;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Quantity(currentkWh, maxkWh);
|
|
||||||
}
|
|
||||||
|
|
||||||
Quantity GetHydrogenVolume()
|
|
||||||
{
|
|
||||||
double currentVolume = 0;
|
|
||||||
double totalVolume = 0;
|
|
||||||
var tanks = this.GridTerminalSystem.GetBlocks<IMyGasTank>(grid: this.grid, filter: tank => tank.CustomName.Contains("Hydrogen"));
|
|
||||||
|
|
||||||
foreach (var tank in tanks)
|
|
||||||
{
|
|
||||||
currentVolume += (double)tank.Capacity * (double)tank.FilledRatio;
|
|
||||||
totalVolume += (double)tank.Capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Quantity(currentVolume, totalVolume);
|
|
||||||
}
|
|
||||||
|
|
||||||
Quantity GetOxygenVolume()
|
|
||||||
{
|
|
||||||
double currentVolume = 0;
|
|
||||||
double totalVolume = 0;
|
|
||||||
var tanks = this.GridTerminalSystem.GetBlocks<IMyGasTank>(grid: this.grid, filter: tank => tank.CustomName.Contains("Oxygen"));
|
|
||||||
|
|
||||||
foreach (var tank in tanks)
|
|
||||||
{
|
|
||||||
currentVolume += (double)tank.Capacity * (double)tank.FilledRatio;
|
|
||||||
totalVolume += (double)tank.Capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Quantity(currentVolume, totalVolume);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
<package id="Mal.Mdk2.PbPackager" version="2.0.0-alpha073" targetFramework="net48" />
|
|
||||||
</packages>
|
|
||||||
|
|
@ -33,38 +33,26 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
partial class Program : MyGridProgram
|
partial class Program : MyGridProgram
|
||||||
{
|
{
|
||||||
|
//const string MISSILE_GRID_PREFIX = "[PM]";
|
||||||
|
|
||||||
const float EPSILON = 0.05f;
|
const float EPSILON = 0.05f;
|
||||||
const double DISTANCE_BEFORE_ROTATING = 15; // [m].
|
const double DELAY_BEFORE_TRAVELLING_MODE = 5000; // [ms] (5 s).
|
||||||
const float ROTATION_SPEED = 0.5f; // [rad/s].
|
const double AUTO_DESTRUCTION_AFTER = 120000; // [ms] (2 min). Or if the hydrogen tank is empty.
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
NORMAL,
|
NORMAL,
|
||||||
LAUNCHING,
|
LAUNCHING,
|
||||||
TURNING,
|
|
||||||
ACCELERATING,
|
|
||||||
TRAVELLING,
|
TRAVELLING,
|
||||||
AI,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
State currentState = State.NORMAL;
|
State currentState = State.NORMAL;
|
||||||
|
|
||||||
int tickFromStart;
|
|
||||||
int begginningOfaccelerationTick;
|
|
||||||
bool launchPositionSet = false;
|
|
||||||
Vector3D launchPosition;
|
|
||||||
Vector3D directionBeforeTurning;
|
|
||||||
|
|
||||||
Vector3D lastPosition;
|
|
||||||
double speed;
|
|
||||||
double acceleration;
|
|
||||||
|
|
||||||
readonly Output output;
|
readonly Output output;
|
||||||
readonly IMyCubeGrid grid;
|
readonly IMyCubeGrid grid;
|
||||||
|
|
||||||
|
int tickFromStart;
|
||||||
IMyThrust forwardThruster;
|
IMyThrust forwardThruster;
|
||||||
IMyThrust backwardThruster;
|
|
||||||
IMyGyro gyroscope;
|
|
||||||
IEnumerable<IMyThrust> thrusters;
|
IEnumerable<IMyThrust> thrusters;
|
||||||
IMyFlightMovementBlock aiMove;
|
IMyFlightMovementBlock aiMove;
|
||||||
IMyOffensiveCombatBlock aiCombat;
|
IMyOffensiveCombatBlock aiCombat;
|
||||||
|
|
@ -95,22 +83,6 @@ namespace IngameScript
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.backwardThruster == null)
|
|
||||||
this.backwardThruster = this.GridTerminalSystem.GetBlock<IMyThrust>("[PM] Hydrogen Thruster 06", this.grid);
|
|
||||||
if (this.backwardThruster == null)
|
|
||||||
{
|
|
||||||
this.output.Print("Error: Cannot find backward thruster");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.gyroscope == null)
|
|
||||||
this.gyroscope = this.GridTerminalSystem.GetBlock<IMyGyro>("[PM] Gyroscope", this.grid);
|
|
||||||
if (this.gyroscope == null)
|
|
||||||
{
|
|
||||||
this.output.Print("Error: Cannot find gyroscope");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.thrusters == null)
|
if (this.thrusters == null)
|
||||||
{
|
{
|
||||||
this.thrusters = this.GridTerminalSystem.GetBlocksFromGroup<IMyThrust>("[PM] Thrusters", this.grid);
|
this.thrusters = this.GridTerminalSystem.GetBlocksFromGroup<IMyThrust>("[PM] Thrusters", this.grid);
|
||||||
|
|
@ -169,15 +141,15 @@ namespace IngameScript
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool BlinkBeforeBeingAutodestructed()
|
bool BlinkBeforeBeingAutodestructed()
|
||||||
//{
|
{
|
||||||
// return this.MsSinceLaunch > AUTO_DESTRUCTION_AFTER - 3000;
|
return this.MsSinceLaunch > AUTO_DESTRUCTION_AFTER - 3000;
|
||||||
//}
|
}
|
||||||
|
|
||||||
//bool MustBeAutodestructed()
|
bool MustBeAutodestructed()
|
||||||
//{
|
{
|
||||||
// return this.MsSinceLaunch > AUTO_DESTRUCTION_AFTER;
|
return this.MsSinceLaunch > AUTO_DESTRUCTION_AFTER;
|
||||||
//}
|
}
|
||||||
|
|
||||||
bool EnemyAtRange()
|
bool EnemyAtRange()
|
||||||
{
|
{
|
||||||
|
|
@ -188,20 +160,6 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
this.tickFromStart += 10;
|
this.tickFromStart += 10;
|
||||||
|
|
||||||
if (this.forwardThruster != null)
|
|
||||||
{
|
|
||||||
var currentPosition = this.forwardThruster.GetPosition();
|
|
||||||
if (this.lastPosition != new Vector3D())
|
|
||||||
{
|
|
||||||
var d = (currentPosition - this.lastPosition).Length();
|
|
||||||
var speed = d * 10;
|
|
||||||
this.acceleration = (speed - this.speed) * 10;
|
|
||||||
this.speed = speed;
|
|
||||||
//this.output.Print($"Spd: {this.speed:0.0}, Acc: {this.acceleration:0.0}");
|
|
||||||
}
|
|
||||||
this.lastPosition = currentPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (this.currentState)
|
switch (this.currentState)
|
||||||
{
|
{
|
||||||
case State.LAUNCHING:
|
case State.LAUNCHING:
|
||||||
|
|
@ -212,69 +170,35 @@ namespace IngameScript
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.launchPositionSet)
|
this.forwardThruster.Enabled = true; // Only one thruster is enabled when launching.
|
||||||
|
this.forwardThruster.ThrustOverridePercentage = 1;
|
||||||
|
if (this.MsSinceLaunch > DELAY_BEFORE_TRAVELLING_MODE && (this.EnemyAtRange() || this.BlinkBeforeBeingAutodestructed()))
|
||||||
{
|
{
|
||||||
this.launchPosition = this.forwardThruster.GetPosition();
|
foreach (var thruster in this.thrusters)
|
||||||
this.launchPositionSet = true;
|
{
|
||||||
}
|
if (thruster != this.forwardThruster)
|
||||||
|
thruster.Enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
//this.forwardThruster.Enabled = true; // Only one thruster is enabled when launching. Replaced by the loop below to avoid issues when gravity is present.
|
|
||||||
foreach (var thruster in this.thrusters)
|
|
||||||
{
|
|
||||||
if (thruster != this.backwardThruster)
|
|
||||||
thruster.Enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.forwardThruster.ThrustOverridePercentage = 1f; // Can be lowered for low gravity but set to 1f for 1G planet gravity.
|
|
||||||
|
|
||||||
//this.output.Print($"Distance from launch: {this.DistanceFromLaunch:0.0} m");
|
|
||||||
|
|
||||||
if (this.DistanceFromLaunch > DISTANCE_BEFORE_ROTATING)
|
|
||||||
{
|
|
||||||
this.directionBeforeTurning = this.forwardThruster.WorldMatrix.Forward.Normalized();
|
|
||||||
this.gyroscope.GyroOverride = true;
|
|
||||||
this.gyroscope.Roll = ROTATION_SPEED;
|
|
||||||
|
|
||||||
this.output.Print($"Turning mode");
|
|
||||||
this.currentState = State.TURNING;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State.TURNING:
|
|
||||||
var dotProduct = this.forwardThruster.WorldMatrix.Forward.Normalized().Dot(this.directionBeforeTurning);
|
|
||||||
//this.output.Print($"Dot product: {dotProduct:0.000}");
|
|
||||||
if (dotProduct <= EPSILON)
|
|
||||||
{
|
|
||||||
this.gyroscope.GyroOverride = false;
|
|
||||||
this.gyroscope.Roll = 0;
|
|
||||||
this.forwardThruster.ThrustOverridePercentage = 1f;
|
|
||||||
|
|
||||||
this.output.Print($"Accelerating mode");
|
|
||||||
this.begginningOfaccelerationTick = this.tickFromStart;
|
|
||||||
this.currentState = State.ACCELERATING;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State.ACCELERATING:
|
|
||||||
//this.CheckTank();
|
|
||||||
this.CheckEnemies();
|
|
||||||
|
|
||||||
if (this.acceleration <= EPSILON)
|
|
||||||
{
|
|
||||||
this.forwardThruster.ThrustOverridePercentage = 0;
|
this.forwardThruster.ThrustOverridePercentage = 0;
|
||||||
|
this.aiMove.Enabled = true;
|
||||||
|
|
||||||
|
foreach (var warhead in this.warheads)
|
||||||
|
warhead.IsArmed = true;
|
||||||
|
|
||||||
this.output.Print($"Travelling mode");
|
this.output.Print($"Travelling mode");
|
||||||
this.currentState = State.TRAVELLING;
|
this.currentState = State.TRAVELLING;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State.TRAVELLING:
|
case State.TRAVELLING:
|
||||||
//this.CheckTank();
|
if (this.BlinkBeforeBeingAutodestructed())
|
||||||
this.CheckEnemies();
|
this.light.BlinkIntervalSeconds = 0.5f;
|
||||||
|
|
||||||
break;
|
if (this.gasTank.FilledRatio <= EPSILON || this.MustBeAutodestructed())
|
||||||
|
{
|
||||||
case State.AI:
|
Detonate();
|
||||||
//this.CheckTank();
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State.NORMAL:
|
case State.NORMAL:
|
||||||
|
|
@ -282,33 +206,6 @@ namespace IngameScript
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//void CheckTank()
|
|
||||||
//{
|
|
||||||
// if (this.gasTank.FilledRatio <= EPSILON)
|
|
||||||
// {
|
|
||||||
// this.output.Print("Tank empty, detonating");
|
|
||||||
// Detonate();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void CheckEnemies()
|
|
||||||
{
|
|
||||||
if (this.EnemyAtRange())
|
|
||||||
{
|
|
||||||
this.forwardThruster.ThrustOverridePercentage = 0;
|
|
||||||
|
|
||||||
foreach (var warhead in this.warheads)
|
|
||||||
warhead.IsArmed = true;
|
|
||||||
|
|
||||||
this.backwardThruster.Enabled = true;
|
|
||||||
this.aiMove.Enabled = true;
|
|
||||||
|
|
||||||
this.output.Print("Enemy in range, switching to AI mode");
|
|
||||||
this.currentState = State.AI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Detonate()
|
void Detonate()
|
||||||
{
|
{
|
||||||
foreach (var warhead in this.warheads)
|
foreach (var warhead in this.warheads)
|
||||||
|
|
@ -319,14 +216,9 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//double MsSinceLaunch
|
double MsSinceLaunch
|
||||||
//{
|
|
||||||
// get { return (double)this.tickFromStart / 60 * 1000; }
|
|
||||||
//}
|
|
||||||
|
|
||||||
double DistanceFromLaunch
|
|
||||||
{
|
{
|
||||||
get { return (this.forwardThruster.GetPosition() - this.launchPosition).Length(); }
|
get { return (double)this.tickFromStart / 60 * 1000; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Main(string argument, UpdateType updateSource)
|
public void Main(string argument, UpdateType updateSource)
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
NOMINAL,
|
NOMINAL,
|
||||||
STARTING_SEQUENCE,
|
STARTING_SEQUENCE,
|
||||||
|
FILLING_TANK,
|
||||||
LAUNCHING,
|
LAUNCHING,
|
||||||
ABORTING,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly int number;
|
readonly int number;
|
||||||
|
|
@ -59,7 +59,6 @@ namespace IngameScript
|
||||||
|
|
||||||
readonly IMyGridTerminalSystem gridTerminal;
|
readonly IMyGridTerminalSystem gridTerminal;
|
||||||
readonly IMyShipConnector connector;
|
readonly IMyShipConnector connector;
|
||||||
readonly IMyProjector projector;
|
|
||||||
|
|
||||||
Missile missile;
|
Missile missile;
|
||||||
State currentState = State.NOMINAL;
|
State currentState = State.NOMINAL;
|
||||||
|
|
@ -72,13 +71,12 @@ namespace IngameScript
|
||||||
/// <param name="grid"></param>
|
/// <param name="grid"></param>
|
||||||
/// <param name="output">To output some text</param>
|
/// <param name="output">To output some text</param>
|
||||||
/// <param name="connector">Connector of the launcher (not the missile)</param>
|
/// <param name="connector">Connector of the launcher (not the missile)</param>
|
||||||
public Launcher(int number, IMyGridTerminalSystem gridTerminal, Output output, IMyShipConnector connector, IMyProjector projector)
|
public Launcher(int number, IMyGridTerminalSystem gridTerminal, Output output, IMyShipConnector connector)
|
||||||
{
|
{
|
||||||
this.number = number;
|
this.number = number;
|
||||||
this.gridTerminal = gridTerminal;
|
this.gridTerminal = gridTerminal;
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.connector = connector;
|
this.connector = connector;
|
||||||
this.projector = projector;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Launch()
|
public void Launch()
|
||||||
|
|
@ -87,11 +85,6 @@ namespace IngameScript
|
||||||
this.currentState = State.STARTING_SEQUENCE;
|
this.currentState = State.STARTING_SEQUENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AbortLaunching()
|
|
||||||
{
|
|
||||||
this.currentState = State.ABORTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Print(string message)
|
void Print(string message)
|
||||||
{
|
{
|
||||||
this.output.Print(String.Format("{0:00}: {1}", this.number, message));
|
this.output.Print(String.Format("{0:00}: {1}", this.number, message));
|
||||||
|
|
@ -99,119 +92,92 @@ namespace IngameScript
|
||||||
|
|
||||||
public void UpdateState()
|
public void UpdateState()
|
||||||
{
|
{
|
||||||
this.CheckMissileBuilt();
|
|
||||||
|
|
||||||
switch (this.currentState)
|
switch (this.currentState)
|
||||||
{
|
{
|
||||||
case State.STARTING_SEQUENCE:
|
case State.STARTING_SEQUENCE:
|
||||||
if (!this.CheckMissileBuilt())
|
var missileConnector = this.connector.OtherConnector;
|
||||||
|
if (missileConnector == null)
|
||||||
{
|
{
|
||||||
this.Print("Can't launch missile: Not built, waiting...");
|
this.Print("Cannot find the missile connector");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var missileGrid = missileConnector.CubeGrid;
|
||||||
|
if (missileGrid == null)
|
||||||
|
{
|
||||||
|
this.Print("Cannot find the missile grid");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMyGasTank tank = this.gridTerminal.GetBlock<IMyGasTank>("[PM] Hydrogen Tank", missileGrid);
|
||||||
|
if (tank == null)
|
||||||
|
{
|
||||||
|
this.Print("Cannot find the missile hydrogen tank");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMyShipMergeBlock mergeBlock = this.gridTerminal.GetBlock<IMyShipMergeBlock>("[PM] Merge Block", missileGrid);
|
||||||
|
if (mergeBlock == null)
|
||||||
|
{
|
||||||
|
this.Print("Cannot find the missile merge block");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMyProgrammableBlock programmableBlock = this.gridTerminal.GetBlock<IMyProgrammableBlock>("[PM] Programmable Block", missileGrid);
|
||||||
|
if (programmableBlock == null)
|
||||||
|
{
|
||||||
|
this.Print("Cannot find the missile programmable block");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<IMyThrust> thrusters = this.gridTerminal.GetBlocksFromGroup<IMyThrust>("[PM] Thrusters", missileGrid);
|
||||||
|
if (thrusters.Count() == 0)
|
||||||
|
{
|
||||||
|
this.Print("Cannot find missile thrusters");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When launched the missile will enabled itself its thrusters.
|
||||||
|
foreach (var thruster in thrusters)
|
||||||
|
thruster.Enabled = false;
|
||||||
|
|
||||||
|
tank.Stockpile = true;
|
||||||
|
connector.Connect();
|
||||||
|
|
||||||
|
this.missile = new Missile(tank, connector, mergeBlock, programmableBlock);
|
||||||
|
|
||||||
|
this.currentState = State.FILLING_TANK;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State.FILLING_TANK:
|
||||||
|
this.Print($"Waiting missile tank filled... ({this.missile.Tank.FilledRatio * 100:.0}%)");
|
||||||
|
|
||||||
if (this.missile.Tank.FilledRatio >= Program.HYDRO_TANK_FILLED_PERCENT / 100)
|
if (this.missile.Tank.FilledRatio >= Program.HYDRO_TANK_FILLED_PERCENT / 100)
|
||||||
{
|
{
|
||||||
this.missile.Tank.Stockpile = false;
|
this.missile.Tank.Stockpile = false;
|
||||||
this.currentState = State.LAUNCHING;
|
this.currentState = State.LAUNCHING;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Print($"Waiting missile tank filled... ({this.missile.Tank.FilledRatio * 100:.0}%)");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State.LAUNCHING:
|
case State.LAUNCHING:
|
||||||
this.Print("Launching missile...");
|
this.Print("Launching missile...");
|
||||||
|
|
||||||
this.missile.MergeBlock.Enabled = false;
|
|
||||||
|
|
||||||
if (this.missile.ProgrammableBlock.TryRun("START"))
|
if (this.missile.ProgrammableBlock.TryRun("START"))
|
||||||
this.Print("Missile launched!");
|
this.Print("Missile launched!");
|
||||||
else
|
else
|
||||||
this.Print("ERROR: Can't send START command to missile");
|
this.Print("ERROR: Can't send START command to missile");
|
||||||
|
|
||||||
|
this.missile.MergeBlock.Enabled = false;
|
||||||
this.connector.Disconnect();
|
this.connector.Disconnect();
|
||||||
this.currentState = State.NOMINAL;
|
this.currentState = State.NOMINAL;
|
||||||
this.missile = null;
|
this.missile = null;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State.ABORTING:
|
|
||||||
this.missile = null;
|
|
||||||
this.currentState = State.NOMINAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State.NOMINAL:
|
case State.NOMINAL:
|
||||||
break; // Nothing;
|
break; // Nothing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns true if missile ready.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
bool CheckMissileBuilt()
|
|
||||||
{
|
|
||||||
if (this.missile != null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
var missileConnector = this.connector.OtherConnector;
|
|
||||||
if (missileConnector == null)
|
|
||||||
{
|
|
||||||
//this.Print("Cannot find the missile connector");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var missileGrid = missileConnector.CubeGrid;
|
|
||||||
if (missileGrid == null)
|
|
||||||
{
|
|
||||||
//this.Print("Cannot find the missile grid");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IMyGasTank tank = this.gridTerminal.GetBlock<IMyGasTank>("[PM] Hydrogen Tank", missileGrid);
|
|
||||||
if (tank == null)
|
|
||||||
{
|
|
||||||
//this.Print("Cannot find the missile hydrogen tank");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IMyShipMergeBlock mergeBlock = this.gridTerminal.GetBlock<IMyShipMergeBlock>("[PM] Merge Block", missileGrid);
|
|
||||||
if (mergeBlock == null)
|
|
||||||
{
|
|
||||||
//this.Print("Cannot find the missile merge block");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IMyProgrammableBlock programmableBlock = this.gridTerminal.GetBlock<IMyProgrammableBlock>("[PM] Programmable Block", missileGrid);
|
|
||||||
if (programmableBlock == null)
|
|
||||||
{
|
|
||||||
//this.Print("Cannot find the missile programmable block");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<IMyThrust> thrusters = this.gridTerminal.GetBlocksFromGroup<IMyThrust>("[PM] Thrusters", missileGrid);
|
|
||||||
if (thrusters.Count() == 0)
|
|
||||||
{
|
|
||||||
//this.Print("Cannot find missile thrusters");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.projector.RemainingBlocks > 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// When launched the missile will enabled itself its thrusters.
|
|
||||||
foreach (var thruster in thrusters)
|
|
||||||
thruster.Enabled = false;
|
|
||||||
|
|
||||||
tank.Stockpile = true;
|
|
||||||
connector.Connect();
|
|
||||||
|
|
||||||
this.missile = new Missile(tank, connector, mergeBlock, programmableBlock);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class Program : MyGridProgram
|
partial class Program : MyGridProgram
|
||||||
|
|
@ -224,12 +190,11 @@ namespace IngameScript
|
||||||
LAUNCHING_CONTINUOUS,
|
LAUNCHING_CONTINUOUS,
|
||||||
}
|
}
|
||||||
|
|
||||||
public const string GRID_PREFIX = "[Mimine]";
|
public const string GRID_PREFIX = "[PML]";
|
||||||
public const string MISSILE_GRID_PREFIX = "[PM]";
|
public const string MISSILE_GRID_PREFIX = "[PM]";
|
||||||
public const double HYDRO_TANK_FILLED_PERCENT = 60;
|
public const double HYDRO_TANK_FILLED_PERCENT = 40;
|
||||||
|
|
||||||
const string LAUNCHER_SMALL_CONNECTOR_NAME = "Connector Launcher"; // Following by a number: "01", "02", etc.
|
const string LAUNCHER_SMALL_CONNECTOR_NAME = "Connector Launcher"; // Following by a number: "01", "02", etc.
|
||||||
const string PROJECTOR_NAME = "Projector Missile"; // Following by a number: "01", "02", etc.
|
|
||||||
const string DOORS_MISSILES_GROUP = "Doors Missiles";
|
const string DOORS_MISSILES_GROUP = "Doors Missiles";
|
||||||
|
|
||||||
const float EPSILON = 0.05f;
|
const float EPSILON = 0.05f;
|
||||||
|
|
@ -269,12 +234,10 @@ namespace IngameScript
|
||||||
foreach (var connector in launcherConnectors)
|
foreach (var connector in launcherConnectors)
|
||||||
{
|
{
|
||||||
var n = int.Parse(connector.CustomName.Substring(connectorNamePrefix.Length));
|
var n = int.Parse(connector.CustomName.Substring(connectorNamePrefix.Length));
|
||||||
var projector = this.GridTerminalSystem.GetBlock<IMyProjector>($"{GRID_PREFIX} {PROJECTOR_NAME} {n:0,0}");
|
this.launchers.Add(new Launcher(n, this.GridTerminalSystem, this.output, connector));
|
||||||
|
|
||||||
this.launchers.Add(new Launcher(n, this.GridTerminalSystem, this.output, connector, projector));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Runtime.UpdateFrequency = UpdateFrequency.Update100;
|
this.Runtime.UpdateFrequency = UpdateFrequency.Update10;
|
||||||
|
|
||||||
this.output.Print($"Missile launcher system started ({this.launchers.Count} launcher(s))");
|
this.output.Print($"Missile launcher system started ({this.launchers.Count} launcher(s))");
|
||||||
}
|
}
|
||||||
|
|
@ -301,9 +264,6 @@ namespace IngameScript
|
||||||
|
|
||||||
void ResetToNominal()
|
void ResetToNominal()
|
||||||
{
|
{
|
||||||
foreach (var launcher in this.launchers)
|
|
||||||
launcher.AbortLaunching();
|
|
||||||
|
|
||||||
this.nbLaunched = 0;
|
this.nbLaunched = 0;
|
||||||
this.currentState = State.NOMINAL;
|
this.currentState = State.NOMINAL;
|
||||||
}
|
}
|
||||||
|
|
@ -343,7 +303,7 @@ namespace IngameScript
|
||||||
|
|
||||||
public void Main(string argument, UpdateType updateSource)
|
public void Main(string argument, UpdateType updateSource)
|
||||||
{
|
{
|
||||||
if ((updateSource & UpdateType.Update100) != 0)
|
if ((updateSource & UpdateType.Update10) != 0)
|
||||||
{
|
{
|
||||||
this.UpdateState();
|
this.UpdateState();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# Modules
|
# Modules
|
||||||
|
|
||||||
AutoPilot: Automatic control of piloting on planet.
|
AutoPilot: Automatic control of piloting on planet.
|
||||||
SSPifou: The main control for the spaceship SSPifou. (TODO)
|
SSPifou: The main control for the spaceship SSPifou.
|
||||||
MissileController: Run in the missile computer to pilot it to its target.
|
MissileController: Run in the missile computer to pilot it to its target.
|
||||||
MissileLauncher: Can launch multiple missiles.
|
MissileLauncher: Can launch multiple missiles.
|
||||||
|
|
||||||
|
|
@ -14,9 +14,4 @@ MissileLauncher: Can launch multiple missiles.
|
||||||
|
|
||||||
## Elements
|
## Elements
|
||||||
|
|
||||||
* [PML] Connector Launcher 01
|
*
|
||||||
* [PML] Merge Block Missile 01
|
|
||||||
* [PML] Projector 01
|
|
||||||
* Offsets: (0, -8, 2), pitch: 0°
|
|
||||||
* [PML] Projector 02
|
|
||||||
* Offsets: (0, -8, -2), pitch: 180°
|
|
||||||
|
|
@ -26,8 +26,8 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
class Output
|
class Output
|
||||||
{
|
{
|
||||||
readonly IList<IMyTextSurface> outputs;
|
IList<IMyTextSurface> outputs;
|
||||||
readonly int maxNbLines;
|
int maxNbLines;
|
||||||
|
|
||||||
public Output(IList<IMyTextSurface> surfaces, int maxNbLines = 10)
|
public Output(IList<IMyTextSurface> surfaces, int maxNbLines = 10)
|
||||||
{
|
{
|
||||||
|
|
@ -58,68 +58,47 @@ namespace IngameScript
|
||||||
: this(new List<IMyTextSurface> { surface }, maxNbLines)
|
: this(new List<IMyTextSurface> { surface }, maxNbLines)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public void Print(string text, int outputNumber = -1)
|
public void Print(string text, int outputNumber = 0)
|
||||||
{
|
{
|
||||||
if (outputNumber >= 0 && this.outputs.Count() <= outputNumber)
|
if (this.outputs.Count() <= outputNumber)
|
||||||
{
|
{
|
||||||
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (outputNumber == -1)
|
var output = this.outputs[outputNumber];
|
||||||
|
var currentText = output.GetText();
|
||||||
|
var lines = currentText.Split('\n');
|
||||||
|
if (lines.Count() >= this.maxNbLines)
|
||||||
{
|
{
|
||||||
foreach (var output in this.outputs)
|
output.WriteText(lines.Skip(lines.Count() - this.maxNbLines + 1).Append(text).Aggregate((a, b) => a + Environment.NewLine + b));
|
||||||
this.Print(text, output);
|
}
|
||||||
|
else if (lines.Count() == 0)
|
||||||
|
{
|
||||||
|
output.WriteText(text);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Print(text, this.outputs[outputNumber]);
|
output.WriteText(Environment.NewLine + text, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Print(string text, IMyTextSurface surface)
|
|
||||||
{
|
|
||||||
var currentText = surface.GetText();
|
|
||||||
var lines = currentText.Split('\n');
|
|
||||||
if (lines.Count() >= this.maxNbLines)
|
|
||||||
{
|
|
||||||
surface.WriteText(lines.Skip(lines.Count() - this.maxNbLines + 1).Append(text).Aggregate((a, b) => a + Environment.NewLine + b));
|
|
||||||
}
|
|
||||||
else if (lines.Count() == 0)
|
|
||||||
{
|
|
||||||
surface.WriteText(text);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
surface.WriteText(Environment.NewLine + text, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PrintError(string text, int outputNumber = 0)
|
public void PrintError(string text, int outputNumber = 0)
|
||||||
{
|
{
|
||||||
this.Print($"Error: {text}", outputNumber);
|
this.Print($"Error: {text}", outputNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Display(string text, int outputNumber = -1)
|
public void Display(string text, int outputNumber = 0)
|
||||||
{
|
{
|
||||||
if (outputNumber >= 0 && this.outputs.Count() <= outputNumber)
|
if (this.outputs.Count() <= outputNumber)
|
||||||
{
|
{
|
||||||
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
throw new Exception($"Output number {outputNumber} doesn't exist (number of output: {this.outputs.Count()}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (outputNumber == -1)
|
this.outputs[outputNumber].WriteText(text);
|
||||||
{
|
|
||||||
foreach (var output in this.outputs)
|
|
||||||
output.WriteText(text);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.outputs[outputNumber].WriteText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
|
|
||||||
using Sandbox.ModAPI.Ingame;
|
using Sandbox.ModAPI.Ingame;
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
using VRage.Game.ModAPI.Ingame;
|
using VRage.Game.ModAPI.Ingame;
|
||||||
|
|
@ -35,12 +33,12 @@ namespace IngameScript
|
||||||
/// <param name="name"></param>
|
/// <param name="name"></param>
|
||||||
/// <param name="grid"></param>
|
/// <param name="grid"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<T> GetBlocks<T>(this IMyGridTerminalSystem gridTerminal, string name = null, IMyCubeGrid grid = null, Func<T, bool> filter = null)
|
public static IEnumerable<T> GetBlocks<T>(this IMyGridTerminalSystem gridTerminal, string name = null, IMyCubeGrid grid = null)
|
||||||
where T : class, IMyTerminalBlock
|
where T : class, IMyTerminalBlock
|
||||||
{
|
{
|
||||||
var l = new List<T>();
|
var l = new List<T>();
|
||||||
gridTerminal.GetBlocksOfType(l, (T block) =>
|
gridTerminal.GetBlocksOfType(l, (T block) =>
|
||||||
(name == null || block.CustomName == name) && (grid == null || block.CubeGrid == grid) && (filter == null || filter(block))
|
(name == null || block.CustomName == name) && (grid == null || block.CubeGrid == grid)
|
||||||
);
|
);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
@ -92,46 +90,5 @@ namespace IngameScript
|
||||||
|
|
||||||
return new List<T>();
|
return new List<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<IMyInventory> GetAllInventories(this IMyGridTerminalSystem gridTerminal, IMyCubeGrid grid = null)
|
|
||||||
{
|
|
||||||
var inventories = new List<IMyInventory>();
|
|
||||||
|
|
||||||
// Containers.
|
|
||||||
foreach (var container in gridTerminal.GetBlocks<IMyCargoContainer>(grid: grid))
|
|
||||||
inventories.Add(container.GetInventory());
|
|
||||||
|
|
||||||
// Assemblers.
|
|
||||||
foreach (var assembler in gridTerminal.GetBlocks<IMyAssembler>(grid: grid))
|
|
||||||
{
|
|
||||||
inventories.Add(assembler.InputInventory);
|
|
||||||
inventories.Add(assembler.OutputInventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refineries
|
|
||||||
foreach (var refinery in gridTerminal.GetBlocks<IMyRefinery>(grid: grid))
|
|
||||||
{
|
|
||||||
inventories.Add(refinery.InputInventory);
|
|
||||||
inventories.Add(refinery.OutputInventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connectors.
|
|
||||||
foreach (var connector in gridTerminal.GetBlocks<IMyShipConnector>(grid: grid))
|
|
||||||
inventories.Add(connector.GetInventory());
|
|
||||||
|
|
||||||
// Welders.
|
|
||||||
foreach (var welder in gridTerminal.GetBlocks<IMyShipWelder>(grid: grid))
|
|
||||||
inventories.Add(welder.GetInventory());
|
|
||||||
|
|
||||||
// Turrets.
|
|
||||||
foreach (var turret in gridTerminal.GetBlocks<IMyLargeTurretBase>(grid: grid))
|
|
||||||
inventories.Add(turret.GetInventory());
|
|
||||||
|
|
||||||
// Artillery and missile launcher.
|
|
||||||
foreach (var missileLauncher in gridTerminal.GetBlocks<IMySmallMissileLauncher>(grid: grid))
|
|
||||||
inventories.Add(missileLauncher.GetInventory());
|
|
||||||
|
|
||||||
return inventories;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,10 +22,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MissileLauncher", "MissileL
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaseMiner", "BaseMiner\BaseMiner.csproj", "{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaseMiner", "BaseMiner\BaseMiner.csproj", "{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PML", "PML\PML.csproj", "{F280FA02-7E9E-7390-1771-4B1F144AC88C}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mimine", "Mimine\Mimine.csproj", "{1E123126-9FA8-67F1-5E48-3B8C400AAEDF}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
|
|
@ -52,14 +48,6 @@ Global
|
||||||
{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}.Debug|x64.Build.0 = Debug|x64
|
{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}.Debug|x64.Build.0 = Debug|x64
|
||||||
{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}.Release|x64.ActiveCfg = Release|x64
|
{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}.Release|x64.ActiveCfg = Release|x64
|
||||||
{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}.Release|x64.Build.0 = Release|x64
|
{1C2F7DB3-26AD-4C5E-B6C5-D6715B3CFB36}.Release|x64.Build.0 = Release|x64
|
||||||
{F280FA02-7E9E-7390-1771-4B1F144AC88C}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{F280FA02-7E9E-7390-1771-4B1F144AC88C}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{F280FA02-7E9E-7390-1771-4B1F144AC88C}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{F280FA02-7E9E-7390-1771-4B1F144AC88C}.Release|x64.Build.0 = Release|x64
|
|
||||||
{1E123126-9FA8-67F1-5E48-3B8C400AAEDF}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{1E123126-9FA8-67F1-5E48-3B8C400AAEDF}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{1E123126-9FA8-67F1-5E48-3B8C400AAEDF}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{1E123126-9FA8-67F1-5E48-3B8C400AAEDF}.Release|x64.Build.0 = Release|x64
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -70,11 +58,9 @@ Global
|
||||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||||
SECommon\SECommon.projitems*{141e1804-f644-48f8-a3d8-befeee66ecba}*SharedItemsImports = 5
|
SECommon\SECommon.projitems*{141e1804-f644-48f8-a3d8-befeee66ecba}*SharedItemsImports = 5
|
||||||
SECommon\SECommon.projitems*{1c2f7db3-26ad-4c5e-b6c5-d6715b3cfb36}*SharedItemsImports = 5
|
SECommon\SECommon.projitems*{1c2f7db3-26ad-4c5e-b6c5-d6715b3cfb36}*SharedItemsImports = 5
|
||||||
SECommon\SECommon.projitems*{1e123126-9fa8-67f1-5e48-3b8c400aaedf}*SharedItemsImports = 5
|
|
||||||
SECommon\SECommon.projitems*{761f968e-ce71-404b-a20a-7c1458d6c014}*SharedItemsImports = 5
|
SECommon\SECommon.projitems*{761f968e-ce71-404b-a20a-7c1458d6c014}*SharedItemsImports = 5
|
||||||
SECommon\SECommon.projitems*{9e97399c-4fe6-495b-aa87-acc2213647cd}*SharedItemsImports = 13
|
SECommon\SECommon.projitems*{9e97399c-4fe6-495b-aa87-acc2213647cd}*SharedItemsImports = 13
|
||||||
SECommon\SECommon.projitems*{dbcd62fe-f7aa-4a03-9241-0a4be6952664}*SharedItemsImports = 5
|
SECommon\SECommon.projitems*{dbcd62fe-f7aa-4a03-9241-0a4be6952664}*SharedItemsImports = 5
|
||||||
SECommon\SECommon.projitems*{f280fa02-7e9e-7390-1771-4b1f144ac88c}*SharedItemsImports = 5
|
|
||||||
SECommon\SECommon.projitems*{f902e413-8f1a-423d-98a5-f26b684e28ba}*SharedItemsImports = 5
|
SECommon\SECommon.projitems*{f902e413-8f1a-423d-98a5-f26b684e28ba}*SharedItemsImports = 5
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
||||||
32
TODO.md
32
TODO.md
|
|
@ -1,39 +1,15 @@
|
||||||
# Active
|
# Active
|
||||||
|
|
||||||
## SSPifou
|
## SSPifou
|
||||||
|
|
||||||
* Remote control for the Bee
|
* Missile autodestruction (after 1min or when tank empty)
|
||||||
|
* Finish missile launchers
|
||||||
* Add external lights + commands
|
* Add external lights + commands
|
||||||
|
* Command to stop thrusters
|
||||||
* Add weapons rack
|
* Add weapons rack
|
||||||
* Embedded computer:
|
* Embedded computer:
|
||||||
|
* Auto landing + auto stabilization
|
||||||
* Display of ore, ingot, ammo status
|
* Display of ore, ingot, ammo status
|
||||||
* Autocraft of some element: ammo + components
|
* Autocraft of some element: ammo + components
|
||||||
* Auto landing + auto stabilization
|
|
||||||
|
|
||||||
## Missile
|
|
||||||
|
|
||||||
* Missile autodestruction (after 1min or when tank empty)
|
|
||||||
|
|
||||||
### Components:
|
|
||||||
Steel plate: 252
|
|
||||||
Construction Comp: 167
|
|
||||||
Motor: 18
|
|
||||||
Interior Plate: 40
|
|
||||||
Computer: 47
|
|
||||||
Powercell: 2
|
|
||||||
Display: 1
|
|
||||||
Small Steel Tube: 27
|
|
||||||
Metal Grid: 48
|
|
||||||
Large Steel Tube: 16
|
|
||||||
Detector Comp: 8
|
|
||||||
Girder: 11
|
|
||||||
Explosives: 22
|
|
||||||
|
|
||||||
Volume: 3'084 L
|
|
||||||
|
|
||||||
# Finished
|
# Finished
|
||||||
|
|
||||||
* Cockpit commands to open/close hangar doors (3 commands)
|
|
||||||
* Command to stop thrusters
|
|
||||||
* Finish missile launchers
|
|
||||||
* Why the missile stops after ~100 m?
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue