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 mining system starting...");
63 this.GridTerminalSystem
.GetBlocksOfType(
65 (IMyShipDrill drill
) => drill
.CustomName
.StartsWith(GRID_PREFIX
)
68 this.output
.Print($"Nb of drills: {this.drills.Count}");
70 this.GridTerminalSystem
.GetBlocksOfType(
72 (IMyExtendedPistonBase piston
) => piston
.CustomName
.StartsWith(GRID_PREFIX
) && piston
.CustomName
.Contains("Miner")
75 this.output
.Print($"Nb of pistons: {this.pistons.Count}");
77 this.magneticPlate
= this.GridTerminalSystem
.GetBlockWithName("[Base] Magnetic Plate Miner") as IMyLandingGear
;
79 this.soundAlert
= this.GridTerminalSystem
.GetBlockWithName("[Base] Sound Block Miner") as IMySoundBlock
;
80 if (this.soundAlert
== null)
81 this.output
.Print($"Error: sound alert system not found");
83 this.GridTerminalSystem
.GetBlocksOfType(
85 (IMyLightingBlock light
) => light
.CustomName
.StartsWith(GRID_PREFIX
) && light
.CustomName
.Contains("Miner")
88 this.output
.Print($"Nb of rotating lights: {this.rotatingLights.Count}");
90 this.minerConnector
= this.GridTerminalSystem
.GetBlockWithName("[Base] Connector Miner") as IMyShipConnector
;
91 if (this.minerConnector
== null)
92 this.output
.Print($"Error: miner connector not found");
94 this.Runtime
.UpdateFrequency
= UpdateFrequency
.Update100
;
96 this.output
.Print("base Mining system has started");
105 if (this.currentState
== State
.STOPPING_MINING
)
107 bool finished
= true;
109 foreach (var d
in this.drills
)
114 foreach (var p
in this.pistons
)
116 var distanceDocked
= 0.0;
118 if (p
.CustomName
== "[Base] Piston Miner 02")
119 distanceDocked
= 0.1;
121 if (p
.CurrentPosition
> distanceDocked
+ EPSILON
)
124 p
.Velocity
= 5 * -PISTON_SPEED
;
134 foreach (var p
in this.pistons
)
137 foreach (var l
in this.rotatingLights
)
140 this.soundAlert
.Stop();
142 this.output
.Print("Drills parked, operation terminated");
143 this.currentState
= State
.NORMAL
;
146 else if (this.currentState
== State
.MINING
)
148 this.magneticPlate
.Unlock();
150 foreach (var p
in this.pistons
)
153 p
.Velocity
= PISTON_SPEED
;
156 foreach (var d
in this.drills
)
162 // Send miner connector position.
163 this.IGC
.SendBroadcastMessage("POSITION_CONNECTOR_MINER", this.minerConnector
.WorldMatrix
);
166 public void Main(string argument
, UpdateType updateSource
)
168 if ((updateSource
& UpdateType
.Update100
) != 0)
172 else if ((updateSource
& (UpdateType
.Terminal
| UpdateType
.Trigger
)) != 0)
177 this.output
.Print("Stopping mining...");
178 this.currentState
= State
.STOPPING_MINING
;
182 this.soundAlert
.Play();
183 foreach (var l
in this.rotatingLights
)
186 this.output
.Print("Mining in progress...");
187 this.currentState
= State
.MINING
;
191 this.output
.Print($"Uknown command: {argument}");