1
using Sandbox
.Game
.Entities
.Cube
;
2 using Sandbox
.Game
.EntityComponents
;
3 //using Sandbox.ModAPI;
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
;
14 using System
.Runtime
.CompilerServices
;
15 using System
.Runtime
.InteropServices
;
19 using VRage
.Collections
;
21 using VRage
.Game
.Components
;
22 using VRage
.Game
.GUI
.TextPanel
;
23 using VRage
.Game
.ModAPI
.Ingame
;
24 using VRage
.Game
.ModAPI
.Ingame
.Utilities
;
25 using VRage
.Game
.ObjectBuilders
.Definitions
;
29 namespace IngameScript
31 partial class Program
: MyGridProgram
33 const string MISSILE_GRID_PREFIX
= "[PM]";
35 const float EPSILON
= 0.05f;
36 const double DELAY_BEFORE_TRAVELLING_MODE
= 3000; // [ms].
37 const double AUTO_DESTRUCTION_AFTER
= 60000; // [ms] (1 min).
47 State currentState
= State
.NORMAL
;
49 readonly Output output
;
52 IMyThrust forwardThruster
;
53 IMyFlightMovementBlock aiMove
;
54 IMyOffensiveCombatBlock aiCombat
;
55 IMySensorBlock sensor
;
56 List
<IMyWarhead
> warheads
= new List
<IMyWarhead
>();
58 IMyLightingBlock light
;
62 var output
= this.Me
.GetSurface(0);
63 this.output
= new Output(output
);
65 this.output
.Print("Missile controller system starting...");
67 this.Runtime
.UpdateFrequency
= UpdateFrequency
.Update10
;
69 this.output
.Print("Missile controller system started");
74 if (this.forwardThruster
== null)
75 this.forwardThruster
= this.GridTerminalSystem
.GetBlockWithName("[PM] Hydrogen Thruster 01") as IMyThrust
;
76 if (this.forwardThruster
== null)
78 this.output
.Print("Error: Cannot find forward thruster");
82 if (this.aiMove
== null)
83 this.aiMove
= this.GridTerminalSystem
.GetBlockWithName("[PM] AI Flight (Move)") as IMyFlightMovementBlock
;
84 if (this.aiMove
== null)
86 this.output
.Print("Error: Cannot find AI move");
90 if (this.aiCombat
== null)
91 this.aiCombat
= this.GridTerminalSystem
.GetBlockWithName("[PM] AI Offensive (Combat)") as IMyOffensiveCombatBlock
;
92 if (this.aiCombat
== null)
94 this.output
.Print("Error: Cannot find AI combat");
98 if (this.sensor
== null)
99 this.sensor
= this.GridTerminalSystem
.GetBlockWithName("[PM] Sensor") as IMySensorBlock
;
100 if (this.sensor
== null)
102 this.output
.Print("Error: Cannot find sensor");
106 if (this.warheads
.Count
== 0)
107 this.GridTerminalSystem
.GetBlockGroupWithName("[PM] Warheads").GetBlocksOfType(this.warheads
);
108 if (this.warheads
.Count
== 0)
110 this.output
.Print("Error: Cannot find any warhead");
114 if (this.gasTank
== null)
115 this.gasTank
= this.GridTerminalSystem
.GetBlockWithName("[PM] Hydrogen Tank") as IMyGasTank
;
116 if (this.gasTank
== null)
118 this.output
.Print("Error: Cannot find gas tank");
122 if (this.light
== null)
123 this.light
= this.GridTerminalSystem
.GetBlockWithName("[PM] Light") as IMyLightingBlock
;
124 if (this.light
== null)
126 this.output
.Print("Error: Cannot find light");
130 switch (this.currentState
)
132 case State
.LAUNCHING
:
133 // this.output.Print($"Tick: {this.tickFromStart}");
134 //this.forwardThruster.ove
135 this.forwardThruster
.ThrustOverridePercentage
= 1;
136 if (this.MsSinceLaunch
> DELAY_BEFORE_TRAVELLING_MODE
)
138 this.forwardThruster
.ThrustOverridePercentage
= 0;
139 this.aiMove
.Enabled
= true;
140 this.aiCombat
.Enabled
= true;
142 foreach (var warhead
in this.warheads
)
143 warhead
.IsArmed
= true;
145 this.output
.Print($"Travelling mode");
146 this.currentState
= State
.TRAVELLING
;
150 case State
.TRAVELLING
:
151 var detectedEntity
= this.sensor
.LastDetectedEntity
;
153 if (this.MsSinceLaunch
> AUTO_DESTRUCTION_AFTER
- 3000)
154 this.light
.BlinkIntervalSeconds
= 0.5f;
156 if (this.gasTank
.FilledRatio
<= EPSILON
|| detectedEntity
.Type
!= MyDetectedEntityType
.None
|| this.MsSinceLaunch
> AUTO_DESTRUCTION_AFTER
)
169 foreach (var warhead
in this.warheads
)
179 get { return (double)this.tickFromStart
/ 60 * 1000; }
182 public void Main(string argument
, UpdateType updateSource
)
184 if ((updateSource
& UpdateType
.Update10
) != 0)
186 this.tickFromStart
+= 10;
187 this.UpdateState10();
189 else if ((updateSource
& (UpdateType
.Script
| UpdateType
.Terminal
| UpdateType
.Trigger
)) != 0)
194 this.output
.Print("Launching mode");
195 this.tickFromStart
= 0;
196 this.currentState
= State
.LAUNCHING
;
200 this.output
.Print($"Uknown command: {argument}");