Use the new utilities functions and add the STOP command
This commit is contained in:
parent
0aa3ae21d2
commit
ebf5477ad1
1 changed files with 24 additions and 18 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using Sandbox.Game.Entities.Cube;
|
using Sandbox.Game.Entities;
|
||||||
|
using Sandbox.Game.Entities.Cube;
|
||||||
using Sandbox.Game.EntityComponents;
|
using Sandbox.Game.EntityComponents;
|
||||||
//using Sandbox.ModAPI;
|
//using Sandbox.ModAPI;
|
||||||
using Sandbox.ModAPI.Ingame;
|
using Sandbox.ModAPI.Ingame;
|
||||||
|
|
@ -30,13 +31,12 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
partial class Program : MyGridProgram
|
partial class Program : MyGridProgram
|
||||||
{
|
{
|
||||||
const string MISSILE_GRID_PREFIX = "[PM]";
|
//const string MISSILE_GRID_PREFIX = "[PM]";
|
||||||
|
|
||||||
const float EPSILON = 0.05f;
|
const float EPSILON = 0.05f;
|
||||||
const double DELAY_BEFORE_TRAVELLING_MODE = 3000; // [ms].
|
const double DELAY_BEFORE_TRAVELLING_MODE = 3000; // [ms].
|
||||||
const double AUTO_DESTRUCTION_AFTER = 60000; // [ms] (1 min). Or if the hydrogen tank is empty.
|
const double AUTO_DESTRUCTION_AFTER = 60000; // [ms] (1 min). Or if the hydrogen tank is empty.
|
||||||
|
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
NORMAL,
|
NORMAL,
|
||||||
|
|
@ -47,13 +47,14 @@ namespace IngameScript
|
||||||
State currentState = State.NORMAL;
|
State currentState = State.NORMAL;
|
||||||
|
|
||||||
readonly Output output;
|
readonly Output output;
|
||||||
|
readonly IMyCubeGrid grid;
|
||||||
|
|
||||||
int tickFromStart;
|
int tickFromStart;
|
||||||
IMyThrust forwardThruster;
|
IMyThrust forwardThruster;
|
||||||
IMyFlightMovementBlock aiMove;
|
IMyFlightMovementBlock aiMove;
|
||||||
IMyOffensiveCombatBlock aiCombat;
|
IMyOffensiveCombatBlock aiCombat;
|
||||||
IMySensorBlock sensor;
|
IMySensorBlock sensor;
|
||||||
List<IMyWarhead> warheads = new List<IMyWarhead>();
|
IEnumerable<IMyWarhead> warheads;
|
||||||
IMyGasTank gasTank;
|
IMyGasTank gasTank;
|
||||||
IMyLightingBlock light;
|
IMyLightingBlock light;
|
||||||
|
|
||||||
|
|
@ -64,6 +65,7 @@ namespace IngameScript
|
||||||
|
|
||||||
this.output.Print("Missile controller system starting...");
|
this.output.Print("Missile controller system starting...");
|
||||||
|
|
||||||
|
this.grid = this.Me.CubeGrid;
|
||||||
this.Runtime.UpdateFrequency = UpdateFrequency.Update10;
|
this.Runtime.UpdateFrequency = UpdateFrequency.Update10;
|
||||||
|
|
||||||
this.output.Print("Missile controller system started");
|
this.output.Print("Missile controller system started");
|
||||||
|
|
@ -72,7 +74,7 @@ namespace IngameScript
|
||||||
void UpdateState10()
|
void UpdateState10()
|
||||||
{
|
{
|
||||||
if (this.forwardThruster == null)
|
if (this.forwardThruster == null)
|
||||||
this.forwardThruster = this.GridTerminalSystem.GetBlockWithName("[PM] Hydrogen Thruster 01") as IMyThrust;
|
this.forwardThruster = this.GridTerminalSystem.GetBlock<IMyThrust>("[PM] Hydrogen Thruster 01", this.grid);
|
||||||
if (this.forwardThruster == null)
|
if (this.forwardThruster == null)
|
||||||
{
|
{
|
||||||
this.output.Print("Error: Cannot find forward thruster");
|
this.output.Print("Error: Cannot find forward thruster");
|
||||||
|
|
@ -80,7 +82,7 @@ namespace IngameScript
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.aiMove == null)
|
if (this.aiMove == null)
|
||||||
this.aiMove = this.GridTerminalSystem.GetBlockWithName("[PM] AI Flight (Move)") as IMyFlightMovementBlock;
|
this.aiMove = this.GridTerminalSystem.GetBlock<IMyFlightMovementBlock>("[PM] AI Flight (Move)", this.grid);
|
||||||
if (this.aiMove == null)
|
if (this.aiMove == null)
|
||||||
{
|
{
|
||||||
this.output.Print("Error: Cannot find AI move");
|
this.output.Print("Error: Cannot find AI move");
|
||||||
|
|
@ -88,31 +90,31 @@ namespace IngameScript
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.aiCombat == null)
|
if (this.aiCombat == null)
|
||||||
this.aiCombat = this.GridTerminalSystem.GetBlockWithName("[PM] AI Offensive (Combat)") as IMyOffensiveCombatBlock;
|
this.aiCombat = this.GridTerminalSystem.GetBlock<IMyOffensiveCombatBlock>("[PM] AI Offensive (Combat)", this.grid);
|
||||||
if (this.aiCombat == null)
|
if (this.aiCombat == null)
|
||||||
{
|
{
|
||||||
this.output.Print("Error: Cannot find AI combat");
|
this.output.Print("Error: Cannot find AI combat");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sensor == null)
|
if (this.sensor == null)
|
||||||
this.sensor = this.GridTerminalSystem.GetBlockWithName("[PM] Sensor") as IMySensorBlock;
|
this.sensor = this.GridTerminalSystem.GetBlock<IMySensorBlock>("[PM] Sensor", this.grid);
|
||||||
if (this.sensor == null)
|
if (this.sensor == null)
|
||||||
{
|
{
|
||||||
this.output.Print("Error: Cannot find sensor");
|
this.output.Print("Error: Cannot find sensor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.warheads.Count == 0)
|
if (this.warheads == null)
|
||||||
this.GridTerminalSystem.GetBlockGroupWithName("[PM] Warheads").GetBlocksOfType(this.warheads);
|
this.warheads = this.GridTerminalSystem.GetBlocksFromGroup<IMyWarhead>("[PM] Warheads", this.grid);
|
||||||
if (this.warheads.Count == 0)
|
if (this.warheads.Count() == 0)
|
||||||
{
|
{
|
||||||
this.output.Print("Error: Cannot find any warhead");
|
this.output.Print("Error: Cannot find any warhead");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.gasTank == null)
|
if (this.gasTank == null)
|
||||||
this.gasTank = this.GridTerminalSystem.GetBlockWithName("[PM] Hydrogen Tank") as IMyGasTank;
|
this.gasTank = this.GridTerminalSystem.GetBlock<IMyGasTank>("[PM] Hydrogen Tank", this.grid);
|
||||||
if (this.gasTank == null)
|
if (this.gasTank == null)
|
||||||
{
|
{
|
||||||
this.output.Print("Error: Cannot find gas tank");
|
this.output.Print("Error: Cannot find gas tank");
|
||||||
|
|
@ -120,18 +122,18 @@ namespace IngameScript
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.light == null)
|
if (this.light == null)
|
||||||
this.light = this.GridTerminalSystem.GetBlockWithName("[PM] Light") as IMyLightingBlock;
|
this.light = this.GridTerminalSystem.GetBlock<IMyLightingBlock>("[PM] Light", this.grid);
|
||||||
if (this.light == null)
|
if (this.light == null)
|
||||||
{
|
{
|
||||||
this.output.Print("Error: Cannot find light");
|
this.output.Print("Error: Cannot find light");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.tickFromStart += 10;
|
||||||
|
|
||||||
switch (this.currentState)
|
switch (this.currentState)
|
||||||
{
|
{
|
||||||
case State.LAUNCHING:
|
case State.LAUNCHING:
|
||||||
// this.output.Print($"Tick: {this.tickFromStart}");
|
|
||||||
//this.forwardThruster.ove
|
|
||||||
this.forwardThruster.ThrustOverridePercentage = 1;
|
this.forwardThruster.ThrustOverridePercentage = 1;
|
||||||
if (this.MsSinceLaunch > DELAY_BEFORE_TRAVELLING_MODE)
|
if (this.MsSinceLaunch > DELAY_BEFORE_TRAVELLING_MODE)
|
||||||
{
|
{
|
||||||
|
|
@ -167,7 +169,7 @@ namespace IngameScript
|
||||||
void Detonate()
|
void Detonate()
|
||||||
{
|
{
|
||||||
foreach (var warhead in this.warheads)
|
foreach (var warhead in this.warheads)
|
||||||
warhead.Detonate();
|
warhead.Detonate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
|
|
@ -183,7 +185,6 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
if ((updateSource & UpdateType.Update10) != 0)
|
if ((updateSource & UpdateType.Update10) != 0)
|
||||||
{
|
{
|
||||||
this.tickFromStart += 10;
|
|
||||||
this.UpdateState10();
|
this.UpdateState10();
|
||||||
}
|
}
|
||||||
else if ((updateSource & (UpdateType.Script | UpdateType.Terminal | UpdateType.Trigger)) != 0)
|
else if ((updateSource & (UpdateType.Script | UpdateType.Terminal | UpdateType.Trigger)) != 0)
|
||||||
|
|
@ -196,6 +197,11 @@ namespace IngameScript
|
||||||
this.currentState = State.LAUNCHING;
|
this.currentState = State.LAUNCHING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "STOP":
|
||||||
|
this.output.Print("Stop mode");
|
||||||
|
this.currentState = State.NORMAL;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.output.Print($"Uknown command: {argument}");
|
this.output.Print($"Uknown command: {argument}");
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue