1
using Sandbox
.Game
.EntityComponents
;
2 using Sandbox
.ModAPI
.Ingame
;
3 using Sandbox
.ModAPI
.Interfaces
;
5 using SpaceEngineers
.Game
.ModAPI
.Ingame
;
8 using System
.Collections
;
9 using System
.Collections
.Generic
;
10 using System
.Collections
.Immutable
;
15 using VRage
.Collections
;
17 using VRage
.Game
.Components
;
18 using VRage
.Game
.GUI
.TextPanel
;
19 using VRage
.Game
.ModAPI
.Ingame
;
20 using VRage
.Game
.ModAPI
.Ingame
.Utilities
;
21 using VRage
.Game
.ObjectBuilders
.Definitions
;
25 namespace IngameScript
27 partial class Program
: MyGridProgram
29 const int CONSOLE_NB_LINES
= 7;
30 const string GRID_PREFIX
= "[Base]";
32 const float PISTON_SPEED
= 0.05f;
40 const float EPSILON
= 0.05f;
42 State currentState
= State
.NORMAL
;
44 readonly Output output
;
46 List
<IMyExtendedPistonBase
> pistons
= new List
<IMyExtendedPistonBase
>();
48 IMyLandingGear magneticPlate
;
49 List
<IMyShipDrill
> drills
= new List
<IMyShipDrill
>();
51 IMySoundBlock soundAlert
;
52 List
<IMyLightingBlock
> rotatingLights
= new List
<IMyLightingBlock
>();
54 IMyShipConnector minerConnector
;
58 var output
= this.Me
.GetSurface(0);
59 this.output
= new Output(output
, CONSOLE_NB_LINES
);
61 this.output
.Print("Base system starting...");
63 this.InitMiningSystem();
65 this.minerConnector
= this.GridTerminalSystem
.GetBlockWithName("[Base] Connector Miner") as IMyShipConnector
;
66 if (this.minerConnector
== null)
67 this.output
.Print($"Error: miner connector not found");
69 this.Runtime
.UpdateFrequency
= UpdateFrequency
.Update100
;
71 this.output
.Print("Base system has started");
74 void InitMiningSystem()
76 this.output
.Print("Mining system initializing...");
78 this.GridTerminalSystem
.GetBlocksOfType(
80 (IMyShipDrill drill
) => drill
.CustomName
.StartsWith(GRID_PREFIX
)
83 this.output
.Print($"Nb of drills: {this.drills.Count}");
85 this.GridTerminalSystem
.GetBlocksOfType(
87 (IMyExtendedPistonBase piston
) => piston
.CustomName
.StartsWith(GRID_PREFIX
) && piston
.CustomName
.Contains("Miner")
90 this.output
.Print($"Nb of pistons: {this.pistons.Count}");
92 this.magneticPlate
= this.GridTerminalSystem
.GetBlockWithName("[Base] Magnetic Plate Miner") as IMyLandingGear
;
94 this.soundAlert
= this.GridTerminalSystem
.GetBlockWithName("[Base] Sound Block Miner") as IMySoundBlock
;
95 if (this.soundAlert
== null)
96 this.output
.Print($"Error: sound alert system not found");
98 this.GridTerminalSystem
.GetBlocksOfType(
100 (IMyLightingBlock light
) => light
.CustomName
.StartsWith(GRID_PREFIX
) && light
.CustomName
.Contains("Miner")
103 this.output
.Print($"Nb of rotating lights: {this.rotatingLights.Count}");
105 this.output
.Print("Mining system initialized");
114 if (this.currentState
== State
.STOPPING_MINING
)
116 bool finished
= true;
118 foreach (var d
in this.drills
)
123 foreach (var p
in this.pistons
)
125 var distanceDocked
= 0.0;
127 if (p
.CustomName
== "[Base] Piston Miner 02")
128 distanceDocked
= 0.1;
130 if (p
.CurrentPosition
> distanceDocked
+ EPSILON
)
133 p
.Velocity
= 5 * -PISTON_SPEED
;
143 foreach (var p
in this.pistons
)
146 foreach (var l
in this.rotatingLights
)
149 this.soundAlert
.Stop();
151 this.output
.Print("Drills parked, operation terminated");
152 this.currentState
= State
.NORMAL
;
155 else if (this.currentState
== State
.MINING
)
157 this.magneticPlate
.Unlock();
159 foreach (var p
in this.pistons
)
162 p
.Velocity
= PISTON_SPEED
;
165 foreach (var d
in this.drills
)
171 // Send miner connector position.
172 this.IGC
.SendBroadcastMessage("POSITION_CONNECTOR_MINER", this.minerConnector
.WorldMatrix
);
175 public void Main(string argument
, UpdateType updateSource
)
177 if ((updateSource
& UpdateType
.Update100
) != 0)
181 else if ((updateSource
& (UpdateType
.Terminal
| UpdateType
.Trigger
)) != 0)
186 this.output
.Print("Stopping mining...");
187 this.currentState
= State
.STOPPING_MINING
;
191 this.soundAlert
.Play();
192 foreach (var l
in this.rotatingLights
)
195 this.output
.Print("Mining in progress...");
196 this.currentState
= State
.MINING
;
200 this.output
.Print($"Uknown command: {argument}");