1
using Sandbox
.Game
.Entities
.Cube
;
2 using Sandbox
.Game
.EntityComponents
;
3 using Sandbox
.Game
.GameSystems
;
4 using Sandbox
.ModAPI
.Ingame
;
5 using Sandbox
.ModAPI
.Interfaces
;
7 using SpaceEngineers
.Game
.ModAPI
.Ingame
;
10 using System
.Collections
;
11 using System
.Collections
.Generic
;
12 using System
.Collections
.Immutable
;
17 using VRage
.Collections
;
19 using VRage
.Game
.Components
;
20 using VRage
.Game
.GUI
.TextPanel
;
21 using VRage
.Game
.ModAPI
.Ingame
;
22 using VRage
.Game
.ModAPI
.Ingame
.Utilities
;
23 using VRage
.Game
.ObjectBuilders
.Definitions
;
27 using static VRageRender
.Utils
.MyWingedEdgeMesh
;
29 namespace IngameScript
42 readonly string tankName
= "Hydrogen Tank";
43 readonly string connectorName
= "Connector";
44 readonly string mergeBlockName
= "Merge Block";
45 readonly string programmableBlockName
= "Programmable Block";
47 State currentState
= State
.NORMAL
;
49 IMyGridTerminalSystem gridTerminalSystem
;
51 IMyGasTank tank
= null;
52 IMyShipConnector connector
= null;
53 IMyShipMergeBlock mergeBlock
= null;
54 IMyProgrammableBlock programmableBlock
= null;
56 // bool loop = false; // Not used for the moment.
57 public Missile(string prefix
, IMyGridTerminalSystem gridTerminalSystem
)
60 this.gridTerminalSystem
= gridTerminalSystem
;
64 partial class Program
: MyGridProgram
66 const string GRID_PREFIX
= "[PML]";
67 const string MISSILE_GRID_PREFIX
= "[PM]";
68 const double HYDRO_TANK_FILLED_PERCENT
= 20;
70 const float EPSILON
= 0.05f;
72 readonly Output output
;
76 var output
= this.Me
.GetSurface(0);
77 this.output
= new Output(output
);
78 this.output
.Print("Missile launcher system starting...");
80 this.Runtime
.UpdateFrequency
= UpdateFrequency
.Update100
;
82 this.output
.Print("Missile launcher system started");
87 switch (this.currentState
)
89 case State
.STARTING_SEQUENCE
:
90 this.tank
= this.GridTerminalSystem
.GetBlockWithName("[PM] Hydrogen Tank") as IMyGasTank
;
91 if (this.tank
== null)
93 this.output
.Print("Cannot find the missile hydrogen tank");
97 this.connector
= this.GridTerminalSystem
.GetBlockWithName("[PM] Connector") as IMyShipConnector
;
98 if (this.connector
== null)
100 this.output
.Print("Cannot find the missile connector");
104 this.mergeBlock
= this.GridTerminalSystem
.GetBlockWithName("[PM] Merge Block") as IMyShipMergeBlock
;
105 if (this.mergeBlock
== null)
107 this.output
.Print("Cannot find the missile merge block");
111 this.programmableBlock
= this.GridTerminalSystem
.GetBlockWithName("[PM] Programmable Block") as IMyProgrammableBlock
;
112 if (this.programmableBlock
== null)
114 this.output
.Print("Cannot find the missile programmable block");
118 this.tank
.Stockpile
= true;
119 this.connector
.Connect();
121 this.currentState
= State
.FILLING_TANK
;
124 case State
.FILLING_TANK
:
125 this.output
.Print("Waiting missile tank filled...");
126 if (this.tank
.FilledRatio
>= HYDRO_TANK_FILLED_PERCENT
/ 100)
128 this.tank
.Stockpile
= false;
129 this.currentState
= State
.LAUNCHING
;
133 case State
.LAUNCHING
:
134 this.output
.Print("Launching missile...");
136 if (this.programmableBlock
.TryRun("START"))
137 this.output
.Print("Missile launched!");
139 this.output
.Print("ERROR: Can't send START command to missile");
141 this.mergeBlock
.Enabled
= false;
142 this.connector
.Disconnect();
145 this.currentState
= State
.STARTING_SEQUENCE
;
147 this.currentState
= State
.NORMAL
;
161 public void Main(string argument
, UpdateType updateSource
)
163 if ((updateSource
& UpdateType
.Update100
) != 0)
167 else if ((updateSource
& (UpdateType
.Terminal
| UpdateType
.Trigger
)) != 0)
173 this.currentState
= State
.STARTING_SEQUENCE
;
178 this.currentState
= State
.STARTING_SEQUENCE
;
183 this.currentState
= State
.NORMAL
;
187 this.output
.Print($"Uknown command: {argument}");